From 1e060cbfb6aa9adaa9f614293ea4d0c684d621e9 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Sat, 14 Dec 2024 22:19:36 +0200 Subject: [PATCH] refactor(install.sh): check if user is root --- scripts/install.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index deaeb6b..3749356 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -15,6 +15,16 @@ TMP_RELEASE_TAR="$TMP_DIR/release.tar.gz" OUTPUT_DIR="/usr/local/bin" PROGRAM_NAME="adless" +check_root() { + if [ "$EUID" -ne 0 ]; then + echo "${INFO} ${COL_RED}Script called with non-root privileges${COL_NC}" + echo "For safety, please check the installer for any concerns regarding this requirement" + echo "Make sure to download this script from a trusted source" + + exit 1 + fi +} + check_system() { local uname_os="$(uname -s)" local uname_arch="$(uname -m)" @@ -42,23 +52,23 @@ check_dependencies() { find_latest_version() { LATEST_VERSION=$(curl -s "https://api.github.com/repos/wittyjudge/adless/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') - echo -e "${INFO} Latest version: $LATEST_VERSION" + echo "${INFO} Latest version: $LATEST_VERSION" } find_latest_release_tar_url() { URL="https://github.com//WIttyJudge/adless/releases/download/${LATEST_VERSION}/adless_${LATEST_VERSION}_${OS}_${ARCH}.tar.gz" - echo -e "${INFO} Latest release tar: ${URL}" + echo "${INFO} Latest release tar: ${URL}" } install_release_tar() { - echo -e "${INFO} Downloading release tar ${URL}.." + echo "${INFO} Downloading release tar ${URL}.." curl --fail --progress-bar -L -o "$TMP_RELEASE_TAR" "$URL" - echo -e "${TICK} Release tar downloaded" + echo "${TICK} Release tar downloaded" tar -xzf "$TMP_RELEASE_TAR" -C "$TMP_DIR" - mv "$TMP_DIR/${PROGRAM_NAME}" "${OUTPUT_DIR}" || fail "Failed to make program executable, re-run the command using \"sudo bash\"" - chmod +x "${OUTPUT_DIR}/${PROGRAM_NAME}" || fail "Failed to move binary, re-run the command using \"sudo bash\"" + mv "$TMP_DIR/${PROGRAM_NAME}" "${OUTPUT_DIR}" + chmod +x "${OUTPUT_DIR}/${PROGRAM_NAME}" cleanup } @@ -91,6 +101,7 @@ cat <<'EOF' EOF +check_root check_system check_dependencies