thumbor: Update to post v6.0
[dockerfile.git] / ngircd / setup-ngircd-config-from-environment.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2013-2014 W. Trevor King <wking@tremily.us>
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright notice, this
9 # list of conditions and the following disclaimer.
10 #
11 # * Redistributions in binary form must reproduce the above copyright notice,
12 # this list of conditions and the following disclaimer in the documentation
13 # and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26
27 # usage: DESCRIPTION="My IRC server" LOCATION="My attic" \
28 #        EMAIL="admin@example.net" INFO="testing, testing" \
29 #        setup-ngircd-config-from-environment
30
31 ENVSUBST='
32         ${HOSTNAME}
33         ${DESCRIPTION}
34         ${LOCATION}
35         ${EMAIL}
36         ${INFO}
37         '
38
39 if [ -n "${GLOBAL_PASSWORD}" ]
40 then
41         ENVSUBST="${ENVSUBST} \${GLOBAL_PASSWORD}"
42         # In lines matching '# Global password' or the two succeeding lines,
43         # replace ';Password = .*' with 'Password = ${GLOBAL_PASSWORD}'
44         sed -i '/# Global password/,+2 s/;Password = .*/Password = ${GLOBAL_PASSWORD}/' /etc/ngircd/ngircd.conf
45 fi
46
47 HOSTNAME=$(hostname -f) \
48         envsubst "${ENVSUBST}" < /etc/ngircd/ngircd.conf > /tmp/ngircd.conf &&
49 mv /tmp/ngircd.conf /etc/ngircd/ngircd.conf
50
51 if [ "${SSL}" = 'yes' ] || [ "${SSL}" = 'optional' ]
52 then
53         if [ "${SSL}" = 'optional' ]
54         then
55                 sed -i 's/;Ports = 6667.*/Ports = 6667/' /etc/ngircd/ngircd.conf
56         fi
57         sed -i \
58                 -e 's/;\[SSL\]/[SSL]/' \
59                 -e 's/;Ports = 6697, 9999/Ports = 6697/' \
60                 /etc/ngircd/ngircd.conf
61         if [ -f '/etc/ngircd/ssl/server-cert.pem' ]
62         then
63                 sed -i 's/;CertFile/CertFile/' /etc/ngircd/ngircd.conf
64         fi
65         if [ -f '/etc/ngircd/ssl/server-key.pem' ]
66         then
67                 sed -i 's/;KeyFile/KeyFile/' /etc/ngircd/ngircd.conf
68         fi
69         if [ -f '/etc/ngircd/ssl/dhparams.pem' ]
70         then
71                 sed -i 's/;DHFile/DHFile/' /etc/ngircd/ngircd.conf
72         fi
73 fi