From 10d54262fb1a6a8768a39dc5782ad8f0e902ef8f Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Sat, 30 Jul 2022 02:59:49 -0500 Subject: [PATCH] Add CentOS 9 - Add support for version 9 of CentOS Stream, RHEL, Rocky Linux and AlmaLinux. --- extras/ikev2changeaddr.sh | 16 ++-------------- extras/ikev2setup.sh | 9 ++++++--- extras/quickstart.sh | 10 ++++++++-- extras/vpnuninstall.sh | 9 +++++++-- extras/vpnupgrade.sh | 7 +++++-- extras/vpnupgrade_centos.sh | 7 +++++-- vpnsetup.sh | 10 ++++++++-- vpnsetup_centos.sh | 26 ++++++++++++++++++-------- 8 files changed, 59 insertions(+), 35 deletions(-) diff --git a/extras/ikev2changeaddr.sh b/extras/ikev2changeaddr.sh index 9c45609..9cd36f6 100755 --- a/extras/ikev2changeaddr.sh +++ b/extras/ikev2changeaddr.sh @@ -42,16 +42,12 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol - if grep -qs "release 7" "$rh_file"; then - os_ver=7 - elif grep -qs "release 8" "$rh_file"; then - os_ver=8 - grep -qi stream "$rh_file" && os_ver=8s + if grep -qs "release 7" "$rh_file" || grep -qs "release 8" "$rh_file" \ + || grep -qs "release 9" "$rh_file"; then grep -qi rocky "$rh_file" && os_type=rocky grep -qi alma "$rh_file" && os_type=alma elif grep -qs "Amazon Linux release 2" /etc/system-release; then os_type=amzn - os_ver=2 else os_type=$(lsb_release -si 2>/dev/null) [ -z "$os_type" ] && [ -f /etc/os-release ] && os_type=$(. /etc/os-release && printf '%s' "$ID") @@ -77,14 +73,6 @@ EOF exit 1 ;; esac - if [ "$os_type" = "alpine" ]; then - os_ver=$(. /etc/os-release && printf '%s' "$VERSION_ID" | cut -d '.' -f 1,2) - if [ "$os_ver" != "3.15" ] && [ "$os_ver" != "3.16" ]; then - exiterr "This script only supports Alpine Linux 3.15/3.16." - fi - else - os_ver=$(sed 's/\..*//' /etc/debian_version | tr -dc 'A-Za-z0-9') - fi fi } diff --git a/extras/ikev2setup.sh b/extras/ikev2setup.sh index 24e8aef..05f3c6c 100755 --- a/extras/ikev2setup.sh +++ b/extras/ikev2setup.sh @@ -53,13 +53,16 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol + grep -qi rocky "$rh_file" && os_type=rocky + grep -qi alma "$rh_file" && os_type=alma if grep -qs "release 7" "$rh_file"; then os_ver=7 elif grep -qs "release 8" "$rh_file"; then os_ver=8 grep -qi stream "$rh_file" && os_ver=8s - grep -qi rocky "$rh_file" && os_type=rocky - grep -qi alma "$rh_file" && os_type=alma + elif grep -qs "release 9" "$rh_file"; then + os_ver=9 + grep -qi stream "$rh_file" && os_ver=9s elif grep -qs "Amazon Linux release 2" /etc/system-release; then os_type=amzn os_ver=2 @@ -151,7 +154,7 @@ confirm_or_abort() { show_header() { cat <<'EOF' -IKEv2 Script Copyright (c) 2020-2022 Lin Song 27 Jul 2022 +IKEv2 Script Copyright (c) 2020-2022 Lin Song 31 Jul 2022 EOF } diff --git a/extras/quickstart.sh b/extras/quickstart.sh index 2deb7ff..f732c73 100755 --- a/extras/quickstart.sh +++ b/extras/quickstart.sh @@ -75,16 +75,22 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol + grep -qi rocky "$rh_file" && os_type=rocky + grep -qi alma "$rh_file" && os_type=alma if grep -qs "release 7" "$rh_file"; then os_ver=7 elif grep -qs "release 8" "$rh_file"; then os_ver=8 grep -qi stream "$rh_file" && os_ver=8s - grep -qi rocky "$rh_file" && os_type=rocky - grep -qi alma "$rh_file" && os_type=alma if [ "$os_type" = "centos" ] && [ "$os_ver" = "8" ]; then exiterr "CentOS Linux 8 is EOL and not supported." fi + elif grep -qs "release 9" "$rh_file"; then + os_ver=9 + grep -qi stream "$rh_file" && os_ver=9s + if [ "$os_type" = "ol" ]; then + exiterr "Oracle Linux 9 is not supported." + fi elif grep -qs "Amazon Linux release 2" /etc/system-release; then os_type=amzn os_ver=2 diff --git a/extras/vpnuninstall.sh b/extras/vpnuninstall.sh index 6f5c05d..2af1cc2 100755 --- a/extras/vpnuninstall.sh +++ b/extras/vpnuninstall.sh @@ -40,7 +40,8 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol - if grep -qs "release 7" "$rh_file" || grep -qs "release 8" "$rh_file"; then + if grep -qs "release 7" "$rh_file" || grep -qs "release 8" "$rh_file" \ + || grep -qs "release 9" "$rh_file"; then grep -qi rocky "$rh_file" && os_type=rocky grep -qi alma "$rh_file" && os_type=alma elif grep -qs "Amazon Linux release 2" /etc/system-release; then @@ -272,8 +273,12 @@ update_iptables_rules() { else nft_bk=$(find /etc/sysconfig -maxdepth 1 -name 'nftables.conf.old-*-*-*-*_*_*' -print0 \ | xargs -r -0 ls -1 -t | head -1) + diff_count=24 + if grep -qs "release 9" /etc/redhat-release; then + diff_count=38 + fi if [ -f "$nft_bk" ] \ - && [ "$(diff -y --suppress-common-lines "$IPT_FILE" "$nft_bk" | wc -l)" = "24" ]; then + && [ "$(diff -y --suppress-common-lines "$IPT_FILE" "$nft_bk" | wc -l)" = "$diff_count" ]; then bigecho "Restoring nftables rules..." conf_bk "$IPT_FILE" /bin/cp -f "$nft_bk" "$IPT_FILE" && /bin/rm -f "$nft_bk" diff --git a/extras/vpnupgrade.sh b/extras/vpnupgrade.sh index 0669765..9d646f1 100755 --- a/extras/vpnupgrade.sh +++ b/extras/vpnupgrade.sh @@ -43,16 +43,19 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol + grep -qi rocky "$rh_file" && os_type=rocky + grep -qi alma "$rh_file" && os_type=alma if grep -qs "release 7" "$rh_file"; then os_ver=7 elif grep -qs "release 8" "$rh_file"; then os_ver=8 grep -qi stream "$rh_file" && os_ver=8s - grep -qi rocky "$rh_file" && os_type=rocky - grep -qi alma "$rh_file" && os_type=alma if [ "$os_type" = "centos" ] && [ "$os_ver" = "8" ]; then exiterr "CentOS Linux 8 is EOL and not supported." fi + elif grep -qs "release 9" "$rh_file"; then + os_ver=9 + grep -qi stream "$rh_file" && os_ver=9s elif grep -qs "Amazon Linux release 2" /etc/system-release; then os_type=amzn os_ver=2 diff --git a/extras/vpnupgrade_centos.sh b/extras/vpnupgrade_centos.sh index 3afcc0a..dc0c1c6 100755 --- a/extras/vpnupgrade_centos.sh +++ b/extras/vpnupgrade_centos.sh @@ -46,16 +46,19 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol + grep -qi rocky "$rh_file" && os_type=rocky + grep -qi alma "$rh_file" && os_type=alma if grep -qs "release 7" "$rh_file"; then os_ver=7 elif grep -qs "release 8" "$rh_file"; then os_ver=8 grep -qi stream "$rh_file" && os_ver=8s - grep -qi rocky "$rh_file" && os_type=rocky - grep -qi alma "$rh_file" && os_type=alma if [ "$os_type" = "centos" ] && [ "$os_ver" = "8" ]; then exiterr "CentOS Linux 8 is EOL and not supported." fi + elif grep -qs "release 9" "$rh_file"; then + os_ver=9 + grep -qi stream "$rh_file" && os_ver=9s else cat 1>&2 <<'EOF' Error: This script only supports one of the following OS: diff --git a/vpnsetup.sh b/vpnsetup.sh index 2deb7ff..f732c73 100755 --- a/vpnsetup.sh +++ b/vpnsetup.sh @@ -75,16 +75,22 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol + grep -qi rocky "$rh_file" && os_type=rocky + grep -qi alma "$rh_file" && os_type=alma if grep -qs "release 7" "$rh_file"; then os_ver=7 elif grep -qs "release 8" "$rh_file"; then os_ver=8 grep -qi stream "$rh_file" && os_ver=8s - grep -qi rocky "$rh_file" && os_type=rocky - grep -qi alma "$rh_file" && os_type=alma if [ "$os_type" = "centos" ] && [ "$os_ver" = "8" ]; then exiterr "CentOS Linux 8 is EOL and not supported." fi + elif grep -qs "release 9" "$rh_file"; then + os_ver=9 + grep -qi stream "$rh_file" && os_ver=9s + if [ "$os_type" = "ol" ]; then + exiterr "Oracle Linux 9 is not supported." + fi elif grep -qs "Amazon Linux release 2" /etc/system-release; then os_type=amzn os_ver=2 diff --git a/vpnsetup_centos.sh b/vpnsetup_centos.sh index 8f938b7..4a1475b 100755 --- a/vpnsetup_centos.sh +++ b/vpnsetup_centos.sh @@ -80,16 +80,22 @@ check_os() { os_type=rhel fi [ -f /etc/oracle-release ] && os_type=ol + grep -qi rocky "$rh_file" && os_type=rocky + grep -qi alma "$rh_file" && os_type=alma if grep -qs "release 7" "$rh_file"; then os_ver=7 elif grep -qs "release 8" "$rh_file"; then os_ver=8 grep -qi stream "$rh_file" && os_ver=8s - grep -qi rocky "$rh_file" && os_type=rocky - grep -qi alma "$rh_file" && os_type=alma if [ "$os_type" = "centos" ] && [ "$os_ver" = "8" ]; then exiterr "CentOS Linux 8 is EOL and not supported." fi + elif grep -qs "release 9" "$rh_file"; then + os_ver=9 + grep -qi stream "$rh_file" && os_ver=9s + if [ "$os_type" = "ol" ]; then + exiterr "Oracle Linux 9 is not supported." + fi else cat 1>&2 <<'EOF' Error: This script only supports one of the following OS: @@ -218,11 +224,14 @@ install_vpn_pkgs_1() { rp1="$erp=epel" rp2="$erp=*server-*optional*" rp3="$erp=*releases-optional*" - if [ "$os_type" = "ol" ] && [ "$os_ver" = "8" ]; then - rp1="$erp=ol8_developer_EPEL" - fi - if [ "$os_type" = "ol" ] && [ "$os_ver" = "7" ]; then - rp3="$erp=ol7_optional_latest" + if [ "$os_type" = "ol" ]; then + if [ "$os_ver" = "9" ]; then + rp1="$erp=ol9_developer_EPEL" + elif [ "$os_ver" = "8" ]; then + rp1="$erp=ol8_developer_EPEL" + else + rp3="$erp=ol7_optional_latest" + fi fi ( set -x @@ -255,7 +264,8 @@ install_vpn_pkgs_3() { set -x yum -y -q install $p1 $p2 >/dev/null ) || exiterr2 - if systemctl is-active --quiet firewalld \ + if [ "$os_ver" = "9" ] || [ "$os_ver" = "9s" ] \ + || systemctl is-active --quiet firewalld \ || systemctl is-active --quiet nftables \ || grep -qs "hwdsl2 VPN script" /etc/sysconfig/nftables.conf; then use_nft=1