File: postinst

package info (click to toggle)
base-passwd 3.6.8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 516 kB
  • sloc: ansic: 1,216; sh: 115; makefile: 60
file content (135 lines) | stat: -rw-r--r-- 2,790 bytes parent folder | download | duplicates (2)
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
#! /bin/sh

set -e

# Load the debconf confmodule if it is available.  It may not be because this
# package is essential and therefore can't depend on debconf directly.
if [ -f /usr/share/debconf/confmodule ]; then
	# shellcheck disable=SC1091
	. /usr/share/debconf/confmodule
fi

changes=0

askyesno () {
	if [ "$DEBIAN_FRONTEND" = "noninteractive" ] ; then
		a=y
		return
	fi

	while : ; do
		printf '%s ' "$1"
		read -r a || true
		if [ "$a" = "" ] ; then
			a="y"
		fi
		a=$(echo $a | tr '[:upper:]' '[:lower:]')
		if [ "$a" = "y" ] || [ "$a" = "n" ] ; then
			break
		fi
		echo "Illegal answer"
	done
}

# A cut-down version of 'which' from debianutils.
searchpath () {
	PROGRAM="$1"
	IFS_SAVE="$IFS"
	IFS=:
	RET=1
	for ELEMENT in $PATH; do
		if [ -z "$ELEMENT" ]; then
			ELEMENT=.
		fi
		if [ -f "$ELEMENT/$PROGRAM" ] && \
		   [ -x "$ELEMENT/$PROGRAM" ]; then
			RET=0
			break
		fi
	done
	IFS="$IFS_SAVE"
	return "$RET"
}


if [ ! "$1" = "configure" ] ; then
    exit 0
fi

if [ ! -e "$DPKG_ROOT/etc/passwd" ] ; then
	cp "$DPKG_ROOT/usr/share/base-passwd/passwd.master" "$DPKG_ROOT/etc/passwd"
fi

if [ ! -e "$DPKG_ROOT/etc/group" ] ; then
	cp "$DPKG_ROOT/usr/share/base-passwd/group.master" "$DPKG_ROOT/etc/group"
fi

if [ ! -e "$DPKG_ROOT/etc/subuid" ] ; then
	touch "$DPKG_ROOT/etc/subuid"
	chown 0:0 "$DPKG_ROOT/etc/subuid"
	chmod 644 "$DPKG_ROOT/etc/subuid"
fi

if [ ! -e "$DPKG_ROOT/etc/subgid" ] ; then
	touch "$DPKG_ROOT/etc/subgid"
	chown 0:0 "$DPKG_ROOT/etc/subgid"
	chmod 644 "$DPKG_ROOT/etc/subgid"
fi


tmp=$(mktemp)
if [ -n "$2" ] && ! update-passwd --dry-run > "$tmp" ; then
	if [ -f /usr/share/debconf/confmodule ] ; then
		db_version 2.0
		update-passwd --verbose
		changes=1
	else
		cat <<EOF

update-passwd has found some differences between your system accounts
and the current Debian defaults.  It is advisable to allow update-passwd
to change your system; without those changes some packages might not work
correctly.  For more documentation on the Debian account policies, please
see /usr/share/doc/base-passwd/README.

The list of proposed changes is:

EOF

		cat "$tmp"
		cat <<EOF

It is highly recommended that you allow update-passwd to make these changes
(a backup file of modified files is made with the extension .org so you can
always restore the current settings).

EOF
		askyesno "May I update your system? [Y/n]"
	fi

	if [ "$a" = "y" ] ; then
		echo "Okay, I am going to make the necessary updates now"
		update-passwd --verbose
		changes=1
	elif [ "$a" = "n" ] ; then
		cat <<EOF

Okay, I will not update your system.  If you want to make this update later
please check the update-passwd utility.

EOF

	fi
fi

rm -f "$tmp"

if [ "$changes" -gt 0 ] ; then
	if searchpath nscd; then
		nscd -i passwd -i group || true
	fi
fi

#DEBHELPER#

exit 0