/
installer
executable file
·55 lines (47 loc) · 1.63 KB
/
installer
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
#!/usr/bin/env bash
readonly script=otomi
readonly branch=${OTOMI_TAG:-master}
readonly remote=https://raw.githubusercontent.com/redkubes/otomi-core/$branch/binzx/$script
readonly path=/usr/local/bin
readonly msg="Please choose the default install location [$path]: "
# https://unix.stackexchange.com/questions/121231/how-to-read-user-input-from-a-pipe
read -p "$msg" answer <&2
answer=${answer:-$path}
if [ ! -d $answer ]; then
echo "$answer does not exist, please provide an existing path"
exit 1
fi
if [[ $PATH != *$answer* ]]; then
echo "$answer is not in your PATH please add it to run $script from anywhere"
echo "export PATH=$answer:\$PATH"
fi
file="$answer/$script"
if command -v wget &>/dev/null; then
wget $remote -O $file
elif command -v curl &>/dev/null; then
curl $remote -o $file
fi
chmod +x $file
if [[ $SHELL == *zsh* ]] || [[ $SHELL == *bash* ]]; then
readonly msgAC="Do you want to install autocompletion for otomi? [Yes/no]: "
read -p "$msgAC" autocompleteAnswer <&2
autocompleteAnswer=${autocompleteAnswer:-yes}
case $autocompleteAnswer in
[Yy]*)
acPath='/usr/local/share/zsh/site-functions/_otomi'
if [[ $SHELL == *bash* ]]; then
acPath='/usr/local/etc/bash_completion.d/otomi.bash'
fi
otomi completion | tr -d '\r' >$acPath
chmod +x $acPath
echo "Autocompletion has been installed in ${acPath}"
echo "Please restart your terminal to use autocompletion"
;;
[Nn]*)
echo "If you need autocompletion you can run:"
echo "\`otomi completion\`"
;;
esac
fi
echo "Otomi has been installed in $file"
echo 'You can now run it by calling `otomi`'