-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstall.sh
executable file
·49 lines (42 loc) · 1.34 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
set -euo pipefail
MV_OPTS="-n"
[ -t 0 ] && MV_OPTS="-i" # Interactive, prompt before overwrite
while getopts ':v:d:fnx' OPT; do
case $OPT in
f) # Don't prompt before overwriting
MV_OPTS='-f';;
n) # Don't overwrite an existing file
MV_OPTS='-n';;
x)
XTRACE="y";;
v)
DRUN_VERSION="$OPTARG";;
d)
INSTALL_DIR="$OPTARG";;
\?)
echo >&2 "Unknown option -$OPTARG"
exit 1;;
:)
echo >&2 "Missing argument for option -$OPTARG"
exit 1;;
esac
done
shift $((OPTIND-1))
INSTALL_DIR=${INSTALL_DIR:-'/usr/local/bin'}
INSTALL_PATH="${INSTALL_DIR}/drun"
INSTALL_DIR=$(dirname "$INSTALL_PATH")
if [ "${MV_OPTS}" = '-n' ] && [ -e "$INSTALL_PATH" ]; then
echo >&2 "Not overwriting $INSTALL_PATH"
exit 0;
fi
if [ -z "${DRUN_VERSION:-}" ]; then
echo 'Determining latest version…'
DRUN_VERSION=$(curl -sS https://api.github.com/repos/jpbochi/drun/releases/latest | grep '"tag_name"' | sed 's/.*"tag_name": "v\(.*\)".*/\1/')
fi
echo "Installing drun v${DRUN_VERSION} to ${INSTALL_PATH}…"
TEMP_DIR=$(mktemp -d)
mkdir -p "$INSTALL_DIR"
[ "${XTRACE:-}" = 'y' ] && set -o xtrace
curl -sSLf "https://github.com/jpbochi/drun/archive/v${DRUN_VERSION}.tar.gz" | tar -C "$TEMP_DIR" -zxf - --strip-components=1 "drun-$DRUN_VERSION/drun"
mv -v ${MV_OPTS} "$TEMP_DIR/drun" "$INSTALL_PATH"