-
Notifications
You must be signed in to change notification settings - Fork 9
/
install
executable file
·49 lines (37 loc) · 1.34 KB
/
install
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
STRAP_RELEASE_REF="${STRAP_RELEASE_REF:-}"
[ -z "$STRAP_RELEASE_REF" ] && STRAP_RELEASE_REF='master'
user_strap_dir="$HOME/.strap"
mkdir -p "$user_strap_dir"
releases_dir="$user_strap_dir/releases"
mkdir -p "$releases_dir"
file="$releases_dir/${STRAP_RELEASE_REF}.zip"
rm -rf "$file"
STRAP_RELEASE_URL="https://github.com/strapsh/strap/archive/${STRAP_RELEASE_REF}.zip"
if command -v wget >/dev/null; then
wget -qO "$file" "$STRAP_RELEASE_URL"
elif command -v curl >/dev/null; then
curl -fsSL "$STRAP_RELEASE_URL" -o "$file"
else
echo "Neither wget nor curl are available. Cannot download strap." >&2
exit 1
fi
release_dir="$releases_dir/${STRAP_RELEASE_REF}"
rm -rf "$release_dir"
mkdir -p "$release_dir"
unzip-strip() {
local zip="${1:-}" && [[ -z "$zip" ]] && { echo '$1 must be a zip file' >&2; return 1; }
local dest="${2:-.}"
local temp="$(mktemp -d 2>/dev/null || mktemp -d -t 'strap_dl_temp_dir')" && \
unzip -q -d "$temp" "$zip" && mkdir -p "$dest" && \
shopt -s dotglob && local f=("$temp"/*) && \
if (( ${#f[@]} == 1 )) && [[ -d "${f[0]}" ]] ; then
mv "$temp"/*/* "$dest"
else
mv "$temp"/* "$dest"
fi && rm -rf "$temp"
}
unzip-strip "$file" "$release_dir"
rm -rf "$file"
rm -rf "$releases_dir/current"
ln -s "$release_dir" "$releases_dir/current"