From 6d9eb9a2fadd4b620d5483c2b7d3b4d7b1da6019 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Thu, 23 Mar 2017 12:39:01 -0500 Subject: [PATCH] Improve OS detection - Fix OS detection on Debian when lsb_release is not available - Closes #123 --- extras/vpnupgrade.sh | 7 +++++-- vpnsetup.sh | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/extras/vpnupgrade.sh b/extras/vpnupgrade.sh index 26e6bbc..dfc0c55 100644 --- a/extras/vpnupgrade.sh +++ b/extras/vpnupgrade.sh @@ -21,8 +21,11 @@ exiterr() { echo "Error: $1" >&2; exit 1; } exiterr2() { echo "Error: 'apt-get install' failed." >&2; exit 1; } os_type="$(lsb_release -si 2>/dev/null)" -if [ -z "$os_type" ] && [ -f "/etc/lsb-release" ]; then - os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" +if [ -z "$os_type" ]; then + [ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")" + [ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" + [ "$os_type" = "debian" ] && os_type=Debian + [ "$os_type" = "ubuntu" ] && os_type=Ubuntu fi if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != "Raspbian" ]; then exiterr "This script only supports Ubuntu/Debian." diff --git a/vpnsetup.sh b/vpnsetup.sh index dca0e84..e44f766 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -47,8 +47,11 @@ check_ip() { } os_type="$(lsb_release -si 2>/dev/null)" -if [ -z "$os_type" ] && [ -f "/etc/lsb-release" ]; then - os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" +if [ -z "$os_type" ]; then + [ -f /etc/os-release ] && os_type="$(. /etc/os-release && echo "$ID")" + [ -f /etc/lsb-release ] && os_type="$(. /etc/lsb-release && echo "$DISTRIB_ID")" + [ "$os_type" = "debian" ] && os_type=Debian + [ "$os_type" = "ubuntu" ] && os_type=Ubuntu fi if [ "$os_type" != "Ubuntu" ] && [ "$os_type" != "Debian" ] && [ "$os_type" != "Raspbian" ]; then exiterr "This script only supports Ubuntu/Debian."