File: postinst

package info (click to toggle)
adjtimex 1.29-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,096 kB
  • sloc: ansic: 12,625; sh: 311; makefile: 237
file content (115 lines) | stat: -rw-r--r-- 2,368 bytes parent folder | download | duplicates (4)
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
#! /bin/sh

set -e

# Source debconf library.
. /usr/share/debconf/confmodule

#		 old scripts
oldfile=/etc/adjtimex.conf
olderfile=/etc/rc.boot/adjtimex
#		 new starting script
startfile=/etc/init.d/adjtimex
#		 new configuration file
conffile=/etc/default/adjtimex

migrate_old_adjtimex_conf()
{

	TICK=10000
	FREQ=0

	if [ -f $oldfile ]; then
		TICK=`awk '
		BEGIN{tick=10000;}
		/[ \t]*TICK[ \t]*=[ \t]*"?[0-9]+"?/ {
			sub(/[ \t]*TICK[ \t]*=[ \t]*"?/,"");
			tick=$0+0;
		}
		END {print tick;}
		' $oldfile`

		FREQ=`awk '
		BEGIN{freq=0;}
		/[ \t]*FREQ[ \t]*=[ \t]*"?[0-9]+"?/ {
			sub(/[ \t]*FREQ[ \t]*=[ \t]*"?/,"");
			freq=$0+0;
		}
		END {print freq;}
		' $oldfile`

#		echo "parameters from $oldfile: TICK=$TICK FREQ=$FREQ";
	elif [ -f $olderfile ]; then
		TICK=`awk '
		BEGIN{tick=10000;}
		/[ \t]*TICK[ \t]*=[ \t]*"?[0-9]+"?/ {
			sub(/[ \t]*TICK[ \t]*=[ \t]*"?/,"");
			tick=$0+0;
		}
		END {print tick;}
		' $olderfile`

		FREQ=`awk '
		BEGIN{freq=0;}
		/[ \t]*FREQ[ \t]*=[ \t]*"?[0-9]+"?/ {
			sub(/[ \t]*FREQ[ \t]*=[ \t]*"?/,"");
			freq=$0+0;
		}
		END {print freq;}
		' $olderfile`

#		echo "parameters from $olderfile: TICK=$TICK FREQ=$FREQ";
	fi

	if [ -f $conffile ]; then
#		echo "using existing $conffile";
		true;
	elif [ -f $oldfile ] || [ -f $olderfile ]; then
		[ ! -d /etc/default ] && mkdir /etc/default
		cat >$conffile <<EOF
#  $conffile - configuration file for adjtimex(8)
#
#  you may adjust these values manually or by calling /usr/sbin/adjtimexconfig
#
#  This file is sourced by $startfile
#
TICK=$TICK
FREQ=$FREQ

EOF
	fi

	rm -f $oldfile $olderfile
}


case "$1" in
	configure)

# A previous installation may have left a corrupt conffile.
# The regexp matches only blank lines, comments, and integer assignments:
		if [ -f $conffile ]; then
			egrep -qv '^([[:space:]]*(#.*)?|[[:space:]]*[a-zA-Z][a-zA-Z0-9]*[[:space:]]*=[[:space:]]*-?[0-9]+[[:space:]]*)$' $conffile && rm -f $conffile
		fi

		migrate_old_adjtimex_conf

		# service starting depends on existence of /etc/default/adjtimex, which is ready only after running adjtimexconfig
		update-rc.d adjtimex defaults > /dev/null

		db_get adjtimex/compare_rtc
		if [ "$RET" = "true" ]; then
			adjtimexconfig
		fi

		;;
	abort-upgrade|abort-remove|abort-deconfigure)
		exit 0
		;;
	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 0
		;;
esac

#DEBHELPER#