-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·102 lines (85 loc) · 1.7 KB
/
setup.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
#!/usr/bin/env bash
#
# setup script for dcc.sh
source "./src/settings.sh"
source "./lib/installer.sh"
usage() {
cat << EOF
setup
Usage:
./setup <i|install|r|remove|upgrade>
Commands:
i|install
install dcc.sh and create its manpage
r|remove
uninstall dcc.sh and remove its manpage
upgrade
update manpage
EOF
}
get_args() {
if [[ -z $1 ]]; then
usage
fi
local POSITIONAL=()
while [[ $# -gt 0 ]]
do
local key=$1
case $key in
-h|--help)
usage
exit 0
;;
i|install)
install
exit 0
;;
r|remove)
uninstall
exit 0
;;
up|upgrade)
upgrade
exit 0
;;
-v|--version)
printf '%s\n' "$VERSION"
exit 0
;;
*)
# get operator
if [[ $1 =~ ^.+@.+$ ]]; then
OPERATOR="$1"
fi
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}"
}
install_manpage() {
printf '%s\n' "Create man page to /usr/local/man/man8"
if [[ -e "${_dir}/static/man8/${INSTALLABLE_NAME}.8" ]] ; then
if [[ ! -e "/usr/local/man/man8/${INSTALLABLE_NAME}.8.gz" ]] ; then
mkdir -p /usr/local/man/man8
cp "${_dir}/static/man8/${INSTALLABLE_NAME}.8" /usr/local/man/man8
gzip "/usr/local/man/man8/${INSTALLABLE_NAME}.8"
fi
fi
}
install() {
printf '%s\n' "Create symbolic link to /usr/local/bin"
if [[ -e "${_dir}/bin/${INSTALLABLE_NAME}" ]] ; then
if [[ ! -e "/usr/local/bin/${INSTALLABLE_NAME}" ]] ; then
ln -s "${_dir}/bin/${INSTALLABLE_NAME}" /usr/local/bin
fi
fi
install_manpage
}
main() {
check_os
get_args "$@"
}
main "$@"
exit 0