-
Notifications
You must be signed in to change notification settings - Fork 78
/
install
executable file
·134 lines (115 loc) · 3.07 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
#!/bin/bash
# Generic install script
# Copyright (c) 2023 Jernej Jakob <jernej.jakob@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
: "${PREFIX:="/usr/local"}"
bin_files="certbot_zimbra.sh"
man_files="certbot_zimbra.sh.1"
valid_targets=("bin" "man")
# do not modify anything below this line
targets=()
uninstall=
quiet=
if (( ${BASH_VERSINFO[0]} < 4 || ( ${BASH_VERSINFO[0]} == 4 && ${BASH_VERSINFO[1]} < 3 ) )); then
printf '%s\n' "This script requires at least bash 4.3 (due to using nameref variables). Exiting." >&2
exit 1
fi
for arg; do
case "$arg" in
-u|--uninstall)
uninstall=1
shift
;;
-q|--quiet)
quiet=1
shift
;;
-h|--help)
cat >&2 <<-EOF
Usage: install [options...] targets...
Options:
--uninstall uninstall
--quiet do not print progress to stderr
--help print this help message
targets list of targets to install
Targets:
bin install binary to \$DESTDIR/\$PREFIX/bin
man install manpage to \$DESTDIR/\$PREFIX/share/man
all install all targets
Environment:
DESTDIR: current "$DESTDIR" (default "")
PREFIX: current "$PREFIX" (default "/usr/local")
EOF
exit 0
;;
-*)
printf 'Error: unknown option "%s".\n' "$arg" >&2
exit 1
;;
*)
targets+=("$arg")
shift
;;
esac
done
verb=-v
if (( quiet )); then verb=; fi
if (( EUID != 0 )); then
printf 'Error: This script must be run as root.\n' >&2
exit 1
fi
if ! [[ "${targets[*]}" ]]; then
printf 'Error: nothing to do. Need at least one target.\n' >&2
exit 1
fi
for target in "${targets[@]}"; do
if [[ "$target" == "all" ]]; then
targets=("${valid_targets[@]}")
break
fi
for valid_target in "${valid_targets[@]}"; do
if [[ "$target" == "$valid_target" ]]; then
continue 2
fi
done
printf 'Error: target "%s" not valid.\n' "$target" >&2
exit 1
done
umask 022
for target in "${targets[@]}"; do
declare -n target_files="${target}_files"
for f in $target_files; do
if [[ "$target" == "bin" ]]; then
if (( uninstall )); then
rm $verb "$DESTDIR/$PREFIX/bin/$f"
else
install $verb -m 0755 -o root -g root "$f" "$DESTDIR/$PREFIX/bin/"
fi
fi
if [[ "$target" == "man" ]]; then
section="${f##*.}"
if (( uninstall )); then
rm $verb "$DESTDIR/$PREFIX/share/man/man$section/$f"
else
mkdir $verb -p "$DESTDIR/$PREFIX/share/man/man$section" &&
install $verb -m 0644 -o root -g root "$f" "$DESTDIR/$PREFIX/share/man/man$section/"
fi
fi
done
if [[ "$target" == "man" ]]; then
mandb
fi
done
exit 0