forked from tmrts/boilr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·134 lines (113 loc) · 3.22 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
set -u
[[ "$@" =~ --pre ]] && version=0.3.1 pre=1 ||
version=0.3.1 pre=0
# If stdin is a tty, we are "interactive".
interactive=
[ -t 0 ] && interactive=yes
ask() {
# non-interactive shell: wait for a linefeed
# interactive shell: continue after a single keypress
[ -n "$interactive" ] && read_n='-n 1' || read_n=
read -p "$1 ([y]/n) " $read_n -r
echo
[[ $REPLY =~ ^[Nn]$ ]]
}
symlink() {
echo " - Creating symlink: bin/$1 -> bin/boilr"
(cd "$HOME"/bin &&
rm -f boilr &&
ln -sf $1 boilr)
if [ $? -ne 0 ]; then
binary_error="Failed to create symlink"
return 1
fi
}
configure() {
$HOME/bin/boilr init
if [ $? -ne 0 ]; then
binary_error="Failed to complete boilr initialization"
return
fi
# Auto-completion prompt
if [ -z "$auto_completion" ]; then
ask "Do you want to enable auto-completion for boilr commmands?"
auto_completion=$?
fi
if [ $auto_completion -eq 1 ]; then
$HOME/bin/boilr configure-bash-completion
fi
}
check_binary() {
echo -n " - Checking boilr executable ... "
local output
output=$("$HOME"/bin/boilr version --dont-prettify 2>&1)
if [ $? -ne 0 ]; then
echo "Error: $output"
binary_error="Invalid binary"
elif [ "$version" != "$output" ]; then
echo "$output != $version"
binary_error="Invalid version"
else
echo "$output"
binary_error=""
return 0
fi
rm -f "$HOME"/bin/boilr
return 1
}
download() {
echo "Downloading boilr ..."
if [ -x "$HOME"/bin/boilr ]; then
echo " - Already exists"
check_binary && return
fi
if [ -x "$HOME"/bin/$1 ]; then
symlink $1 && check_binary && return
fi
if which_boilr="$(which boilr 2> /dev/null)"; then
echo " - Found in \$PATH"
echo " - Creating symlink: $which_boilr -> bin/boilr"
(cd "$HOME"/bin && rm -f boilr && ln -sf "$which_boilr" boilr)
check_binary && return
fi
mkdir -p "$HOME"/bin && cd "$HOME"/bin
if [ $? -ne 0 ]; then
binary_error="Failed to create bin directory"
return
fi
local url=https://github.com/Wattpad/boilr/releases/download/$version/${1}.tar.gz
echo "Downloading file from: " $url
if which curl > /dev/null; then
curl -fL $url | tar -xz
elif which wget > /dev/null; then
wget -O - $url | tar -xz
else
binary_error="curl or wget not found"
return
fi
if [ ! -f $1 ]; then
binary_error="Failed to download ${1}"
return
fi
chmod +x $1 && symlink $1 && check_binary
configure
}
# Try to download binary executable
archi=$(uname -sm)
binary_available=1
binary_error=""
case "$archi" in
Darwin\ x86_64) download boilr-$version-darwin-${binary_arch:-amd64} ;;
Darwin\ arm64) download boilr-$version-darwin-${binary_arch:-arm64} ;;
Darwin\ i*86) download boilr-$version-darwin-${binary_arch:-386} ;;
Linux\ x86_64) download boilr-$version-linux-${binary_arch:-amd64} ;;
Linux\ arm64) download boilr-$version-linux-${binary_arch:-arm64} ;;
Linux\ i*86) download boilr-$version-linux-${binary_arch:-386} ;;
*) binary_available=0 binary_error=1 ;;
esac
cat << EOF
Completed installation
Boilr executable is installed to ~/bin/boilr
For more information, see: https://github.com/Wattpad/boilr
EOF