1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#!/bin/bash
show_help() {
echo "usage: is-core, is-classic"
echo " is-core16, is-core18, is-core20"
echo " is-trusty, is-xenial, is-bionic, is-focal, is-groovy, is-hirsute"
echo " is-ubuntu, is-debian, is-fedora, is-amazon-linux, is-arch-linux, is-centos, is-opensuse"
echo " is-opensuse-tumbleweed, is-debian-sid"
echo " is-pc-amd64, is-pc-i386, is-arm, is-armhf, is-arm64"
echo ""
echo "Get general information about the current system"
}
is_core() {
[[ "$SPREAD_SYSTEM" == ubuntu-core-* ]]
}
is_core16() {
[[ "$SPREAD_SYSTEM" == ubuntu-core-16-* ]]
}
is_core18() {
[[ "$SPREAD_SYSTEM" == ubuntu-core-18-* ]]
}
is_core20() {
[[ "$SPREAD_SYSTEM" == ubuntu-core-20-* ]]
}
is_classic() {
! is_core
}
is_trusty() {
grep -qFx 'ID=ubuntu' /etc/os-release && grep -qFx 'VERSION_ID="14.04"' /etc/os-release
}
is_xenial() {
grep -qFx 'UBUNTU_CODENAME=xenial' /etc/os-release
}
is_bionic() {
grep -qFx 'UBUNTU_CODENAME=bionic' /etc/os-release
}
is_focal() {
grep -qFx 'UBUNTU_CODENAME=focal' /etc/os-release
}
is_groovy() {
grep -qFx 'UBUNTU_CODENAME=groovy' /etc/os-release
}
is_hirsute() {
grep -qFx 'UBUNTU_CODENAME=hirsute' /etc/os-release
}
is_ubuntu() {
grep -qFx 'ID=ubuntu' /etc/os-release || grep -qFx 'ID=ubuntu-core' /etc/os-release
}
is_debian() {
grep -qFx 'ID=debian' /etc/os-release
}
is_debian_sid() {
grep -qFx 'ID=debian' /etc/os-release && grep -qx 'PRETTY_NAME=".*/sid"' /etc/os-release
}
is_fedora() {
grep -qFx 'ID=fedora' /etc/os-release
}
is_amazon_linux() {
grep -qFx 'ID="amzn"' /etc/os-release
}
is_centos() {
grep -qFx 'ID="centos"' /etc/os-release
}
is_arch_linux() {
grep -qFx 'ID=arch' /etc/os-release
}
is_opensuse() {
grep -qFx 'ID="opensuse-leap"' /etc/os-release || grep -qFx 'ID="opensuse-tumbleweed"' /etc/os-release
}
is_opensuse_tumbleweed() {
grep -qFx 'ID="opensuse-tumbleweed"'
}
is_pc_amd64() {
uname -m | grep -qFx 'x86_64'
}
is_pc_i386() {
uname -m | grep -Eq '(i686|i386)'
}
is_arm() {
uname -m | grep -Eq '(^arm.*|^aarch*)'
}
is_armhf() {
uname -m | grep -qx 'armv7.*'
}
is_arm64() {
uname -m | grep -Eq '(aarch64.*|armv8.*)'
}
main() {
if [ $# -eq 0 ]; then
show_help
exit 0
fi
local subcommand="$1"
local action=
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
show_help
exit 0
;;
*)
action=$(echo "$subcommand" | tr '-' '_')
shift
break
;;
esac
done
if [ -z "$(declare -f "$action")" ]; then
echo "os.query: no such command: $subcommand" >&2
show_help
exit 1
fi
"$action" "$@"
}
main "$@"
|