File: monotone-server.postinst

package info (click to toggle)
monotone 0.48-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 20,096 kB
  • ctags: 8,077
  • sloc: cpp: 81,000; sh: 6,402; perl: 1,241; lisp: 1,045; makefile: 655; python: 566; sql: 112; ansic: 52
file content (251 lines) | stat: -rw-r--r-- 8,037 bytes parent folder | download
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#! /bin/sh
# postinst script for monotone-server
#
# This script attempts to perform any db migrations neccessary during an
# upgrade.
#
# see: dh_installdeb(1)

set -e

# 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 http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

# source debconf stuff
. /usr/share/debconf/confmodule

MTN=/usr/bin/mtn

monotone_check_minimum_previous_version ()
{
    if dpkg --compare-versions "$MTN_VERSION" lt "0.17"; then
	# monotone version to old to automatically upgrade
	echo "Cannot automatically upgrade from monotone version $2." >&2
	echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2
	echo "information on manually upgrading your database." >&2
	false
    else
	true
    fi
}

monotone_migrate ()
{
    if dpkg --compare-versions "$MTN_VERSION" lt "0.46-1"; then
	# upgradable version of monotone
	echo "Attempting to migrate monotone database.  This may take a while..." >&2
	echo "A backup named '`basename $MTN_DB~`' will be created in $MTN_HOME." >&2

	cp $MTN_DB $MTN_DB~

	if $MTN --db=$MTN_DB db migrate --rcfile=$MTN_CONFDIR/hooks.lua \
	    --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR >&2; then
	    echo "Database successfully migrated." >&2
	    true
	else
	    echo "*** Error migrating database. ***" >&2
	    echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2
	    echo "information on manually upgrading your database." >&2
	    false
	fi
    else
	true
    fi
}

monotone_rosterify ()
{
    if dpkg --compare-versions "$MTN_VERSION" lt "0.26"; then
	# now we need to rosterify
	echo "Attempting to rosterify monotone database..." >&2

	if $MTN --db=$MTN_DB db rosterify --rcfile=$MTN_CONFDIR/hooks.lua \
	    --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR >&2; then
	    echo "Database successfully rosterified." >&2
	    true
	else
	    echo "*** Error rosterifying database. ***" >&2
	    echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2
	    echo "information on manually upgrading your database." >&2
	    false
	fi
    else
	true
    fi
}

monotone_regenerate_caches ()
{
    if dpkg --compare-versions "$MTN_VERSION" lt "0.31-90.1"; then
	# now we need to regenerate caches
	echo "Attempting to regenerate caches..." >&2

	if $MTN --db=$MTN_DB db regenerate_caches --rcfile=$MTN_CONFDIR/hooks.lua \
	    --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR >&2; then
	    echo "Caches successfully regenerated." >&2
	    true
	else
	    echo "*** Error regenerating roster. ***" >&2
	    echo "Please see UPGRADE and README.changesets in /usr/share/doc/monotone for" >&2
	    echo "information on manually upgrading your database." >&2
	    false
	fi
    else
	true
    fi
}

