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: Thu May 17 15:44:56 CEST 2007 [mika]
8 ################################################################################
12 . /etc/grml_colors || exit 5
13 . /etc/grml/lsb-functions || exit 6
15 # /usr/share/doc/texlive-latex-recommended/latex/
16 # /usr/share/doc/texlive-latex-base/latex/
17 # /usr/share/doc/texlive-base-bin/pdftex/thanh/
18 # /usr/share/doc/texlive-latex-base/latex/base/
19 # /usr/share/doc/texlive-latex-base/latex/hyperref/
20 # /usr/share/doc/texlive-latex-base/generic/babel/
21 # /usr/share/doc/texlive-latex-recommended/latex/koma-script/
22 # /usr/share/doc/texmf/pgf/pgfmanual.pdf.gz
25 grep -q small /etc/grml_version && GRML_SMALL=yes || GRML_SMALL=''
26 [ -x /lib64 ] && GRML64=yes || GRML64=''
27 if [ -n "$GRML_SMALL" ] ; then
28 echo -n 'Are you sure you want to run GRML_SMALL stuff? [y|N] '
30 if [ "$a" == 'y' ] ; then
31 echo 'Continuing as requested.'
33 echo 'Exiting as requested.'
39 # detect kernel version, assume newest kernel version
40 KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
42 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
43 if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
44 eerror "Broken diversion of artwiz-cursor, see #341397"
49 #if [ -r /usr/share/fonts/X11/misc/cursor.pcf.gz ] ; then
50 # einfo "Fixing the broken artwiz-cursor"
51 # ( cd /usr/share/fonts/X11/misc/ && \
52 # dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
56 # start of main cleanup process...
57 if ! [ -r /boot/config-"$KERNEL" ] ; then
58 eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
63 einfo "Preparing grml-system: `cat /etc/grml_version`." ; eend 0
65 einfo "Setting up /etc/motd.tail"
66 echo "" > /etc/motd.tail ; eend 0
68 einfo "Do not forget to run the final check:"
70 einfo 'adjust grml-version: vim -X /etc/grml_version'
71 einfo 'is runlevel.conf ok: vimdiff -X /etc/runlevel.conf /etc/runlevel.conf.livecd'
72 einfo 'find old files: find /etc -name \*dpkg\*'
73 einfo "delete conffiles: dpkg --purge \`dpkg --list | grep '^rc' | awk '{print \$2}'\`"
74 einfo 'dangling symlinks: ls **/*(-@)'
77 einfo "Setting up /etc/modules: "
79 # /etc/modules: kernel modules to load at boot time.
81 # This file should contain the names of kernel modules that are
82 # to be loaded at boot time, one per line. Comments begin with
83 # a \`#', and everything on the line after them are ignored.
85 echo "" >> /etc/modules
86 grep '^[a-z]' /etc/grml/modules >> /etc/modules
89 einfo "Setting up /etc/inittab"
90 if [ -z "$GRML_SMALL" ] ; then
91 cp /etc/inittab.grml /etc/inittab
93 cp /etc/inittab.small /etc/inittab
97 if [ -z "$GRML_SMALL" ] ; then
98 if [ -L /usr/include/linux ] ; then
99 einfo "/usr/include/linux is ok" ; eend 0
100 elif [ -n "$GRML64" ] ; then
101 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
102 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
104 eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
107 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
108 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
112 ewarn "linux-headers-$KERNEL not installed." ; eend 0
116 einfo "Creating ~/.zshrc"
120 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
121 einfo "Stripping ion3-stuff"
122 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
123 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
125 ewarn "ion3 not installed" ; eend 0
128 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
129 einfo "Stripping /usr/lib/valgrind/x86-linux/"
130 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
133 ewarn "valgrind not installed" ; eend 0
136 if [ -x /usr/sbin/localepurge ] ; then
137 einfo "Running localepurge"
138 localepurge ; eend $?
140 ewarn "localepurg not available" ; eend 0
143 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
144 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
145 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
147 ewarn "backuppc not installed" ; eend 0
150 # find /var -name \*.pid
151 einfo "Removing pid-files"
152 find /var/run -name \*.pid -exec rm {} \;
155 einfo "Unmounting proc, /dev/pts, /dev/capi"
156 umount /proc 2>/dev/null
157 umount /dev/pts 2>/dev/null
158 umount /dev/capi 2>/dev/null
159 umount -a 2>/dev/null
162 einfo "Removing initrd-images"
163 rm -f /boot/initrd.img-*
166 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
167 # for i in $(find /var/lib/apt/lists -type f \( -name \*Packages -o -name \*Sources \) 2>/dev/null); do :>"$i"; done
168 # for i in /var/lib/apt/lists/*_{Release,Packages,Sources}; do :>$i; touch -t 198103190000.00 $i; done
169 # sync-available 2>/dev/null
171 rm -f /var/lib/apt/lists/*Packages
172 rm -f /var/lib/apt/lists/*Release
173 rm -f /var/lib/apt/lists/*Sources
174 rm -f /var/lib/apt/lists/*.gpg
175 rm -f /var/cache/apt-show-versions/*
176 # :> /var/cache/apt/pkgcache.bin
177 # :> /var/cache/apt/srcpkgcache.bin
178 rm -f /var/cache/debconf/templates.dat-old
179 rm -f /var/cache/apt/*.bin
180 apt-get check 2>/dev/null
182 apt-cache gencaches 2>/dev/null
183 rm -f /var/lib/dpkg/status-old
184 rm -f /var/lib/dpkg/available-old
187 if [ -x /usr/bin/grep-dctrl ] ; then
188 einfo "Cleaning up /var/lib/dpkg/status"
189 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
190 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
191 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
193 ewarn "Warning: /usr/bin/grep-dctrl not available."
196 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
197 if ! [ -z $GRML_SMALL ] ; then
198 cp /etc/runlevel.conf.livecd.small /etc/runlevel.conf
200 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
204 einfo "Removing x-server-conffiles"
205 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
206 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
209 einfo "Removing ssh-keys"
213 # remove only "temporary" or saved files in the given directories
215 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
220 # set all files in the given directories to a length of zero
222 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
227 #rmdir /mnt/cdrom?* /mnt/hd?* 2>/dev/null
229 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
230 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
233 if [ -d /var/spool/squid/ ] ; then
234 einfo "Cleaning /var/spool/squid/0*"
235 rm -rf /var/spool/squid/0*
238 ewarn "update-ca-certificates not installed" ; eend 0
241 # delete old dowloaded packages
242 einfo "Running apt-get clean"
246 # remove files from packages which have been removed
247 # COLUMNS=200 dpkg --purge `dpkg -l | grep '^rc' | awk '{ print $2 }'`
249 if [ -x /usr/bin/nvi ] ; then
250 if ! [ -d /var/tmp/vi.recover ] ; then
251 einfo "Creating nvi /var/tmp directory"
252 mkdir -p /var/tmp/vi.recover
253 chown root:root /var/tmp/vi.recover
254 chmod 1777 /var/tmp/vi.recover
258 ewarn "nvi not installed" ; eend 0
261 if [ -x /sbin/depmod ] ; then
262 if [ -r /lib/modules/$KERNEL ] ; then
263 einfo "Updating modules.dep for kernel $KERNEL"
265 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
269 ewarn "depmod not installed" ; eend 0
272 if [ -n "$NOONLINE" ] ; then
273 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
276 if [ -x /usr/bin/freshclam ] ; then
277 einfo "Updating clamav database via running freshclam"
278 /usr/bin/freshclam ; eend $?
280 ewarn "freshclam not installed" ; eend 0
283 if [ -x /usr/bin/update-pciids ] ; then
284 einfo "Updating PCI- and USB-ids"
287 # ls -la /usr/share/misc/*.ids*
288 # ls -la /var/lib/usbutils/usb*
291 ewarn "update-pciids/update-usbids not installed" ; eend 0
294 if [ -x /usr/sbin/nessus-update-plugins ] ; then
295 einfo "Updating nessus-plugins"
296 nessus-update-plugins
299 ewarn "nessus-update-plugins not installed" ; eend 0
302 fi # end of $NOONLINE-check
304 einfo "Cleaning and removing some misc files and directories"
305 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
306 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
307 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
308 /var/state/*/* /var/state/* /var/log/nessus/* \
309 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
310 /etc/resolv.conf /etc/*passwd- /etc/*shadow- /etc/*group- \
311 /var/spool/postfix/maildrop/* \
312 /etc/lvm/.cache 2>/dev/null
313 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
314 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
315 /var/lib/mysql /var/log/lilo_log.* 2>/dev/null
316 nuke /var/log /var/cache
317 zero /var/local /var/log /var/spool \
318 /var/lib/games /var/cache/man \
319 /var/lib/nfs /var/lib/xkb \
320 /var/mail/grml /var/account/pacct
321 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
322 # Recreate empty utmp and wtmp
327 einfo "Setting up /etc/resolv.conf"
328 if [ -d /etc/dhcpc ] ; then
329 cat >/etc/dhcpc/resolv.conf <<EOT
330 # insert nameservers here
331 # nameserver 127.0.0.1
333 chmod 644 /etc/dhcpc/resolv.conf
335 cat >/etc/resolv.conf <<EOT
336 # insert nameservers here
337 # nameserver 127.0.0.1
339 chmod 644 /etc/resolv.conf
342 # is resolvconf available?
343 if [ -r /etc/resolvconf/run/resolv.conf ] ; then
344 ln -sf /etc/resolvconf/run/resolv.conf /etc/
346 ln -s /etc/dhcpc/resolv.conf /etc/
350 if [ -x /usr/sbin/update-ca-certificates ] ; then
351 einfo "Updating ca-certificates"
352 update-ca-certificates 1>/dev/null
355 ewarn "update-ca-certificates not installed" ; eend 0
358 # some stuff does not have to run every single time...
359 if [ -n "$FAST" ] ; then
360 einfo "\$FAST is set, skipping some tasks" ; eend 0
363 # regenerate module dependencies and ls.so.cache
364 if [ -x /sbin/ldconfig ] ; then
365 einfo "Updating ld.so.cache"
369 ewarn "ldconfig not installed" ; eend 0
372 #if [ -r /lib/modules/$KERNEL/ ] ; then
373 # einfo "Searching for modules not compiled against $KERNEL"
374 # ( cd /lib/modules/$KERNEL/ && modinfo **/*.ko | grep vermagic | grep -v $KERNEL )
377 # eerror "/lib/modules/$KERNEL/ not found" ; eend 1
380 if [ -x /usr/bin/update-menus ] ; then
381 einfo "Updating windowmanager menus"
385 ewarn "update-menus not installed" ; eend 0
388 if [ -x /usr/bin/mktexlsr ] ; then
389 einfo "Updating texhash"
393 ewarn "mktexlsr not installed" ; eend 0
396 if [ -x /usr/bin/mandb ] ; then
397 einfo "Updating mandb"
399 man doesnotexist >/dev/null 2>&1
402 ewarn "mandb not installed" ; eend 0
405 if [ -n "$GRML_SMALL" ] ; then
406 einfo "Cleaning up /etc/skel..."
407 rm -rf /etc/skel/.fluxbox
408 rm -rf /etc/skel/.gkrellm2
409 rm -rf /etc/skel/.idesktop
410 rm -rf /etc/skel/.pekwm
413 einfo "Cleaning documentation directories..."
414 mv /usr/share/doc/grml-docs /tmp/
415 rm -rf /usr/share/doc
417 mv /tmp/grml-docs /usr/share/doc/grml-docs
418 rm -rf /usr/share/gtk-doc/
419 rm -rf /usr/share/man/
421 rm -rf /usr/share/info
424 einfo "Creating /usr/share/info/..."
425 mkdir -p /usr/share/info/
429 if [ -d /var/lib/clamav/ ] ; then
430 einfo "Cleaning /var/lib/clamav/"
431 rm -f /var/lib/clamav/clamav-* ; eend $?
432 if [ -f /var/lib/clamav/daily.cvd ] ; then
433 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
434 cd /usr/share/doc/clamav-freshclam/examples/ && \
435 ln -sf /var/lib/clamav/daily.cvd . && \
436 ln -sf /var/lib/clamav/main.cvd . )
439 ewarn "clamav[-freshclam] not installed" ; eend 0
442 if ! [ -r /etc/ld.so.nohwcap ] ; then
443 einfo "Creating /etc/ld.so.nohwcap"
444 touch /etc/ld.so.nohwcap
447 if [ -x /usr/bin/updatedb ] ; then
448 einfo "Updating locate-database"
449 mount -t proc none /proc
450 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
454 ewarn "updatedb not installed" ; eend 0
457 fi # end of $FAST-check
459 einfo "Unmounting all filesystems"
463 ################################################################################
468 # find / \! -type l -perm -2000 -ls > audit/sgid-files
469 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
470 # find / \! -type l -perm -4000 -ls > audit/suid-files
471 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
472 # find / -perm -0777 -type d -ls > audit/writeable-dirs
473 # find / -size +3000k > audit/big_files.new
474 # find /all_filesystems -name ".. " -print -xdev | cat -vet
475 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
476 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
478 # list non-stripped files:
479 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
481 # einfo "Removing unused architecture Kernel sources: "
482 # for i in `ls -1 /usr/src/linux/arch/ | grep -v i386`; do
483 # echo -n "$i "; rm -rf /usr/src/linux/arch/"$i" /usr/src/linux/include/asm-"$i"
487 # Is software by grml-repos up2date?
488 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
491 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
492 ################################################################################
495 # /usr/bin/mksquashfs /home/mika/grml/chroot/grml_uncompressed.large/* \
496 # /home/mika/grml/chroot/grml_cd.large/GRML/GRML -noappend -sort /home/mika/grml/svn/grml/remastering/sort
498 # mkisofs -V "grml 0.8" -publisher 'Michael Prokop <mika@grml.org>' -l -r \
499 # -J -no-emul-boot -boot-load-size 4 -boot-info-table -c boot/isolinux/boot.cat \
500 # -b boot/isolinux/isolinux.bin -o /home/mika/grml/chroot/grml_0.8.iso .
502 # vim grml_cd.large/GRML/grml-version
504 # find . -type f -not -name md5sums -not -name boot.cat -exec md5sum {} \; > GRML/md5sums
505 ################################################################################
507 ## END OF FILE #################################################################