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 ################################################################################
62 echo -n "CN: Configuring system (this will take a while):"
64 # generate kernel-img.conf
65 if [ ! -e /etc/kernel-img.conf ]; then
66 touch /etc/kernel-img.conf
69 # update postinst_hook for grub
70 if grep -q postinst_hook /etc/kernel-img.conf; then
71 cp_check_and_sed '^postinst_hook' \
72 's;^postinst_hook[[:blank:]]*=.*;postinst_hook = /usr/sbin/update-grub;g' \
73 /etc/kernel-img.conf || true
75 echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
78 # update postrm_hook for grub
79 if grep -q postrm_hook /etc/kernel-img.conf; then
80 cp_check_and_sed '^postrm_hook' \
81 's;^postrm_hook[[:blank:]]*=.*;postrm_hook = /usr/sbin/update-grub;g' \
82 /etc/kernel-img.conf || true
84 echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
88 if grep -q do_initrd /etc/kernel-img.conf; then
89 cp_check_and_sed '^do_initrd' \
90 's/^do_initrd[[:blank:]]*=.*/do_initrd = yes/g' \
91 /etc/kernel-img.conf || true
93 echo "do_initrd = yes" >> /etc/kernel-img.conf
96 echo -n " kernel-img.conf"
98 # generate initial grub loaders
99 if [ ! -d /boot/grub ]; then
101 if [ -d /usr/lib/grub/i386-pc ]; then
102 cp -a /usr/lib/grub/i386-pc/* /boot/grub
106 # create/update grub configuration
107 if [ -e /boot/grub/menu.lst ]; then
108 # is there uncompatibile grub conf present?
109 if ! grep -q 'AUTOMAGIC KERNELS LIST' /boot/grub/menu.lst; then
110 mv -f /boot/grub/menu.lst /boot/grub/menu.lst.old
113 if [ ! -e /boot/grub/menu.lst ]; then
114 yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
116 /usr/sbin/update-grub >/dev/null 2>&1 || true
120 if [ -x /sbin/chpax ]; then
121 if [ -x /usr/sbin/grub-install ]; then
122 chpax -ps /usr/sbin/grub-install
124 if [ -x /usr/sbin/grub-probe ]; then
125 chpax -ps /usr/sbin/grub-probe
129 # workaround execshield
130 SHIELD=$(sysctl -e -n kernel.exec-shield)
131 if [ ! -z "$SHIELD" ]; then
132 sysctl -w -e kernel.exec-shield=0 >/dev/null 2>&1
135 # install grub loader
136 if ! grub-install --no-floppy '(hd0)' >/dev/null 2>&1; then
138 echo "CN: FATAL ERROR running grub-install!"
139 echo "CN: Do not reboot your server and report this to OTRS immediately!"
143 # restore execshield state
144 if [ ! -z "$SHIELD" ]; then
145 sysctl -w -e "kernel.exec-shield=$SHIELD" >/dev/null 2>&1
149 if [ -e /etc/lilo.conf ]; then
150 mv -f /etc/lilo.conf /etc/lilo.conf.old
155 if [ -x /usr/share/mdadm/mkconf ]; then
156 if [ ! -e /etc/mdadm/mdadm.conf ]; then
157 touch /etc/mdadm/mdadm.conf
160 /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
161 if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
162 mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
164 rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
165 /var/lib/mdadm/CONF-UNCHECKED
169 # update initramfs accordingly
170 update-initramfs -u -k all >/dev/null 2>&1 || true
176 ################################################################################
178 # rest of configuration...
179 echo -n "CN: Modifying the neccessary system files:"
182 if getent group proc >/dev/null 2>&1; then
183 groupdel proc >/dev/null 2>&1
187 # remove oidentd from oident group
188 if getent group oident >/dev/null 2>&1; then
190 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
191 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
192 /etc/default/oidentd || true
194 # old kernel-2.6-cn default
195 cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
196 's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
197 /etc/default/oidentd || true
202 # default kernel parameters
203 rm -f /etc/sysctl.conf.$$
204 cat > /etc/sysctl.conf.$$ <<EOF
206 kernel.maps_protect=1
207 net.core.rmem_default=1048576
208 net.core.wmem_default=1048576
209 net.ipv4.conf.all.accept_redirects=0
210 net.ipv4.conf.all.accept_source_route=0
211 net.ipv4.conf.all.log_martians=1
212 net.ipv4.conf.all.rp_filter=1
213 net.ipv4.conf.all.secure_redirects=1
214 net.ipv4.conf.all.send_redirects=0
215 net.ipv4.icmp_echo_ignore_broadcasts=1
216 net.ipv4.icmp_ignore_bogus_error_responses=1
217 net.ipv4.ip_forward=0
218 net.ipv4.ip_local_port_range=10000 65000
219 net.ipv4.tcp_congestion_control=cubic
221 net.ipv4.tcp_max_syn_backlog=8192
222 net.ipv4.tcp_retries1=2
223 net.ipv4.tcp_rfc1337=1
224 net.ipv4.tcp_syncookies=1
225 vm.mmap_min_addr=65536
229 if [ -e /etc/sysctl.conf ]; then
230 #cat /etc/sysctl.conf >> /etc/sysctl.conf.$$
231 #ignore some of 2.4 stuff
232 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' \
233 /etc/sysctl.conf >> /etc/sysctl.conf.$$
236 # add sysctl.conf Debian headers
237 rm -f /etc/sysctl.conf-head
238 cat > /etc/sysctl.conf-head <<EOF
240 # /etc/sysctl.conf - Configuration file for setting system variables
241 # See sysctl.conf (5) for information.
245 # merge old and new in one conf, primarily respecting old
252 if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
254 my ($key, $value) = ($1, $2);
256 $confhash{$key} = $value;
259 for (sort { $a cmp $b } keys %confhash)
261 print $_, "=", $confhash{$_}, "\n";
264 rm -f /etc/sysctl.conf-new
265 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
266 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
267 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
269 # finished with merging, move into sysctl.conf
270 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
271 echo -n " sysctl.conf"
273 # finished with basic kernel-2.6-cn stuff
276 ################################################################################
279 echo -n "CN: Setting up PAM configurations:"
281 # update pam_limits accordingly
282 if [ -e /etc/security/limits.conf ]; then
283 rm -f /etc/security/limits.conf.$$
284 cp /etc/security/limits.conf /etc/security/limits.conf.$$
285 cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
290 cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
295 if [ -e /etc/pam.d/login ]; then
296 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
297 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
298 /etc/pam.d/login || true
303 if [ -e /etc/pam.d/ssh ]; then
304 cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
305 's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
306 /etc/pam.d/ssh || true
313 ################################################################################
315 # remove obsolete links
316 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
317 /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain
318 echo "CN: Removed old symlinks in / and /boot."
320 ################################################################################
322 # fix old kernel-2.4-cn postrm
323 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
324 echo "CN: Fixed old kernel-2.4-cn postrm."
325 cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
331 if [ "$1" != "remove" ]; then
335 # import CN-functions
336 . /usr/share/carnet-tools/functions.sh
338 # remove us from limits.conf
339 cp-update -r kernel-2.4-cn /etc/security/limits.conf
341 # remove us from modules
342 cp-update -r kernel-2.4-cn /etc/modules
344 if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
345 /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
346 mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
347 /var/lib/dpkg/info/kernel-2.4-cn.postrm
348 chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
350 rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
353 ################################################################################
355 # fix old kernel-cn postrm
356 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
357 echo "CN: Fixed old kernel-cn postrm."
358 cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
364 if [ "$1" != "remove" ]; then
368 # import CN-functions
369 . /usr/share/carnet-tools/functions.sh
371 # remove us from limits.conf
372 cp-update -r kernel-cn /etc/security/limits.conf
374 # remove us from modules
375 cp-update -r kernel-cn /etc/modules
377 if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
378 /var/lib/dpkg/info/kernel-cn.postrm.$$; then
379 mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
380 /var/lib/dpkg/info/kernel-cn.postrm
381 chmod +x /var/lib/dpkg/info/kernel-cn.postrm
383 rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
386 ################################################################################
388 # dh_installdeb will replace this with shell code automatically
389 # generated by other debhelper scripts.