summaryrefslogtreecommitdiff
path: root/debian/openssh-client.preinst
diff options
context:
space:
mode:
Diffstat (limited to 'debian/openssh-client.preinst')
-rw-r--r--debian/openssh-client.preinst49
1 files changed, 49 insertions, 0 deletions
diff --git a/debian/openssh-client.preinst b/debian/openssh-client.preinst
new file mode 100644
index 000000000..0b29c051d
--- /dev/null
+++ b/debian/openssh-client.preinst
@@ -0,0 +1,49 @@
1#! /bin/sh -e
2
3ETC_SSH_MODULI=@ETC_SSH_MODULI@
4
5ETC_SSH_SSH_CONFIG=@ETC_SSH_SSH_CONFIG@
6
7action="$1"
8version="$2"
9
10prepare_transfer_conffile () {
11 CONFFILE="$1"
12 TEXT="$2"
13 MODE="$3"
14 [ "$CONFFILES" ] || return 0
15 [ -e "$CONFFILE" ] || return 0
16
17 md5sum="$(md5sum "$CONFFILE" |sed -e 's/ .*//')"
18 old_md5sum="$(echo "$CONFFILES" | awk '$1 == "'"$CONFFILE"'" { print $2 }')"
19 if [ "$md5sum" = "$old_md5sum" ]; then
20 echo >&2 "Transferring ownership of conffile $CONFFILE ..."
21 # We have to write out the desired new text of the conffile,
22 # which is tricky in the preinst, hence the nasty way we
23 # have to hardcode the text here. Fortunately, this is only
24 # necessary with sarge's dpkg and older.
25 if echo "$TEXT" | head -n1 | grep -q '^@.*@$'; then
26 echo >&2 'Unsubstituted conffile text! Please report this bug.'
27 exit 1
28 fi
29 printf '%s' "$TEXT" >"$CONFFILE.dpkg-new"
30 chmod "$MODE" "$CONFFILE.dpkg-new"
31 mv -f "$CONFFILE" "$CONFFILE.moved-by-preinst"
32 mv -f "$CONFFILE.dpkg-new" "$CONFFILE"
33 return 0
34 fi
35}
36
37case $action in
38 install|upgrade)
39 if dpkg --compare-versions "$version" lt 0; then
40 CONFFILES="$(dpkg-query -W -f '${Conffiles}\n' ssh 2>/dev/null | sed 's/^ *//')"
41 prepare_transfer_conffile /etc/ssh/moduli "$ETC_SSH_MODULI" 0644
42 prepare_transfer_conffile /etc/ssh/ssh_config "$ETC_SSH_SSH_CONFIG" 0644
43 fi
44 ;;
45esac
46
47#DEBHELPER#
48
49exit 0