Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add installation script #120

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh

success() { printf " \033[1;32m ✔ %s\033[0m\n" "$*"; }
Chaitanyabsprip marked this conversation as resolved.
Show resolved Hide resolved
inprogress() { printf " \033[1;34m ... %s\033[0m\n" "$*"; }
warning() { printf " \033[1;33m ⚠️%s\033[0m\n" "$*"; }
error() { printf " \033[1;31m ❌%s\033[0m\n" "$*"; }
distro() {
Chaitanyabsprip marked this conversation as resolved.
Show resolved Hide resolved
if [ -f /etc/os-release ]; then
# shellcheck disable=SC1091
. /etc/os-release
DISTRO=$NAME
VERSION=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
DISTRO=$(lsb_release -si)
VERSION=$(lsb_release -sr)
else
DISTRO=$(uname -s)
VERSION=$(uname -r)
fi
echo "$DISTRO:$VERSION"
}

pkg_install() {
Chaitanyabsprip marked this conversation as resolved.
Show resolved Hide resolved
case "$DISTRO" in
Arch\ Linux) paru -S --noconfirm gitmux ;;
Darwin)
brew tap arl/arl
brew install gitmux
;;
*) error "Unsupported platform" && return 1 ;;
esac
}

go_install() { :; }
Chaitanyabsprip marked this conversation as resolved.
Show resolved Hide resolved

gh_install() {
Chaitanyabsprip marked this conversation as resolved.
Show resolved Hide resolved
ver="$1"
repo='arl/gitmux'
[ -z "$ver" ] && {
archi=$(uname -sm)
latest="https://api.github.com/repos/$repo/releases/latest"
ver=$(curl -sS "$latest" | grep tarball_url | sed 's>.*: "\(.*\)".*>\1>') && test -n "$ver"
ver=${ver##*/}
}
tarname=''
case "$archi" in
Darwin\ arm64) tarname="gitmux_${ver}_macOS_arm64.tar.gz" ;;
Darwin\ x86_64) tarname="gitmux_${ver}_macOS_amd64.tar.gz" ;;
Linux\ aarch64*) tarname="gitmux_${ver}_linux_arm64.tar.gz" ;;
Linux\ *64) tarname="gitmux_${ver}_linux_amd64.tar.gz" ;;
*) error "Unsupported architecture" && return 1 ;;
esac
tmpdir="$(mktemp -d)"
cd "$tmpdir" || :
curl -sSLO "https://github.com/$repo/releases/download/$ver/$tarname"
tar -xf gitmux*.tar.gz &&
mv gitmux "${SCRIPTS:-"$HOME/.local/bin"}"
[ -d "$tmpdir" ] && rm -rf "$tmpdir"
}

SCRIPTS="${SCRIPTS:-$HOME/.local/bin}"
! [ -d "$SCRIPTS" ] && mkdir -p "$SCRIPTS"
DISTRO=$(distro | cut -d ':' -f1)

inprogress "Installing gitmux"

if pkg_install || gh_install "$@"; then
success "Succesfully installed gitmux"
else
warning "Could not install gitmux"
fi