/
postinst
201 lines (164 loc) · 6.58 KB
/
postinst
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#! /bin/sh
# postinst script for foswiki
#
# see: dh_installdeb(1)
# not www-data. remember to sync with rules.
WIKI_OWNER=www-data
set -e
# Source debconf library.
. /usr/share/debconf/confmodule
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see /usr/share/doc/packaging-manual/
#
# quoting from the policy:
# Any necessary prompting should almost always be confined to the
# post-installation script, and should be protected with a conditional
# so that unnecessary prompting doesn't happen if a package's
# installation fails and the `postinst' is called with `abort-upgrade',
# `abort-remove' or `abort-deconfigure'.
db_get foswiki/samplefiles
if [ "$RET" = true ]; then
#upgrade topics - because we don't ship ,v files, I can use find&sed to make a list of all files that have no ,v,
#and then exclude them from the un-tar
echo
echo Upgrading distributed topics and attachments - skipping files changed via the Foswiki
echo see /var/log/foswiki/exclude-topics.lst and /var/log/foswiki/exclude-attachments.lst
echo
find /var/lib/foswiki/data -name '*,v' | sed 's/^\///g' | sed 's/,v$//g' > /var/log/foswiki/exclude-topics.lst
tar -zx -C / --exclude-from=/var/log/foswiki/exclude-topics.lst -f /usr/share/foswiki/foswiki-data.tar.gz
find /var/lib/foswiki/pub -name '*,v' | sed 's/^\///g' | sed 's/,v$//g' > /var/log/foswiki/exclude-attachments.lst
tar -zx -C / --exclude-from=/var/log/foswiki/exclude-attachments.lst -f /usr/share/foswiki/foswiki-pub.tar.gz
# clean up the .mailnotify timestamps.
webs="Main Sandbox System Trash _default";
for web in $webs; do
date +%s > /var/lib/foswiki/data/$web/.mailnotify
done
fi
db_get foswiki/defaultUrlHost
# be more robust later:
perl -pi~ -e '$U=q{'"$RET"'}; s{http://your.domain.com}{$U}g;' /etc/foswiki/LocalSite.cfg
perl -pi~ -e '$U=q{'"$RET"'}; s{http://your.domain.com}{$U}g;' /etc/foswiki/apache.conf
#remove the double //bin caused by putting a / at the end of the hostUrl
perl -pi~ -e 's{/(/bin)}{$1}g;' /etc/foswiki/apache.conf
rm /etc/foswiki/*~
db_get foswiki/wikiwebmaster
perl -pi~ -e '$U=q{'"$RET"'}; s{WEBMASTEREMAIL}{$U}g;' /etc/foswiki/LocalSite.cfg
# user + password authorized to run configure script
db_get foswiki/adminuser
configuser="$RET"
perl -pi~ -e '$U=q{'"$RET"'}; s/^([^#]*Require user).*/$1 $U/g;' /etc/foswiki/apache.conf
db_get foswiki/adminpassword
configpassword="$RET"
#upgrade from 1.0 to 1.1
#remove ZonePlugin
perl -pi~ -e 's{^.*ZonePlugin.*$}{}g;' /etc/foswiki/LocalSite.cfg
#update JQueryPlugin to use 1.4.3
perl -pi~ -e 's{jquery-1.\d*.\d*}{jquery-1.4.3}g;' /etc/foswiki/LocalSite.cfg
# prevent further confusion: done with debconfig
# regrettably, this doesn't actually permit us to do further I/O.
# Rewrite this in perl, if we ever find a non-kerberos example of how
# to do so.
case "$1" in
configure)
#note that only apache2 really seems to exist in Etch etc, but the others I've left for historical reasons
servers="apache apache-perl apache-ssl apache2"
for server in $servers; do
if [ `which $server` ]; then
if [ -e /etc/$server/conf.d ]; then
includefile=/etc/foswiki/apache.conf
if [ -e /etc/$server/conf.d/foswiki.conf ]; then
rm -f /etc/foswiki/$server-conf.d-foswiki.conf_old
mv /etc/$server/conf.d/foswiki.conf /etc/foswiki/$server-conf.d-foswiki.conf_old
fi
ln -s $includefile /etc/$server/conf.d/foswiki.conf
if [ $server = "apache2" ]; then
a2enmod authn_file || a2enmod auth_plain || true
a2enmod rewrite
else
apache-modconf $server enable authn_file
apache-modconf $server enable rewrite
fi
fi
fi
done
#add apache2 cgi
if [ -e /etc/apache2/mods-available/cgi.load ]; then
if [ ! -e /etc/apache2/mods-enabled/cgi.load ]; then
ln -s /etc/apache2/mods-available/cgi.load /etc/apache2/mods-enabled/cgi.load
fi
fi
# create initial htpasswd, if needed
if [ -e /var/lib/foswiki/data ]; then
#for now prefer apache 1 config, I don't know how to detect which one is prefered
if [ -e /usr/bin/htpasswd2 ]; then
HTPASSWDCMD="/usr/bin/htpasswd2";
fi
if [ -e /usr/bin/htpasswd ]; then
HTPASSWDCMD="/usr/bin/htpasswd";
fi
if [ -e $HTPASSWDCMD ]; then
#if the user has installed without initial universe then we can't do this
if [ ! -e /var/lib/foswiki/data/.htpasswd ]; then
touch /var/lib/foswiki/data/.htpasswd
chmod 660 /var/lib/foswiki/data/.htpasswd
fi
$HTPASSWDCMD -b /var/lib/foswiki/data/.htpasswd "$configuser" "$configpassword"
chown $WIKI_OWNER.www-data /var/lib/foswiki/data/.htpasswd
#add the same password into the LocalLib.cfg
passwordhash=`grep "$configuser" /var/lib/foswiki/data/.htpasswd | sed "s/$configuser://"`
perl -pi~ -e '$U=q{'"$passwordhash"'}; s{PASSWORD}{$U}g;' /etc/foswiki/LocalSite.cfg
fi
fi
#create securer-foswiki session dir
if [ ! -e /var/lib/foswiki/working ]; then
mkdir /var/lib/foswiki/working
fi
chown $WIKI_OWNER.www-data /var/lib/foswiki/working
if [ ! -e /var/lib/foswiki/working/work_areas ]; then
mkdir /var/lib/foswiki/working/work_areas
fi
chown $WIKI_OWNER.www-data /var/lib/foswiki/working/work_areas
#mmmm, mailnotify etc may be running _not_ as www-data
#and for some reason create a session
#use 1777 to prevent third parties replacing the file with a doctored one
if [ ! -e /var/lib/foswiki/log ]; then
ln -s /var/log/foswiki /var/lib/foswiki/log
fi
chown -R $WIKI_OWNER.www-data /var/log/foswiki
chmod -R 755 /var/log/foswiki
chown $WIKI_OWNER.www-data /etc/foswiki/LocalSite.cfg
chown -R $WIKI_OWNER.www-data /var/lib/foswiki
chown -R $WIKI_OWNER.www-data /var/lib/foswiki/locale
chown -R $WIKI_OWNER.www-data /var/lib/foswiki/templates
chown -R $WIKI_OWNER.www-data /var/lib/foswiki/tools
db_stop
# reload apache configs
for server in $servers; do
if [ -e /etc/init.d/$server ]; then
echo reloading $server config
if which invoke-rc.d >/dev/null 2>&1 ; then
invoke-rc.d $server reload
else
/etc/init.d/$server reload
fi
fi
done
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0