2 # postinst script for spamassassin-cn
4 # see: dh_installdeb(1)
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>
13 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 # <failed-install-package> <version> `removing'
15 # <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
21 configure|reconfigure)
31 . /usr/share/carnet-tools/functions.sh
33 ################################################################################
36 echo -n "CN: Backed up to /var/backups:"
39 if [ -e /etc/lilo.conf ]; then
40 cp_backup_conffile /etc/lilo.conf
44 # backup old kernel params
45 if [ -e /etc/sysctl.conf ]; then
46 cp_backup_conffile /etc/sysctl.conf
47 echo -n " sysctl.conf"
50 # backup old kernel params
51 if [ -e /etc/kernel-img.conf ]; then
52 cp_backup_conffile /etc/kernel-img.conf
53 echo -n " kernel-img.conf"
59 ################################################################################
61 # remove obsolete symlinks and kernels
62 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
63 /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain \
64 /boot/vmlinuz.generic /boot/vmlinuz-generic /boot/vmlinuz-old
65 echo "CN: Removed old symlinks in / and /boot."
67 ################################################################################
70 echo -n "CN: Configuring system (this will take a while):"
72 # generate kernel-img.conf
73 if [ ! -e /etc/kernel-img.conf ]; then
74 touch /etc/kernel-img.conf
77 # update postinst_hook for grub
78 if grep -q postinst_hook /etc/kernel-img.conf; then
79 cp_check_and_sed '^postinst_hook' \
80 's;^postinst_hook[[:blank:]]*=.*;postinst_hook = /usr/sbin/update-grub;g' \
81 /etc/kernel-img.conf || true
83 echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
86 # update postrm_hook for grub
87 if grep -q postrm_hook /etc/kernel-img.conf; then
88 cp_check_and_sed '^postrm_hook' \
89 's;^postrm_hook[[:blank:]]*=.*;postrm_hook = /usr/sbin/update-grub;g' \
90 /etc/kernel-img.conf || true
92 echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
96 if grep -q do_initrd /etc/kernel-img.conf; then
97 cp_check_and_sed '^do_initrd' \
98 's/^do_initrd[[:blank:]]*=.*/do_initrd = yes/g' \
99 /etc/kernel-img.conf || true
101 echo "do_initrd = yes" >> /etc/kernel-img.conf
104 echo -n " kernel-img.conf"
106 # generate initial grub loaders
107 if [ ! -d /boot/grub ]; then
109 if [ -d /usr/lib/grub/i386-pc ]; then
110 cp -a /usr/lib/grub/i386-pc/* /boot/grub
115 # create/update grub configuration
116 if [ -e /boot/grub/menu.lst ]; then
117 # is there uncompatibile grub conf present?
118 if ! grep -q 'AUTOMAGIC KERNELS LIST' /boot/grub/menu.lst; then
119 mv -f /boot/grub/menu.lst /boot/grub/menu.lst.old
122 if [ ! -e /boot/grub/menu.lst ]; then
123 yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
125 /usr/sbin/update-grub >/dev/null 2>&1 || true
130 if [ -x /sbin/chpax ]; then
131 if [ -x /usr/sbin/grub ]; then
132 chpax -spmrx /usr/sbin/grub || true
134 if [ -x /usr/sbin/grub-probe ]; then
135 chpax -spmrx /usr/sbin/grub-probe || true
140 # workaround execshield
141 SHIELD=$(sysctl -e -n kernel.exec-shield)
142 if [ ! -z "$SHIELD" ]; then
143 sysctl -w -e kernel.exec-shield=0 >/dev/null 2>&1
146 # install grub loader
147 if ! grub-install --no-floppy '(hd0)' >/dev/null 2>&1; then
149 echo "CN: FATAL ERROR running grub-install!"
150 echo "CN: Do not reboot your server and report this to OTRS immediately!"
155 # restore execshield state
156 if [ ! -z "$SHIELD" ]; then
157 sysctl -w -e "kernel.exec-shield=$SHIELD" >/dev/null 2>&1
161 if [ -e /etc/lilo.conf ]; then
162 mv -f /etc/lilo.conf /etc/lilo.conf.old
167 if [ -x /usr/share/mdadm/mkconf ]; then
168 if [ ! -e /etc/mdadm/mdadm.conf ]; then
169 touch /etc/mdadm/mdadm.conf
172 /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
173 if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
174 mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
176 rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
177 /var/lib/mdadm/CONF-UNCHECKED
181 # update initramfs accordingly
182 update-initramfs -u -k all >/dev/null 2>&1 || true
188 ################################################################################
190 # rest of configuration...
191 echo -n "CN: Modifying the neccessary system files:"
194 if getent group proc >/dev/null 2>&1; then
195 groupdel proc >/dev/null 2>&1
199 # remove oidentd from oident group
200 if getent group oident >/dev/null 2>&1; then
202 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
203 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
204 /etc/default/oidentd || true
206 # old kernel-2.6-cn default
207 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
208 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
209 /etc/default/oidentd || true
214 # default kernel parameters
215 rm -f /etc/sysctl.conf.$$
216 cat > /etc/sysctl.conf.$$ <<EOF
218 kernel.maps_protect=1
219 net.core.rmem_default=1048576
220 net.core.wmem_default=1048576
221 net.ipv4.conf.all.accept_redirects=0
222 net.ipv4.conf.all.accept_source_route=0
223 net.ipv4.conf.all.log_martians=1
224 net.ipv4.conf.all.rp_filter=1
225 net.ipv4.conf.all.secure_redirects=1
226 net.ipv4.conf.all.send_redirects=0
227 net.ipv4.icmp_echo_ignore_broadcasts=1
228 net.ipv4.icmp_ignore_bogus_error_responses=1
229 net.ipv4.ip_forward=0
230 net.ipv4.ip_local_port_range=10000 65000
231 net.ipv4.tcp_congestion_control=cubic
233 net.ipv4.tcp_max_syn_backlog=8192
234 net.ipv4.tcp_retries1=2
235 net.ipv4.tcp_rfc1337=1
236 net.ipv4.tcp_syncookies=1
237 vm.mmap_min_addr=65536
241 if [ -e /etc/sysctl.conf ]; then
242 #cat /etc/sysctl.conf >> /etc/sysctl.conf.$$
243 #ignore some of 2.4 stuff
244 egrep -v 'net\.core\.(r|w)mem_max|net\.ipv4\.tcp_(r|w)mem|vm\.bdflush|net\.ipv4\.ip_local_port_range|kernel\.rtsig-max|net\.ipv4\.tcp_syncookies' \
245 /etc/sysctl.conf >> /etc/sysctl.conf.$$
248 # add sysctl.conf Debian headers
249 rm -f /etc/sysctl.conf-head
250 cat > /etc/sysctl.conf-head <<EOF
252 # /etc/sysctl.conf - Configuration file for setting system variables
253 # See sysctl.conf (5) for information.
257 # merge old and new in one conf, primarily respecting old
264 if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
266 my ($key, $value) = ($1, $2);
268 $confhash{$key} = $value;
271 for (sort { $a cmp $b } keys %confhash)
273 print $_, "=", $confhash{$_}, "\n";
276 rm -f /etc/sysctl.conf-new
277 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
278 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
279 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
281 # finished with merging, move into sysctl.conf
282 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
283 echo -n " sysctl.conf"
285 # finished with basic kernel-2.6-cn stuff
288 ################################################################################
291 echo -n "CN: Setting up PAM configurations:"
293 # update pam_limits accordingly
294 if [ -e /etc/security/limits.conf ]; then
295 rm -f /etc/security/limits.conf.$$
296 cp /etc/security/limits.conf /etc/security/limits.conf.$$
297 cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
302 cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
307 if [ -e /etc/pam.d/login ]; then
308 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
309 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
310 /etc/pam.d/login || true
315 if [ -e /etc/pam.d/ssh ]; then
316 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
317 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
318 /etc/pam.d/ssh || true
325 ################################################################################
327 # fix old kernel-2.4-cn postrm
328 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
329 echo "CN: Fixed old kernel-2.4-cn postrm."
330 cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
336 if [ "$1" != "remove" ]; then
340 # import CN-functions
341 . /usr/share/carnet-tools/functions.sh
343 # remove us from limits.conf
344 cp-update -r kernel-2.4-cn /etc/security/limits.conf
346 # remove us from modules
347 cp-update -r kernel-2.4-cn /etc/modules
349 if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
350 /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
351 mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
352 /var/lib/dpkg/info/kernel-2.4-cn.postrm
353 chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
355 rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
358 ################################################################################
360 # fix old kernel-cn postrm
361 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
362 echo "CN: Fixed old kernel-cn postrm."
363 cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
369 if [ "$1" != "remove" ]; then
373 # import CN-functions
374 . /usr/share/carnet-tools/functions.sh
376 # remove us from limits.conf
377 cp-update -r kernel-cn /etc/security/limits.conf
379 # remove us from modules
380 cp-update -r kernel-cn /etc/modules
382 if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
383 /var/lib/dpkg/info/kernel-cn.postrm.$$; then
384 mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
385 /var/lib/dpkg/info/kernel-cn.postrm
386 chmod +x /var/lib/dpkg/info/kernel-cn.postrm
388 rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
391 ################################################################################
393 # dh_installdeb will replace this with shell code automatically
394 # generated by other debhelper scripts.