From d8897192f4c1f77f47dde8dc8232eea08e5978ba Mon Sep 17 00:00:00 2001 From: Chaitanya Sharma Date: Mon, 10 Jun 2024 02:42:37 +0530 Subject: [PATCH 1/5] feat: add installation script --- install | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 install diff --git a/install b/install new file mode 100644 index 0000000..fdc736c --- /dev/null +++ b/install @@ -0,0 +1,71 @@ +#!/bin/sh + +success() { printf " \033[1;32m ✔ %s\033[0m\n" "$*"; } +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() { + 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() { + 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() { :; } + +gh_install() { + 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 From 78635ecfe51426af2ebba9cf57ca910bb93a720e Mon Sep 17 00:00:00 2001 From: Chaitanya Sharma Date: Mon, 10 Jun 2024 03:53:48 +0530 Subject: [PATCH 2/5] feat(install): ask install path as an envvar --- install | 54 ++++++++++-------------------------------------------- 1 file changed, 10 insertions(+), 44 deletions(-) diff --git a/install b/install index fdc736c..ac9acad 100644 --- a/install +++ b/install @@ -1,71 +1,37 @@ #!/bin/sh -success() { printf " \033[1;32m ✔ %s\033[0m\n" "$*"; } -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() { - 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() { - 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() { :; } - +_have() { type "$1" >/dev/null 2>&1; } gh_install() { 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='' + archi=$(uname -sm) 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 ;; + *) echo "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"}" + mv gitmux "${INSTALL_PATH}" [ -d "$tmpdir" ] && rm -rf "$tmpdir" } -SCRIPTS="${SCRIPTS:-$HOME/.local/bin}" -! [ -d "$SCRIPTS" ] && mkdir -p "$SCRIPTS" -DISTRO=$(distro | cut -d ':' -f1) - -inprogress "Installing gitmux" +_have curl || echo "This script depends on curl" && exit 1 +[ -z "$INSTALL_PATH" ] && echo "Please set the INSTALL_PATH envvar to specify installation directory" && exit 1 -if pkg_install || gh_install "$@"; then - success "Succesfully installed gitmux" +echo "Installing gitmux" +if gh_install "$@"; then + echo "Successfully installed gitmux" else - warning "Could not install gitmux" + echo "Could not install gitmux" && exit 1 fi From ae7894d3e77ef084cafebe40e59b8ecd64d9c2ab Mon Sep 17 00:00:00 2001 From: Chaitanya Sharma Date: Mon, 10 Jun 2024 03:55:07 +0530 Subject: [PATCH 3/5] feat: add help command to installation script --- install | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/install b/install index ac9acad..a60f2aa 100644 --- a/install +++ b/install @@ -1,6 +1,31 @@ #!/bin/sh _have() { type "$1" >/dev/null 2>&1; } + +help() { + cat < Date: Mon, 10 Jun 2024 04:05:22 +0530 Subject: [PATCH 4/5] docs(install): say that INSTALL_PATH is required --- install | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 install diff --git a/install b/install old mode 100644 new mode 100755 index a60f2aa..d8231e8 --- a/install +++ b/install @@ -13,7 +13,7 @@ Arguments: version Specify the version of gitmux to install. If not provided, the latest version will be installed. Environment Variables: - INSTALL_PATH Specify the directory where gitmux should be installed. + INSTALL_PATH Specify the directory where gitmux should be installed. Required Description: This script installs the gitmux tool, which provides Git status information in the tmux status line. From 31413d56cdfee06f0571482127bfe42e040a32af Mon Sep 17 00:00:00 2001 From: Chaitanya Sharma Date: Mon, 10 Jun 2024 04:05:51 +0530 Subject: [PATCH 5/5] fix(install): should exit early if curl is not found --- install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install b/install index d8231e8..e3ac77e 100755 --- a/install +++ b/install @@ -53,10 +53,10 @@ gh_install() { if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then help && exit 0; fi -_have curl || echo "This script depends on curl" && exit 1 +! _have curl && echo "This script depends on curl" && exit 1 [ -z "$INSTALL_PATH" ] && echo "Please set the INSTALL_PATH envvar to specify installation directory" && exit 1 -echo "Installing gitmux" +echo "Installing gitmux..." if gh_install "$@"; then echo "Successfully installed gitmux" else