-
Notifications
You must be signed in to change notification settings - Fork 0
/
10-listen-on-ipv6-by-default.sh
executable file
·61 lines (49 loc) · 1.92 KB
/
10-listen-on-ipv6-by-default.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
#!/bin/sh
# vim:sw=4:ts=4:et
set -e
ME=$(basename $0)
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
# check if we have ipv6 available
if [ ! -f "/proc/net/if_inet6" ]; then
echo "$ME: error: ipv6 not available" 1>&2
exit 0
fi
if [ ! -f "/$DEFAULT_CONF_FILE" ]; then
echo "$ME: error: /$DEFAULT_CONF_FILE is not a file or does not exist" 1>&2
exit 0
fi
# check if the file can be modified, e.g. not on a r/o filesystem
touch /$DEFAULT_CONF_FILE 2>/dev/null || { echo "$ME: error: can not modify /$DEFAULT_CONF_FILE (read-only file system?)" 1>&2; exit 0; }
# check if the file is already modified, e.g. on a container restart
grep -q "listen \[::]\:80;" /$DEFAULT_CONF_FILE && { echo >&3 "$ME: error: IPv6 listen already enabled"; exit 0; }
if [ -f "/etc/os-release" ]; then
. /etc/os-release
else
echo "$ME: error: can not guess the operating system" 1>&2
exit 0
fi
echo >&3 "$ME: Getting the checksum of /$DEFAULT_CONF_FILE"
case "$ID" in
"debian")
CHECKSUM=$(dpkg-query --show --showformat='${Conffiles}\n' nginx | grep $DEFAULT_CONF_FILE | cut -d' ' -f 3)
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | md5sum -c - >/dev/null 2>&1 || {
echo "$ME: error: /$DEFAULT_CONF_FILE differs from the packaged version" 1>&2
exit 0
}
;;
"alpine")
CHECKSUM=$(apk manifest nginx 2>/dev/null| grep $DEFAULT_CONF_FILE | cut -d' ' -f 1 | cut -d ':' -f 2)
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | sha1sum -c - >/dev/null 2>&1 || {
echo "$ME: error: /$DEFAULT_CONF_FILE differs from the packages version" 1>&2
exit 0
}
;;
*)
echo "$ME: error: Unsupported distribution" 1>&2
exit 0
;;
esac
# enable ipv6 on default.conf listen sockets
sed -i -E 's,listen 80;,listen 80;\n listen [::]:80;,' /$DEFAULT_CONF_FILE
echo >&3 "$ME: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"
exit 0