File: postinst

package info (click to toggle)
rng-tools 5migrate1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 76 kB
  • sloc: sh: 22; makefile: 11
file content (151 lines) | stat: -rw-r--r-- 4,636 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
#!/bin/mksh

set -e

# This maintainer script can be called the following ways:
#
# * new-postinst "configure" [$most_recently_configured_version]
# The package is unpacked; all dependencies are unpacked and, when there
# are no circular dependencies, configured.
#
# * old-postinst "abort-upgrade" $new_version
# * old-postinst "abort-remove"
# * conflictors-postinst "abort-remove" "in-favour" $new_package
#	$new_version
# * deconfigureds-postinst "abort-deconfigure" "in-favour"
#	$failed_install_package $fip_version		# new-package
#	["removing" $conflicting_package $cp_version]	# old-package
# The package is unpacked; all dependencies are at least Half-Installed,
# previously been configured, and not removed. In some error situations,
# dependencies may not be even fully unpacked.
#
# * postinst "triggered" "${triggers[*]}"
# For trigger-only calls, i.e. if "configure" is not called.
#
# * new-postinst "reconfigure" [$most_recently_configured_version](?)
# Treat this as just like "configure" for a future extension by debconf.

function stripcomments {
	set -o noglob
	while read _line; do
		_line=${_line%%#*}
		[[ -z $_line ]] || print -r -- $_line
	done
}

didmigrate=0
function domigrate {
	local m m1=$1 m2=$2 p=$3

	[[ -e $p ]] || return 0
	(( didmigrate )) || print -ru2 "I: rng-tools: migrating old conffiles"
	m=$(md5sum <"$p")
	if [[ $m = "$m1"* || $m = "$m2"* ]]; then
		# identical to shipped files, 2-unofficial-mt.14-1 or 5-1
		(( didmigrate |= 1 ))
		rm -- "$p"
		return 0
	fi
	m=$(stripcomments <"$p")
	if [[ -z $m ]]; then
		# empty, other than, perhaps, comments
		(( didmigrate |= 1 ))
		rm -- "$p"
		return 0
	fi
	mv -- "$p" "$p.dpkg-bak"
	p=$p.dpkg-bak
	if [[ $p != /etc/default/rng-tools.dpkg-bak ]]; then
		(( didmigrate |= 2 ))
		print -ru2 "W: local changes saved as ${p@Q}"
		return 0
	fi
	if [[ $m = *--hrng=tpm* ]]; then
		(( didmigrate |= 4 ))
		print -ru2 "E: old configuration uses rng-tools5 feature"
		print -ru2 "E: cannot migrate"
		print -ru2 "N: local changes saved as ${p@Q}"
		return 0
	fi
	dfltconv <"$p" >/etc/default/rng-tools-debian
	rm -- "$p"
	(( didmigrate |= 8 ))
	print -ru2 "I: /etc/default/rng-tools migrated to /etc/default/rng-tools-debian"
}

function dfltconv {
	local state=0 bk ln
	while IFS= read -r ln; do
		if [[ $state$ln = '0# Configuration for the rng-tools initscript' || \
		    $state$ln = '1# $Id: rng-tools.default,v 1.1.2.5 2008-06-10 19:51:37 hmh Exp $' || \
		    $state$ln = '2' ||
		    $state$ln = '3# This is a POSIX shell fragment' ]]; then
			bk+=$ln$'\n'
			let ++state
			continue
		fi
		[[ $ln != '#RNGDOPTIONS="--hrng=tpm --fill-watermark=90% --feed-interval=1"' ]] || \
		    continue
		[[ $ln != '# for the viapadlock and tpm drivers.' ]] || \
		    ln='# for the viapadlock driver.'
		if (( state == 4 )); then
			print -r -- '# -*- mode: sh -*-'
			print -r -- '#-'
			print -r -- '# Configuration for the rng-tools-debian initscript'
		elif (( state > 0 && state < 5 )); then
			print -nr -- "$bk"
		fi
		if (( state < 5 )); then
			(( state != 4 )) || print
			print -r -- '# migrated from /etc/defaults/rng-tools'
			[[ -z $ln ]] || print
			state=5
		fi
		print -r -- "$ln"
	done
	print -r -- '# For TPM (also add tpm-rng to /etc/modules):'
	print -r -- '#RNGDOPTIONS="--fill-watermark=90% --feed-interval=1"'
	print -r -- ''
	print -r -- '# If you need to configure which RNG to use, do it here:'
	print -r -- '#HRNGSELECT="virtio_rng.0"'
	print -r -- '# Use this instead of sysfsutils, which starts too late.'
}

case $1 in
(configure|reconfigure)
	domigrate 29a6dfb91ef76469550026ea912f9307 80e82742d3612fbcc5b2fe28d9be198e \
	    /etc/default/rng-tools
	domigrate 46da7b710e34cbaaf4a40077975bd7cc 7c9474cbf0b1317efd82ce1cce1c1648 \
	    /etc/logcheck/ignore.d.server/rng-tools
	domigrate 46da7b710e34cbaaf4a40077975bd7cc 7c9474cbf0b1317efd82ce1cce1c1648 \
	    /etc/logcheck/violations.ignore.d/rng-tools
	if (( didmigrate == 1 )); then
		print -ru2 "I: rng-tools: all old conffiles were pruned"
	elif (( didmigrate == 9 )); then
		print -ru2 "I: rng-tools: all old conffiles were pruned or merged"
	elif (( didmigrate & 2 )); then
		print -ru2 "I: rng-tools: some old conffiles were moved aside for review"
	fi
	if (( didmigrate & 8 )) && ! invoke-rc.d rng-tools-debian restart; then
		print -ru2 "W: rng-tools-debian still cannot be started"
	fi
	;;

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

(triggered)
	;;

(*)
	echo >&2 "E: postinst called with unknown subcommand '$1'"
	exit 1
	;;
esac

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

#DEBHELPER#

exit 0