It is /etc/resolvconf/run/interface instead ..../interfaces
[grml-live.git] / etc / grml / fai / grml / grml_cleanup_chroot
1 #!/bin/bash
2 # Filename:      /etc/grml/fai/grml/grml_cleanup_chroot
3 # Purpose:       clean up grml chroot
4 # Authors:       (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 # Latest change: Mon Sep 17 22:14:33 CEST 2007 [mika]
8 ################################################################################
9
10 # misc stuff
11   umask 022
12   [ -n "$NOCOLORS" ] || . /etc/grml_colors
13   . /etc/grml/lsb-functions || exit 6
14   [ -x /lib64 ] && GRML64=yes || GRML64=''
15
16 # detect kernel version, assume newest kernel version
17   KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
18
19 if [ -n "$LATEX_CLEANUP" ] ; then
20    rm -rf /usr/share/doc/texlive-latex-recommended/latex/ \
21           /usr/share/doc/texlive-latex-base/latex/ \
22           /usr/share/doc/texlive-base-bin/pdftex/thanh/ \
23           /usr/share/doc/texlive-latex-base/latex/base/ \
24           /usr/share/doc/texlive-latex-base/latex/hyperref/ \
25           /usr/share/doc/texlive-latex-base/generic/babel/  \
26           /usr/share/doc/texlive-latex-recommended/latex/koma-script/ \
27           /usr/share/doc/texmf/pgf/pgfmanual.pdf.gz
28 fi
29
30 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
31   if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
32      eerror "Broken diversion of artwiz-cursor, see #341397, trying to fix it"
33      ( cd /usr/share/fonts/X11/misc/ &&
34        dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
35      eend 0
36   fi
37 fi
38
39 # start of main cleanup process...
40 if ! [ -r /boot/config-"$KERNEL" ] ; then
41   eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
42   eend 1
43   exit 9
44 fi
45
46 einfo "Preparing grml-system: $(cat /etc/grml_version)" ; eend 0
47
48 einfo "Setting up /etc/motd.tail"
49 echo "" > /etc/motd.tail ; eend 0
50
51 einfo "Setting up /etc/modules: "
52 cat>/etc/modules<<EOF
53 # /etc/modules: kernel modules to load at boot time.
54 #
55 # This file should contain the names of kernel modules that are
56 # to be loaded at boot time, one per line.  Comments begin with
57 # a \`#', and everything on the line after them are ignored.
58 EOF
59 echo "" >> /etc/modules
60 grep '^[a-z]' /etc/grml/modules >> /etc/modules
61 eend 0
62
63 einfo "Setting up /etc/inittab"
64 cp /etc/inittab.grml  /etc/inittab
65 eend $?
66
67 if [ -L /usr/include/linux ] ; then
68   einfo "/usr/include/linux is ok" ; eend 0
69 elif [ -n "$GRML64" ] ; then
70     if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
71        einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
72     else
73        eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
74        exit 10
75     fi
76 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
77      eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
78      eend 1
79      exit 10
80 else
81      ewarn "linux-headers-$KERNEL not installed." ; eend 0
82 fi
83
84 einfo "Creating ~/.zshrc"
85   touch ~/.zshrc
86 eend $?
87
88 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
89   einfo "Stripping ion3-stuff"
90   cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
91   sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
92 else
93   ewarn "ion3 not installed" ; eend 0
94 fi
95
96 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
97   einfo "Stripping /usr/lib/valgrind/x86-linux/"
98   strip  --strip-unneeded  /usr/lib/valgrind/x86-linux/*
99   eend $?
100 else
101   ewarn "valgrind not installed" ; eend 0
102 fi
103
104 if [ -x /usr/sbin/localepurge ] ; then
105   einfo "Running localepurge"
106   localepurge ; eend $?
107 else
108   ewarn "localepurg not available" ; eend 0
109 fi
110
111 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
112   einfo "Cleaning /var/lib/backuppc/pc/localhost/"
113   rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
114 else
115   ewarn "backuppc not installed" ; eend 0
116 fi
117
118 # find /var -name \*.pid
119 einfo "Removing pid-files"
120   find /var/run -name \*.pid -exec rm {} \;
121 eend $?
122
123 einfo "Unmounting proc, /dev/pts, /dev/capi"
124   umount /proc     2>/dev/null
125   umount /dev/pts  2>/dev/null
126   umount /dev/capi 2>/dev/null
127   umount -a 2>/dev/null
128 eend $?
129
130 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
131   rm -f /var/lib/apt/lists/*Packages
132   rm -f /var/lib/apt/lists/*Release
133   rm -f /var/lib/apt/lists/*Sources
134   rm -f /var/lib/apt/lists/*.gpg
135   rm -f /var/cache/apt-show-versions/*
136   rm -f /var/cache/debconf/templates.dat-old
137   rm -f /var/cache/apt/*.bin
138   apt-get check 2>/dev/null
139   dpkg --clear-avail
140   apt-cache gencaches 2>/dev/null
141   rm -f /var/lib/dpkg/status-old
142   rm -f /var/lib/dpkg/available-old
143 eend $?
144
145 if [ -x /usr/bin/grep-dctrl ] ; then
146    einfo "Cleaning up /var/lib/dpkg/status"
147    grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
148    cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status  && \
149    chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
150 else
151    ewarn "Warning: /usr/bin/grep-dctrl not available."
152 fi
153
154 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
155 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
156 eend $?
157
158 einfo "Removing x-server-conffiles"
159   rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
160         /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4 
161 eend $?
162
163 einfo "Removing ssh-keys"
164   rm -f /etc/ssh/*key*
165 eend $?
166
167 # remove only "temporary" or saved files in the given directories
168 nuke(){
169   for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
170     rm -f "$i"
171   done
172 }
173
174 # set all files in the given directories to a length of zero
175 zero(){
176   for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
177     :> "$i"
178   done
179 }
180
181 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
182 #  [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
183 #done
184
185 if [ -d /var/spool/squid/ ] ; then
186   einfo "Cleaning /var/spool/squid/0*"
187   rm -rf /var/spool/squid/0*
188   eend $?
189 else
190   ewarn "update-ca-certificates not installed" ; eend 0
191 fi
192
193 # delete old dowloaded packages
194 einfo "Running apt-get clean"
195   apt-get clean
196 eend $?
197
198 if [ -x /usr/bin/nvi ] ; then
199   if ! [ -d /var/tmp/vi.recover ] ; then
200     einfo "Creating nvi /var/tmp directory"
201     mkdir -p /var/tmp/vi.recover
202     chown root:root /var/tmp/vi.recover
203     chmod 1777 /var/tmp/vi.recover
204     eend $?
205   fi
206 else
207   ewarn "nvi not installed" ; eend 0
208 fi
209
210 if [ -x /sbin/depmod ] ; then
211   if [ -r /lib/modules/$KERNEL ] ; then
212     einfo "Updating modules.dep for kernel $KERNEL"
213     depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
214     eend $?
215   fi
216 else
217   ewarn "depmod not installed" ; eend 0
218 fi
219
220 if [ -n "$NOONLINE" ] ; then
221    einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
222 else
223
224 if [ -x /usr/bin/freshclam ] ; then
225   einfo "Updating clamav database via running freshclam"
226   /usr/bin/freshclam ; eend $?
227 else
228   ewarn "freshclam not installed" ; eend 0
229 fi
230
231 if [ -x /usr/bin/update-pciids ] ; then
232   einfo "Updating PCI- and USB-ids"
233   update-pciids
234   update-usbids
235   eend $?
236 else
237   ewarn "update-pciids/update-usbids not installed" ; eend 0
238 fi
239
240 if [ -x /usr/sbin/nessus-update-plugins ] ; then
241    einfo "Updating nessus-plugins"
242    nessus-update-plugins
243    eend $?
244 else
245   ewarn "nessus-update-plugins not installed" ; eend 0
246 fi
247
248 fi # end of $NOONLINE-check
249
250 einfo "Cleaning and removing some misc files and directories"
251   rm -f  /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new    \
252          /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
253          /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/*    \
254          /var/state/*/* /var/state/* /var/log/nessus/*                            \
255          /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv*           \
256          /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/*   \
257          /etc/lvm/.cache 2>/dev/null
258   rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
259          /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R  /var/spool/texmf/ls-R    \
260          /var/lib/mysql /var/log/lilo_log.* 2>/dev/null
261   nuke   /var/log       /var/cache
262   zero   /var/local     /var/log /var/spool \
263          /var/lib/games /var/cache/man      \
264          /var/lib/nfs   /var/lib/xkb        \
265          /var/mail/grml /var/account/pacct
266   mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
267   # Recreate empty utmp and wtmp
268   :>/var/run/utmp
269   :>/var/run/wtmp
270 eend $?
271
272 if [ -x /usr/sbin/update-ca-certificates ] ; then
273   einfo "Updating ca-certificates"
274   update-ca-certificates 1>/dev/null
275   eend $?
276 else
277   ewarn "update-ca-certificates not installed" ; eend 0
278 fi
279
280 # some stuff does not have to run every single time...
281 if [ -n "$FAST" ] ; then
282    einfo "\$FAST is set, skipping some tasks" ; eend 0
283 else
284
285 # regenerate module dependencies and ls.so.cache
286 if [ -x /sbin/ldconfig ] ; then
287   einfo "Updating ld.so.cache"
288   ldconfig
289   eend $?
290 else
291   ewarn "ldconfig not installed" ; eend 0
292 fi
293
294 if [ -x /usr/bin/update-menus ] ; then
295   einfo "Updating windowmanager menus"
296   update-menus -v
297   eend $?
298 else
299   ewarn "update-menus not installed" ; eend 0
300 fi
301
302 if [ -x /usr/bin/mktexlsr ] ; then
303   einfo "Updating texhash"
304   mktexlsr
305   eend $?
306 else
307   ewarn "mktexlsr not installed" ; eend 0
308 fi
309
310 if [ -x /usr/bin/mandb ] ; then
311   einfo "Updating mandb"
312   mandb -c
313   man doesnotexist >/dev/null 2>&1
314   eend $?
315 else
316   ewarn "mandb not installed" ; eend 0
317 fi
318
319 if [ -n "$REMOVE_DOCS" ] ; then
320   einfo "Cleaning documentation directories..."
321   if [ -d /usr/share/doc/grml-docs ] ; then
322      mv /usr/share/doc/grml-docs /tmp/
323   fi
324
325   rm -rf /usr/share/doc
326   mkdir /usr/share/doc
327
328   if [ -d /tmp/grml-docs ] ; then
329      mv /tmp/grml-docs /usr/share/doc/grml-docs
330   fi
331
332   rm -rf /usr/share/gtk-doc/
333   rm -rf /usr/share/man/
334   rm -rf /usr/man
335   rm -rf /usr/share/info
336   eend $?
337
338   einfo "Creating /usr/share/info/..."
339   mkdir -p /usr/share/info/
340   eend $?
341 fi
342
343 if [ -d /var/lib/clamav/ ] ; then
344   einfo "Cleaning /var/lib/clamav/"
345   rm -f /var/lib/clamav/clamav-* ; eend $?
346   if [ -f /var/lib/clamav/daily.cvd ] ; then
347      ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
348        cd /usr/share/doc/clamav-freshclam/examples/ && \
349        ln -sf /var/lib/clamav/daily.cvd . && \
350        ln -sf /var/lib/clamav/main.cvd  . )
351   fi
352 else
353   ewarn "clamav[-freshclam] not installed" ; eend 0
354 fi
355
356 if ! [ -r /etc/ld.so.nohwcap ] ; then
357    einfo "Creating /etc/ld.so.nohwcap"
358    touch /etc/ld.so.nohwcap
359 fi
360
361 # installation of resolvconf in chroot *with* /proc
362 # is different from an installation without /proc,
363 # so make sure it is OK in any case; don't use /dev/shm
364 if [ -d /etc/resolvconf ] ; then
365    rm -rf /etc/resolvconf/run
366    mkdir /etc/resolvconf/run
367    touch /etc/resolvconf/run/enable-updates
368    mkdir /etc/resolvconf/run/interface
369    cat > /etc/resolvconf/run/resolv.conf << EOF
370 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
371 #     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
372 EOF
373 fi
374
375 if [ -x /usr/bin/updatedb ] ; then
376   einfo "Updating locate-database"
377   mount -t proc none /proc
378   updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
379   umount /proc
380   eend $?
381 else
382   ewarn "updatedb not installed" ; eend 0
383 fi
384
385 fi # end of $FAST-check
386
387 einfo "Unmounting all filesystems"
388   umount -a
389 eend $?
390
391 ################################################################################
392 # MISC STUFF
393 # ~~~~~~~~~~
394 # list dangling symlinks: ls **/*(-@)
395 #
396 # Security-audit:
397 # find / \! -type l -perm -2000 -ls > audit/sgid-files 
398 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
399 # find / \! -type l -perm -4000 -ls > audit/suid-files
400 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
401 # find / -perm -0777 -type d -ls > audit/writeable-dirs
402 # find / -size +3000k > audit/big_files.new
403 # find /all_filesystems -name ".. " -print -xdev | cat -vet
404 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
405 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
406 #
407 # list non-stripped files:
408 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
409 #
410 # Is software by grml-repos up2date?
411 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo 
412 #
413 # runlevel.conf:
414 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
415 ################################################################################
416
417 ## END OF FILE #################################################################