-
Notifications
You must be signed in to change notification settings - Fork 33
/
install.sh
executable file
·89 lines (69 loc) · 2.04 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
#!/bin/sh
{ # ensure the whole script is loaded
set -eu
print_bold()
{
tput bold; echo "${1}"; tput sgr0
}
download_file()
{
if 'curl' -V >/dev/null 2>&1
then 'curl' -fsSL "${1}"
else 'wget' -qO- "${1}"
fi
}
# install_file baseurl file
install_file()
{
if [ -e "${2}" ]
then
cp "${2}" "${LUAVER_DIR}/${2}"
else
download_file "${1}/${2}" >"${LUAVER_DIR}/${2}"
fi
}
## Option parsing
LUAVER_DIR=~/.luaver
REVISION=v1.1.0
SHELL_TYPE="$(basename /"${SHELL}")"
while getopts hr:s: OPT
do
case "$OPT" in
r ) REVISION="${OPTARG}" ;;
h )
echo "Usage: ${0} [-r REVISION]"
echo " -r luaver reversion [${REVISION}]"
exit 0
;;
esac
done
print_bold "Installing luaver..."
## Download script
URL="https://raw.githubusercontent.com/DhavalKapil/luaver/${REVISION}"
mkdir -p "${LUAVER_DIR}/completions"
install_file "${URL}" "luaver"
chmod a+x "${LUAVER_DIR}/luaver"
install_file "${URL}" "completions/luaver.bash" || rm "${LUAVER_DIR}/completions/luaver.bash"
## Set up profile
APPEND_COMMON="[ -s ~/.luaver/luaver ] && . ~/.luaver/luaver"
APPEND_BASH="${APPEND_COMMON}
[ -s ~/.luaver/completions/luaver.bash ] && . ~/.luaver/completions/luaver.bash"
APPEND_ZSH="${APPEND_COMMON}"
case "${SHELL_TYPE}" in
bash ) APPEND="${APPEND_BASH}" ;;
zsh ) APPEND="${APPEND_ZSH}" ;;
* ) APPEND="${APPEND_COMMON}"
esac
if [ -f ~/."${SHELL_TYPE}"rc ]
then
'grep' -qF "${APPEND}" ~/."${SHELL_TYPE}"rc || printf "\n%s\n\n" "${APPEND}" >>~/."${SHELL_TYPE}"rc
print_bold "Appending the following lines at the end of ~/.${SHELL_TYPE}rc if lines not exists:"
printf "\n%s\n\n" "${APPEND}"
print_bold "To use luaver, you must restart the shell or execute '. ~/.${SHELL_TYPE}rc'"
else
print_bold "Add the following lines at the end of your profile (~/.bashrc, ~/.zshrc, etc):"
printf "\n%s\n\n" "${APPEND}"
print_bold "To use luaver, you must restart the shell or execute the above lines"
fi
print_bold "luaver was successfully installed!"
}