Skip to content

Commit

Permalink
feat: add scripts/install to install adless
Browse files Browse the repository at this point in the history
  • Loading branch information
WIttyJudge committed Dec 11, 2024
1 parent 493b949 commit d587d11
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 5 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,34 @@ And that's how Adless was made.

## Installation

### Package manager
### Manual Installation

Download the latest tar from the [releases page](https://github.com/WIttyJudge/adless/releases) and decompress.

Arch Linux (AUR):
If you use Linux or MacOS, you can simple run:

```bash
yay -S adless-bin
curl -sL https://raw.githubusercontent.com/WIttyJudge/adless/refs/heads/main/scripts/install | sudo bash
```

### Manual Installation
### Building from source

Download a binary from the [releases page](https://github.com/WIttyJudge/adless/releases) for Linux, macOS or Windows.
The [Makefile](https://github.com/WIttyJudge/adless/blob/main/Makefile) has everything you need.

There are different commands to build a binary for different platforms.
Choose one that you need.

```bash
make build-linux
make build-windows
make build-darwnin
```

To run then the binary:

```bash
./build/adless
```

## Usage

Expand Down
109 changes: 109 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env bash

set -e

COL_GREEN=''
COL_RED=''
COL_NC=''

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

0 comments on commit d587d11

Please sign in to comment.