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 22 14:15:03 CEST 2007 [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 if [ -n "$GRML_SMALL" ] ; then
18 echo -n 'Are you sure you want to run GRML_SMALL stuff? [y|N] '
20 if [ "$a" == 'y' ] ; then
21 echo 'Continuing as requested.'
23 echo 'Exiting as requested.'
29 # detect kernel version, assume newest kernel version
30 KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
32 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
33 if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
34 eerror "Broken diversion of artwiz-cursor, see #341397"
39 #if [ -r /usr/share/fonts/X11/misc/cursor.pcf.gz ] ; then
40 # einfo "Fixing the broken artwiz-cursor"
41 # ( cd /usr/share/fonts/X11/misc/ && \
42 # dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
46 # start of main cleanup process...
47 if ! [ -r /boot/config-"$KERNEL" ] ; then
48 eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
53 einfo "Preparing grml-system: `cat /etc/grml_version`." ; eend 0
55 einfo "Setting up /etc/motd.tail"
56 echo "" > /etc/motd.tail ; eend 0
58 einfo "Do not forget to run the final check:"
60 einfo 'adjust grml-version: vim -X /etc/grml_version'
61 einfo 'is runlevel.conf ok: vimdiff -X /etc/runlevel.conf /etc/runlevel.conf.livecd'
62 einfo 'find old files: find /etc -name \*dpkg\*'
63 einfo "delete conffiles: dpkg --purge \`dpkg --list | grep '^rc' | awk '{print \$2}'\`"
64 einfo 'dangling symlinks: ls **/*(-@)'
67 einfo "Setting up /etc/modules: "
69 # /etc/modules: kernel modules to load at boot time.
71 # This file should contain the names of kernel modules that are
72 # to be loaded at boot time, one per line. Comments begin with
73 # a \`#', and everything on the line after them are ignored.
75 echo "" >> /etc/modules
76 grep '^[a-z]' /etc/grml/modules >> /etc/modules
79 if [ -z "$GRML_SMALL" ] ; then
80 if [ -L /usr/include/linux ] ; then
81 einfo "/usr/include/linux is ok" ; eend 0
83 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
84 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
88 ewarn "linux-headers-$KERNEL not installed." ; eend 0
93 einfo "Creating ~/.zshrc"
97 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
98 einfo "Stripping ion3-stuff"
99 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
100 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
102 ewarn "ion3 not installed" ; eend 0
105 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
106 einfo "Stripping /usr/lib/valgrind/x86-linux/"
107 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
110 ewarn "valgrind not installed" ; eend 0
113 if [ -x /usr/sbin/localepurge ] ; then
114 einfo "Running localepurge"
115 localepurge ; eend $?
117 ewarn "localepurg not available" ; eend 0
120 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
121 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
122 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
124 ewarn "backuppc not installed" ; eend 0
127 if [ -d /var/lib/clamav/ ] ; then
128 einfo "Cleaning /var/lib/clamav/"
129 rm -f /var/lib/clamav/clamav-* ; eend $?
130 if [ -f /var/lib/clamav/daily.cvd ] ; then
131 ( cd /usr/share/doc/clamav-freshclam/examples/ && \
132 ln -sf /var/lib/clamav/daily.cvd . && \
133 ln -sf /var/lib/clamav/main.cvd . )
136 ewarn "clamav[-freshclam] not installed" ; eend 0
139 # find /var -name \*.pid
140 einfo "Removing pid-files"
141 find /var/run -name \*.pid -exec rm {} \;
144 einfo "Unmounting proc, /dev/pts, /dev/capi"
145 umount /proc 2>/dev/null
146 umount /dev/pts 2>/dev/null
147 umount /dev/capi 2>/dev/null
151 einfo "Removing initrd-images"
152 rm -f /boot/initrd.img-*
155 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
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
158 # sync-available 2>/dev/null
160 rm -f /var/lib/apt/lists/*Packages
161 rm -f /var/lib/apt/lists/*Release
162 rm -f /var/lib/apt/lists/*Sources
163 rm -f /var/lib/apt/lists/*.gpg
164 # :> /var/cache/apt/pkgcache.bin
165 # :> /var/cache/apt/srcpkgcache.bin
166 rm -f /var/cache/debconf/templates.dat-old
167 rm -f /var/cache/apt/*.bin
168 apt-get check 2>/dev/null
170 apt-cache gencaches 2>/dev/null
171 rm -f /var/lib/dpkg/status-old
172 rm -f /var/lib/dpkg/available-old
175 if [ -x /usr/bin/grep-dctrl ] ; then
176 einfo "Cleaning up /var/lib/dpkg/status"
177 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
178 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
179 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
181 ewarn "Warning: /usr/bin/grep-dctrl not available."
184 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
185 if ! [ -z $GRML_SMALL ] ; then
186 cp /etc/runlevel.conf.livecd.small /etc/runlevel.conf
188 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
192 einfo "Removing x-server-conffiles"
193 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
194 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
197 einfo "Removing ssh-keys"
201 # remove only "temporary" or saved files in the given directories
203 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
208 # set all files in the given directories to a length of zero
210 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
215 #rmdir /mnt/cdrom?* /mnt/hd?* 2>/dev/null
217 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
218 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
221 if [ -d /var/spool/squid/ ] ; then
222 einfo "Cleaning /var/spool/squid/0*"
223 rm -rf /var/spool/squid/0*
226 ewarn "update-ca-certificates not installed" ; eend 0
229 # delete old dowloaded packages
230 einfo "Running apt-get clean"
234 # remove files from packages which have been removed
235 # COLUMNS=200 dpkg --purge `dpkg -l | grep '^rc' | awk '{ print $2 }'`
237 if [ -x /usr/bin/nvi ] ; then
238 if ! [ -d /var/tmp/vi.recover ] ; then
239 einfo "Creating nvi /var/tmp directory"
240 mkdir -p /var/tmp/vi.recover
241 chown root:root /var/tmp/vi.recover
242 chmod 1777 /var/tmp/vi.recover
246 ewarn "nvi not installed" ; eend 0
249 if [ -x /sbin/depmod ] ; then
250 if [ -r /lib/modules/$KERNEL ] ; then
251 einfo "Updating modules.dep for kernel $KERNEL"
256 ewarn "depmod not installed" ; eend 0
259 if [ -n "$NOONLINE" ] ; then
260 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
263 if [ -x /usr/bin/freshclam ] ; then
264 einfo "Updating clamav database via running freshclam"
265 /usr/bin/freshclam ; eend $?
267 ewarn "freshclam not installed" ; eend 0
270 if [ -x /usr/bin/update-pciids ] ; then
271 einfo "Updating PCI- and USB-ids"
274 # ls -la /usr/share/misc/*.ids*
275 # ls -la /var/lib/usbutils/usb*
278 ewarn "update-pciids/update-usbids not installed" ; eend 0
281 if [ -x /usr/sbin/nessus-update-plugins ] ; then
282 einfo "Updating nessus-plugins"
283 nessus-update-plugins
286 ewarn "nessus-update-plugins not installed" ; eend 0
289 fi # end of $NOONLINE-check
291 einfo "Cleaning and removing some misc files and directories"
292 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
293 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
294 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
295 /var/state/*/* /var/state/* /var/log/nessus/* \
296 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
297 /etc/resolv.conf /etc/*passwd- /etc/*shadow- /etc/*group- \
298 /var/spool/postfix/maildrop/* \
299 /etc/lvm/.cache 2>/dev/null
300 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
301 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
302 /var/lib/mysql 2>/dev/null
303 nuke /var/log /var/cache
304 zero /var/local /var/log /var/spool \
305 /var/lib/games /var/cache/man \
306 /var/lib/nfs /var/lib/xkb \
307 /var/mail/grml /var/account/pacct
308 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
309 # Recreate empty utmp and wtmp
314 einfo "Setting up /etc/resolv.conf"
315 if [ -d /etc/dhcpc ] ; then
316 cat >/etc/dhcpc/resolv.conf <<EOT
317 # insert nameservers here
318 # nameserver 127.0.0.1
320 chmod 644 /etc/dhcpc/resolv.conf
322 cat >/etc/resolv.conf <<EOT
323 # insert nameservers here
324 # nameserver 127.0.0.1
326 chmod 644 /etc/resolv.conf
329 # is resolvconf available?
330 if ! [ -r /etc/resolv.conf ] ; then
331 if [ -r /etc/resolvconf/run/resolv.conf ] ; then
332 ln -sf /etc/resolvconf/run/resolv.conf /etc/
334 ln -s /etc/dhcpc/resolv.conf /etc/
339 if [ -x /usr/sbin/update-ca-certificates ] ; then
340 einfo "Updating ca-certificates"
341 update-ca-certificates 1>/dev/null
344 ewarn "update-ca-certificates not installed" ; eend 0
347 # some stuff does not have to run every single time...
348 if [ -n "$FAST" ] ; then
349 einfo "\$FAST is set, skipping some tasks" ; eend 0
352 # regenerate module dependencies and ls.so.cache
353 if [ -x /sbin/ldconfig ] ; then
354 einfo "Updating ld.so.cache"
358 ewarn "ldconfig not installed" ; eend 0
361 #if [ -r /lib/modules/$KERNEL/ ] ; then
362 # einfo "Searching for modules not compiled against $KERNEL"
363 # ( cd /lib/modules/$KERNEL/ && modinfo **/*.ko | grep vermagic | grep -v $KERNEL )
366 # eerror "/lib/modules/$KERNEL/ not found" ; eend 1
369 if [ -x /usr/bin/update-menus ] ; then
370 einfo "Updating windowmanager menus"
374 ewarn "update-menus not installed" ; eend 0
377 if [ -x /usr/bin/mktexlsr ] ; then
378 einfo "Updating texhash"
382 ewarn "mktexlsr not installed" ; eend 0
385 if [ -x /usr/bin/mandb ] ; then
386 einfo "Updating mandb"
388 man doesnotexist >/dev/null 2>&1
391 ewarn "mandb not installed" ; eend 0
394 if [ -n "$GRML_SMALL" ] ; then
395 einfo "Cleaning up /etc/skel..."
396 rm -rf /etc/skel/.fluxbox
397 rm -rf /etc/skel/.gkrellm2
398 rm -rf /etc/skel/.idesktop
399 rm -rf /etc/skel/.pekwm
402 einfo "Cleaning documentation directories..."
403 mv /usr/share/doc/grml-docs /tmp/
404 rm -rf /usr/share/doc
406 mv /tmp/grml-docs /usr/share/doc/grml-docs
407 rm -rf /usr/share/gtk-doc/
408 rm -rf /usr/share/man/
410 rm -rf /usr/share/info
413 einfo "Creating /usr/share/info/..."
414 mkdir -p /usr/share/info/
418 if ! [ -r /etc/ld.so.nohwcap ] ; then
419 einfo "Creating /etc/ld.so.nohwcap"
420 touch /etc/ld.so.nohwcap
423 if [ -x /usr/bin/updatedb ] ; then
424 einfo "Updating locate-database"
425 mount -t proc none /proc
426 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
430 ewarn "updatedb not installed" ; eend 0
433 fi # end of $FAST-check
435 einfo "Unmounting all filesystems"
439 ################################################################################
444 # find / \! -type l -perm -2000 -ls > audit/sgid-files
445 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
446 # find / \! -type l -perm -4000 -ls > audit/suid-files
447 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
448 # find / -perm -0777 -type d -ls > audit/writeable-dirs
449 # find / -size +3000k > audit/big_files.new
450 # find /all_filesystems -name ".. " -print -xdev | cat -vet
451 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
452 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
454 # list non-stripped files:
455 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
457 # einfo "Removing unused architecture Kernel sources: "
458 # for i in `ls -1 /usr/src/linux/arch/ | grep -v i386`; do
459 # echo -n "$i "; rm -rf /usr/src/linux/arch/"$i" /usr/src/linux/include/asm-"$i"
463 # Is software by grml-repos up2date?
464 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
467 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
468 ################################################################################
471 # /usr/bin/mksquashfs /home/mika/grml/chroot/grml_uncompressed.large/* \
472 # /home/mika/grml/chroot/grml_cd.large/GRML/GRML -noappend -sort /home/mika/grml/svn/grml/remastering/sort
474 # mkisofs -V "grml 0.8" -publisher 'Michael Prokop <mika@grml.org>' -l -r \
475 # -J -no-emul-boot -boot-load-size 4 -boot-info-table -c boot/isolinux/boot.cat \
476 # -b boot/isolinux/isolinux.bin -o /home/mika/grml/chroot/grml_0.8.iso .
478 # vim grml_cd.large/GRML/grml-version
480 # find . -type f -not -name md5sums -not -name boot.cat -exec md5sum {} \; > GRML/md5sums
481 ################################################################################
483 ## END OF FILE #################################################################