Skip to content

Commit

Permalink
refactor(install.sh): check if user is root
Browse files Browse the repository at this point in the history
  • Loading branch information
WIttyJudge committed Dec 14, 2024
1 parent 387dcdf commit 1e060cb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -91,6 +101,7 @@ cat <<'EOF'
EOF

check_root
check_system
check_dependencies

Expand Down

0 comments on commit 1e060cb

Please sign in to comment.