File: bit-babbler.postinst

package info (click to toggle)
bit-babbler 0.8
  • links: PTS
  • area: main
  • in suites: buster, sid
  • size: 1,900 kB
  • sloc: cpp: 10,297; sh: 4,301; perl: 1,017; ansic: 1,013; makefile: 84
file content (106 lines) | stat: -rw-r--r-- 3,791 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
#!/bin/sh

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>
#        * <postinst> `abort-remove'
#        * <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


migrate_seedd_conf()
{
    local oldconf='/etc/default/seedd'
    local newconf='/etc/bit-babbler/seedd.conf'
    local saveconf="${oldconf}.dpkg-old"

    # Remove the old config if it was unmodified
    rm -f "${oldconf}.dpkg-remove"

    # Otherwise, if it's still there and we still own it, let's convert it.
    [ -e "$oldconf" ] || return 0
    dpkg-query -L bit-babbler | grep -F -q -x "$oldconf" || return 0

    # Preserve the new config file that was shipped with the package, in the
    # same way as if the user had chosen "keep my local changes" at the dpkg
    # conffile update prompt.  Except for this we keep them without prompting.
    [ ! -e "$newconf" ] || mv -f "$newconf" "${newconf}.dpkg-new"

    # Simulate how the old config was converted to command line options in the
    # init script, then generate a new format config file using those options.
    # Pretend we were invoked by systemd for that, since the new init script
    # will itself add the needed options which that would omit.
    (
      SEEDD_ARGS="-k"
      . "$oldconf"
      [ -z "$CONTROL_GROUP" ] || SEEDD_ARGS="$SEEDD_ARGS --socket-group $CONTROL_GROUP"

      export NOTIFY_SOCKET=@dummy

      cat > "$newconf" <<-EOF
	# These options were automatically migrated from $oldconf
	# during upgrade to the bit-babbler 0.8 (or later) release.
	#
	# A copy of the old file has been preserved in $saveconf
	# which can safely be deleted now after confirming that there is nothing
	# remaining in it which you do wish to retain a copy of.
	#
	# This file can safely be edited to customise the seedd configuration, it will
	# not be automatically (re)generated again after the initial conversion of the
	# old configuration file has created it.

	EOF

      if /usr/bin/seedd --gen-conf $SEEDD_ARGS >> "$newconf" 2>/dev/null; then
	# Preserve a copy of their old config.  We migrated anything which was
	# actively being used by the old init script, but there may be comments
	# or commented out configurations, or other things which it would be a
	# bit rude of us to just completely delete without asking.
	cat - "$oldconf" > "$saveconf" <<-EOF
		# NOTE: This file contains the last content from $oldconf
		#       prior to it being converted into the new $newconf
		#
		#       It may safely be deleted if there is nothing else in it which you wish
		#       to retain.  The seedd configuration uses options from the new file now
		#       and there is nothing which still uses anything from the old one at all.

	EOF

	rm -f "$oldconf"
	echo "Automatically migrated $oldconf configuration to $newconf"
	echo "The previous configuration file was saved to $saveconf"
      fi
    )
}

case "$1" in
    configure)
	addgroup --quiet --system bit-babbler
	sysctl -q -p /etc/sysctl.d/bit-babbler-sysctl.conf || true

	# Version 0.8 adds /etc/bit-babbler/seedd.conf, replacing the previous
	# daemon configuration options which were set in /etc/default/seedd.
	dpkg --compare-versions -- "$2" ge-nl '0.8~' || migrate_seedd_conf
    ;;

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

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

#DEBHELPER#

exit 0

# vi:sts=4:sw=4:noet