From 7ef957c2d7c9687b4e8371ae678c7a4e7e3b5042 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Sun, 18 Aug 2024 17:41:54 +0200 Subject: [PATCH 1/5] Added comments for during the update for more context --- update.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/update.sh b/update.sh index 943cd87..1ed62e8 100755 --- a/update.sh +++ b/update.sh @@ -6,9 +6,8 @@ CPOLIS_DIR=$EXTRACTION_DIR/cpolis TAILWINDCSS_REPO_URL=https://api.github.com/repos/tailwindlabs/tailwindcss/releases/latest TMP_DIR=/tmp BIN_DIR=/usr/local/bin -SYSTEMD_DIR=/lib/systemd/system -! groups | grep -E 'root|wheel|sudo' && echo "You need administrative privileges for this script" && exit 1 +! groups | grep -E 'root|wheel|sudo' >/dev/null && echo "You need administrative privileges for this script" && exit 1 ! which curl >/dev/null 2>&1 && echo "curl needs to be installed" >&2 && exit 1 ! which go >/dev/null 2>&1 && echo "go needs to be installed" >&2 && exit 1 @@ -16,12 +15,14 @@ SYSTEMD_DIR=/lib/systemd/system ! which tar >/dev/null 2>&1 && echo "tar needs to be installed" >&2 && exit 1 ! which xargs >/dev/null 2>&1 && echo "xargs needs to be installed" >&2 && exit 1 +echo -e '\nDownloading cpolis...' rm -fr $CPOLIS_DIR/* latest_release=$(curl -s $CPOLIS_REPO_URL | jq -r '.[0].tag_name') curl -Lo $TMP_DIR/cpolis.tar.gz https://git.streifling.com/jason/cpolis/archive/$latest_release.tar.gz tar -xzf $TMP_DIR/cpolis.tar.gz -C $EXTRACTION_DIR rm $TMP_DIR/cpolis.tar.gz +echo -e '\nDownloading TailwindCSS...' curl -s $TAILWINDCSS_REPO_URL | grep -F browser_download_url | grep -F linux-x64 | @@ -31,10 +32,11 @@ chmod +x $CPOLIS_DIR/tailwindcss $CPOLIS_DIR/tailwindcss -i web/static/css/input.css -o web/static/css/style.css go build -o $TMP_DIR/cpolis $CPOLIS_DIR/cmd/main.go + +echo -e 'Setting system files up' sudo mv $TMP_DIR/cpolis $BIN_DIR/cpolis chmod +x $BIN_DIR/cpolis -[ ! -f $SYSTEMD_DIR ] && mkdir -p $SYSTEMD_DIR -sudo mv $CPOLIS_DIR/cpolis.service $SYSTEMD_DIR +sudo mv $CPOLIS_DIR/cpolis.service /etc/systemd/system sudo systemctl daemon-reload sudo systemctl is-active --quiet cpolis.service && sudo systemctl restart cpolis.service From beec20cddaf528451d831ffdd1a5895c7e9ddb4d Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 23 Aug 2024 20:34:13 +0200 Subject: [PATCH 2/5] Make sure bin and service are owned by root --- update.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/update.sh b/update.sh index 1ed62e8..e973328 100755 --- a/update.sh +++ b/update.sh @@ -35,8 +35,10 @@ go build -o $TMP_DIR/cpolis $CPOLIS_DIR/cmd/main.go echo -e 'Setting system files up' sudo mv $TMP_DIR/cpolis $BIN_DIR/cpolis +sudo chown root:root $BIN_DIR/cpolis chmod +x $BIN_DIR/cpolis -sudo mv $CPOLIS_DIR/cpolis.service /etc/systemd/system +sudo mv $CPOLIS_DIR/cpolis.service $SYSTEMD_DIR +sudo chown root:root $SYSTEMD_DIR/cpolis.service sudo systemctl daemon-reload sudo systemctl is-active --quiet cpolis.service && sudo systemctl restart cpolis.service From ee31a9f8e2c5c42460f8cdcf32db57906a8bf02a Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 23 Aug 2024 20:36:01 +0200 Subject: [PATCH 3/5] create check_dependency function --- update.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/update.sh b/update.sh index e973328..2436823 100755 --- a/update.sh +++ b/update.sh @@ -7,13 +7,20 @@ TAILWINDCSS_REPO_URL=https://api.github.com/repos/tailwindlabs/tailwindcss/relea TMP_DIR=/tmp BIN_DIR=/usr/local/bin +check_dependency() { + if ! which $1 >/dev/null 2>&1; then + echo "$1 needs to be installed" >&2 + exit 1 + fi +} + ! groups | grep -E 'root|wheel|sudo' >/dev/null && echo "You need administrative privileges for this script" && exit 1 -! which curl >/dev/null 2>&1 && echo "curl needs to be installed" >&2 && exit 1 -! which go >/dev/null 2>&1 && echo "go needs to be installed" >&2 && exit 1 -! which jq >/dev/null 2>&1 && echo "jq needs to be installed" >&2 && exit 1 -! which tar >/dev/null 2>&1 && echo "tar needs to be installed" >&2 && exit 1 -! which xargs >/dev/null 2>&1 && echo "xargs needs to be installed" >&2 && exit 1 +check_dependency curl +check_dependency go +check_dependency jq +check_dependency tar +check_dependency xargs echo -e '\nDownloading cpolis...' rm -fr $CPOLIS_DIR/* From 4cb2831e9a0d687e35e173ddb586a750e0ac7e6a Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 23 Aug 2024 20:51:33 +0200 Subject: [PATCH 4/5] Minor changes --- update.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/update.sh b/update.sh index 2436823..7f50a75 100755 --- a/update.sh +++ b/update.sh @@ -14,7 +14,10 @@ check_dependency() { fi } -! groups | grep -E 'root|wheel|sudo' >/dev/null && echo "You need administrative privileges for this script" && exit 1 +if ! groups | grep -E 'root|wheel|sudo' >/dev/null; then + echo "You need administrative privileges for this script" >&2 + exit 1 +fi check_dependency curl check_dependency go @@ -22,14 +25,14 @@ check_dependency jq check_dependency tar check_dependency xargs -echo -e '\nDownloading cpolis...' +echo -e '\nDownloading cpolis...' >&2 rm -fr $CPOLIS_DIR/* latest_release=$(curl -s $CPOLIS_REPO_URL | jq -r '.[0].tag_name') curl -Lo $TMP_DIR/cpolis.tar.gz https://git.streifling.com/jason/cpolis/archive/$latest_release.tar.gz tar -xzf $TMP_DIR/cpolis.tar.gz -C $EXTRACTION_DIR rm $TMP_DIR/cpolis.tar.gz -echo -e '\nDownloading TailwindCSS...' +echo -e '\nDownloading TailwindCSS...' >&2 curl -s $TAILWINDCSS_REPO_URL | grep -F browser_download_url | grep -F linux-x64 | @@ -40,7 +43,7 @@ $CPOLIS_DIR/tailwindcss -i web/static/css/input.css -o web/static/css/style.css go build -o $TMP_DIR/cpolis $CPOLIS_DIR/cmd/main.go -echo -e 'Setting system files up' +echo -e 'Setting system files up' >&2 sudo mv $TMP_DIR/cpolis $BIN_DIR/cpolis sudo chown root:root $BIN_DIR/cpolis chmod +x $BIN_DIR/cpolis From c2cadd15427388b30d06773831728eab2ee24750 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Fri, 23 Aug 2024 20:56:44 +0200 Subject: [PATCH 5/5] Add messages for user --- update.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update.sh b/update.sh index 7f50a75..8795306 100755 --- a/update.sh +++ b/update.sh @@ -41,9 +41,10 @@ curl -s $TAILWINDCSS_REPO_URL | chmod +x $CPOLIS_DIR/tailwindcss $CPOLIS_DIR/tailwindcss -i web/static/css/input.css -o web/static/css/style.css +echo -e 'Building cpolis...' >&2 go build -o $TMP_DIR/cpolis $CPOLIS_DIR/cmd/main.go -echo -e 'Setting system files up' >&2 +echo -e 'Setting system files up...' >&2 sudo mv $TMP_DIR/cpolis $BIN_DIR/cpolis sudo chown root:root $BIN_DIR/cpolis chmod +x $BIN_DIR/cpolis