- inicijalna verzija paketa..
[kernel-cn.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for spamassassin-cn
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 http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
18 #
19
20 case "$1" in
21     configure|reconfigure)
22       # continue below
23     ;;
24
25     *)
26         exit 0
27     ;;
28 esac
29
30 # import CN-functions
31 . /usr/share/carnet-tools/functions.sh
32
33 ################################################################################
34
35 # starting up backup
36 echo -n "CN: Backed up to /var/backups:"
37
38 # backup lilo.conf
39 if [ -e /etc/lilo.conf ]; then
40   cp_backup_conffile /etc/lilo.conf
41   echo -n " lilo.conf"
42 fi
43
44 # backup old kernel params
45 if [ -e /etc/sysctl.conf ]; then
46   cp_backup_conffile /etc/sysctl.conf
47   echo -n " sysctl.conf"
48 fi
49
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"
54 fi
55
56 # finished
57 echo "."
58
59 ################################################################################
60
61 # intro msg
62 echo -n "CN: Configuring system (this will take a while):"
63
64 # generate kernel-img.conf
65 if [ ! -e /etc/kernel-img.conf ]; then
66     touch /etc/kernel-img.conf
67 fi
68
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
74 else
75     echo "postinst_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
76 fi
77
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
83 else
84     echo "postrm_hook = /usr/sbin/update-grub" >> /etc/kernel-img.conf
85 fi
86
87 # enable initrd
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
92 else
93     echo "do_initrd = yes" >> /etc/kernel-img.conf
94 fi
95
96 echo -n " kernel-img.conf"
97
98 # generate initial grub loaders
99 if [ ! -d /boot/grub ]; then
100     mkdir -p /boot/grub
101     if [ -d /usr/lib/grub/i386-pc ]; then
102         cp -a /usr/lib/grub/i386-pc/* /boot/grub
103     fi
104 fi
105
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
111     fi
112 fi
113 if [ ! -e /boot/grub/menu.lst ]; then
114     yes | /usr/sbin/update-grub >/dev/null 2>&1 || true
115 else
116     /usr/sbin/update-grub >/dev/null 2>&1 || true
117 fi
118
119 if ! grub-install --no-floppy '(hd0)' >/dev/null 2>&1; then
120     echo "."
121     echo "CN: FATAL ERROR running grub-install!"
122     echo "CN: Do not reboot your server and report this to OTRS immediately!"
123     exit 1
124 fi
125 echo -n " grub"
126
127 # disable lilo
128 if [ -e /etc/lilo.conf ]; then
129     mv -f /etc/lilo.conf /etc/lilo.conf.old
130 fi
131 echo -n " lilo"
132
133 # mdadm
134 if [ -x /usr/share/mdadm/mkconf ]; then
135     if [ ! -e /etc/mdadm/mdadm.conf ]; then
136         touch /etc/mdadm/mdadm.conf
137     fi
138
139     /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf.$$
140     if ! cmp -s /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf; then
141         mv /etc/mdadm/mdadm.conf.$$ /etc/mdadm/mdadm.conf
142     fi
143     rm -f /etc/mdadm/mdadm.conf.$$ /etc/initramfs-tools/hooks/md \
144         /var/lib/mdadm/CONF-UNCHECKED
145     echo -n " mdadm"
146 fi
147
148 # update initramfs accordingly
149 update-initramfs -u -k all >/dev/null 2>&1 || true
150 echo -n " initramfs"
151
152 # finished
153 echo "."
154
155 ################################################################################
156
157 # rest of configuration...
158 echo -n "CN: Modifying the neccessary system files:"
159
160 # remove group 99
161 if getent group proc >/dev/null 2>&1; then
162     groupdel proc >/dev/null 2>&1
163 fi
164 echo -n " proc"
165
166 # remove oidentd from oident group
167 if getent group oident >/dev/null 2>&1; then
168     # sarge default
169     cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup' \
170       's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*nogroup/OIDENT_GROUP=oident/g' \
171           /etc/default/oidentd || true
172
173     # old kernel-2.6-cn default
174     cp_check_and_sed '^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc' \
175       's/^OIDENT_GROUP[[:blank:]]*=[[:blank:]]*proc/OIDENT_GROUP=oident/g' \
176           /etc/default/oidentd || true
177
178     echo -n " oidentd"
179 fi
180
181 # default kernel parameters
182 rm -f /etc/sysctl.conf.$$
183 cat > /etc/sysctl.conf.$$ <<EOF
184 kernel.exec-shield=3
185 kernel.maps_protect=1
186 net.core.rmem_default=1048576
187 net.core.wmem_default=1048576
188 net.ipv4.conf.all.accept_redirects=0
189 net.ipv4.conf.all.accept_source_route=0
190 net.ipv4.conf.all.log_martians=1
191 net.ipv4.conf.all.rp_filter=1
192 net.ipv4.conf.all.secure_redirects=1
193 net.ipv4.conf.all.send_redirects=0
194 net.ipv4.icmp_echo_ignore_broadcasts=1
195 net.ipv4.icmp_ignore_bogus_error_responses=1
196 net.ipv4.ip_forward=0
197 net.ipv4.ip_local_port_range=10000 65000
198 net.ipv4.tcp_congestion_control=cubic
199 net.ipv4.tcp_ecn=0
200 net.ipv4.tcp_max_syn_backlog=8192
201 net.ipv4.tcp_retries1=2
202 net.ipv4.tcp_rfc1337=1
203 net.ipv4.tcp_syncookies=1
204 vm.mmap_min_addr=65536
205 EOF
206
207 # old kernel params
208 if [ -e /etc/sysctl.conf ]; then
209   #cat /etc/sysctl.conf >> /etc/sysctl.conf.$$
210   #ignore some of 2.4 stuff
211   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' \
212     /etc/sysctl.conf >> /etc/sysctl.conf.$$
213 fi
214
215 # add sysctl.conf Debian headers
216 rm -f /etc/sysctl.conf-head
217 cat > /etc/sysctl.conf-head <<EOF
218 #
219 # /etc/sysctl.conf - Configuration file for setting system variables
220 # See sysctl.conf (5) for information.
221 #
222 EOF
223
224 # merge old and new in one conf, primarily respecting old
225 script='
226 my %confhash = ();
227 my ($key, $value);
228 while (<>)
229 {
230   chomp();
231   if (/^\s*(\S+)\s*=\s*(.+)\s*$/o)
232   {
233     my ($key, $value) = ($1, $2);
234     $key =~ s/\//./go;
235     $confhash{$key} = $value;
236   }
237 }
238 for (sort { $a cmp $b } keys %confhash)
239 {
240   print $_, "=", $confhash{$_}, "\n";
241 }
242 '
243 rm -f /etc/sysctl.conf-new
244 perl -e "$script" < /etc/sysctl.conf.$$ > /etc/sysctl.conf-new
245 cat /etc/sysctl.conf-head /etc/sysctl.conf-new > /etc/sysctl.conf.$$
246 rm -f /etc/sysctl.conf-head /etc/sysctl.conf-new
247
248 # finished with merging, move into sysctl.conf
249 cp_mv /etc/sysctl.conf.$$ /etc/sysctl.conf
250 echo -n " sysctl.conf"
251
252 # finished with basic kernel-2.6-cn stuff
253 echo "."
254
255 ################################################################################
256
257 # intro
258 echo -n "CN: Setting up PAM configurations:"
259
260 # update pam_limits accordingly
261 if [ -e /etc/security/limits.conf ]; then
262   rm -f /etc/security/limits.conf.$$
263   cp /etc/security/limits.conf /etc/security/limits.conf.$$
264   cp-update kernel-2.6-cn /etc/security/limits.conf.$$ <<EOF
265 *               soft    core            0
266 *               hard    nofile          4096
267 *               soft    nofile          4096
268 EOF
269   cp_mv /etc/security/limits.conf.$$ /etc/security/limits.conf
270   echo -n " limits"
271 fi
272
273 # check pam.d/login
274 if [ -e /etc/pam.d/login ]; then
275   cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
276     's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
277     /etc/pam.d/login || true
278   echo -n " login"
279 fi
280
281 # check pam.d/ssh
282 if [ -e /etc/pam.d/ssh ]; then
283   cp_check_and_sed '^#.*session.+required.+pam_limits.so' \
284     's/^#.*session.+required.+pam_limits.so/session required pam_limits.so/' \
285     /etc/pam.d/ssh || true
286   echo -n " ssh"
287 fi
288
289 # finished with PAM
290 echo "."
291
292 ################################################################################
293
294 # remove obsolete links
295 rm -f /boot/vmlinuz /boot/vmlinuz.old /boot/vmlinuz.old2 \
296   /boot/vmlinuz.plain /vmlinuz /vmlinuz.old /boot/vmlinuz.plain
297 echo "CN: Removed old symlinks in / and /boot."
298
299 ################################################################################
300
301 # fix old kernel-2.4-cn postrm
302 if [ -e /var/lib/dpkg/info/kernel-2.4-cn.postrm ]; then
303     echo "CN: Fixed old kernel-2.4-cn postrm."
304     cat > /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ <<EOF
305 #!/bin/sh
306
307 set -e
308
309 # be sure, be safe
310 if [ "$1" != "remove" ]; then
311   exit 0
312 fi
313
314 # import CN-functions
315 . /usr/share/carnet-tools/functions.sh
316
317 # remove us from limits.conf
318 cp-update -r kernel-2.4-cn /etc/security/limits.conf
319
320 # remove us from modules
321 cp-update -r kernel-2.4-cn /etc/modules
322 EOF
323     if ! cmp -s /var/lib/dpkg/info/kernel-2.4-cn.postrm \
324         /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$; then
325         mv /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$ \
326             /var/lib/dpkg/info/kernel-2.4-cn.postrm
327         chmod +x /var/lib/dpkg/info/kernel-2.4-cn.postrm
328     fi
329     rm -f /var/lib/dpkg/info/kernel-2.4-cn.postrm.$$
330 fi
331
332 ################################################################################
333
334 # fix old kernel-cn postrm
335 if [ -e /var/lib/dpkg/info/kernel-cn.postrm ]; then
336     echo "CN: Fixed old kernel-cn postrm."
337     cat > /var/lib/dpkg/info/kernel-cn.postrm.$$ <<EOF
338 #!/bin/sh
339
340 set -e
341
342 # be sure, be safe
343 if [ "$1" != "remove" ]; then
344   exit 0
345 fi
346
347 # import CN-functions
348 . /usr/share/carnet-tools/functions.sh
349
350 # remove us from limits.conf
351 cp-update -r kernel-cn /etc/security/limits.conf
352
353 # remove us from modules
354 cp-update -r kernel-cn /etc/modules
355 EOF
356     if ! cmp -s /var/lib/dpkg/info/kernel-cn.postrm \
357         /var/lib/dpkg/info/kernel-cn.postrm.$$; then
358         mv /var/lib/dpkg/info/kernel-cn.postrm.$$ \
359             /var/lib/dpkg/info/kernel-cn.postrm
360         chmod +x /var/lib/dpkg/info/kernel-cn.postrm
361     fi
362     rm -f /var/lib/dpkg/info/kernel-cn.postrm.$$
363 fi
364
365 ################################################################################
366
367 # dh_installdeb will replace this with shell code automatically
368 # generated by other debhelper scripts.
369
370 #DEBHELPER#
371
372 exit 0