From 9fd7dcc60bbc1445f34d1481254b3237a71b2396 Mon Sep 17 00:00:00 2001 From: travisladuke Date: Wed, 28 Aug 2024 12:34:29 -0700 Subject: [PATCH] Add shellcheck and some integration tests And fix the Errors that shellcheck found. runs curl | bash installer on a handful of containers for distros that we support. The fedora/redhat type distros don't put systemd in their containers, or the containers otherwise don't work the way we expect the real os to, so they aren't in the test matrix. --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++++++++ install.sh.in | 15 +++++++------- 2 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..44824f3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +name: Curl | Bash Test +on: + push: + paths: + - install.sh.in + - .github/workflows/ci.yml + # branches: [ main ] + schedule: + - cron: "0 0 * * 0" # weekly +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - run: sudo apt install -y shellcheck + - run: shellcheck -S error install.sh.in + + curl-bash: + needs: shellcheck + runs-on: ubuntu-latest + strategy: + matrix: + container: + - "ubuntu:latest" + - "ubuntu:24.10" + - "ubuntu:24.04" + - "ubuntu:22.04" + - "ubuntu:20.04" + - "debian:latest" + - "debian:12" + - "debian:11" + - "debian:10" + - "kalilinux/kali-rolling:latest" + + container: + image: ${{ matrix.container }} + + steps: + - name: Check out repository code + uses: actions/checkout@v4 + - name: apt + run: apt-get -y update && apt-get -y install curl gnupg2 gnupg gpg bc || true + - name: install ${{ matrix.container }} + run: bash install.sh.in diff --git a/install.sh.in b/install.sh.in index e1e3b3e..03d14a9 100644 --- a/install.sh.in +++ b/install.sh.in @@ -1,3 +1,4 @@ +# shellcheck disable=SC2148 ENDOFSIGSTART= export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin @@ -230,21 +231,21 @@ write_apt_repo() { $SUDO apt-get install -y gpg $SUDO chmod a+r /tmp/zt-gpg-key - if [[ "$DISTRIBUTION" == "ubuntu" && "$VERSION" < "22.04" ]]; then + if [[ "$DISTRIBUTION" == "ubuntu" && $(echo "$VERSION < 22.04" | bc) ]]; then _old_apt_signing $URL $CODENAME - elif [[ ("$DISTRIBUTION" == "debian" || "$DISTRIBUTION" == "raspbian") && "$VERSION" -lt "10" ]]; then + elif [[ ("$DISTRIBUTION" == "debian" || "$DISTRIBUTION" == "raspbian") && $(echo "$VERSION < 10" | bc ) ]]; then _old_apt_signing $URL $CODENAME - elif [[ "$DISTRIBUTION" == "ubuntu" && "$VERSION" > "22.03" ]]; then # comparison to 22.03 is intentional + elif [[ "$DISTRIBUTION" == "ubuntu" && $(echo "$VERSION > 22.03" | bc) ]]; then # comparison to 22.03 is intentional _new_apt_signing $URL $CODENAME - elif [[ ("$DISTRIBUTION" == "debian" || "$DISTRIBUTION" == "raspbian") && "$VERSION" -ge "10" ]]; then + elif [[ ("$DISTRIBUTION" == "debian" || "$DISTRIBUTION" == "raspbian") && $(echo "$VERSION >= 10" | bc) ]]; then _new_apt_signing $URL $CODENAME elif [[ "$DISTRIBUTION" == "kali" ]]; then _new_apt_signing $URL $CODENAME elif [[ "$DISTRIBUTION" == "linuxmint" && "$VERSION" == "6" ]]; then _new_apt_signing $URL $CODENAME - elif [[ "$DISTRIBUTION" == "linuxmint" && ( "$VERSION" == "21" || "$VERSION" > "21" ) ]]; then + elif [[ "$DISTRIBUTION" == "linuxmint" && ( "$VERSION" == "21" || $(echo "$VERSION > 21" | bc) ) ]]; then _new_apt_signing $URL $CODENAME - elif [[ "$DISTRIBUTION" == "linuxmint" && ( "$VERSION" == "20" || ("$VERSION" > "20" && "$VERSION" < "21" ) ) ]]; then + elif [[ "$DISTRIBUTION" == "linuxmint" && ( "$VERSION" == "20" || ( $(echo "$VERSION > 20" | bc) && $(echo "$VERSION < 21" | bc ) ) ) ]]; then _old_apt_signing $URL $CODENAME else echo "Unsupported distribution $DISTRIBUTION $VERSION" @@ -296,7 +297,7 @@ elif [ $ID == "ubuntu" ] || [ $ID == "pop" ]; then elif [ $ID == "linuxmint" ]; then echo '*** Detected Linux Mint, creating /etc/apt/sources.list.d/zerotier.list' - if [[ "$VERSION_ID" > "$MAX_SUPPORTED_MINT_VERSION" ]]; then + if [[ "$VERSION_ID" -gt "$MAX_SUPPORTED_MINT_VERSION" ]]; then write_apt_repo $ID $MAX_SUPPORTED_MINT_VERSION $ZT_BASE_URL_HTTP $MAX_SUPPORTED_MINT_VERSION_NAME else write_apt_repo $ID $VERSION_ID $ZT_BASE_URL_HTTP ${MINT_CODENAME_MAP[${VERSION_CODENAME}]}