1 | #! /bin/sh␊ |
2 | # postinst script for monotone-server␊ |
3 | #␊ |
4 | # This script attempts to perform any db migrations neccessary during an␊ |
5 | # upgrade.␊ |
6 | #␊ |
7 | # see: dh_installdeb(1)␊ |
8 | ␊ |
9 | set -e␊ |
10 | ␊ |
11 | # summary of how this script can be called:␊ |
12 | # * <postinst> `configure' <most-recently-configured-version>␊ |
13 | # * <old-postinst> `abort-upgrade' <new version>␊ |
14 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package>␊ |
15 | # <new-version>␊ |
16 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'␊ |
17 | # <failed-install-package> <version> `removing'␊ |
18 | # <conflicting-package> <version>␊ |
19 | # for details, see http://www.debian.org/doc/debian-policy/ or␊ |
20 | # the debian-policy package␊ |
21 | #␊ |
22 | ␊ |
23 | # source debconf stuff␊ |
24 | . /usr/share/debconf/confmodule␊ |
25 | ␊ |
26 | MTN=/usr/bin/mtn␊ |
27 | ␊ |
28 | monotone_check_minimum_previous_version ()␊ |
29 | {␊ |
30 | if dpkg --compare-versions "$MTN_VERSION" lt "0.17"; then␊ |
31 | ␉# monotone version to old to automatically upgrade␊ |
32 | ␉echo "Cannot automatically upgrade from monotone version $2." >&2␊ |
33 | ␉echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2␊ |
34 | ␉echo "information on manually upgrading your database." >&2␊ |
35 | ␉false␊ |
36 | else␊ |
37 | ␉true␊ |
38 | fi␊ |
39 | }␊ |
40 | ␊ |
41 | monotone_migrate ()␊ |
42 | {␊ |
43 | if dpkg --compare-versions "$MTN_VERSION" lt "0.99-1"; then␊ |
44 | ␉# upgradable version of monotone␊ |
45 | ␉echo "Attempting to migrate monotone database. This may take a while..." >&2␊ |
46 | ␉echo "A backup named '`basename $MTN_DB~`' will be created in $MTN_HOME." >&2␊ |
47 | ␊ |
48 | ␉cp $MTN_DB $MTN_DB~␊ |
49 | ␊ |
50 | ␉if $MTN --db=$MTN_DB db migrate --rcfile=$MTN_CONFDIR/serverrc \␊ |
51 | ␉ --no-standard-rcfiles --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR \␊ |
52 | ␉ >&2; then␊ |
53 | ␉ echo "Database successfully migrated." >&2␊ |
54 | ␉ true␊ |
55 | ␉else␊ |
56 | ␉ echo "*** Error migrating database. ***" >&2␊ |
57 | ␉ echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2␊ |
58 | ␉ echo "information on manually upgrading your database." >&2␊ |
59 | ␉ false␊ |
60 | ␉fi␊ |
61 | else␊ |
62 | ␉true␊ |
63 | fi␊ |
64 | }␊ |
65 | ␊ |
66 | monotone_rosterify ()␊ |
67 | {␊ |
68 | if dpkg --compare-versions "$MTN_VERSION" lt "0.26"; then␊ |
69 | ␉# now we need to rosterify␊ |
70 | ␉echo "Attempting to rosterify monotone database..." >&2␊ |
71 | ␊ |
72 | ␉if $MTN --db=$MTN_DB db rosterify --rcfile=$MTN_CONFDIR/serverrc \␊ |
73 | ␉ --no-standard-rcfiles --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR \␊ |
74 | ␉ >&2; then␊ |
75 | ␉ echo "Database successfully rosterified." >&2␊ |
76 | ␉ true␊ |
77 | ␉else␊ |
78 | ␉ echo "*** Error rosterifying database. ***" >&2␊ |
79 | ␉ echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2␊ |
80 | ␉ echo "information on manually upgrading your database." >&2␊ |
81 | ␉ false␊ |
82 | ␉fi␊ |
83 | else␊ |
84 | ␉true␊ |
85 | fi␊ |
86 | }␊ |
87 | ␊ |
88 | monotone_regenerate_caches ()␊ |
89 | {␊ |
90 | if dpkg --compare-versions "$MTN_VERSION" lt "0.31-90.1"; then␊ |
91 | ␉# now we need to regenerate caches␊ |
92 | ␉echo "Attempting to regenerate caches..." >&2␊ |
93 | ␊ |
94 | ␉if $MTN --db=$MTN_DB db regenerate_caches --rcfile=$MTN_CONFDIR/serverrc \␊ |
95 | ␉ --no-standard-rcfiles --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR \␊ |
96 | ␉ >&2; then␊ |
97 | ␉ echo "Caches successfully regenerated." >&2␊ |
98 | ␉ true␊ |
99 | ␉else␊ |
100 | ␉ echo "*** Error regenerating roster. ***" >&2␊ |
101 | ␉ echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2␊ |
102 | ␉ echo "information on manually upgrading your database." >&2␊ |
103 | ␉ false␊ |
104 | ␉fi␊ |
105 | else␊ |
106 | ␉true␊ |
107 | fi␊ |
108 | }␊ |
109 | ␊ |
110 | case "$1" in␊ |
111 | configure)␊ |
112 | ␊ |
113 | # directory turned into symlink; give dpkg a hand␊ |
114 | ␉if [ ! -L /usr/share/doc/monotone-server ] && \␊ |
115 | ␉ [ -e /usr/share/doc/monotone-server ]; then␊ |
116 | rmdir /usr/share/doc/monotone-server␊ |
117 | ␉ ln -sf monotone /usr/share/doc/monotone-server␊ |
118 | ␉fi␊ |
119 | ␊ |
120 | MTN_HOME=/var/lib/monotone␊ |
121 | MTN_DB=$MTN_HOME/default.mtn␊ |
122 | MTN_CONFDIR=/etc/monotone␊ |
123 | MTN_KEYDIR=$MTN_HOME/keys␊ |
124 | ␊ |
125 | ucf --debconf-ok /usr/share/monotone/write-permissions.base $MTN_CONFDIR/write-permissions␊ |
126 | ucf --debconf-ok /usr/share/monotone/read-permissions.base $MTN_CONFDIR/read-permissions␊ |
127 | if [ -f $MTN_CONFDIR/hooks.lua -a ! -f $MTN_CONFDIR/serverrc ]; then␊ |
128 | ␉ ucf --debconf-ok /usr/share/monotone/serverrc.base $MTN_CONFDIR/hooks.lua␊ |
129 | ␉ mv $MTN_CONFDIR/hooks.lua $MTN_CONFDIR/serverrc␊ |
130 | # mimic dpkg and remove backups too␊ |
131 | for ext in '' '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do␊ |
132 | rm -f $MTN_CONFDIR/hooks.lua$ext || true␊ |
133 | done␊ |
134 | ␉ ucfr --purge monotone-server $MTN_CONFDIR/hooks.lua␊ |
135 | else␊ |
136 | ␉ ucf --debconf-ok /usr/share/monotone/serverrc.base $MTN_CONFDIR/serverrc␊ |
137 | fi␊ |
138 | ␊ |
139 | if [ ! -f $MTN_CONFDIR/hooks.d/get_passphrase_from_file.lua ]; then␊ |
140 | ␉ ln -s /usr/share/monotone/hooks/get_passphrase_from_file.lua $MTN_CONFDIR/hooks.d/␊ |
141 | fi␊ |
142 | ␊ |
143 | ucfr monotone-server $MTN_CONFDIR/write-permissions␊ |
144 | ucfr monotone-server $MTN_CONFDIR/read-permissions␊ |
145 | ucfr monotone-server $MTN_CONFDIR/serverrc␊ |
146 | ␊ |
147 | # if this is our first install give config files correct permissions␊ |
148 | if [ -z "$2" ]; then␊ |
149 | # create monotone user and fix permissions of files␊ |
150 | if [ -z "`id -u monotone 2>/dev/null`" ]; then␊ |
151 | ␉ adduser --system --group --home $MTN_HOME \␊ |
152 | ␉ --no-create-home --disabled-password --quiet \␊ |
153 | ␉ --gecos "Monotone" monotone␊ |
154 | fi␊ |
155 | ␊ |
156 | chown monotone:monotone $MTN_HOME␊ |
157 | chown monotone:monotone $MTN_CONFDIR␊ |
158 | chown monotone:monotone $MTN_KEYDIR␊ |
159 | chown monotone:monotone /var/log/monotone␊ |
160 | ␊ |
161 | chmod 0750 $MTN_HOME␊ |
162 | chmod 0750 $MTN_CONFDIR␊ |
163 | chmod 0750 $MTN_KEYDIR␊ |
164 | ␊ |
165 | chown monotone:monotone $MTN_CONFDIR/write-permissions␊ |
166 | chown monotone:monotone $MTN_CONFDIR/read-permissions␊ |
167 | chown monotone:monotone $MTN_CONFDIR/serverrc␊ |
168 | chmod 0640 $MTN_CONFDIR/write-permissions␊ |
169 | chmod 0640 $MTN_CONFDIR/read-permissions␊ |
170 | chmod 0640 $MTN_CONFDIR/serverrc␊ |
171 | fi␊ |
172 | ␊ |
173 | db_get monotone-server/manage-db␊ |
174 | if [ "$RET" = "true" ]; then␊ |
175 | db_get monotone-server/key␊ |
176 | MTN_KEY=$RET␊ |
177 | ␊ |
178 | # read our passphrase from a file␊ |
179 | if [ -e "$MTN_CONFDIR/passphrases" ]; then␊ |
180 | db_set monotone-server/passphrase "`grep "$MTN_KEY" $MTN_CONFDIR/passphrases | cut -f2 -d"\\""`"␊ |
181 | fi␊ |
182 | ␊ |
183 | db_get monotone-server/passphrase␊ |
184 | MTN_KEY_PASSWD=$RET␊ |
185 | ␊ |
186 | MTN_VERSION="$2"␊ |
187 | ␊ |
188 | # Since we are configuring, we should check if we are upgrading. If we are␊ |
189 | # upgrading, we should run the proper db migrate commands if necessary.␊ |
190 | ␊ |
191 | if [ -z "$2" ]; then␊ |
192 | # not upgrading, fresh install␊ |
193 | ␊ |
194 | # if there is no database, create one␊ |
195 | if [ ! -e $MTN_DB ]; then␊ |
196 | echo "Creating Monotone database..." >&2␊ |
197 | $MTN --db=$MTN_DB db init \␊ |
198 | --no-standard-rcfiles --keydir=$MTN_KEYDIR \␊ |
199 | --confdir=$MTN_CONFDIR␊ |
200 | ␊ |
201 | chmod 0600 $MTN_DB␊ |
202 | chown monotone:monotone $MTN_DB␊ |
203 | ␊ |
204 | echo "Creating Monotone server keypair..." >&2␊ |
205 | ␊ |
206 | yes "$MTN_KEY_PASSWD" |␊ |
207 | $MTN --db=$MTN_DB genkey $MTN_KEY --quiet \␊ |
208 | --no-standard-rcfiles --keydir=$MTN_KEYDIR \␊ |
209 | --confdir=$MTN_CONFDIR␊ |
210 | ␊ |
211 | chown monotone:monotone $MTN_HOME/keys/*␊ |
212 | ␊ |
213 | echo "Monotone database created successfully." >&2␊ |
214 | fi␊ |
215 | ␉ else␊ |
216 | ␉ set +e␊ |
217 | ␉ monotone_check_minimum_previous_version && \␊ |
218 | ␉␉ monotone_migrate && \␊ |
219 | ␉␉ monotone_rosterify && \␊ |
220 | ␉␉ monotone_regenerate_caches␊ |
221 | ␉ set -e␊ |
222 | fi␊ |
223 | ␊ |
224 | echo "$MTN_KEY \"$MTN_KEY_PASSWD\"" > $MTN_CONFDIR/passphrases␊ |
225 | chown monotone:monotone $MTN_CONFDIR/passphrases␊ |
226 | chmod 0400 $MTN_CONFDIR/passphrases␊ |
227 | db_set monotone-server/passphrase ""␊ |
228 | fi␊ |
229 | ␊ |
230 | ;;␊ |
231 | ␊ |
232 | abort-upgrade|abort-remove|abort-deconfigure)␊ |
233 | ␊ |
234 | ;;␊ |
235 | ␊ |
236 | *)␊ |
237 | echo "postinst called with unknown argument \`$1'" >&2␊ |
238 | exit 1␊ |
239 | ;;␊ |
240 | esac␊ |
241 | ␊ |
242 | # stop debconf␊ |
243 | db_stop␊ |
244 | ␊ |
245 | # Those using dependency based boot sequencing and installing␊ |
246 | # monotone before version 0.44-2 would miss the runlevel 2 symlink.␊ |
247 | # Recover from this. Try not to mess with local configuration --␊ |
248 | # look for the specific combination of S and K links that we␊ |
249 | # know was wrong.␊ |
250 | ␊ |
251 | if [ "$1" = "configure" ] && dpkg --compare-versions "$2" le "0.44-2" \␊ |
252 | && [ -L /etc/rc0.d/K[0-9][0-9]monotone ] \␊ |
253 | && [ -L /etc/rc1.d/K[0-9][0-9]monotone ] \␊ |
254 | && [ -L /etc/rc2.d/[SK][0-9][0-9]monotone ] \␊ |
255 | && [ -L /etc/rc3.d/S[0-9][0-9]monotone ] \␊ |
256 | && [ -L /etc/rc4.d/S[0-9][0-9]monotone ] \␊ |
257 | && [ -L /etc/rc5.d/S[0-9][0-9]monotone ] \␊ |
258 | && [ -L /etc/rc6.d/K[0-9][0-9]monotone ]␊ |
259 | then␊ |
260 | update-rc.d -f monotone remove␊ |
261 | fi␊ |
262 | ␊ |
263 | # dh_installdeb will replace this with shell code automatically␊ |
264 | # generated by other debhelper scripts.␊ |
265 | ␊ |
266 | #DEBHELPER#␊ |
267 | ␊ |
268 | exit 0␊ |
269 | ␊ |
270 | ␊ |