From 09f06110232b0aae0323f804b4ca12eed149783c Mon Sep 17 00:00:00 2001 From: randomshell Date: Wed, 1 Jul 2020 18:30:50 +0000 Subject: [PATCH] Add checkOS() --- wireguard-install.sh | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index fa4b087..ea9ba5a 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -23,6 +23,24 @@ function checkVirt() { fi } +function checkOS() { + # Check OS version + if [[ -e /etc/debian_version ]]; then + source /etc/os-release + OS=$ID # debian or ubuntu + elif [[ -e /etc/fedora-release ]]; then + source /etc/os-release + OS=$ID + elif [[ -e /etc/centos-release ]]; then + OS=centos + elif [[ -e /etc/arch-release ]]; then + OS=arch + else + echo "Looks like you aren't running this installer on a Debian, Ubuntu, Fedora, CentOS or Arch Linux system" + exit 1 + fi +} + function addClient() { # Load params source /etc/wireguard/params @@ -99,22 +117,6 @@ elif [[ -e /etc/wireguard/params ]]; then exit 1 fi -# Check OS version -if [[ -e /etc/debian_version ]]; then - source /etc/os-release - OS=$ID # debian or ubuntu -elif [[ -e /etc/fedora-release ]]; then - source /etc/os-release - OS=$ID -elif [[ -e /etc/centos-release ]]; then - OS=centos -elif [[ -e /etc/arch-release ]]; then - OS=arch -else - echo "Looks like you aren't running this installer on a Debian, Ubuntu, Fedora, CentOS or Arch Linux system" - exit 1 -fi - # Detect public IPv4 address and pre-fill for the user SERVER_PUB_IPV4=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) read -rp "IPv4 or IPv6 public address: " -e -i "$SERVER_PUB_IPV4" SERVER_PUB_IP