Skip to content

Commit

Permalink
Merge pull request profclems#560 from profclems/ch-posix-script
Browse files Browse the repository at this point in the history
chore(scripts): make quick installer script POSIX sh compliant
  • Loading branch information
profclems authored Jan 13, 2021
2 parents b205855 + f0646ca commit 4e90222
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 58 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ Read the [documentation](https://glab.readthedocs.io/) for more information on t
## Installation
Download a binary suitable for your OS at the [releases page](https://github.com/profclems/glab/releases/latest).
### Quick Install (Bash)
### Quick Install (shell)
**Supported Platforms**: Linux and macOS
You can install or update `glab` with:
```bash
curl -sL https://j.mp/glab-i | sudo bash
```sh
curl -sL https://j.mp/glab-cli | sudo sh
```
or
```bash
curl -s https://raw.githubusercontent.com/profclems/glab/trunk/scripts/quick_install.sh | sudo bash
```sh
curl -s https://raw.githubusercontent.com/profclems/glab/trunk/scripts/install.sh | sudo sh
```
*Installs into `usr/local/bin`*
*Installs into `usr/bin`*
**NOTE**: Please take care when running scripts in this fashion. Consider peaking at the install script itself and verify that it works as intended.
Expand Down
72 changes: 72 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/sh
# Usage: [sudo] [BINDIR=/usr/local/bin] ./install.sh [<BINDIR>]
#
# Example:
# 1. sudo ./install.sh /usr/local/bin
# 2. sudo ./install.sh /usr/bin
# 3. ./install.sh $HOME/usr/bin
# 4. BINDIR=$HOME/usr/bin ./install.sh
#
# Default BINDIR=/usr/bin

set -euf

if [ -n "${DEBUG-}" ]; then
set -x
fi

: "${BINDIR:=/usr/bin}"

if [ $# -gt 0 ]; then
BINDIR=$1
fi

_can_install() {
if [ ! -d "${BINDIR}" ]; then
mkdir -p "${BINDIR}" 2> /dev/null
fi
[ -d "${BINDIR}" ] && [ -w "${BINDIR}" ]
}

if ! _can_install && [ "$(id -u)" != 0 ]; then
printf "Run script as sudo\n"
exit 1
fi

if ! _can_install; then
printf -- "Can't install to %s\n" "${BINDIR}"
exit 1
fi

machine=$(uname -m)

case $(uname -s) in
Linux)
os="Linux"
;;
Darwin)
os="Darwin"
;;
*)
printf "OS not supported\n"
exit 1
;;
esac

printf "Fetching latest version\n"
latest="$(curl -sL 'https://api.github.com/repos/profclems/glab/releases/latest' | grep 'tag_name' | grep --only 'v[0-9\.]\+' | cut -c 2-)"
tempFolder="/tmp/glab_v${latest}"

printf -- "Found version %s\n" "${latest}"

mkdir -p "${tempFolder}" 2> /dev/null
printf -- "Downloading glab_%s_%s_%s.tar.gz\n" "${latest}" "${os}" "${machine}"
curl -sL "https://github.com/profclems/glab/releases/download/v${latest}/glab_${latest}_${os}_${machine}.tar.gz" | tar -C "${tempFolder}" -xzf -

printf -- "Installing...\n"
install -m755 "${tempFolder}/bin/glab" "${BINDIR}/glab"

printf "Cleaning up temp files\n"
rm -rf "${tempFolder}"

printf -- "Successfully installed glab into %s/\n" "${BINDIR}"
52 changes: 0 additions & 52 deletions scripts/quick_install.sh

This file was deleted.

0 comments on commit 4e90222

Please sign in to comment.