-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
install.sh
executable file
·198 lines (178 loc) · 4.43 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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/sh
target=/usr/local/bin
user_arg=$1
stream_cmd="curl -sL install.mob.sh"
readme="https://mob.sh"
determine_arch() {
case "$(uname -s)" in
Darwin)
echo "universal"
;;
*)
echo "amd64"
;;
esac
}
determine_os() {
case "$(uname -s)" in
Darwin)
echo "darwin"
;;
MINGW64*)
echo "windows"
;;
*)
echo "linux"
;;
esac
}
determine_user_install() {
case "$(determine_os)" in
windows)
echo "--user"
;;
*)
echo "$user_arg"
;;
esac
}
determine_local_target() {
case "$(determine_os)" in
windows)
# shellcheck disable=SC1003
echo "$USERPROFILE/bin" | tr '\\' '/'
;;
linux)
systemd-path user-binaries
;;
esac
}
determine_mob_binary() {
case "$(determine_os)" in
windows)
echo "mob.exe"
;;
*)
echo "mob"
;;
esac
}
determine_ending() {
case "$(determine_os)" in
windows)
echo "tar.gz"
;;
*)
echo "tar.gz"
;;
esac
}
handle_user_installation() {
user_install=$(determine_user_install)
if [ "$user_install" = "--user" ]; then
local_target=$(determine_local_target)
if [ "$local_target" != "" ] && [ ! -d "$local_target" ]; then
mkdir -p "$local_target"
fi
if [ -d "$local_target" ]; then
target=$local_target
else
echo "unfortunately, there is no user-binaries path on your system. aborting installation."
exit 1
fi
fi
}
check_access_rights() {
if [ ! -w "$target" ]; then
echo "you do not have access rights to $target."
echo
local_target=$(determine_local_target)
if [ "$local_target" != "" ]; then
echo "we recommend that you use the --user flag"
echo "to install the app into your user binary path $local_target"
echo
echo " $stream_cmd | sh -s - --user"
echo
fi
if [ "$(command -v sudo)" != "" ]; then
echo "calling the installation with sudo might help."
echo
echo " $stream_cmd | sudo sh"
echo
fi
exit 1
fi
}
install_remote_binary() {
echo "installing latest 'mob' release from GitHub to $target..."
url=$(curl -s https://api.github.com/repos/remotemobprogramming/mob/releases/latest |
grep "browser_download_url.*mob_.*$(determine_os)_$(determine_arch)\.$(determine_ending)" |
cut -d ":" -f 2,3 |
tr -d ' \"')
curl -sSL "$url" | tar xz -C "$target" "$(determine_mob_binary)" && chmod +x "$target"/mob
}
add_to_path() {
case "$(determine_os)" in
windows)
powershell -command "[System.Environment]::SetEnvironmentVariable('Path', [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)+';$target', [System.EnvironmentVariableTarget]::User)"
;;
esac
}
check_command() {
location="$(command -v mob)"
if [ $location = "" ]; then
echo
echo "(!) 'mob' could not be found after install!"
case "$(determine_os)" in
linux)
echo " If you installed using --user it should be found when you login next time."
echo " If it does not, you might need to manually add it to your .profile or equivalent like so:"
echo
echo " echo \"export PATH=$target:\\\$PATH\" >> ~/.profile"
;;
*)
echo " Make sure that $target is in your PATH"
esac
return
fi
echo "Mob binary location: $location"
version="$(mob version)"
echo "Mob binary version: $version"
}
check_say() {
case "$(determine_os)" in
linux)
say=$(command -v say)
if [ ! -e "$say" ]; then
echo
echo "Couldn't find a 'say' command on your system."
echo "While 'mob' will still work, you won't get any spoken indication that your time is up."
echo "Please refer to the documentation how to setup text to speech on a *NIX system:"
echo
echo " $readme#$(determine_os)-timer"
echo
fi
;;
esac
}
check_installation_path() {
location="$(command -v mob)"
if [ "$(determine_os)" = "windows" ]; then
location=$(echo $location | sed -E 's|^/([a-zA-Z])|\U\1:|')
fi
if [ "$location" != "$target/mob" ] && [ "$location" != "" ]; then
echo "(!) The installation location doesn't match the location of the mob binary."
echo " This means that the binary that's used is not the binary that has just been installed"
echo " You probably want to delete the binary at $location"
fi
}
main() {
handle_user_installation
check_access_rights
install_remote_binary
add_to_path
check_command
check_say
check_installation_path
}
main