monotone on Debian

monotone on Debian Mtn Source Tree

Root/monotone-server.postinst

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

Archive Download this file

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status