|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# gah! installer |
| 4 | +# |
| 5 | +# @author Marek `marverix` Sierociński |
| 6 | +# @license GNU GPLv3 |
| 7 | + |
| 8 | +# Pipeline mode |
| 9 | +set -e |
| 10 | + |
| 11 | +#-------------------------------------------------- |
| 12 | +#region Utils |
| 13 | +function print_blue() { |
| 14 | + echo -e "\033[0;34m$1\033[0m" |
| 15 | +} |
| 16 | + |
| 17 | +function print_green() { |
| 18 | + echo -e "\033[0;32m$1\033[0m" |
| 19 | +} |
| 20 | + |
| 21 | +function print_yellow() { |
| 22 | + echo -e "\033[0;33m$1\033[0m" |
| 23 | +} |
| 24 | + |
| 25 | +function throw_error() { |
| 26 | + echo -e "\033[0;31mError: $2\033[0m" >&2 |
| 27 | + exit $1 |
| 28 | +} |
| 29 | + |
| 30 | +function require_command() { |
| 31 | + print_blue "Checking if $1 is installed..." |
| 32 | + if ! command -v $1 2>&1 >/dev/null; then |
| 33 | + throw_error 2 "$1 is not installed" |
| 34 | + fi |
| 35 | + print_green "OK" |
| 36 | +} |
| 37 | + |
| 38 | +#endregion |
| 39 | +#-------------------------------------------------- |
| 40 | + |
| 41 | +# Require that bash is at least 4.0 |
| 42 | +print_blue "Checking if Bash 4.0 or higher is installed..." |
| 43 | +if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then |
| 44 | + throw_error 1 "Bash 4.0 or higher is required" |
| 45 | +fi |
| 46 | +print_green "OK" |
| 47 | + |
| 48 | +# Check if required commands are installed |
| 49 | +require_command tar |
| 50 | +require_command unzip |
| 51 | +require_command curl |
| 52 | +require_command jq |
| 53 | + |
| 54 | +# Ensure ~/.local/bin exists |
| 55 | +print_blue "Ensuring ~/.local/bin exists..." |
| 56 | +mkdir -p ~/.local/bin |
| 57 | +print_green "OK" |
| 58 | + |
| 59 | +# Check if ~/.local/bin is in PATH |
| 60 | +print_blue "Checking if ~/.local/bin is in PATH..." |
| 61 | +if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then |
| 62 | + print_yellow "WARNING: ~/.local/bin is not in PATH. gah will not work if ~/.local/bin is not in PATH." |
| 63 | +else |
| 64 | + print_green "OK, looks good!" |
| 65 | +fi |
| 66 | + |
| 67 | +# Check gah latest tag |
| 68 | +print_blue "Checking latest gah release..." |
| 69 | +tag=$(curl -s https://api.github.com/repos/marverix/gah/releases/latest | jq -r '.tag_name') |
| 70 | +print_green "OK, latest tag is $tag" |
| 71 | + |
| 72 | +# Download gah! script |
| 73 | +print_blue "Downloading gah $tag script..." |
| 74 | +curl -sL https://raw.githubusercontent.com/marverix/gah/refs/tags/$tag/gah -o ~/.local/bin/gah |
| 75 | +chmod +x ~/.local/bin/gah |
| 76 | +print_green "OK" |
| 77 | + |
| 78 | +print_green "Done!" |
0 commit comments