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: Sun Nov 04 12:12:57 CET 2007 [mika]
8 ################################################################################
12 . /etc/grml/lsb-functions || exit 6
13 [ -x /lib64 ] && GRML64=yes || GRML64=''
15 # detect kernel version, assume newest kernel version
16 KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
18 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
19 if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
20 eerror "Broken diversion of artwiz-cursor, see #341397, trying to fix it"
21 ( cd /usr/share/fonts/X11/misc/ &&
22 dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
27 # start of main cleanup process...
28 if ! [ -r /boot/config-"$KERNEL" ] ; then
29 eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
34 einfo "Preparing grml-system: $(cat /etc/grml_version)" ; eend 0
36 einfo "Setting up /etc/motd.tail"
37 echo "" > /etc/motd.tail ; eend 0
39 einfo "Setting up /etc/modules: "
41 # /etc/modules: kernel modules to load at boot time.
43 # This file should contain the names of kernel modules that are
44 # to be loaded at boot time, one per line. Comments begin with
45 # a \`#', and everything on the line after them are ignored.
47 echo "" >> /etc/modules
48 grep '^[a-z]' /etc/grml/modules >> /etc/modules
51 einfo "Setting up /etc/inittab"
52 cp /etc/inittab.grml /etc/inittab
55 if [ "$(dpkg --list | awk '/^rc/ { print $2}')" != '' ] ; then
56 einfo "Purging removed packages"
57 dpkg --purge $(dpkg --list | awk '/^rc/ { print $2}')
61 if [ -x /usr/bin/make -a -r /usr/src/Makefile ] ; then
62 einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
64 VER=$(/bin/ls -d /usr/src/linux-headers-* | head -1)
65 VER=${VER##/usr/src/linux-headers-}
66 if [ -n "$VER" ] ; then
67 VER=$VER make clean && \
68 VER=$VER make symlinks
77 if [ -L /usr/include/linux ] ; then
78 einfo "/usr/include/linux is ok" ; eend 0
79 elif [ -n "$GRML64" ] ; then
80 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
81 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
83 ewarn "Warning: /usr/src/linux-headers-$KERNEL not found, exiting." ; eend 0
85 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
86 ewarn "Warning: /usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ (possible an error)"
87 ewarn "Common reason: you forgot to install linux-kernel-headers-grml and use linux-libc-dev instead"
90 ewarn "Warning: 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 # find /var -name \*.pid
128 einfo "Removing pid-files"
129 find /var/run -name \*.pid -exec rm {} \;
132 einfo "Unmounting proc, /dev/pts, /dev/capi"
133 umount /proc 2>/dev/null
134 umount /dev/pts 2>/dev/null
135 umount /dev/capi 2>/dev/null
136 umount -a 2>/dev/null
139 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
140 rm -f /var/lib/apt/lists/*Packages
141 rm -f /var/lib/apt/lists/*Release
142 rm -f /var/lib/apt/lists/*Sources
143 rm -f /var/lib/apt/lists/*IndexDiff
144 rm -f /var/lib/apt/lists/*.gpg
145 rm -f /var/cache/apt-show-versions/*
146 rm -f /var/cache/debconf/templates.dat-old
147 rm -f /var/cache/apt/*.bin
148 apt-get check 2>/dev/null
150 apt-cache gencaches 2>/dev/null
151 rm -f /var/lib/dpkg/status-old
152 rm -f /var/lib/dpkg/available-old
155 if ifclass GRML_SMALL ; then
156 einfo "Removing /var/cache/debconf/templates.dat"
157 rm -f /var/cache/debconf/templates.dat
160 einfo "Removing /usr/share/ssh/blacklist.*"
161 rm -f /usr/share/ssh/blacklist.DSA-1024 /usr/share/ssh/blacklist.RSA-2048
165 # get rid of large kernel modules:
166 if ifclass GRML_SMALL ; then
167 if [ -r "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko" ] ; then
168 einfo "Removing /lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
169 rm -f "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
172 if [ -r "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko" ] ; then
173 einfo "Removing /lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko"
174 rm -f "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko"
179 if [ -x /usr/bin/grep-dctrl ] ; then
180 einfo "Cleaning up /var/lib/dpkg/status"
181 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
182 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
183 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
185 ewarn "Warning: /usr/bin/grep-dctrl not available."
188 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
189 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 einfo "Removing unused/backup files"
202 find / -name *~ -print0 | xargs -0 rm -f
205 # remove only "temporary" or saved files in the given directories
207 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
212 # set all files in the given directories to a length of zero
214 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
219 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
220 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
223 if [ -d /var/spool/squid/ ] ; then
224 einfo "Cleaning /var/spool/squid/0*"
225 rm -rf /var/spool/squid/0*
228 ewarn "update-ca-certificates not installed" ; eend 0
231 # delete old dowloaded packages
232 einfo "Running apt-get clean"
236 if [ -x /usr/bin/nvi ] ; then
237 if ! [ -d /var/tmp/vi.recover ] ; then
238 einfo "Creating nvi /var/tmp directory"
239 mkdir -p /var/tmp/vi.recover
240 chown root:root /var/tmp/vi.recover
241 chmod 1777 /var/tmp/vi.recover
245 ewarn "nvi not installed" ; eend 0
248 if [ -x /sbin/depmod ] ; then
249 if [ -r /lib/modules/$KERNEL ] ; then
250 einfo "Updating modules.dep for kernel $KERNEL"
251 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
255 ewarn "depmod not installed" ; eend 0
258 einfo "Cleaning and removing some misc files and directories"
259 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
260 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
261 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
262 /var/state/*/* /var/state/* /var/log/nessus/* \
263 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
264 /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
265 /etc/lvm/.cache 2>/dev/null
266 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
267 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
268 /var/lib/mysql /var/log/lilo_log.* /core* 2>/dev/null
269 nuke /var/log /var/cache
270 zero /var/local /var/log /var/spool \
271 /var/lib/games /var/cache/man \
272 /var/lib/nfs /var/lib/xkb \
273 /var/mail/grml /var/account/pacct
274 # Recreate empty utmp and wtmp
279 if [ -x /usr/sbin/update-ca-certificates ] ; then
280 einfo "Updating ca-certificates"
281 update-ca-certificates 1>/dev/null
284 ewarn "update-ca-certificates not installed" ; eend 0
287 # regenerate module dependencies and ls.so.cache
288 if [ -x /sbin/ldconfig ] ; then
289 einfo "Updating ld.so.cache"
293 ewarn "ldconfig not installed" ; eend 0
296 if [ -x /usr/bin/update-menus ] ; then
297 einfo "Updating windowmanager menus"
301 ewarn "update-menus not installed" ; eend 0
304 if [ -x /usr/bin/mktexlsr ] ; then
305 einfo "Updating texhash"
309 ewarn "mktexlsr not installed" ; eend 0
312 if [ -x /usr/bin/mandb ] ; then
313 einfo "Updating mandb"
315 man doesnotexist >/dev/null 2>&1
318 ewarn "mandb not installed" ; eend 0
321 if [ -d /var/lib/clamav/ ] ; then
322 einfo "Cleaning /var/lib/clamav/"
323 rm -f /var/lib/clamav/clamav-* ; eend $?
324 if [ -f /var/lib/clamav/daily.cvd ] ; then
325 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
326 cd /usr/share/doc/clamav-freshclam/examples/ && \
327 ln -sf /var/lib/clamav/daily.cvd . && \
328 ln -sf /var/lib/clamav/main.cvd . )
331 ewarn "clamav[-freshclam] not installed" ; eend 0
334 if [ -f /etc/default/snort.dpkg-dist -a -f /etc/default/snort ] ; then
335 einfo "Fixxing /etc/default/snort"
336 mv /etc/default/snort.dpkg-dist /etc/default/snort
340 if ! [ -r /etc/ld.so.nohwcap ] ; then
341 einfo "Creating /etc/ld.so.nohwcap"
342 touch /etc/ld.so.nohwcap
345 # installation of resolvconf in chroot *with* /proc
346 # is different from an installation without /proc,
347 # so make sure it is OK in any case; don't use /dev/shm
348 if [ -d /etc/resolvconf ] ; then
349 rm -rf /etc/resolvconf/run
350 mkdir /etc/resolvconf/run
351 touch /etc/resolvconf/run/enable-updates
352 mkdir /etc/resolvconf/run/interface
353 cat > /etc/resolvconf/run/resolv.conf << EOF
354 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
355 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
359 if [ -x /usr/bin/updatedb ] ; then
360 einfo "Updating locate-database"
361 mount -t proc none /proc
362 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
366 ewarn "updatedb not installed" ; eend 0
369 einfo "Unmounting all filesystems"
373 ################################################################################
376 # list dangling symlinks: ls **/*(-@)
379 # find / \! -type l -perm -2000 -ls > audit/sgid-files
380 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
381 # find / \! -type l -perm -4000 -ls > audit/suid-files
382 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
383 # find / -perm -0777 -type d -ls > audit/writeable-dirs
384 # find / -size +3000k > audit/big_files.new
385 # find /all_filesystems -name ".. " -print -xdev | cat -vet
386 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
387 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
389 # list non-stripped files:
390 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
392 # Is software by grml-repos up2date?
393 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
396 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
397 ################################################################################
399 ## END OF FILE #################################################################