Skip to content

Commit

Permalink
feat: Add install.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
marverix committed Dec 4, 2024
0 parents commit 4527d57
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4

[{gah,*.sh,*.bash,*.bats}]
indent_style = tab

[*.md]
indent_size = 2
78 changes: 78 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

# gah! installer
#
# @author Marek `marverix` Sierociński
# @license GNU GPLv3

# Pipeline mode
set -e

#--------------------------------------------------
#region Utils
function print_blue() {
echo -e "\033[0;34m$1\033[0m"
}

function print_green() {
echo -e "\033[0;32m$1\033[0m"
}

function print_yellow() {
echo -e "\033[0;33m$1\033[0m"
}

function throw_error() {
echo -e "\033[0;31mError: $2\033[0m" >&2
exit $1
}

function require_command() {
print_blue "Checking if $1 is installed..."
if ! command -v $1 2>&1 >/dev/null; then
throw_error 2 "$1 is not installed"
fi
print_green "OK"
}

#endregion
#--------------------------------------------------

# Require that bash is at least 4.0
print_blue "Checking if Bash 4.0 or higher is installed..."
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
throw_error 1 "Bash 4.0 or higher is required"
fi
print_green "OK"

# Check if required commands are installed
require_command tar
require_command unzip
require_command curl
require_command jq

# Ensure ~/.local/bin exists
print_blue "Ensuring ~/.local/bin exists..."
mkdir -p ~/.local/bin
print_green "OK"

# Check if ~/.local/bin is in PATH
print_blue "Checking if ~/.local/bin is in PATH..."
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
print_yellow "WARNING: ~/.local/bin is not in PATH. gah will not work if ~/.local/bin is not in PATH."
else
print_green "OK, looks good!"
fi

# Check gah latest tag
print_blue "Checking latest gah release..."
tag=$(curl -s https://api.github.com/repos/marverix/gah/releases/latest | jq -r '.tag_name')
print_green "OK, latest tag is $tag"

# Download gah! script
print_blue "Downloading gah $tag script..."
curl -sL https://raw.githubusercontent.com/marverix/gah/refs/tags/$tag/gah -o ~/.local/bin/gah
chmod +x ~/.local/bin/gah
print_green "OK"

print_green "Done!"

0 comments on commit 4527d57

Please sign in to comment.