case "$1" in
    configure)

        # directory turned into symlink; give dpkg a hand
	if [ ! -L /usr/share/doc/monotone-server ] && \
	   [ -e /usr/share/doc/monotone-server ]; then
            rmdir /usr/share/doc/monotone-server
	    ln -sf monotone /usr/share/doc/monotone-server
	fi

       MTN_HOME=/var/lib/monotone
       MTN_DB=$MTN_HOME/default.mtn
       MTN_CONFDIR=/etc/monotone
       MTN_KEYDIR=$MTN_HOME/keys

       ucf --debconf-ok /usr/share/monotone/write-permissions.base /etc/monotone/write-permissions
       ucf --debconf-ok /usr/share/monotone/read-permissions.base /etc/monotone/read-permissions
       ucf --debconf-ok /usr/share/monotone/hooks.lua.base /etc/monotone/hooks.lua

       ucfr monotone-server /etc/monotone/write-permissions
       ucfr monotone-server /etc/monotone/read-permissions
       ucfr monotone-server /etc/monotone/hooks.lua

       # if this is our first install give config files correct permissions
       if [ -z "$2" ]; then
           # create monotone user and fix permissions of files
           if [ -z "`id -u monotone 2>/dev/null`" ]; then
	       adduser --system --group --home $MTN_HOME \
	       --no-create-home --disabled-password --quiet        \
	       --gecos "Monotone" monotone
           fi

           chown monotone:monotone $MTN_HOME
           chown monotone:monotone $MTN_CONFDIR
           chown monotone:monotone $MTN_KEYDIR
           chown monotone:monotone /var/log/monotone

           chmod 0750 $MTN_HOME
           chmod 0750 $MTN_CONFDIR
           chmod 0750 $MTN_KEYDIR

           chown monotone:monotone /etc/monotone/write-permissions
           chown monotone:monotone /etc/monotone/read-permissions
           chown monotone:monotone /etc/monotone/hooks.lua
           chmod 0640 /etc/monotone/write-permissions
           chmod 0640 /etc/monotone/read-permissions
           chmod 0640 /etc/monotone/hooks.lua
       fi

       db_get monotone-server/manage-db
       if [ "$RET" = "true" ]; then
           db_get monotone-server/key
           MTN_KEY=$RET

           # read our passphrase from a file
           if [ -e "$MTN_CONFDIR/passphrases" ]; then
               db_set monotone-server/passphrase "`grep "$MTN_KEY" $MTN_CONFDIR/passphrases | awk -F ' "|" "|" |"' '{print $2}'`"
           fi

           db_get monotone-server/passphrase
           MTN_KEY_PASSWD=$RET

           MTN_VERSION="$2"

           # Since we are configuring, we should check if we are upgrading.  If we are
           # upgrading, we should run the proper db migrate commands if necessary.

           if [ -z "$2" ]; then
              # not upgrading, fresh install

              # if there is no database, create one
              if [ ! -e $MTN_DB ]; then
                  echo "Creating Monotone database..." >&2
                  $MTN --db=$MTN_DB db init \
                     --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR

                  chmod 0600 $MTN_DB
                  chown monotone:monotone $MTN_DB

                  echo "Creating Monotone server keypair..." >&2

                  yes "$MTN_KEY_PASSWD" |
                     $MTN --db=$MTN_DB genkey $MTN_KEY --quiet \
                     --norc --keydir=$MTN_KEYDIR --confdir=$MTN_CONFDIR

                  chown monotone:monotone $MTN_HOME/keys/*

                  echo "Monotone database created successfully." >&2
              fi
	   else
	      set +e
	      monotone_check_minimum_previous_version && \
		 monotone_migrate && \
		 monotone_rosterify && \
		 monotone_regenerate_caches
	      set -e
           fi

           echo "$MTN_KEY \"$MTN_KEY_PASSWD\"" > $MTN_CONFDIR/passphrases
           chown monotone:monotone $MTN_CONFDIR/passphrases
           chmod 0400 $MTN_CONFDIR/passphrases
           db_set monotone-server/passphrase ""
       fi

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# stop debconf
db_stop

# Those using dependency based boot sequencing and installing
# monotone before version 0.44-2 would miss the runlevel 2 symlink.
# Recover from this.  Try not to mess with local configuration --
# look for the specific combination of S and K links that we
# know was wrong.

if [ "$1" = "configure" ] && dpkg --compare-versions "$2" le "0.44-2" \
   && [ -L /etc/rc0.d/K[0-9][0-9]monotone ] \
   && [ -L /etc/rc1.d/K[0-9][0-9]monotone ] \
   && [ -L /etc/rc2.d/[SK][0-9][0-9]monotone ] \
   && [ -L /etc/rc3.d/S[0-9][0-9]monotone ] \
   && [ -L /etc/rc4.d/S[0-9][0-9]monotone ] \
   && [ -L /etc/rc5.d/S[0-9][0-9]monotone ] \
   && [ -L /etc/rc6.d/K[0-9][0-9]monotone ]
then
   update-rc.d -f monotone remove
fi

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0