Debian Codegraph @

debian/postinst

raw
1 #! /bin/sh
2 # postinst script for quota
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # summary of how this script can be called:
9 # * <postinst> `configure' <most-recently-configured-version>
10 # * <old-postinst> `abort-upgrade' <new version>
11 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 # <new-version>
13 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 # <failed-install-package> <version> `removing'
15 # <conflicting-package> <version>
16 # for details, see /usr/doc/packaging-manual/
17 #
18 # quoting from the policy:
19 # Any necessary prompting should almost always be confined to the
20 # post-installation script, and should be protected with a conditional
21 # so that unnecessary prompting doesn't happen if a package's
22 # installation fails and the `postinst' is called with `abort-upgrade',
23 # `abort-remove' or `abort-deconfigure'.
24
25 # create list of all fs with quota
26 scan_fstab()
27 {
28 tmplist=`egrep -e "^[ ]*[^#].*(usrquota|usrjquota|uquota|uqnoenforce|grpquota|grpjquota|gquota|gqnoenforce)" /etc/fstab | \
29 sed -e 's/\(^[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*[[:space:]]*[^[:space:]]*\).*/\1/g' \
30 -e 's/^[[:space:]]*[^[:space:]]*[[:space:]]*//g'`
31 list=${tmplist:=empty}
32 }
33
34 if [ "$1" = "configure" ]; then
35 . /usr/share/debconf/confmodule
36 #
37 # generate the config files if they don't exist
38 #
39
40 if [ ! -f /etc/warnquota.conf ]; then
41 db_get quota/mailfrom
42 mailfrom="$RET"
43 db_get quota/supportemail
44 supportemail="$RET"
45 db_get quota/supportphone
46 supportphone="$RET"
47 db_get quota/message
48 message="$RET"
49 db_get quota/signature
50 signature="$RET"
51 db_get quota/subject
52 subject="$RET"
53 db_get quota/cc
54 cc="$RET"
55 db_get quota/charset
56 charset="$RET"
57 db_get quota/cc_before
58 cc_before="$RET"
59
60 temp=`mktemp /etc/warnquota.conf.XXXXXX`
61 cat <<EOF >"$temp"
62 # Debian configuration
63 # generated from debconf on `date`
64 #
65 # Command used to send email
66 MAIL_CMD = "/usr/sbin/sendmail -t"
67 # From email used in generated emails
68 FROM = "$mailfrom"
69 # Subject line
70 SUBJECT = $subject
71 # Send a copy to this address
72 CC_TO = "$cc"
73 # Support email for assistance (included in generated mail)
74 SUPPORT = "$supportemail"
75 # Support phone for assistance (included in generated mail)
76 PHONE = "$supportphone"
77 EOF
78
79 if [ -n "$message" ]; then
80 cat <<EOF >>"$temp"
81 # The message to send
82 MESSAGE = "$message"
83 EOF
84 fi
85
86 if [ -n "$signature" ]; then
87 cat <<EOF >>"$temp"
88 # The signature of the mail
89 SIGNATURE = "$signature"
90 EOF
91 fi
92
93 if [ -n "$charset" ]; then
94 cat <<EOF >>"$temp"
95 # character set the email is to be send in
96 CHARSET = "$charset"
97 EOF
98 fi
99
100 if [ -n "$cc_before" ]; then
101 cat <<EOF >>"$temp"
102 # CC admin this time before the end of grace period
103 CC_BEFORE = "$cc_before"
104 EOF
105 fi
106
107 mv $temp /etc/warnquota.conf
108 fi
109
110 if [ ! -f /etc/default/quota ]; then
111 db_get quota/run_warnquota
112 run_warnquota="$RET"
113 temp=`mktemp /etc/default/quota.XXXXXX`
114 cat <<EOF >"$temp"
115 # Configuration for quota scripts
116 # generated from debconf on `date`
117 #
118 # Set to "true" if warnquota should be run in cron.daily
119 run_warnquota="$run_warnquota"
120 EOF
121 mv $temp /etc/default/quota
122 fi
123
124 #
125 # stop debconf
126 #
127 db_stop
128 fi
129
130 case "$1" in
131 configure)
132 # if we have a recenty configured package, do nothing
133 if test ! -f /var/run/quota.upgrade; then
134 if [ -f /etc/fstab ]; then
135 # enable quota if already configured
136 scan_fstab
137 set -- $list
138 if [ $# -ge 2 ]; then
139 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
140 invoke-rc.d quota start
141 else
142 /etc/init.d/quota start > /dev/null 2>&1 &
143 fi
144 fi
145 fi
146
147 # set quota_is_new file
148 touch /var/lib/quota/new
149 fi
150 # if the old /var/state/quota dir exists, move the files to the new location
151 if [ -d /var/state/quota ]; then
152 [ ! -f /var/state/quota/off ] || touch /var/lib/quota/off
153 [ ! -f /var/state/quota/new ] || touch /var/lib/quota/new
154 rm -rf /var/state/quota
155 fi
156 ;;
157
158 abort-upgrade|abort-remove|abort-deconfigure)
159
160 ;;
161
162 *)
163 echo "postinst called with unknown argument \`$1'" >&2
164 exit 0
165 ;;
166 esac
167
168 #
169 # remove old links
170 #
171 if test -f /var/run/quota.upgrade
172 then
173 if dpkg --compare-versions "$2" lt 3.00pre01-10
174 then
175 update-rc.d -f quota remove 2>/dev/null > /dev/null
176 elif dpkg --compare-versions "$2" lt 3.12-3
177 then
178 update-rc.d -f quotarpc remove 2>/dev/null > /dev/null
179 elif dpkg --compare-versions "$2" lt 3.17-4
180 then
181 rm -f /etc/rcS.d/S*quotarpc
182 fi
183 fi
184
185 rm -f /var/run/quota.upgrade
186
187 #DEBHELPER#
188
189 exit 0
190