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 ################################################################################
12 [ -n "$NOCOLORS" ] || . /etc/grml_colors
13 . /etc/grml/lsb-functions || exit 6
14 [ -x /lib64 ] && GRML64=yes || GRML64=''
16 # detect kernel version, assume newest kernel version
17 KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
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
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 )
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?"
46 einfo "Preparing grml-system: $(cat /etc/grml_version)" ; eend 0
48 einfo "Setting up /etc/motd.tail"
49 echo "" > /etc/motd.tail ; eend 0
51 einfo "Setting up /etc/modules: "
53 # /etc/modules: kernel modules to load at boot time.
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.
59 echo "" >> /etc/modules
60 grep '^[a-z]' /etc/grml/modules >> /etc/modules
63 einfo "Setting up /etc/inittab"
64 cp /etc/inittab.grml /etc/inittab
67 einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
68 ( cd /usr/src && make clean && make symlinks )
71 if [ -L /usr/include/linux ] ; then
72 einfo "/usr/include/linux is ok" ; eend 0
73 elif [ -n "$GRML64" ] ; then
74 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
75 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
77 eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
80 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
81 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
85 ewarn "linux-headers-$KERNEL not installed." ; eend 0
88 einfo "Creating ~/.zshrc"
92 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
93 einfo "Stripping ion3-stuff"
94 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
95 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
97 ewarn "ion3 not installed" ; eend 0
100 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
101 einfo "Stripping /usr/lib/valgrind/x86-linux/"
102 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
105 ewarn "valgrind not installed" ; eend 0
108 if [ -x /usr/sbin/localepurge ] ; then
109 einfo "Running localepurge"
110 localepurge ; eend $?
112 ewarn "localepurg not available" ; eend 0
115 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
116 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
117 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
119 ewarn "backuppc not installed" ; eend 0
122 # find /var -name \*.pid
123 einfo "Removing pid-files"
124 find /var/run -name \*.pid -exec rm {} \;
127 einfo "Unmounting proc, /dev/pts, /dev/capi"
128 umount /proc 2>/dev/null
129 umount /dev/pts 2>/dev/null
130 umount /dev/capi 2>/dev/null
131 umount -a 2>/dev/null
134 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
135 rm -f /var/lib/apt/lists/*Packages
136 rm -f /var/lib/apt/lists/*Release
137 rm -f /var/lib/apt/lists/*Sources
138 rm -f /var/lib/apt/lists/*.gpg
139 rm -f /var/cache/apt-show-versions/*
140 rm -f /var/cache/debconf/templates.dat-old
141 rm -f /var/cache/apt/*.bin
142 apt-get check 2>/dev/null
144 apt-cache gencaches 2>/dev/null
145 rm -f /var/lib/dpkg/status-old
146 rm -f /var/lib/dpkg/available-old
149 if [ -x /usr/bin/grep-dctrl ] ; then
150 einfo "Cleaning up /var/lib/dpkg/status"
151 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
152 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
153 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
155 ewarn "Warning: /usr/bin/grep-dctrl not available."
158 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
159 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
162 einfo "Removing x-server-conffiles"
163 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
164 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
167 einfo "Removing ssh-keys"
171 # remove only "temporary" or saved files in the given directories
173 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
178 # set all files in the given directories to a length of zero
180 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
185 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
186 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
189 if [ -d /var/spool/squid/ ] ; then
190 einfo "Cleaning /var/spool/squid/0*"
191 rm -rf /var/spool/squid/0*
194 ewarn "update-ca-certificates not installed" ; eend 0
197 # delete old dowloaded packages
198 einfo "Running apt-get clean"
202 if [ -x /usr/bin/nvi ] ; then
203 if ! [ -d /var/tmp/vi.recover ] ; then
204 einfo "Creating nvi /var/tmp directory"
205 mkdir -p /var/tmp/vi.recover
206 chown root:root /var/tmp/vi.recover
207 chmod 1777 /var/tmp/vi.recover
211 ewarn "nvi not installed" ; eend 0
214 if [ -x /sbin/depmod ] ; then
215 if [ -r /lib/modules/$KERNEL ] ; then
216 einfo "Updating modules.dep for kernel $KERNEL"
217 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
221 ewarn "depmod not installed" ; eend 0
224 if [ -n "$NOONLINE" ] ; then
225 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
228 if [ -x /usr/bin/freshclam ] ; then
229 einfo "Updating clamav database via running freshclam"
230 /usr/bin/freshclam ; eend $?
232 ewarn "freshclam not installed" ; eend 0
235 if [ -x /usr/bin/update-pciids ] ; then
236 einfo "Updating PCI- and USB-ids"
241 ewarn "update-pciids/update-usbids not installed" ; eend 0
244 if [ -x /usr/sbin/nessus-update-plugins ] ; then
245 einfo "Updating nessus-plugins"
246 nessus-update-plugins
249 ewarn "nessus-update-plugins not installed" ; eend 0
252 fi # end of $NOONLINE-check
254 einfo "Cleaning and removing some misc files and directories"
255 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
256 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
257 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
258 /var/state/*/* /var/state/* /var/log/nessus/* \
259 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
260 /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
261 /etc/lvm/.cache 2>/dev/null
262 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
263 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
264 /var/lib/mysql /var/log/lilo_log.* /core* 2>/dev/null
265 nuke /var/log /var/cache
266 zero /var/local /var/log /var/spool \
267 /var/lib/games /var/cache/man \
268 /var/lib/nfs /var/lib/xkb \
269 /var/mail/grml /var/account/pacct
270 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
271 # Recreate empty utmp and wtmp
276 if [ -x /usr/sbin/update-ca-certificates ] ; then
277 einfo "Updating ca-certificates"
278 update-ca-certificates 1>/dev/null
281 ewarn "update-ca-certificates not installed" ; eend 0
284 # some stuff does not have to run every single time...
285 if [ -n "$FAST" ] ; then
286 einfo "\$FAST is set, skipping some tasks" ; eend 0
289 # regenerate module dependencies and ls.so.cache
290 if [ -x /sbin/ldconfig ] ; then
291 einfo "Updating ld.so.cache"
295 ewarn "ldconfig not installed" ; eend 0
298 if [ -x /usr/bin/update-menus ] ; then
299 einfo "Updating windowmanager menus"
303 ewarn "update-menus not installed" ; eend 0
306 if [ -x /usr/bin/mktexlsr ] ; then
307 einfo "Updating texhash"
311 ewarn "mktexlsr not installed" ; eend 0
314 if [ -x /usr/bin/mandb ] ; then
315 einfo "Updating mandb"
317 man doesnotexist >/dev/null 2>&1
320 ewarn "mandb not installed" ; eend 0
323 if [ -n "$REMOVE_DOCS" ] ; then
324 einfo "Cleaning documentation directories..."
325 if [ -d /usr/share/doc/grml-docs ] ; then
326 mv /usr/share/doc/grml-docs /tmp/
329 rm -rf /usr/share/doc
332 if [ -d /tmp/grml-docs ] ; then
333 mv /tmp/grml-docs /usr/share/doc/grml-docs
336 rm -rf /usr/share/gtk-doc/
337 rm -rf /usr/share/man/
339 rm -rf /usr/share/info
342 einfo "Creating /usr/share/info/..."
343 mkdir -p /usr/share/info/
347 if [ -d /var/lib/clamav/ ] ; then
348 einfo "Cleaning /var/lib/clamav/"
349 rm -f /var/lib/clamav/clamav-* ; eend $?
350 if [ -f /var/lib/clamav/daily.cvd ] ; then
351 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
352 cd /usr/share/doc/clamav-freshclam/examples/ && \
353 ln -sf /var/lib/clamav/daily.cvd . && \
354 ln -sf /var/lib/clamav/main.cvd . )
357 ewarn "clamav[-freshclam] not installed" ; eend 0
360 if ! [ -r /etc/ld.so.nohwcap ] ; then
361 einfo "Creating /etc/ld.so.nohwcap"
362 touch /etc/ld.so.nohwcap
365 # installation of resolvconf in chroot *with* /proc
366 # is different from an installation without /proc,
367 # so make sure it is OK in any case; don't use /dev/shm
368 if [ -d /etc/resolvconf ] ; then
369 rm -rf /etc/resolvconf/run
370 mkdir /etc/resolvconf/run
371 touch /etc/resolvconf/run/enable-updates
372 mkdir /etc/resolvconf/run/interface
373 cat > /etc/resolvconf/run/resolv.conf << EOF
374 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
375 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
379 if [ -x /usr/bin/updatedb ] ; then
380 einfo "Updating locate-database"
381 mount -t proc none /proc
382 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
386 ewarn "updatedb not installed" ; eend 0
389 fi # end of $FAST-check
391 einfo "Unmounting all filesystems"
395 ################################################################################
398 # list dangling symlinks: ls **/*(-@)
401 # find / \! -type l -perm -2000 -ls > audit/sgid-files
402 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
403 # find / \! -type l -perm -4000 -ls > audit/suid-files
404 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
405 # find / -perm -0777 -type d -ls > audit/writeable-dirs
406 # find / -size +3000k > audit/big_files.new
407 # find /all_filesystems -name ".. " -print -xdev | cat -vet
408 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
409 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
411 # list non-stripped files:
412 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
414 # Is software by grml-repos up2date?
415 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
418 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
419 ################################################################################
421 ## END OF FILE #################################################################