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_CONF_DIR="/etc/monotone"
23MTN_HOOKS_DIR="${MTN_CONF_DIR}/hooks.d"
24MTN_KEY_DIR="${MTN_HOME}/keys"
25MTN_LOG_DIR="/var/log/monotone"
26MTN_RUN_DIR="/var/run/monotone"
27MAINLOG="${MTN_LOG_DIR}/mtn.log"
28ERRORLOG="${MTN_LOG_DIR}/error.log"
29
30locate_key()
31{
32 # This function attempts to locate the auto-generated keypair for the monotone-server.
33 # It may list multiple filenames, or none at all.
34 # Filenames are printed to standard out.
35 db_get monotone-server/key
36
37 if [ -d ${MTN_KEY_DIR} ]; then
38 find ${MTN_KEY_DIR} -type f -regextype posix-egrep -regex "${MTN_KEY_DIR}/${RET}(\.[0-9a-f]{40})?"
39 fi
40}
41
42delete_key()
43{
44 local KEY
45 local KEY_COUNT
46
47 KEY=`locate_key`
48 KEY_COUNT=`echo ${KEY} | wc -w`
49
50 if [ ${KEY_COUNT} -gt 1 ]; then
51 echo "Unable to determine auto-generated monotone-server keypair." >&2
52 echo "Please delete it manually from ${MTN_KEY_DIR}." >&2
53 elif [ ${KEY_COUNT} -eq 1 ]; then
54 rm -f "${KEY}"
55 fi
56}
57
58case "$1" in
59 purge)
60 # note: when executing in this mode, this script cannot assume
61 # the existence of _any_ of the package dependencies. it must
62 # work using only Essential packages. hence, in several cases
63 # below we do cleanups only if the relevant program exists.
64
65 # remove config files from ucf database and filesystem
66 for conf in write-permissions read-permissions serverrc; do
67
68 # mimic dpkg and remove backups too
69 for ext in '' '~' '%' .bak .ucf-new .ucf-old .ucf-dist; do
70 rm -f /etc/monotone/$conf$ext || true
71 done
72
73 # clear entries in ucf database
74 # note: we cannot assume ucf is still installed at this point
75 # (if it isn't, we don't need to worry about its database)
76 if which ucf > /dev/null; then
77 ucf --purge /etc/monotone/$conf
78 fi
79 if which ucfr > /dev/null; then
80 ucfr --purge monotone-server /etc/monotone/$conf
81 fi
82 done
83
84 # if debconf still exists and we were asked to auto-manage the
85 # database, delete the auto-generated key and database. don't
86 # delete anything else in /var/lib/monotone - there might be
87 # hand-created databases and keys that the admin wants to keep.
88 # in any case remove /var/lib/monotone(/keys) if empty.
89
90 if [ -e /usr/share/debconf/confmodule ]; then
91 . /usr/share/debconf/confmodule
92
93 db_get monotone-server/manage-db
94 if [ "$RET" = true ]; then
95 delete_key
96 rm -f ${MTN_HOME}/default.mtn
97 rm -f ${MTN_HOME}/default.mtn~
98 rm -f ${MTN_HOME}/default.mtn-journal
99
100 if [ -f /etc/monotone/passphrases ]; then
101 db_get monotone-server/key
102 grep -v "$RET" /etc/monotone/passphrases \
103 > /etc/monotone/passphrases.dpkg-new || true
104 if [ -s /etc/monotone/passphrases.dpkg-new ]; then
105 mv -f /etc/monotone/passphrases.dpkg-new \
106 /etc/monotone/passphrases
107 else
108 rm -f /etc/monotone/passphrases.dpkg-new \
109 /etc/monotone/passphrases
110 fi
111 fi
112 fi
113 # do not stop debconf, the debhelper additions will need it.
114 fi
115
116 if [ -d ${MTN_KEY_DIR} ]; then
117 rmdir --ignore-fail-on-non-empty ${MTN_KEY_DIR}
118 fi
119
120 if [ -d ${MTN_HOME} ]; then
121 rmdir --ignore-fail-on-non-empty ${MTN_HOME}
122 fi
123
124 if [ -d ${MTN_RUN_DIR} ]; then
125 rmdir --ignore-fail-on-non-empty ${MTN_RUN_DIR}
126 fi
127
128 # We only delete get_passphrase_from_file.lua if it is a symlink
129 # (as that is what the postinst script creates).
130 GET_PASSPHRASE_HOOK="${MTN_HOOKS_DIR}/get_passphrase_from_file.lua"
131 if [ -L ${GET_PASSPHRASE_HOOK} ]; then
132 rm ${GET_PASSPHRASE_HOOK}
133 fi
134
135 if [ -d ${MTN_HOOKS_DIR} ]; then
136 rmdir --ignore-fail-on-non-empty ${MTN_HOOKS_DIR}
137 fi
138
139 if [ -d ${MTN_CONF_DIR} ]; then
140 rmdir --ignore-fail-on-non-empty ${MTN_CONF_DIR}
141 fi
142
143 # delete log files if they exist
144 if [ -d ${MTN_LOG_DIR} ]; then
145 rm -f ${MAINLOG}
146 rm -f ${ERRORLOG}
147 rmdir --ignore-fail-on-non-empty ${MTN_LOG_DIR}
148 fi
149
150 # Create a list of paths that still exist and may contain files owned by the monotone
151 # user or group.
152 MTN_USED_PATHS=""
153 for MTN_USED_PATH in "${MTN_HOME}" "${MTN_CONF_DIR}" "${MTN_LOG_DIR}" "${MTN_RUN_DIR}"; do
154 if [ -d "${MTN_USED_PATH}" ]; then
155 MTN_USED_PATHS="${MTN_USED_PATHS:+${MTN_USED_PATHS}, }${MTN_USED_PATH}"
156 fi
157 done
158
159 # if deluser/delgroup exist, remove the server user and group.
160 # do not do this if /var/lib/monotone or /var/run/monotone still
161 # exists (so that it will still have a named user owning it).
162 if which deluser > /dev/null && [ -z "${MTN_USED_PATHS}" ]; then
163 if [ -n "`id -u monotone 2>/dev/null`" ]; then
164 deluser --quiet monotone 2>/dev/null >/dev/null
165 fi
166
167 if [ -n "`id -g monotone 2>/dev/null`" ]; then
168 delgroup --quiet monotone 2>/dev/null >/dev/null
169 fi
170 else
171 if [ -n "${MTN_USED_PATHS}" ]; then
172 reason="the following paths still exist: ${MTN_USED_PATHS}"
173 else
174 reason="deluser is not available"
175 fi
176 echo "warning: not deleting monotone user or group because $reason." >&2
177 fi
178
179 ;;
180 remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
181 ;;
182
183 *)
184 echo "postrm called with unknown argument \`$1'" >&2
185 exit 1
186
187esac
188
189# dh_installdeb will replace this with shell code automatically
190# generated by other debhelper scripts.
191
192#DEBHELPER#
193
194exit 0

Archive Download this file

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