148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
1 |
#!/bin/bash
|
2 |
# postinst script for libravatar-www
|
|
3 |
#
|
|
4 |
# see: dh_installdeb(1)
|
|
5 |
||
6 |
set -e
|
|
7 |
||
8 |
# summary of how this script can be called:
|
|
9 |
# * <postinst> `configure' <most-recently-configured-version>
|
|
10 |
# * <old-postinst> `abort-upgrade' <new version>
|
|
11 |
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
|
|
12 |
# <new-version>
|
|
13 |
# * <postinst> `abort-remove'
|
|
14 |
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
|
|
15 |
# <failed-install-package> <version> `removing'
|
|
16 |
# <conflicting-package> <version>
|
|
17 |
# for details, see http://www.debian.org/doc/debian-policy/ or
|
|
18 |
# the debian-policy package
|
|
19 |
||
20 |
. /usr/share/debconf/confmodule |
|
21 |
||
22 |
set_dbconfig () { |
|
294
by Francois Marier
Fix the last (hopefully) quoting issues with set_config() |
23 |
perl -i -e '$field=shift;$value=shift if (scalar(@ARGV)>1);$value||="";while (<>) { s/^\s*("$field"\s*:\s*).*/$1"$value",/; print; }' "$1" "$2" "$3"; |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
24 |
}
|
25 |
||
26 |
set_config () { |
|
294
by Francois Marier
Fix the last (hopefully) quoting issues with set_config() |
27 |
perl -i -e '$field=shift;$value=shift if (scalar(@ARGV)>1);$value||="";while (<>) { s/^\s*($field\s*=\s*).*/$1"$value"/; print; }' "$1" "$2" "$3"; |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
28 |
}
|
29 |
||
235
by Francois Marier
Move settings.py to /etc/libravatar/ since it's a config file |
30 |
SETTINGS_PY=/etc/libravatar/settings.py |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
31 |
AVATAR_ROOT=/var/lib/libravatar/avatar |
269
by Francois Marier
Add gearman support for cropping/resizing photos |
32 |
READY_FILES_ROOT=/var/lib/libravatar/ready |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
33 |
UPLOADED_FILES_ROOT=/var/lib/libravatar/uploaded |
188
by Francois Marier
Create a new directory for cropped files ("user" files) |
34 |
USER_FILES_ROOT=/var/lib/libravatar/user |
392.1.1
by Francois Marier
Initial dummy export of user accounts |
35 |
EXPORT_FILES_ROOT=/var/lib/libravatar/export |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
36 |
APACHE_CONFIG=/etc/libravatar/www.apache2.conf |
579
by Francois Marier
Add templated rules.abe files for www, cdn and seccdn (bug #769738) |
37 |
RULES_ABE=/usr/share/libravatar/libravatar/rules.abe |
700
by Francois Marier
awstats: add a config file for www (bug #904468) |
38 |
AWSTATS_CONFIG=/etc/libravatar/awstats.www.conf |
39 |
AWSTATS_DIR=/var/lib/awstats/www |
|
40 |
||
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
41 |
|
42 |
case "$1" in |
|
43 |
configure)
|
|
44 |
cp /usr/share/libravatar/libravatar/settings.py.example ${SETTINGS_PY} |
|
45 |
||
46 |
# Add config entries to $SETTINGS_PY based on answers to debconf questions
|
|
47 |
db_get libravatar-www/db_host |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
48 |
set_dbconfig HOST "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
49 |
|
50 |
db_get libravatar-www/db_port |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
51 |
set_dbconfig PORT "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
52 |
|
53 |
db_get libravatar-www/db_name |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
54 |
set_dbconfig NAME "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
55 |
|
56 |
db_get libravatar-www/db_user |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
57 |
set_dbconfig USER "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
58 |
|
59 |
db_get libravatar-www/db_pass |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
60 |
set_dbconfig PASSWORD "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
61 |
|
62 |
db_get libravatar-common/cdnservername |
|
938.1.8
by Francois Marier
Add trailing slash to *MEDIA_URL |
63 |
set_config MEDIA_URL "http://${RET}/" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
64 |
|
65 |
db_get libravatar-common/seccdnservername |
|
66 |
VALUE=${RET} |
|
67 |
if [ "z${VALUE}" = "z" ] ; then |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
68 |
set_config SECURE_MEDIA_URL "" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
69 |
else
|
938.1.8
by Francois Marier
Add trailing slash to *MEDIA_URL |
70 |
set_config SECURE_MEDIA_URL "https://${VALUE}/" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
71 |
fi
|
72 |
||
73 |
db_get libravatar-common/wwwservername |
|
547
by Francois Marier
libravatar-www: the SITE_URL needs to be on HTTPS |
74 |
set_config SITE_URL "https://${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
75 |
|
76 |
db_get libravatar-www/sitename |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
77 |
set_config SITE_NAME "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
78 |
|
79 |
db_get libravatar-www/fromemail |
|
363
by Francois Marier
settings: Replace FROM_ADDRESS with SERVER_EMAIL |
80 |
set_config SERVER_EMAIL "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
81 |
|
82 |
db_get libravatar-www/supportemail |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
83 |
set_config SUPPORT_EMAIL "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
84 |
|
364
by Francois Marier
settings: add new ADMIN_EMAIL option to receive site errors |
85 |
db_get libravatar-www/adminemail |
86 |
set_config ADMIN_EMAIL "${RET}" ${SETTINGS_PY} |
|
87 |
||
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
88 |
db_get libravatar-www/secretkey |
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
89 |
set_config SECRET_KEY "${RET}" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
90 |
|
291
by Francois Marier
Change quoting in set_config() to allow single quotes in config values |
91 |
set_config AVATAR_ROOT "${AVATAR_ROOT}/" ${SETTINGS_PY} |
92 |
set_config READY_FILES_ROOT "${READY_FILES_ROOT}/" ${SETTINGS_PY} |
|
93 |
set_config UPLOADED_FILES_ROOT "${UPLOADED_FILES_ROOT}/" ${SETTINGS_PY} |
|
94 |
set_config USER_FILES_ROOT "${USER_FILES_ROOT}/" ${SETTINGS_PY} |
|
392.1.1
by Francois Marier
Initial dummy export of user accounts |
95 |
set_config EXPORT_FILES_ROOT "${EXPORT_FILES_ROOT}/" ${SETTINGS_PY} |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
96 |
|
269
by Francois Marier
Add gearman support for cropping/resizing photos |
97 |
# Create a restricted user to crop/resize images with
|
297
by Francois Marier
Hide adduser warnings |
98 |
adduser --system --quiet --disabled-login --shell /bin/false --no-create-home --home ${READY_FILES_ROOT} --gecos 'Libravatar Image Processor,,,' libravatar-img || true |
269
by Francois Marier
Add gearman support for cropping/resizing photos |
99 |
|
100 |
mkdir -p ${READY_FILES_ROOT} |
|
275
by Francois Marier
Add a gearman worker script to delete photos |
101 |
chown -R libravatar-img:root ${READY_FILES_ROOT} |
269
by Francois Marier
Add gearman support for cropping/resizing photos |
102 |
chmod o-rwx ${READY_FILES_ROOT} |
103 |
||
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
104 |
mkdir -p ${UPLOADED_FILES_ROOT} |
105 |
chown -R www-data:www-data ${UPLOADED_FILES_ROOT} |
|
106 |
||
188
by Francois Marier
Create a new directory for cropped files ("user" files) |
107 |
mkdir -p ${USER_FILES_ROOT} |
275
by Francois Marier
Add a gearman worker script to delete photos |
108 |
chown -R root:root ${USER_FILES_ROOT} |
188
by Francois Marier
Create a new directory for cropped files ("user" files) |
109 |
|
392.1.1
by Francois Marier
Initial dummy export of user accounts |
110 |
mkdir -p ${EXPORT_FILES_ROOT} |
111 |
chown -R root:root ${EXPORT_FILES_ROOT} |
|
112 |
||
463
by Francois Marier
Move js and css to -www and split images between -www and -cdn-common |
113 |
mkdir -p ${AVATAR_ROOT} |
114 |
||
388
by Francois Marier
Gearman workers now log warnings and errors to a file |
115 |
touch /var/log/libravatar/workers.log |
116 |
chown libravatar-img /var/log/libravatar/workers.log |
|
117 |
||
579
by Francois Marier
Add templated rules.abe files for www, cdn and seccdn (bug #769738) |
118 |
# Make a copy of the template rules.abe to work on, then copy into place
|
119 |
cp ${RULES_ABE}.template ${RULES_ABE}.working |
|
120 |
||
121 |
for MARKER in $(grep -o -E '__[A-Z0-9_]+__' ${RULES_ABE}.working); do |
|
122 |
# Turns __MARKER__ into marker and puts packagename/ on the front
|
|
123 |
DEBCONF_VAR=$(echo "${MARKER:2:${#MARKER}-4}" | tr '[:upper:]' '[:lower:]') |
|
124 |
db_get libravatar-common/$DEBCONF_VAR
|
|
125 |
sed -i -e "s/${MARKER}/${RET}/g" ${RULES_ABE}.working |
|
126 |
done
|
|
127 |
||
128 |
mv ${RULES_ABE}.working ${RULES_ABE} |
|
129 |
||
700
by Francois Marier
awstats: add a config file for www (bug #904468) |
130 |
# Make a copy of the templates to work on, then copy into place
|
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
131 |
cp ${APACHE_CONFIG} ${APACHE_CONFIG}.working |
700
by Francois Marier
awstats: add a config file for www (bug #904468) |
132 |
cp ${AWSTATS_CONFIG} ${AWSTATS_CONFIG}.working |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
133 |
|
737
by Francois Marier
Add optional ServerAlias directives in Apache config files |
134 |
for MARKER in __WWWSERVERALIAS__ __CDNSERVERALIAS__ __SECCDNSERVERALIAS__ ; do |
135 |
# Turns __MARKER__ into marker and puts packagename/ on the front
|
|
136 |
DEBCONF_VAR=$(echo "${MARKER:2:${#MARKER}-4}" | tr '[:upper:]' '[:lower:]') |
|
137 |
||
138 |
db_get libravatar-common/$DEBCONF_VAR
|
|
139 |
VALUE=${RET} |
|
140 |
if [ "z${VALUE}" = "z" ] ; then |
|
141 |
sed -i -e "s/${MARKER}//g" ${APACHE_CONFIG}.working |
|
142 |
else
|
|
143 |
sed -i -e "s/${MARKER}/ServerAlias ${RET}/g" ${APACHE_CONFIG}.working |
|
144 |
fi
|
|
145 |
done
|
|
146 |
||
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
147 |
for MARKER in $(grep -o -E '__[A-Z0-9_]+__' ${APACHE_CONFIG}.working); do |
148 |
# Turns __MARKER__ into marker and puts packagename/ on the front
|
|
149 |
DEBCONF_VAR=$(echo "${MARKER:2:${#MARKER}-4}" | tr '[:upper:]' '[:lower:]') |
|
150 |
db_get libravatar-common/$DEBCONF_VAR
|
|
151 |
sed -i -e "s/${MARKER}/${RET}/g" ${APACHE_CONFIG}.working |
|
152 |
done
|
|
700
by Francois Marier
awstats: add a config file for www (bug #904468) |
153 |
for MARKER in $(grep -o -E '__[A-Z0-9_]+__' ${AWSTATS_CONFIG}.working); do |
154 |
# Turns __MARKER__ into marker and puts packagename/ on the front
|
|
155 |
DEBCONF_VAR=$(echo "${MARKER:2:${#MARKER}-4}" | tr '[:upper:]' '[:lower:]') |
|
156 |
db_get libravatar-common/$DEBCONF_VAR
|
|
157 |
sed -i -e "s/${MARKER}/${RET}/g" ${AWSTATS_CONFIG}.working |
|
158 |
done
|
|
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
159 |
|
160 |
# Enable apache modules we want unconditionally
|
|
161 |
a2enmod alias > /dev/null 2>&1 |
|
150
by Francois Marier
Make use of mod_expires in the Apache config we ship |
162 |
a2enmod expires > /dev/null 2>&1 |
244
by Francois Marier
Make sure mod_headers is enabled |
163 |
a2enmod headers > /dev/null 2>&1 |
164 |
a2enmod rewrite > /dev/null 2>&1 |
|
664
by Francois Marier
Enable mod_ssl after installing libravatar-www |
165 |
a2enmod ssl > /dev/null 2>&1 |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
166 |
a2enmod wsgi > /dev/null 2>&1 |
167 |
||
168 |
# We a2ensite the site the first time the config is installed, but not after
|
|
169 |
ENABLE_SITE="" |
|
938
by Francois Marier
Update libravatar-www maintainer scripts for jessie |
170 |
if [ ! -e /etc/apache2/sites-available/libravatar-www.conf ]; then |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
171 |
ENABLE_SITE="true" |
172 |
fi
|
|
173 |
||
938
by Francois Marier
Update libravatar-www maintainer scripts for jessie |
174 |
mv ${APACHE_CONFIG}.working /etc/apache2/sites-available/libravatar-www.conf |
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
175 |
|
176 |
if [ "$ENABLE_SITE" != "" ]; then |
|
177 |
a2ensite libravatar-www |
|
178 |
fi
|
|
179 |
||
180 |
echo "" |
|
181 |
echo "Libravatar is now ready for action. You need to restart apache for any" |
|
182 |
echo "configuration changes to take effect" |
|
183 |
echo "" |
|
700
by Francois Marier
awstats: add a config file for www (bug #904468) |
184 |
|
185 |
mkdir -p /etc/awstats |
|
186 |
mv ${AWSTATS_CONFIG}.working /etc/awstats/awstats.www.conf |
|
187 |
||
188 |
mkdir -p ${AWSTATS_DIR} |
|
189 |
chown www-data:www-data ${AWSTATS_DIR} |
|
148
by Francois Marier
Basic working Debian packaging, ready to be deployed |
190 |
;;
|
191 |
||
192 |
abort-upgrade|abort-remove|abort-deconfigure) |
|
193 |
;;
|
|
194 |
||
195 |
*)
|
|
196 |
echo "postinst called with unknown argument \`$1'" >&2 |
|
197 |
exit 1 |
|
198 |
;;
|
|
199 |
esac
|
|
200 |
||
201 |
# dh_installdeb will replace this with shell code automatically
|
|
202 |
# generated by other debhelper scripts.
|
|
203 |
||
204 |
#DEBHELPER#
|
|
205 |
||
206 |
db_stop |
|
207 |
exit 0 |