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 16:57:17 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 if [ -z "$GRML_SMALL" ] ; then
65 cp /etc/inittab.grml /etc/inittab
67 cp /etc/inittab.small /etc/inittab
71 if [ -z "$GRML_SMALL" ] ; then
72 if [ -L /usr/include/linux ] ; then
73 einfo "/usr/include/linux is ok" ; eend 0
74 elif [ -n "$GRML64" ] ; then
75 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
76 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
78 eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
81 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
82 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
86 ewarn "linux-headers-$KERNEL not installed." ; eend 0
90 einfo "Creating ~/.zshrc"
94 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
95 einfo "Stripping ion3-stuff"
96 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
97 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
99 ewarn "ion3 not installed" ; eend 0
102 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
103 einfo "Stripping /usr/lib/valgrind/x86-linux/"
104 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
107 ewarn "valgrind not installed" ; eend 0
110 if [ -x /usr/sbin/localepurge ] ; then
111 einfo "Running localepurge"
112 localepurge ; eend $?
114 ewarn "localepurg not available" ; eend 0
117 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
118 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
119 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
121 ewarn "backuppc not installed" ; eend 0
124 # find /var -name \*.pid
125 einfo "Removing pid-files"
126 find /var/run -name \*.pid -exec rm {} \;
129 einfo "Unmounting proc, /dev/pts, /dev/capi"
130 umount /proc 2>/dev/null
131 umount /dev/pts 2>/dev/null
132 umount /dev/capi 2>/dev/null
133 umount -a 2>/dev/null
136 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
137 rm -f /var/lib/apt/lists/*Packages
138 rm -f /var/lib/apt/lists/*Release
139 rm -f /var/lib/apt/lists/*Sources
140 rm -f /var/lib/apt/lists/*.gpg
141 rm -f /var/cache/apt-show-versions/*
142 rm -f /var/cache/debconf/templates.dat-old
143 rm -f /var/cache/apt/*.bin
144 apt-get check 2>/dev/null
146 apt-cache gencaches 2>/dev/null
147 rm -f /var/lib/dpkg/status-old
148 rm -f /var/lib/dpkg/available-old
151 if [ -x /usr/bin/grep-dctrl ] ; then
152 einfo "Cleaning up /var/lib/dpkg/status"
153 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
154 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
155 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
157 ewarn "Warning: /usr/bin/grep-dctrl not available."
160 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
161 if ! [ -z $GRML_SMALL ] ; then
162 cp /etc/runlevel.conf.livecd.small /etc/runlevel.conf
164 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
168 einfo "Removing x-server-conffiles"
169 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
170 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
173 einfo "Removing ssh-keys"
177 # remove only "temporary" or saved files in the given directories
179 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
184 # set all files in the given directories to a length of zero
186 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
191 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
192 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
195 if [ -d /var/spool/squid/ ] ; then
196 einfo "Cleaning /var/spool/squid/0*"
197 rm -rf /var/spool/squid/0*
200 ewarn "update-ca-certificates not installed" ; eend 0
203 # delete old dowloaded packages
204 einfo "Running apt-get clean"
208 if [ -x /usr/bin/nvi ] ; then
209 if ! [ -d /var/tmp/vi.recover ] ; then
210 einfo "Creating nvi /var/tmp directory"
211 mkdir -p /var/tmp/vi.recover
212 chown root:root /var/tmp/vi.recover
213 chmod 1777 /var/tmp/vi.recover
217 ewarn "nvi not installed" ; eend 0
220 if [ -x /sbin/depmod ] ; then
221 if [ -r /lib/modules/$KERNEL ] ; then
222 einfo "Updating modules.dep for kernel $KERNEL"
223 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
227 ewarn "depmod not installed" ; eend 0
230 if [ -n "$NOONLINE" ] ; then
231 einfo "\$NOONLINE is set, skipping online tasks" ; eend 0
234 if [ -x /usr/bin/freshclam ] ; then
235 einfo "Updating clamav database via running freshclam"
236 /usr/bin/freshclam ; eend $?
238 ewarn "freshclam not installed" ; eend 0
241 if [ -x /usr/bin/update-pciids ] ; then
242 einfo "Updating PCI- and USB-ids"
247 ewarn "update-pciids/update-usbids not installed" ; eend 0
250 if [ -x /usr/sbin/nessus-update-plugins ] ; then
251 einfo "Updating nessus-plugins"
252 nessus-update-plugins
255 ewarn "nessus-update-plugins not installed" ; eend 0
258 fi # end of $NOONLINE-check
260 einfo "Cleaning and removing some misc files and directories"
261 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
262 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
263 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
264 /var/state/*/* /var/state/* /var/log/nessus/* \
265 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
266 /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
267 /etc/lvm/.cache 2>/dev/null
268 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
269 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
270 /var/lib/mysql /var/log/lilo_log.* 2>/dev/null
271 nuke /var/log /var/cache
272 zero /var/local /var/log /var/spool \
273 /var/lib/games /var/cache/man \
274 /var/lib/nfs /var/lib/xkb \
275 /var/mail/grml /var/account/pacct
276 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
277 # Recreate empty utmp and wtmp
282 if [ -x /usr/sbin/update-ca-certificates ] ; then
283 einfo "Updating ca-certificates"
284 update-ca-certificates 1>/dev/null
287 ewarn "update-ca-certificates not installed" ; eend 0
290 # some stuff does not have to run every single time...
291 if [ -n "$FAST" ] ; then
292 einfo "\$FAST is set, skipping some tasks" ; eend 0
295 # regenerate module dependencies and ls.so.cache
296 if [ -x /sbin/ldconfig ] ; then
297 einfo "Updating ld.so.cache"
301 ewarn "ldconfig not installed" ; eend 0
304 if [ -x /usr/bin/update-menus ] ; then
305 einfo "Updating windowmanager menus"
309 ewarn "update-menus not installed" ; eend 0
312 if [ -x /usr/bin/mktexlsr ] ; then
313 einfo "Updating texhash"
317 ewarn "mktexlsr not installed" ; eend 0
320 if [ -x /usr/bin/mandb ] ; then
321 einfo "Updating mandb"
323 man doesnotexist >/dev/null 2>&1
326 ewarn "mandb not installed" ; eend 0
329 if [ -n "$REMOVE_DOCS" ] ; then
330 # einfo "Cleaning up /etc/skel..."
331 # rm -rf /etc/skel/.fluxbox
332 # rm -rf /etc/skel/.gkrellm2
333 # rm -rf /etc/skel/.idesktop
334 # rm -rf /etc/skel/.pekwm
337 einfo "Cleaning documentation directories..."
338 if [ -d /usr/share/doc/grml-docs ] ; then
339 mv /usr/share/doc/grml-docs /tmp/
342 rm -rf /usr/share/doc
345 if [ -d /tmp/grml-docs ] ; then
346 mv /tmp/grml-docs /usr/share/doc/grml-docs
349 rm -rf /usr/share/gtk-doc/
350 rm -rf /usr/share/man/
352 rm -rf /usr/share/info
355 einfo "Creating /usr/share/info/..."
356 mkdir -p /usr/share/info/
360 if [ -d /var/lib/clamav/ ] ; then
361 einfo "Cleaning /var/lib/clamav/"
362 rm -f /var/lib/clamav/clamav-* ; eend $?
363 if [ -f /var/lib/clamav/daily.cvd ] ; then
364 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
365 cd /usr/share/doc/clamav-freshclam/examples/ && \
366 ln -sf /var/lib/clamav/daily.cvd . && \
367 ln -sf /var/lib/clamav/main.cvd . )
370 ewarn "clamav[-freshclam] not installed" ; eend 0
373 if ! [ -r /etc/ld.so.nohwcap ] ; then
374 einfo "Creating /etc/ld.so.nohwcap"
375 touch /etc/ld.so.nohwcap
378 if [ -x /usr/bin/updatedb ] ; then
379 einfo "Updating locate-database"
380 mount -t proc none /proc
381 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
385 ewarn "updatedb not installed" ; eend 0
388 fi # end of $FAST-check
390 einfo "Unmounting all filesystems"
394 ################################################################################
397 # list dangling symlinks: ls **/*(-@)
400 # find / \! -type l -perm -2000 -ls > audit/sgid-files
401 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
402 # find / \! -type l -perm -4000 -ls > audit/suid-files
403 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
404 # find / -perm -0777 -type d -ls > audit/writeable-dirs
405 # find / -size +3000k > audit/big_files.new
406 # find /all_filesystems -name ".. " -print -xdev | cat -vet
407 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
408 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
410 # list non-stripped files:
411 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
413 # Is software by grml-repos up2date?
414 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
417 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
418 ################################################################################
420 ## END OF FILE #################################################################