Add get_os_code helper function to setup scripts

This commit is contained in:
David 2021-07-02 21:28:25 +01:00
parent 3018cdd698
commit c125f462e1
No known key found for this signature in database
GPG key ID: 913FE0F2477D7D6B
2 changed files with 28 additions and 3 deletions

View file

@ -228,3 +228,27 @@ function php_version {
function python_version {
python3 --version | cut -d " " -f 2 | cut -c 1-3
}
export OS_UNSUPPORTED=0
export OS_DEBIAN_10=1
export OS_UBUNTU_2004=2
function get_os_code {
# A lot of if-statements here - dirty code looking tasting today
ID=$(lsb_release -is)
VER=$(lsb_release -rs)
if [[ $ID == "Debian" ]]; then
if [[ $VER == "10" ]]; then
echo $OS_DEBIAN_10
return 0
fi
elif [[ $ID == "Ubuntu" ]]; then
if [[ $VER == "20.04" ]]; then
echo $OS_DEBIAN_2004
return 0
fi
fi
echo $OS_UNSUPPORTED
}

View file

@ -1,3 +1,5 @@
source setup/functions.sh
# Are we running as root?
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root. Please re-run like this:"
@ -8,11 +10,10 @@ if [[ $EUID -ne 0 ]]; then
fi
# Check that we are running on Debian GNU/Linux, or Ubuntu 20.04
OS=$(lsb_release -d | sed 's/.*:\s*//')
if [ "$OS" != "Debian GNU/Linux 10 (buster)" -a "$(echo $OS | grep -o 'Ubuntu 20.04')" != "Ubuntu 20.04" ]; then
if [ $(get_os_code) == $OS_UNSUPPORTED ]; then
echo "Mail-in-a-Box only supports being installed on Debian 10 or Ubuntu 20.04 LTS, sorry. You are running:"
echo
lsb_release -d | sed 's/.*:\s*//'
lsb_release -ds
echo
echo "We can't write scripts that run on every possible setup, sorry."
exit 1