- Fail when apt-get not found on OS

- Generic method to find out os version code name
- Let user decide if they want to continue on a older/newer OS version
This commit is contained in:
Pratik Tripathy
2021-10-27 00:35:54 +05:30
parent fea2d0e18a
commit 0c6cb0512c
2 changed files with 33 additions and 33 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.vscode
.idea

View File

@@ -57,59 +57,56 @@ function usage() {
exit 1 exit 1
} }
# Fail-fast: No apt - no good
if ! command -v apt-get >/dev/null; then
print_os_not_supported
exit 1
fi
# Check supported OSes # Check supported OSes
if [ -f /etc/os-release ]; then if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release . /etc/os-release
OS=$ID OS=$ID
VER=$VERSION_ID VER=$VERSION_ID
CODE_NAME=$VERSION_CODENAME
else else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc. print_os_not_supported
OS=$(uname -s) exit 1
VER=$(uname -r)
fi fi
case "$OS" in case "$OS" in
debian) debian)
if [[ "$VER" -eq 8 ]]; then # If the versions are not 9, 10, 11
DEB_VER_STR="jessie" # warn user and ask them to proceed with caution
elif [[ "$VER" -eq 9 ]]; then DEB_VER_STR=$CODE_NAME
DEB_VER_STR="stretch" if ((VER >= 9 && VER <= 11)); then
elif [[ "$VER" -eq 10 ]]; then new_os_version_warning
DEB_VER_STR="buster"
else
printf "This script only supports Debian 8 and Debian 9, and Debian 10\\n"
printf "\\tUbuntu 14.04, Ubuntu 16.04, Ubuntu 18.04, Ubuntu 18.10, and Ubuntu 20.04\\n"
printf "Your OS is NOT supported.\\n"
exit 1
fi fi
;; ;;
ubuntu) ubuntu)
if [[ "$VER" = "14.04" ]]; then # If the versions are not 16.04, 18.04, 18.10, 20.04. 21.04
UBT_VER_STR="trusty" # warn user and ask them to proceed with caution
elif [[ "$VER" = "16.04" ]]; then UBT_VER_STR=$CODE_NAME
UBT_VER_STR="xenial" if [[ "$VER" != "16.04" ]] && [[ "$VER" != "18.04" ]] && [[ "$VER" != "18.10" ]] && [[ "$VER" != "20.04" ]] && [[ "$VER" != "21.04" ]]; then
elif [[ "$VER" = "18.04" ]]; then new_os_version_warning
UBT_VER_STR="bionic"
elif [[ "$VER" = "18.10" ]]; then
UBT_VER_STR="cosmic"
elif [[ "$VER" = "20.04" ]]; then
UBT_VER_STR="focal"
else
printf "This script only supports Debian 8, Debian 9, and Debian 10\\n"
printf "\\tUbuntu 14.04, Ubuntu 16.04, Ubuntu 18.04, Ubuntu 18.10, and Ubuntu 20.04\\n"
printf "Your OS is NOT supported.\\n"
exit 1
fi fi
;; ;;
*) *)
printf "This script only supports Debian 8 and Debian 9\\n" print_os_not_supported
printf "\\tUbuntu 14.04, Ubuntu 16.04, Ubuntu 18.04, Ubuntu 18.10\\n"
printf "Your OS is NOT supported.\\n"
exit 1 exit 1
;; ;;
esac esac
function new_os_version_warning(){
echo "${OS} version ${VER} is not tested. Continuing is NOT RECOMMENDED."
read -p "Continue (NOT RECOMMENDED)? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1
}
function print_os_not_supported(){
printf "This script only supports Debian 9, 10, and 11\\n"
printf "\\tUbuntu 16.04, 18.04, 18.10, 20.04, and 21.04\\n"
printf "Your OS is NOT supported.\\n"
}
################################## ##################################
# Parse script arguments # Parse script arguments