-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·168 lines (144 loc) · 4.15 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
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
#!/bin/sh
#
# Download latest Hiawatha webserver, compile and update.
# For Hiawatha v8.0 and higher.
#
# (cloux@rote.ch)
#########################################################################
# Set this variable, if you want to receive a status mail:
# example: MAILTO=admin@yourserver.com
MAILTO=
#########################################################################
PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
# working directory
MY_ROOT=/usr/src/hiawatha
# stop hiawatha on supervised init
hiawatha_stop () {
if [ "$(pgrep runsvdir)" ] || [ "$(pgrep s6-svscan)" ]; then
# daemontools-type service supervision
mv -n /etc/init.d/hiawatha /etc/init.d/hiawatha.dpkg
rm -f /etc/init.d/hiawatha; touch /etc/init.d/hiawatha
find /etc/rc*.d -iname '*hiawatha' -delete
fi
if [ "$(pgrep runsvdir)" ]; then
# runit supervisor
sv stop hiawatha
elif [ "$(pgrep s6-svscan)" ]; then
# s6 supervisor
s6-svc -wd hiawatha
else
/etc/init.d/hiawatha stop
fi
}
# start hiawatha on supervised init
hiawatha_start () {
if [ "$(pgrep runsvdir)" ]; then
sv start hiawatha
elif [ "$(pgrep s6-svscan)" ]; then
s6-svc -u hiawatha
else
/etc/init.d/hiawatha start
fi
}
# Make sure that I'm root
if [ $(id -u) -ne 0 ]; then printf 'Need to be root!\n'; exit 1; fi
export DEBIAN_FRONTEND=noninteractive
if [ -z "$(command -v hiawatha)" ]; then
printf 'Hiawatha not found. Install dependencies ...\n'
APTINST=
if [ "$(command -v aptitude)" ]; then
APTINST=aptitude
elif [ "$(command -v apt-get)" ]; then
APTINST=apt-get
fi
if [ "$APTINST" ]; then
$APTINST --assume-yes -o Dpkg::Use-Pty=0 install cmake make lsof libxml2 \
libxml2-dev libxslt1.1 libxslt1-dev libc6-dev libssl-dev \
zlib1g-dev dpkg-dev debhelper fakeroot apache2-utils procps wget
else
printf 'WARNING: Apt packaging system not found, dependencies installation skipped.\n'
fi
fi
if [ -z "$(command -v lsof)" ]; then
printf 'ERROR: lsof not found, exiting.\n'
exit 1
fi
[ -d "$MY_ROOT" ] || mkdir -p "$MY_ROOT"
cd "$MY_ROOT" || exit 1
LATEST=$(wget -q -O - https://www.hiawatha-webserver.org/latest 2>/dev/null)
if [ -z "$(printf '%s' "$LATEST" | head -n 1 | grep '^[0-9][0-9.]*$')" ]; then
printf 'WARNING: Hiawatha latest version checking failed.\n'
exit
fi
if [ -s "$MY_ROOT/hiawatha-$LATEST.tar.gz" ]; then
printf 'Latest Hiawatha v%s already downloaded.\n' "$LATEST"
exit
fi
printf 'Downloading new Hiawatha v%s ...' "$LATEST"
wget -q -O "$MY_ROOT/hiawatha-$LATEST.tar.gz" "https://www.hiawatha-webserver.org/files/hiawatha-$LATEST.tar.gz"
if [ -s "$MY_ROOT/hiawatha-$LATEST.tar.gz" ]; then
printf 'OK\n'
else
printf 'FAILED\n'
rm -f "$MY_ROOT/hiawatha-$LATEST.tar.gz"
exit
fi
printf 'Unpacking ...'
tar -xzf "$MY_ROOT/hiawatha-$LATEST.tar.gz" >/dev/null
if [ $? -ne 0 ]; then
printf 'ERROR\n'
exit 1
fi
printf 'OK\n'
if [ ! -d "$MY_ROOT/hiawatha-$LATEST" ]; then
printf 'ERROR: hiawatha-%s directory not found.\n' "$LATEST"
exit 1
fi
EC=1
if [ "$(command -v dpkg)" ]; then
printf 'Compiling and packaging ...\n'
cd "$MY_ROOT/hiawatha-$LATEST/extra" || exit
"$MY_ROOT/hiawatha-$LATEST/extra/make_debian_package"
DEBPAK=$(ls -1 "$MY_ROOT/hiawatha-$LATEST/hiawatha_$LATEST"_*.deb 2>/dev/null | tail -n 1)
if [ ! -s "$DEBPAK" ]; then
printf '\nFAILED\n'
exit 1
fi
# stop hiawatha on supervised init
hiawatha_stop
printf 'Installing new %s ...\n' "${DEBPAK##*/}"
dpkg -i --force-all "$DEBPAK"
EC=$?
# start hiawatha after update
hiawatha_start
mv "$DEBPAK" "$MY_ROOT"
else
printf 'Cmake build ...\n'
mkdir build
cd build || exit
cmake ..
if [ $? -eq 0 ]; then
# stop hiawatha on supervised init
hiawatha_stop
printf 'Make install ...\n'
make install/strip
EC=$?
# start hiawatha after update
hiawatha_start
fi
fi
printf 'Removing temp files ...'
cd "$MY_ROOT" || exit
rm -rf "$MY_ROOT/hiawatha-$LATEST"
printf 'DONE\n'
if [ $EC -eq 0 ]; then
MSG="Hiawatha webserver successfully updated to v$LATEST."
else
MSG="Hiawatha webserver update to v$LATEST FAILED."
fi
printf '%s\n' "$MSG"
# Email results
if [ "$MAILTO" ]; then
printf '%s\n' "$MSG" | mail -s "$(hostname 2>/dev/null) (IP $(hostname -i 2>/dev/null)) - Hiawatha update v$LATEST" "$MAILTO"
fi
exit $EC