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 ################################################################################
11 . /etc/grml/lsb-functions || exit 6
12 [ -x /lib64 ] && GRML64=yes || GRML64=''
14 # detect kernel version, assume newest kernel version
15 KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
17 if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
18 if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
19 eerror "Broken diversion of artwiz-cursor, see #341397, trying to fix it"
20 ( cd /usr/share/fonts/X11/misc/ &&
21 dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
26 # start of main cleanup process...
27 if ! [ -r /boot/config-"$KERNEL" ] ; then
28 eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
33 einfo "Preparing grml-system: $(cat /etc/grml_version)" ; eend 0
35 einfo "Setting up /etc/motd.tail"
36 echo "" > /etc/motd.tail ; eend 0
38 einfo "Setting up /etc/modules: "
40 # /etc/modules: kernel modules to load at boot time.
42 # This file should contain the names of kernel modules that are
43 # to be loaded at boot time, one per line. Comments begin with
44 # a \`#', and everything on the line after them are ignored.
46 echo "" >> /etc/modules
47 grep '^[a-z]' /etc/grml/modules >> /etc/modules
50 einfo "Setting up /etc/inittab"
51 cp /etc/inittab.grml /etc/inittab
54 if [ "$(dpkg --list | awk '/^rc/ { print $2}')" != '' ] ; then
55 einfo "Purging removed packages"
56 dpkg --purge $(dpkg --list | awk '/^rc/ { print $2}')
60 if [ -x /usr/bin/make -a -r /usr/src/Makefile ] ; then
61 einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
63 VER=$(/bin/ls -d /usr/src/linux-headers-* | head -1)
64 VER=${VER##/usr/src/linux-headers-}
65 if [ -n "$VER" ] ; then
66 VER=$VER make clean && \
67 VER=$VER make symlinks
76 if [ -L /usr/include/linux ] ; then
77 einfo "/usr/include/linux is ok" ; eend 0
78 elif [ -n "$GRML64" ] ; then
79 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
80 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
82 ewarn "Warning: /usr/src/linux-headers-$KERNEL not found, exiting." ; eend 0
84 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
85 ewarn "Warning: /usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ (possible an error)"
86 ewarn "Common reason: you forgot to install linux-kernel-headers-grml and use linux-libc-dev instead"
89 ewarn "Warning: linux-headers-$KERNEL not installed." ; eend 0
92 einfo "Creating ~/.zshrc"
96 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
97 einfo "Stripping ion3-stuff"
98 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
99 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
101 ewarn "ion3 not installed" ; eend 0
104 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
105 einfo "Stripping /usr/lib/valgrind/x86-linux/"
106 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
109 ewarn "valgrind not installed" ; eend 0
112 if [ -x /usr/sbin/localepurge ] ; then
113 einfo "Running localepurge"
114 localepurge ; eend $?
116 ewarn "localepurg not available" ; eend 0
119 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
120 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
121 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
123 ewarn "backuppc not installed" ; eend 0
126 # find /var -name \*.pid
127 einfo "Removing pid-files"
128 find /var/run -name \*.pid -exec rm {} \;
131 einfo "Unmounting proc, /dev/pts, /dev/capi"
132 umount /proc 2>/dev/null
133 umount /dev/pts 2>/dev/null
134 umount /dev/capi 2>/dev/null
135 umount -a 2>/dev/null
138 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
139 rm -f /var/lib/apt/lists/*Packages
140 rm -f /var/lib/apt/lists/*Release
141 rm -f /var/lib/apt/lists/*Sources
142 rm -f /var/lib/apt/lists/*IndexDiff
143 rm -f /var/lib/apt/lists/*.gpg
144 rm -f /var/cache/apt-show-versions/*
145 rm -f /var/cache/debconf/templates.dat-old
146 rm -f /var/cache/apt/*.bin
147 apt-get check 2>/dev/null
149 apt-cache gencaches 2>/dev/null
150 rm -f /var/lib/dpkg/status-old
151 rm -f /var/lib/dpkg/available-old
154 if ifclass GRML_SMALL ; then
155 einfo "Removing /var/cache/debconf/templates.dat"
156 rm -f /var/cache/debconf/templates.dat
159 einfo "Removing /usr/share/ssh/blacklist.*"
160 rm -f /usr/share/ssh/blacklist.DSA-1024 /usr/share/ssh/blacklist.RSA-2048
164 # get rid of large kernel modules:
165 if ifclass GRML_SMALL ; then
166 if [ -r "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko" ] ; then
167 einfo "Removing /lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
168 rm -f "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
171 if [ -r "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko" ] ; then
172 einfo "Removing /lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko"
173 rm -f "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/hisax.ko"
178 if [ -x /usr/bin/grep-dctrl ] ; then
179 einfo "Cleaning up /var/lib/dpkg/status"
180 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
181 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
182 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
184 ewarn "Warning: /usr/bin/grep-dctrl not available."
187 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
188 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
191 einfo "Removing x-server-conffiles"
192 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
193 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
196 einfo "Removing ssh-keys"
200 einfo "Removing unused/backup files"
201 find / -name *~ -print0 | xargs -0 rm -f
204 # remove only "temporary" or saved files in the given directories
206 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
211 # set all files in the given directories to a length of zero
213 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
218 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
219 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
222 if [ -d /var/spool/squid/ ] ; then
223 einfo "Cleaning /var/spool/squid/0*"
224 rm -rf /var/spool/squid/0*
227 ewarn "update-ca-certificates not installed" ; eend 0
230 # delete old dowloaded packages
231 einfo "Running apt-get clean"
235 if [ -x /usr/bin/nvi ] ; then
236 if ! [ -d /var/tmp/vi.recover ] ; then
237 einfo "Creating nvi /var/tmp directory"
238 mkdir -p /var/tmp/vi.recover
239 chown root:root /var/tmp/vi.recover
240 chmod 1777 /var/tmp/vi.recover
244 ewarn "nvi not installed" ; eend 0
247 if [ -x /sbin/depmod ] ; then
248 if [ -r /lib/modules/$KERNEL ] ; then
249 einfo "Updating modules.dep for kernel $KERNEL"
250 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
254 ewarn "depmod not installed" ; eend 0
257 einfo "Cleaning and removing some misc files and directories"
258 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
259 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
260 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
261 /var/state/*/* /var/state/* /var/log/nessus/* \
262 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
263 /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
264 /etc/lvm/.cache 2>/dev/null
265 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
266 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
267 /var/lib/mysql /var/log/lilo_log.* /core* 2>/dev/null
268 nuke /var/log /var/cache
269 zero /var/local /var/log /var/spool \
270 /var/lib/games /var/cache/man \
271 /var/lib/nfs /var/lib/xkb \
272 /var/mail/grml /var/account/pacct
273 # Recreate empty utmp and wtmp
278 if [ -x /usr/sbin/update-ca-certificates ] ; then
279 einfo "Updating ca-certificates"
280 update-ca-certificates 1>/dev/null
283 ewarn "update-ca-certificates not installed" ; eend 0
286 # regenerate module dependencies and ls.so.cache
287 if [ -x /sbin/ldconfig ] ; then
288 einfo "Updating ld.so.cache"
292 ewarn "ldconfig not installed" ; eend 0
295 if [ -x /usr/bin/update-menus ] ; then
296 einfo "Updating windowmanager menus"
300 ewarn "update-menus not installed" ; eend 0
303 if [ -x /usr/bin/mktexlsr ] ; then
304 einfo "Updating texhash"
308 ewarn "mktexlsr not installed" ; eend 0
311 if [ -x /usr/bin/mandb ] ; then
312 einfo "Updating mandb"
314 man doesnotexist >/dev/null 2>&1
317 ewarn "mandb not installed" ; eend 0
320 if [ -d /var/lib/clamav/ ] ; then
321 einfo "Cleaning /var/lib/clamav/"
322 rm -f /var/lib/clamav/clamav-* ; eend $?
323 if [ -f /var/lib/clamav/daily.cvd ] ; then
324 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
325 cd /usr/share/doc/clamav-freshclam/examples/ && \
326 ln -sf /var/lib/clamav/daily.cvd . && \
327 ln -sf /var/lib/clamav/main.cvd . )
330 ewarn "clamav[-freshclam] not installed" ; eend 0
333 if [ -f /etc/default/snort.dpkg-dist -a -f /etc/default/snort ] ; then
334 einfo "Fixxing /etc/default/snort"
335 mv /etc/default/snort.dpkg-dist /etc/default/snort
339 if ! [ -r /etc/ld.so.nohwcap ] ; then
340 einfo "Creating /etc/ld.so.nohwcap"
341 touch /etc/ld.so.nohwcap
344 # installation of resolvconf in chroot *with* /proc
345 # is different from an installation without /proc,
346 # so make sure it is OK in any case; don't use /dev/shm
347 if [ -d /etc/resolvconf ] ; then
348 rm -rf /etc/resolvconf/run
349 mkdir /etc/resolvconf/run
350 touch /etc/resolvconf/run/enable-updates
351 mkdir /etc/resolvconf/run/interface
352 cat > /etc/resolvconf/run/resolv.conf << EOF
353 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
354 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
358 if [ -x /usr/bin/updatedb ] ; then
359 einfo "Updating locate-database"
360 mount -t proc none /proc
361 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
365 ewarn "updatedb not installed" ; eend 0
368 einfo "Unmounting all filesystems"
372 ################################################################################
375 # list dangling symlinks: ls **/*(-@)
378 # find / \! -type l -perm -2000 -ls > audit/sgid-files
379 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
380 # find / \! -type l -perm -4000 -ls > audit/suid-files
381 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
382 # find / -perm -0777 -type d -ls > audit/writeable-dirs
383 # find / -size +3000k > audit/big_files.new
384 # find /all_filesystems -name ".. " -print -xdev | cat -vet
385 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
386 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
388 # list non-stripped files:
389 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
391 # Is software by grml-repos up2date?
392 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
395 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
396 ################################################################################
398 ## END OF FILE #################################################################