-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·70 lines (55 loc) · 1.69 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
set -e
install_dir="/usr/local/bin"
bash_completion_dir="/etc/bash_completion.d"
if [ "$1" = "--user" ]; then
install_dir="$HOME/.local/bin"
bash_completion_dir="$HOME/.bash_completion.d"
fi
get_latest_release() {
curl --silent "https://api.github.com/repos/relnod/dotm/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
target=""
goarch=""
case $(uname) in
"Linux")target=Linux;;
"Darwin")target=Darwin;;
*)
echo "Target $(uname) is not supported"
exit 1
;;
esac
case $(uname -m) in
"x86_64")goarch=x86_64;;
"i386")goarch=i386;;
*)
echo "Arch $(uname -a) is not supported"
exit 1
;;
esac
version=$(get_latest_release)
current_version=$(dotm --version | cut -d ' ' -f3)
if [ -x "$(command -v dotm)" ] && [ "$version" = "$current_version" ]; then
echo "dotm is already installed at the latest version ($version)"
exit
fi
# strip the "v" from the version
rawversion="$(echo "$version" | cut -d "v" -f 2)"
name="dotm_${rawversion}_${target}_${goarch}.tar.gz"
echo "Downloading dotm binary at version ${version}"
curl --silent -L "https://github.com/relnod/dotm/releases/download/${version}/${name}" -o "/tmp/${name}"
[ ! -d "$install_dir" ] && mkdir -p "$install_dir"
[ ! -d "$bash_completion_dir" ] && mkdir -p "$bash_completion_dir"
echo "Installing dotm to $install_dir"
if [ -f "$install_dir/dotm" ]; then
rm -f "$install_dir/dotm"
fi
tar -C "$install_dir" -xzf "/tmp/${name}" dotm
echo "Generating bash completions at $bash_completion_dir"
dotm --genCompletions > "$bash_completion_dir/dotm"
if [ ! -z "$current_version" ]; then
echo "Running 'dotm fix'"
dotm fix
fi