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 if [ -L /usr/include/linux ] ; then
68 einfo "/usr/include/linux is ok" ; eend 0
69 elif [ -n "$GRML64" ] ; then
70 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
71 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
73 eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
76 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
77 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
81 ewarn "linux-headers-$KERNEL not installed." ; eend 0
84 einfo "Creating ~/.zshrc"
88 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
89 einfo "Stripping ion3-stuff"
90 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
91 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
93 ewarn "ion3 not installed" ; eend 0
96 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
97 einfo "Stripping /usr/lib/valgrind/x86-linux/"
98 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
101 ewarn "valgrind not installed" ; eend 0
104 if [ -x /usr/sbin/localepurge ] ; then
105 einfo "Running localepurge"
106 localepurge ; eend $?
108 ewarn "localepurg not available" ; eend 0
111 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
112 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
113 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
115 ewarn "backuppc not installed" ; eend 0
118 # find /var -name \*.pid
119 einfo "Removing pid-files"
120 find /var/run -name \*.pid -exec rm {} \;
123 einfo "Unmounting proc, /dev/pts, /dev/capi"
124 umount /proc 2>/dev/null
125 umount /dev/pts 2>/dev/null
126 umount /dev/capi 2>/dev/null
127 umount -a 2>/dev/null
130 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
131 rm -f /var/lib/apt/lists/*Packages
132 rm -f /var/lib/apt/lists/*Release
133 rm -f /var/lib/apt/lists/*Sources
134 rm -f /var/lib/apt/lists/*.gpg
135 rm -f /var/cache/apt-show-versions/*
136 rm -f /var/cache/debconf/templates.dat-old
137 rm -f /var/cache/apt/*.bin
138 apt-get check 2>/dev/null
140 apt-cache gencaches 2>/dev/null
141 rm -f /var/lib/dpkg/status-old
142 rm -f /var/lib/dpkg/available-old
145 if [ -x /usr/bin/grep-dctrl ] ; then
146 einfo "Cleaning up /var/lib/dpkg/status"
147 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
148 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
149 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
151 ewarn "Warning: /usr/bin/grep-dctrl not available."
154 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
155 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
158 einfo "Removing x-server-conffiles"
159 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
160 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
163 einfo "Removing ssh-keys"
167 # remove only "temporary" or saved files in the given directories
169 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
174 # set all files in the given directories to a length of zero
176 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
181 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
182 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
185 if [ -d /var/spool/squid/ ] ; then
186 einfo "Cleaning /var/spool/squid/0*"
187 rm -rf /var/spool/squid/0*
190 ewarn "update-ca-certificates not installed" ; eend 0
193 # delete old dowloaded packages
194 einfo "Running apt-get clean"
198 if [ -x /usr/bin/nvi ] ; then
199 if ! [ -d /var/tmp/vi.recover ] ; then
200 einfo "Creating nvi /var/tmp directory"
201 mkdir -p /var/tmp/vi.recover
202 chown root:root /var/tmp/vi.recover
203 chmod 1777 /var/tmp/vi.recover
207 ewarn "nvi not installed" ; eend 0
210 if [ -x /sbin/depmod ] ; then
211 if [ -r /lib/modules/$KERNEL ] ; then
212 einfo "Updating modules.dep for kernel $KERNEL"
213 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
217 ewarn "depmod not installed" ; eend 0
220 if [ -n "$NOONLINE" ] ; then
221 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
224 if [ -x /usr/bin/freshclam ] ; then
225 einfo "Updating clamav database via running freshclam"
226 /usr/bin/freshclam ; eend $?
228 ewarn "freshclam not installed" ; eend 0
231 if [ -x /usr/bin/update-pciids ] ; then
232 einfo "Updating PCI- and USB-ids"
237 ewarn "update-pciids/update-usbids not installed" ; eend 0
240 if [ -x /usr/sbin/nessus-update-plugins ] ; then
241 einfo "Updating nessus-plugins"
242 nessus-update-plugins
245 ewarn "nessus-update-plugins not installed" ; eend 0
248 fi # end of $NOONLINE-check
250 einfo "Cleaning and removing some misc files and directories"
251 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
252 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
253 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
254 /var/state/*/* /var/state/* /var/log/nessus/* \
255 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
256 /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
257 /etc/lvm/.cache 2>/dev/null
258 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
259 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
260 /var/lib/mysql /var/log/lilo_log.* 2>/dev/null
261 nuke /var/log /var/cache
262 zero /var/local /var/log /var/spool \
263 /var/lib/games /var/cache/man \
264 /var/lib/nfs /var/lib/xkb \
265 /var/mail/grml /var/account/pacct
266 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
267 # Recreate empty utmp and wtmp
272 if [ -x /usr/sbin/update-ca-certificates ] ; then
273 einfo "Updating ca-certificates"
274 update-ca-certificates 1>/dev/null
277 ewarn "update-ca-certificates not installed" ; eend 0
280 # some stuff does not have to run every single time...
281 if [ -n "$FAST" ] ; then
282 einfo "\$FAST is set, skipping some tasks" ; eend 0
285 # regenerate module dependencies and ls.so.cache
286 if [ -x /sbin/ldconfig ] ; then
287 einfo "Updating ld.so.cache"
291 ewarn "ldconfig not installed" ; eend 0
294 if [ -x /usr/bin/update-menus ] ; then
295 einfo "Updating windowmanager menus"
299 ewarn "update-menus not installed" ; eend 0
302 if [ -x /usr/bin/mktexlsr ] ; then
303 einfo "Updating texhash"
307 ewarn "mktexlsr not installed" ; eend 0
310 if [ -x /usr/bin/mandb ] ; then
311 einfo "Updating mandb"
313 man doesnotexist >/dev/null 2>&1
316 ewarn "mandb not installed" ; eend 0
319 if [ -n "$REMOVE_DOCS" ] ; then
320 einfo "Cleaning documentation directories..."
321 if [ -d /usr/share/doc/grml-docs ] ; then
322 mv /usr/share/doc/grml-docs /tmp/
325 rm -rf /usr/share/doc
328 if [ -d /tmp/grml-docs ] ; then
329 mv /tmp/grml-docs /usr/share/doc/grml-docs
332 rm -rf /usr/share/gtk-doc/
333 rm -rf /usr/share/man/
335 rm -rf /usr/share/info
338 einfo "Creating /usr/share/info/..."
339 mkdir -p /usr/share/info/
343 if [ -d /var/lib/clamav/ ] ; then
344 einfo "Cleaning /var/lib/clamav/"
345 rm -f /var/lib/clamav/clamav-* ; eend $?
346 if [ -f /var/lib/clamav/daily.cvd ] ; then
347 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
348 cd /usr/share/doc/clamav-freshclam/examples/ && \
349 ln -sf /var/lib/clamav/daily.cvd . && \
350 ln -sf /var/lib/clamav/main.cvd . )
353 ewarn "clamav[-freshclam] not installed" ; eend 0
356 if ! [ -r /etc/ld.so.nohwcap ] ; then
357 einfo "Creating /etc/ld.so.nohwcap"
358 touch /etc/ld.so.nohwcap
361 # installation of resolvconf in chroot *with* /proc
362 # is different from an installation without /proc,
363 # so make sure it is OK in any case; don't use /dev/shm
364 if [ -d /etc/resolvconf ] ; then
365 rm -rf /etc/resolvconf/run
366 mkdir /etc/resolvconf/run
367 touch /etc/resolvconf/run/enable-updates
368 mkdir /etc/resolvconf/run/interface
369 cat > /etc/resolvconf/run/resolv.conf << EOF
370 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
371 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
375 if [ -x /usr/bin/updatedb ] ; then
376 einfo "Updating locate-database"
377 mount -t proc none /proc
378 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
382 ewarn "updatedb not installed" ; eend 0
385 fi # end of $FAST-check
387 einfo "Unmounting all filesystems"
391 ################################################################################
394 # list dangling symlinks: ls **/*(-@)
397 # find / \! -type l -perm -2000 -ls > audit/sgid-files
398 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
399 # find / \! -type l -perm -4000 -ls > audit/suid-files
400 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
401 # find / -perm -0777 -type d -ls > audit/writeable-dirs
402 # find / -size +3000k > audit/big_files.new
403 # find /all_filesystems -name ".. " -print -xdev | cat -vet
404 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
405 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
407 # list non-stripped files:
408 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
410 # Is software by grml-repos up2date?
411 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
414 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
415 ################################################################################
417 ## END OF FILE #################################################################