monotone on Debian

monotone on Debian Mtn Source Tree

Root/monotone-server.postrm

1#! /bin/sh
2# vim: set ft=sh sw=4 et:
3# postrm script for #PACKAGE#
4#
5# see: dh_installdeb(1)
6
7set -e
8
9# summary of how this script can be called:
10# * <postrm> `remove'
11# * <postrm> `purge'
12# * <old-postrm> `upgrade' <new-version>
13# * <new-postrm> `failed-upgrade' <old-version>
14# * <new-postrm> `abort-install'
15# * <new-postrm> `abort-install' <old-version>
16# * <new-postrm> `abort-upgrade' <old-version>
17# * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
18# for details, see http://www.debian.org/doc/debian-policy/ or
19# the debian-policy package
20
21MTN_HOME="/var/lib/monotone"
22MTN_KEY_DIR="${MTN_HOME}/keys"
23MTN_LOG_DIR="/var/log/monotone"
24MAINLOG="${MTN_LOG_DIR}/mtn.log"
25ERRORLOG="${MTN_LOG_DIR}/error.log"
26
27locate_key()
28{
29 # This function attempts to locate the auto-generated keypair for the monotone-server.
30 # It may list multiple filenames, or none at all.
31 # Filenames are printed to standard out.
32 db_get monotone-server/key
33
34 if [ -d ${MTN_KEY_DIR} ]; then
35 find ${MTN_KEY_DIR} -type f -regextype posix-egrep -regex "${MTN_KEY_DIR}/${RET}(\.[0-9a-f]{40})?"
36 fi
37}
38
39delete_key()
40{
41 local KEY
42 local KEY_COUNT
43
44 KEY=`locate_key`
45 KEY_COUNT=`echo ${KEY} | wc -w`
46
47 if [ ${KEY_COUNT} -gt 1 ]; then
48 echo "Unable to determine auto-generated monotone-server keypair." >&2
49 echo "Please delete it manually from ${MTN_KEY_DIR}." >&2
50 elif [ ${KEY_COUNT} -eq 1 ]; then
51 rm -f "${KEY}"
52 fi
53}
54
55case "$1" in
56 purge)
57 # note: when executing in this mode, this script cannot assume
58 # the existence of _any_ of the package dependencies. it must
59 # work using only Essential packages. hence, in several cases
60 # below we do cleanups only if the relevant program exists.
61
62 # remove config files from ucf database and filesystem
63 for conf in write-permissions read-permissions hooks.lua; do
64
65 # mimic dpkg and remove backups too
66 for ext in '' '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do
67 rm -f /etc/monotone/$conf$ext || true
68 done
69
70 # clear entries in ucf database
71 # note: we cannot assume ucf is still installed at this point
72 # (if it isn't, we don't need to worry about its database)
73 if which ucf > /dev/null; then
74 ucf --purge /etc/monotone/$conf
75 fi
76 if which ucfr > /dev/null; then
77 ucfr --purge monotone-server /etc/monotone/$conf
78 fi
79 done
80
81 # if debconf still exists and we were asked to auto-manage the
82 # database, delete the auto-generated key and database. don't
83 # delete anything else in /var/lib/monotone - there might be
84 # hand-created databases and keys that the admin wants to keep.
85 # in any case remove /var/lib/monotone(/keys) if empty.
86
87 if [ -e /usr/share/debconf/confmodule ]; then
88 . /usr/share/debconf/confmodule
89
90 db_get monotone-server/manage-db
91 if [ "$RET" = true ]; then
92 delete_key
93 rm -f ${MTN_HOME}/default.mtn
94 rm -f ${MTN_HOME}/default.mtn~
95 rm -f ${MTN_HOME}/default.mtn-journal
96
97 if [ -f /etc/monotone/passphrases ]; then
98 db_get monotone-server/key
99 grep -v "$RET" /etc/monotone/passphrases \
100 > /etc/monotone/passphrases.dpkg-new || true
101 if [ -s /etc/monotone/passphrases.dpkg-new ]; then
102 mv -f /etc/monotone/passphrases.dpkg-new \
103 /etc/monotone/passphrases
104 else
105 rm -f /etc/monotone/passphrases.dpkg-new \
106 /etc/monotone/passphrases
107 fi
108 fi
109 fi
110 # do not stop debconf, the debhelper additions will need it.
111 fi
112
113 if [ -d ${MTN_KEY_DIR} ]; then
114 rmdir --ignore-fail-on-non-empty ${MTN_KEY_DIR}
115 fi
116
117 if [ -d ${MTN_HOME} ]; then
118 rmdir --ignore-fail-on-non-empty ${MTN_HOME}
119 fi
120
121 # if deluser/delgroup exist, remove the server user and group.
122 # do not do this if /var/lib/monotone still exists (so that it
123 # will still have a named user owning it).
124 if which deluser > /dev/null && [ ! -e ${MTN_HOME} ]; then
125 if [ -n "`id -u monotone 2>/dev/null`" ]; then
126 deluser --quiet monotone 2>/dev/null >/dev/null
127 fi
128
129 if [ -n "`id -g monotone 2>/dev/null`" ]; then
130 delgroup --quiet monotone 2>/dev/null >/dev/null
131 fi
132 else
133 if [ -e ${MTN_HOME} ]; then
134 reason="${MTN_HOME} still exists"
135 else
136 reason="deluser is not available"
137 fi
138 echo "warning: not deleting monotone user or group because $reason" >&2
139 fi
140
141 # delete log files if they exist
142 if [ -d ${MTN_LOG_DIR} ]; then
143 rm -f ${MAINLOG}
144 rm -f ${ERRORLOG}
145 rmdir --ignore-fail-on-non-empty ${MTN_LOG_DIR}
146 fi
147
148 ;;
149 remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
150 ;;
151
152 *)
153 echo "postrm called with unknown argument \`$1'" >&2
154 exit 1
155
156esac
157
158# dh_installdeb will replace this with shell code automatically
159# generated by other debhelper scripts.
160
161#DEBHELPER#
162
163exit 0

Archive Download this file

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