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 copyright by Michael Prokop
7 # Latest change: Sun Apr 15 17:31:51 CEST 2007
8 ################################################################################
12 . /etc/grml_colors || exit 5
13 . /etc/grml/lsb-functions || exit 6
16 grep -q small /etc/grml_version && GRML_SMALL=yes || GRML_SMALL=''
17 [ -n "$GRML_SMALL" ] && KERNEL='2.6.20-grml-small' || KERNEL='2.6.20-grml'
18 [ -r /lib64 ] && KERNEL='2.6.20-grml64' && GRML_SMALL=''
20 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
21 if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
22 eerror "Broken diversion of artwiz-cursor, see #341397"
27 #if [ -r /usr/share/fonts/X11/misc/cursor.pcf.gz ] ; then
28 # einfo "Fixing the broken artwiz-cursor"
29 # ( cd /usr/share/fonts/X11/misc/ && \
30 # dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
34 # start of main cleanup process...
35 if ! [ -r /boot/config-"$KERNEL" ] ; then
36 eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
41 einfo "Preparing grml-system: `cat /etc/grml_version`." ; eend 0
43 einfo "Setting up /etc/motd.tail"
44 echo "" > /etc/motd.tail ; eend 0
46 einfo "Do not forget to run the final check:"
48 einfo 'adjust grml-version: vim -X /etc/grml_version'
49 einfo 'is runlevel.conf ok: vimdiff -X /etc/runlevel.conf /etc/runlevel.conf.livecd'
50 einfo 'find old files: find /etc -name \*dpkg\*'
51 einfo "delete conffiles: dpkg --purge \`dpkg --list | grep '^rc' | awk '{print \$2}'\`"
52 einfo 'dangling symlinks: ls **/*(-@)'
55 einfo "Setting up /etc/modules: "
57 # /etc/modules: kernel modules to load at boot time.
59 # This file should contain the names of kernel modules that are
60 # to be loaded at boot time, one per line. Comments begin with
61 # a \`#', and everything on the line after them are ignored.
63 echo "" >> /etc/modules
64 grep '^[a-z]' /etc/grml/modules >> /etc/modules
67 if [ -z "$GRML_SMALL" ] ; then
68 if [ -L /usr/include/linux ] ; then
69 einfo "/usr/include/linux is ok" ; eend 0
71 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
77 einfo "Creating ~/.zshrc"
81 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
82 einfo "Stripping ion3-stuff"
83 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
84 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
86 ewarn "ion3 not installed" ; eend 0
89 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
90 einfo "Stripping /usr/lib/valgrind/x86-linux/"
91 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
94 ewarn "valgrind not installed" ; eend 0
97 if [ -x /usr/sbin/localepurge ] ; then
98 einfo "Running localepurge"
101 ewarn "localepurg not available" ; eend 0
104 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
105 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
106 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
108 ewarn "backuppc not installed" ; eend 0
111 if [ -d /var/lib/clamav/ ] ; then
112 einfo "Cleaning /var/lib/clamav/"
113 rm -f /var/lib/clamav/clamav-* ; eend $?
114 if [ -f /var/lib/clamav/daily.cvd ] ; then
115 ( cd /usr/share/doc/clamav-freshclam/examples/ && \
116 ln -sf /var/lib/clamav/daily.cvd . && \
117 ln -sf /var/lib/clamav/main.cvd . )
120 ewarn "clamav[-freshclam] not installed" ; eend 0
123 # find /var -name \*.pid
124 einfo "Removing pid-files"
125 # find /var/run -name \*.pid | xargs rm ; echo "done"
126 find /var/run -name \*.pid -exec rm {} \;
129 einfo "Unmounting proc, /dev/pts, /dev/capi"
130 umount /proc 2>/dev/null
131 umount /dev/pts 2>/dev/null
132 umount /dev/capi 2>/dev/null
136 einfo "Removing initrd-images"
137 rm -f /boot/initrd.img-*
140 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
141 rm -f /var/lib/apt/lists/*Packages
142 rm -f /var/lib/apt/lists/*Release
143 rm -f /var/lib/apt/lists/*Sources
144 rm -f /var/lib/apt/lists/*.gpg
145 # :> /var/cache/apt/pkgcache.bin
146 # :> /var/cache/apt/srcpkgcache.bin
147 rm -f /var/lib/dpkg/status-old
148 rm -f /var/lib/dpkg/available-old
149 rm -f /var/cache/debconf/templates.dat-old
150 # for i in $(find /var/lib/apt/lists -type f \( -name \*Packages -o -name \*Sources \) 2>/dev/null); do :>"$i"; done
151 # for i in /var/lib/apt/lists/*_{Release,Packages,Sources}; do :>$i; touch -t 198103190000.00 $i; done
154 rm -f /var/cache/apt/*.bin
160 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
161 if ! [ -z $GRML_SMALL ] ; then
162 cp /etc/runlevel.conf.livecd.small /etc/runlevel.conf
164 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
168 einfo "Removing x-server-conffiles"
169 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
170 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
173 einfo "Removing ssh-keys"
177 # remove only "temporary" or saved files in the given directories
179 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
184 # set all files in the given directories to a length of zero
186 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
191 #rmdir /mnt/cdrom?* /mnt/hd?* 2>/dev/null
193 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
194 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
197 if [ -d /var/spool/squid/ ] ; then
198 einfo "Cleaning /var/spool/squid/0*"
199 rm -rf /var/spool/squid/0*
202 ewarn "update-ca-certificates not installed" ; eend 0
205 # delete old dowloaded packages
206 einfo "Running apt-get clean"
210 # remove files from packages which have been removed
211 # COLUMNS=200 dpkg --purge `dpkg -l | grep '^rc' | awk '{ print $2 }'`
213 if [ -x /usr/bin/nvi ] ; then
214 if ! [ -d /var/tmp/vi.recover ] ; then
215 einfo "Creating nvi /var/tmp directory"
216 mkdir -p /var/tmp/vi.recover
217 chown root:root /var/tmp/vi.recover
218 chmod 1777 /var/tmp/vi.recover
222 ewarn "nvi not installed" ; eend 0
225 if [ -x /sbin/depmod ] ; then
226 if [ -r /lib/modules/$KERNEL ] ; then
227 einfo "Updating modules.dep for kernel $KERNEL"
232 ewarn "depmod not installed" ; eend 0
235 if [ -n "$NOONLINE" ] ; then
236 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
239 if [ -x /usr/bin/freshclam ] ; then
240 einfo "Updating clamav database via running freshclam"
241 /usr/bin/freshclam ; eend $?
243 ewarn "freshclam not installed" ; eend 0
246 if [ -x /usr/bin/update-pciids ] ; then
247 einfo "Updating PCI- and USB-ids"
250 # ls -la /usr/share/misc/*.ids*
251 # ls -la /var/lib/usbutils/usb*
254 ewarn "update-pciids/update-usbids not installed" ; eend 0
257 if [ -x /usr/sbin/nessus-update-plugins ] ; then
258 einfo "Updating nessus-plugins"
259 nessus-update-plugins
262 ewarn "nessus-update-plugins not installed" ; eend 0
265 fi # end of $NOONLINE-check
267 einfo "Cleaning and removing some misc files and directories"
268 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
269 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
270 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
271 /var/state/*/* /var/state/* /var/log/nessus/* \
272 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
273 /etc/resolv.conf /etc/*passwd- /etc/*shadow- /etc/*group- \
274 /var/spool/postfix/maildrop/* \
275 /etc/lvm/.cache 2>/dev/null
276 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
277 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
278 /var/lib/mysql 2>/dev/null
279 nuke /var/log /var/cache
280 zero /var/local /var/log /var/spool \
281 /var/lib/games /var/cache/man \
282 /var/lib/nfs /var/lib/xkb \
283 /var/mail/grml /var/account/pacct
284 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
285 # Recreate empty utmp and wtmp
290 einfo "Setting up /etc/resolv.conf"
291 if [ -d /etc/dhcpc ] ; then
292 cat >/etc/dhcpc/resolv.conf <<EOT
293 # insert nameservers here
294 # nameserver 127.0.0.1
296 chmod 644 /etc/dhcpc/resolv.conf
298 # is resolvconf available?
299 if [ -r /etc/resolvconf/run/resolv.conf ] ; then
300 ln -sf /etc/resolvconf/run/resolv.conf /etc/
302 ln -s /etc/dhcpc/resolv.conf /etc/
306 if [ -x /usr/sbin/update-ca-certificates ] ; then
307 einfo "Updating ca-certificates"
308 update-ca-certificates 1>/dev/null
311 ewarn "update-ca-certificates not installed" ; eend 0
314 # some stuff does not have to run every single time...
315 if [ -n "$FAST" ] ; then
316 einfo "\$FAST is set, skipping some tasks" ; eend 0
319 # regenerate module dependencies and ls.so.cache
320 if [ -x /sbin/ldconfig ] ; then
321 einfo "Updating ld.so.cache"
325 ewarn "ldconfig not installed" ; eend 0
328 if [ -r /lib/modules/$KERNEL/ ] ; then
329 einfo "Searching for modules not compiled against $KERNEL"
330 ( cd /lib/modules/$KERNEL/ && modinfo **/*.ko | grep vermagic | grep -v $KERNEL )
333 eerror "/lib/modules/$KERNEL/ not found" ; eend 1
336 if [ -x /usr/bin/update-menus ] ; then
337 einfo "Updating windowmanager menus"
341 ewarn "update-menus not installed" ; eend 0
344 if [ -x /usr/bin/mktexlsr ] ; then
345 einfo "Updating texhash"
349 ewarn "mktexlsr not installed" ; eend 0
352 if [ -x /usr/bin/mandb ] ; then
353 einfo "Updating mandb"
355 man doesnotexist >/dev/null 2>&1
358 ewarn "mandb not installed" ; eend 0
361 if [ -n "$GRML_SMALL" ] ; then
362 einfo "Cleaning up /etc/skel..."
363 rm -rf /etc/skel/.fluxbox
364 rm -rf /etc/skel/.gkrellm2
365 rm -rf /etc/skel/.idesktop
366 rm -rf /etc/skel/.pekwm
369 einfo "Cleaning documentation directories..."
370 mv /usr/share/doc/grml-docs /tmp/
371 rm -rf /usr/share/doc
373 mv /tmp/grml-docs /usr/share/doc/grml-docs
374 rm -rf /usr/share/gtk-doc/
375 rm -rf /usr/share/man/
377 rm -rf /usr/share/info
380 einfo "Creating /usr/share/info/..."
381 mkdir -p /usr/share/info/
385 if ! [ -r /etc/ld.so.nohwcap ] ; then
386 einfo "Creating /etc/ld.so.nohwcap"
387 touch /etc/ld.so.nohwcap
390 if [ -x /usr/bin/updatedb ] ; then
391 einfo "Updating locate-database"
392 mount -t proc none /proc
393 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
397 ewarn "updatedb not installed" ; eend 0
400 fi # end of $FAST-check
402 einfo "Unmounting all filesystems"
406 ################################################################################
411 # find / \! -type l -perm -2000 -ls > audit/sgid-files
412 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
413 # find / \! -type l -perm -4000 -ls > audit/suid-files
414 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
415 # find / -perm -0777 -type d -ls > audit/writeable-dirs
416 # find / -size +3000k > audit/big_files.new
417 # find /all_filesystems -name ".. " -print -xdev | cat -vet
418 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
419 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
421 # list non-stripped files:
422 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
424 # einfo "Removing unused architecture Kernel sources: "
425 # for i in `ls -1 /usr/src/linux/arch/ | grep -v i386`; do
426 # echo -n "$i "; rm -rf /usr/src/linux/arch/"$i" /usr/src/linux/include/asm-"$i"
430 # Is software by grml-repos up2date?
431 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
434 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
435 ################################################################################
438 # /usr/bin/mksquashfs /home/mika/grml/chroot/grml_uncompressed.large/* \
439 # /home/mika/grml/chroot/grml_cd.large/GRML/GRML -noappend -sort /home/mika/grml/svn/grml/remastering/sort
441 # mkisofs -V "grml 0.8" -publisher 'Michael Prokop <mika@grml.org>' -l -r \
442 # -J -no-emul-boot -boot-load-size 4 -boot-info-table -c boot/isolinux/boot.cat \
443 # -b boot/isolinux/isolinux.bin -o /home/mika/grml/chroot/grml_0.8.iso .
445 # vim grml_cd.large/GRML/grml-version
447 # find . -type f -not -name md5sums -not -name boot.cat -exec md5sum {} \; > GRML/md5sums
448 ################################################################################
450 ## END OF FILE #################################################################