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: Sat Sep 16 16:43:05 CEST 2006 [mika]
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.17-grml-small' || KERNEL='2.6.19-grml'
19 # important pre-checks
20 if [ -f /usr/share/initramfs-tools/init ] ; then
21 ORIG=$(md5sum /usr/share/initramfs-tools/init | awk '{print $1}')
22 GRML=$(md5sum /usr/share/initramfs-tools/init.grml | awk '{print $1}')
23 if [ "$ORIG" != "$GRML" ] ; then
24 eerror "Please fix /usr/share/initramfs-tools/init[.grml]" ; eend 1
27 ORIG=$(md5sum /usr/share/initramfs-tools/scripts/functions | awk '{print $1}')
28 GRML=$(md5sum /usr/share/initramfs-tools/scripts/functions.grml | awk '{print $1}')
29 if [ "$ORIG" != "$GRML" ] ; then
30 eerror "Please fix /usr/share/initramfs-tools/scripts/functions[.grml]" ; eend 1
36 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
37 if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
38 eerror "Broken diversion of artwiz-cursor, see #341397"
43 # start of main cleanup process...
44 if ! [ -r /boot/config-"$KERNEL" ] ; then
45 eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
50 einfo "Preparing grml-system: `cat /etc/grml_version`." ; eend 0
52 einfo "Do not forget to run the final check:"
54 einfo 'adjust grml-version: vim -X /etc/grml_version'
55 einfo 'is runlevel.conf ok: vimdiff -X /etc/runlevel.conf /etc/runlevel.conf.livecd'
56 einfo 'find old files: find /etc -name \*dpkg\*'
57 einfo "delete conffiles: dpkg --purge \`dpkg --list | grep '^rc' | awk '{print \$2}'\`"
58 einfo 'dangling symlinks: ls **/*(-@)'
61 einfo "Setting up /etc/modules: "
63 # /etc/modules: kernel modules to load at boot time.
65 # This file should contain the names of kernel modules that are
66 # to be loaded at boot time, one per line. Comments begin with
67 # a \`#', and everything on the line after them are ignored.
69 echo "" >> /etc/modules
70 grep '^[a-z]' /etc/grml/modules >> /etc/modules
73 if [ -z "$GRML_SMALL" ] ; then
74 if [ -L /usr/include/linux ] ; then
75 einfo "/usr/include/linux is ok" ; eend 0
77 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
83 einfo "Creating ~/.zshrc"
87 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
88 einfo "Stripping ion3-stuff"
89 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
90 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
92 ewarn "ion3 not installed" ; eend 0
95 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
96 einfo "Stripping /usr/lib/valgrind/x86-linux/"
97 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
100 ewarn "valgrind not installed" ; eend 0
103 if [ -x /usr/sbin/localepurge ] ; then
104 einfo "Running localepurge"
105 localepurge ; eend $?
107 ewarn "localepurg not available" ; eend 0
110 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
111 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
112 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
114 ewarn "backuppc not installed" ; eend 0
117 if [ -d /var/lib/clamav/ ] ; then
118 einfo "Cleaning /var/lib/clamav/"
119 rm -f /var/lib/clamav/clamav-* ; eend $?
120 if [ -f /var/lib/clamav/daily.cvd ] ; then
121 ( cd /usr/share/doc/clamav-freshclam/examples/ && \
122 ln -sf /var/lib/clamav/daily.cvd . && \
123 ln -sf /var/lib/clamav/main.cvd . )
126 ewarn "clamav[-freshclam] not installed" ; eend 0
129 # find /var -name \*.pid
130 einfo "Removing pid-files"
131 # find /var/run -name \*.pid | xargs rm ; echo "done"
132 find /var/run -name \*.pid -exec rm {} \;
135 einfo "Unmounting proc, /dev/pts, /dev/capi"
136 umount /proc 2>/dev/null
137 umount /dev/pts 2>/dev/null
138 umount /dev/capi 2>/dev/null
142 einfo "Removing initrd-images"
143 rm -f /boot/initrd.img-*
146 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
147 rm -f /var/lib/apt/lists/*Packages
148 rm -f /var/lib/apt/lists/*Release
149 rm -f /var/lib/apt/lists/*Sources
150 rm -f /var/lib/apt/lists/*.gpg
151 # :> /var/cache/apt/pkgcache.bin
152 # :> /var/cache/apt/srcpkgcache.bin
153 rm -f /var/lib/dpkg/status-old
154 rm -f /var/lib/dpkg/available-old
155 rm -f /var/cache/debconf/templates.dat-old
156 # for i in $(find /var/lib/apt/lists -type f \( -name \*Packages -o -name \*Sources \) 2>/dev/null); do :>"$i"; done
157 # for i in /var/lib/apt/lists/*_{Release,Packages,Sources}; do :>$i; touch -t 198103190000.00 $i; done
160 rm -f /var/cache/apt/*.bin
165 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
166 if ! [ -z $GRML_SMALL ] ; then
167 cp /etc/runlevel.conf.livecd.small /etc/runlevel.conf
169 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
173 einfo "Removing x-server-conffiles"
174 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
175 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
178 einfo "Removing ssh-keys"
182 if [ -r /usr/X11R6/lib/X11/fonts/misc/cursor.pcf.gz ] ; then
183 einfo "Fixing the broken artwiz-cursor"
184 ( cd /usr/X11R6/lib/X11/fonts/misc && \
185 dpkg-divert --remove /usr/X11R6/lib/X11/fonts/misc/cursor.pcf.gz && mkfontdir )
189 # remove only "temporary" or saved files in the given directories
191 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
196 # set all files in the given directories to a length of zero
198 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
203 #rmdir /mnt/cdrom?* /mnt/hd?* 2>/dev/null
205 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
206 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
209 if [ -d /var/spool/squid/ ] ; then
210 einfo "Cleaning /var/spool/squid/0*"
211 rm -rf /var/spool/squid/0*
214 ewarn "update-ca-certificates not installed" ; eend 0
217 # delete old dowloaded packages
218 einfo "Running apt-get clean"
222 # remove files from packages which have been removed
223 # COLUMNS=200 dpkg --purge `dpkg -l | grep '^rc' | awk '{ print $2 }'`
225 if [ -x /usr/bin/nvi ] ; then
226 if ! [ -d /var/tmp/vi.recover ] ; then
227 einfo "Creating nvi /var/tmp directory"
228 mkdir -p /var/tmp/vi.recover
229 chown root:root /var/tmp/vi.recover
230 chmod 1777 /var/tmp/vi.recover
234 ewarn "nvi not installed" ; eend 0
237 if [ -x /sbin/depmod ] ; then
238 if [ -r /lib/modules/$KERNEL ] ; then
239 einfo "Updating modules.dep for kernel $KERNEL"
244 ewarn "depmod not installed" ; eend 0
247 if [ -n "$NOONLINE" ] ; then
248 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
251 if [ -x /usr/bin/freshclam ] ; then
252 einfo "Updating clamav database via running freshclam"
253 /usr/bin/freshclam ; eend $?
255 ewarn "freshclam not installed" ; eend 0
258 if [ -x /usr/bin/update-pciids ] ; then
259 einfo "Updating PCI- and USB-ids"
262 # ls -la /usr/share/misc/*.ids*
263 # ls -la /var/lib/usbutils/usb*
266 ewarn "update-pciids/update-usbids not installed" ; eend 0
269 if [ -x /usr/sbin/nessus-update-plugins ] ; then
270 einfo "Updating nessus-plugins"
271 nessus-update-plugins
274 ewarn "nessus-update-plugins not installed" ; eend 0
277 fi # end of $NOONLINE-check
279 einfo "Cleaning and removing some misc files and directories"
280 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
281 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
282 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
283 /var/state/*/* /var/state/* /var/log/nessus/* \
284 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
285 /etc/resolv.conf /etc/*passwd- /etc/*shadow- /etc/*group- \
286 /var/spool/postfix/maildrop/* \
287 /etc/lvm/.cache 2>/dev/null
288 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
289 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
290 /var/lib/mysql 2>/dev/null
291 nuke /var/log /var/cache
292 zero /var/local /var/log /var/spool \
293 /var/lib/games /var/cache/man \
294 /var/lib/nfs /var/lib/xkb \
295 /var/mail/grml /var/account/pacct
296 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
297 # Recreate empty utmp and wtmp
302 einfo "Setting up /etc/resolv.conf"
303 cat >/etc/dhcpc/resolv.conf <<EOT
304 # insert nameservers here
305 # nameserver 127.0.0.1
307 chmod 644 /etc/dhcpc/resolv.conf
308 # is resolvconf available?
309 if [ -L /etc/resolvconf/run/resolv.conf ] ; then
310 ln -sf /etc/resolvconf/run/resolv.conf /etc/
312 ln -s /etc/dhcpc/resolv.conf /etc/
316 if [ -x /usr/sbin/update-ca-certificates ] ; then
317 einfo "Updating ca-certificates"
318 update-ca-certificates 1>/dev/null
321 ewarn "update-ca-certificates not installed" ; eend 0
324 # some stuff does not have to run every single time...
325 if [ -n "$FAST" ] ; then
326 einfo "\$FAST is set, skipping some tasks" ; eend 0
329 # regenerate module dependencies and ls.so.cache
330 if [ -x /sbin/ldconfig ] ; then
331 einfo "Updating ld.so.cache"
335 ewarn "ldconfig not installed" ; eend 0
338 if [ -r /lib/modules/$KERNEL/ ] ; then
339 einfo "Searching for modules not compiled against $KERNEL"
340 ( cd /lib/modules/$KERNEL/ && modinfo **/*.ko | grep vermagic | grep -v $KERNEL )
343 eerror "/lib/modules/$KERNEL/ not found" ; eend 1
346 if [ -x /usr/bin/update-menus ] ; then
347 einfo "Updating windowmanager menus"
351 ewarn "update-menus not installed" ; eend 0
354 if [ -x /usr/bin/mktexlsr ] ; then
355 einfo "Updating texhash"
359 ewarn "mktexlsr not installed" ; eend 0
362 if [ -x /usr/bin/mandb ] ; then
363 einfo "Updating mandb"
365 man doesnotexist >/dev/null 2>&1
368 ewarn "mandb not installed" ; eend 0
371 if [ -n "$GRML_SMALL" ] ; then
372 einfo "Cleaning up /etc/skel..."
373 rm -rf /etc/skel/.fluxbox
374 rm -rf /etc/skel/.gkrellm2
375 rm -rf /etc/skel/.idesktop
376 rm -rf /etc/skel/.pekwm
379 einfo "Cleaning documentation directories..."
380 mv /usr/share/doc/grml-docs /tmp/
381 rm -rf /usr/share/doc
383 mv /tmp/grml-docs /usr/share/doc/grml-docs
384 rm -rf /usr/share/gtk-doc/
385 rm -rf /usr/share/man/
387 rm -rf /usr/share/info
390 einfo "Creating /usr/share/info/..."
391 mkdir -p /usr/share/info/
395 if ! [ -r /etc/ld.so.nohwcap ] ; then
396 einfo "Creating /etc/ld.so.nohwcap"
397 touch /etc/ld.so.nohwcap
400 if [ -x /usr/bin/updatedb ] ; then
401 einfo "Updating locate-database"
402 mount -t proc none /proc
403 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
407 ewarn "updatedb not installed" ; eend 0
410 fi # end of $FAST-check
412 einfo "Unmounting all filesystems"
416 ################################################################################
421 # find / \! -type l -perm -2000 -ls > audit/sgid-files
422 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
423 # find / \! -type l -perm -4000 -ls > audit/suid-files
424 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
425 # find / -perm -0777 -type d -ls > audit/writeable-dirs
426 # find / -size +3000k > audit/big_files.new
427 # find /all_filesystems -name ".. " -print -xdev | cat -vet
428 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
429 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
431 # list non-stripped files:
432 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
434 # einfo "Removing unused architecture Kernel sources: "
435 # for i in `ls -1 /usr/src/linux/arch/ | grep -v i386`; do
436 # echo -n "$i "; rm -rf /usr/src/linux/arch/"$i" /usr/src/linux/include/asm-"$i"
440 # Is software by grml-repos up2date?
441 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
444 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
445 ################################################################################
448 # /usr/bin/mksquashfs /home/mika/grml/chroot/grml_uncompressed.large/* \
449 # /home/mika/grml/chroot/grml_cd.large/GRML/GRML -noappend -sort /home/mika/grml/svn/grml/remastering/sort
451 # mkisofs -V "grml 0.8" -publisher 'Michael Prokop <mika@grml.org>' -l -r \
452 # -J -no-emul-boot -boot-load-size 4 -boot-info-table -c boot/isolinux/boot.cat \
453 # -b boot/isolinux/isolinux.bin -o /home/mika/grml/chroot/grml_0.8.iso .
455 # vim grml_cd.large/GRML/grml-version
457 # find . -type f -not -name md5sums -not -name boot.cat -exec md5sum {} \; > GRML/md5sums
458 ################################################################################
460 ## END OF FILE #################################################################