-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scripts/install to install adless
- Loading branch information
1 parent
493b949
commit d587d11
Showing
2 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
COL_GREEN='[32m' | ||
COL_RED='[91m' | ||
COL_NC='[0m' | ||
|
||
INFO="[i]" | ||
TICK="[${COL_GREEN}✓${COL_NC}]" | ||
CROSS="[${COL_RED}✗${COL_NC}]" | ||
|
||
TMP_DIR="$(mktemp -d)" | ||
TMP_RELEASE_TAR="$TMP_DIR/release.tar.gz" | ||
OUTPUT_DIR="/usr/local/bin" | ||
PROGRAM_NAME="adless" | ||
|
||
check_sudo_user() { | ||
if [ "$EUID" -ne 0 ]; then | ||
fail "Please run the script as a root user" | ||
fi | ||
} | ||
|
||
check_system() { | ||
local uname_os="$(uname -s)" | ||
local uname_arch="$(uname -m)" | ||
|
||
case $uname_os in | ||
Linux*) OS="linux" ;; | ||
Darwin*) OS="darwin" ;; | ||
*) fail "${uname_os} operation system is unsupported" ;; | ||
esac | ||
|
||
|
||
case $uname_arch in | ||
x86_64 | amd64) ARCH="x86_64" ;; | ||
arm64 | arm) ARCH="arm64" ;; | ||
*) fail "${uname_arch} arch is unsupported" ;; | ||
esac | ||
|
||
echo "${INFO} Detected OS: ${OS}_${ARCH}" | ||
} | ||
|
||
check_dependencies() { | ||
which curl > /dev/null || fail "curl not installed" | ||
which grep > /dev/null || fail "grep not installed" | ||
} | ||
|
||
find_latest_version() { | ||
LATEST_VERSION=$(curl -s "https://api.github.com/repos/wittyjudge/adless/releases/latest" | grep -Po "(?<=\"tag_name\": \").*(?=\")") | ||
echo -e "${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}" | ||
} | ||
|
||
install_release_tar() { | ||
echo -e "${INFO} Downloading release tar ${URL}.." | ||
curl --fail --progress-bar -L -o "$TMP_DIR/release.tar.gz" "$URL" | ||
echo -e "${TICK} Release tar downloaded" | ||
|
||
tar -xzf "$TMP_DIR/release.tar.gz" -C "$TMP_DIR" | ||
|
||
mv "$TMP_DIR/${PROGRAM_NAME}" "${OUTPUT_DIR}" | ||
chmod +x "${OUTPUT_DIR}/${PROGRAM_NAME}" | ||
|
||
cleanup | ||
} | ||
|
||
finish() { | ||
echo "" | ||
echo "Adless ${LATEST_VERSION} successfully installed at ${OUTPUT_DIR}/${PROGRAM_NAME}" | ||
echo "run: adless --help" | ||
} | ||
|
||
cleanup() { | ||
rm -rf $TMP_DIR > /dev/null | ||
} | ||
|
||
fail() { | ||
cleanup | ||
msg=$1 | ||
echo "${CROSS} $msg" 1>&2 | ||
exit 1 | ||
} | ||
|
||
# Execution | ||
|
||
cat << 'EOF' | ||
_ _ | ||
__ _ __| | | ___ ___ ___ | ||
/ _` |/ _` | |/ _ \/ __/ __| | ||
| (_| | (_| | | __/\__ \__ \ | ||
\__,_|\__,_|_|\___||___/___/ | ||
EOF | ||
|
||
check_sudo_user | ||
check_system | ||
check_dependencies | ||
|
||
find_latest_version | ||
find_latest_release_tar_url | ||
|
||
install_release_tar | ||
|
||
finish |