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: Wed Sep 19 13:38:45 CEST 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 [ -x /usr/bin/make -a -r /usr/src/Makefile ] ; then
56 einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
57 ( cd /usr/src && make clean && make symlinks )
61 if [ -L /usr/include/linux ] ; then
62 einfo "/usr/include/linux is ok" ; eend 0
63 elif [ -n "$GRML64" ] ; then
64 if [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
65 einfo "grml64 detected, assuming /usr/src/linux-headers-$KERNEL is ok." ; eend 0
67 eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
70 elif [ -d /usr/src/linux-headers-"$KERNEL" ] ; then
71 eerror "/usr/include/linux is NOT a symlink to /usr/src/linux/include/linux/ - error"
75 ewarn "linux-headers-$KERNEL not installed." ; eend 0
78 einfo "Creating ~/.zshrc"
82 if [ -r /usr/share/lintian/overrides/ion3 ] ; then
83 einfo "Stripping ion3-stuff"
84 cat /usr/share/lintian/overrides/ion3 | sed 's#.*./usr#/usr#' | \
85 sed 's/.comment//' | xargs strip --strip-unneeded ; eend $?
87 ewarn "ion3 not installed" ; eend 0
90 if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
91 einfo "Stripping /usr/lib/valgrind/x86-linux/"
92 strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
95 ewarn "valgrind not installed" ; eend 0
98 if [ -x /usr/sbin/localepurge ] ; then
99 einfo "Running localepurge"
100 localepurge ; eend $?
102 ewarn "localepurg not available" ; eend 0
105 if [ -d /var/lib/backuppc/pc/localhost/ ] ; then
106 einfo "Cleaning /var/lib/backuppc/pc/localhost/"
107 rm -rf /var/lib/backuppc/pc/localhost/* ; eend $?
109 ewarn "backuppc not installed" ; eend 0
112 # find /var -name \*.pid
113 einfo "Removing pid-files"
114 find /var/run -name \*.pid -exec rm {} \;
117 einfo "Unmounting proc, /dev/pts, /dev/capi"
118 umount /proc 2>/dev/null
119 umount /dev/pts 2>/dev/null
120 umount /dev/capi 2>/dev/null
121 umount -a 2>/dev/null
124 einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
125 rm -f /var/lib/apt/lists/*Packages
126 rm -f /var/lib/apt/lists/*Release
127 rm -f /var/lib/apt/lists/*Sources
128 rm -f /var/lib/apt/lists/*.gpg
129 rm -f /var/cache/apt-show-versions/*
130 rm -f /var/cache/debconf/templates.dat-old
131 rm -f /var/cache/apt/*.bin
132 apt-get check 2>/dev/null
134 apt-cache gencaches 2>/dev/null
135 rm -f /var/lib/dpkg/status-old
136 rm -f /var/lib/dpkg/available-old
139 if [ -x /usr/bin/grep-dctrl ] ; then
140 einfo "Cleaning up /var/lib/dpkg/status"
141 grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
142 cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
143 chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
145 ewarn "Warning: /usr/bin/grep-dctrl not available."
148 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
149 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
152 einfo "Removing x-server-conffiles"
153 rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
154 /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
157 einfo "Removing ssh-keys"
161 # remove only "temporary" or saved files in the given directories
163 for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
168 # set all files in the given directories to a length of zero
170 for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
175 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
176 # [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
179 if [ -d /var/spool/squid/ ] ; then
180 einfo "Cleaning /var/spool/squid/0*"
181 rm -rf /var/spool/squid/0*
184 ewarn "update-ca-certificates not installed" ; eend 0
187 # delete old dowloaded packages
188 einfo "Running apt-get clean"
192 if [ -x /usr/bin/nvi ] ; then
193 if ! [ -d /var/tmp/vi.recover ] ; then
194 einfo "Creating nvi /var/tmp directory"
195 mkdir -p /var/tmp/vi.recover
196 chown root:root /var/tmp/vi.recover
197 chmod 1777 /var/tmp/vi.recover
201 ewarn "nvi not installed" ; eend 0
204 if [ -x /sbin/depmod ] ; then
205 if [ -r /lib/modules/$KERNEL ] ; then
206 einfo "Updating modules.dep for kernel $KERNEL"
207 depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
211 ewarn "depmod not installed" ; eend 0
214 einfo "Cleaning and removing some misc files and directories"
215 rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
216 /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
217 /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
218 /var/state/*/* /var/state/* /var/log/nessus/* \
219 /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
220 /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
221 /etc/lvm/.cache 2>/dev/null
222 rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
223 /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
224 /var/lib/mysql /var/log/lilo_log.* /core* 2>/dev/null
225 nuke /var/log /var/cache
226 zero /var/local /var/log /var/spool \
227 /var/lib/games /var/cache/man \
228 /var/lib/nfs /var/lib/xkb \
229 /var/mail/grml /var/account/pacct
230 mkdir -p /etc/sysconfig/network-scripts /etc/sysconfig/provider
231 # Recreate empty utmp and wtmp
236 if [ -x /usr/sbin/update-ca-certificates ] ; then
237 einfo "Updating ca-certificates"
238 update-ca-certificates 1>/dev/null
241 ewarn "update-ca-certificates not installed" ; eend 0
244 # regenerate module dependencies and ls.so.cache
245 if [ -x /sbin/ldconfig ] ; then
246 einfo "Updating ld.so.cache"
250 ewarn "ldconfig not installed" ; eend 0
253 if [ -x /usr/bin/update-menus ] ; then
254 einfo "Updating windowmanager menus"
258 ewarn "update-menus not installed" ; eend 0
261 if [ -x /usr/bin/mktexlsr ] ; then
262 einfo "Updating texhash"
266 ewarn "mktexlsr not installed" ; eend 0
269 if [ -x /usr/bin/mandb ] ; then
270 einfo "Updating mandb"
272 man doesnotexist >/dev/null 2>&1
275 ewarn "mandb not installed" ; eend 0
278 if [ -d /var/lib/clamav/ ] ; then
279 einfo "Cleaning /var/lib/clamav/"
280 rm -f /var/lib/clamav/clamav-* ; eend $?
281 if [ -f /var/lib/clamav/daily.cvd ] ; then
282 ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
283 cd /usr/share/doc/clamav-freshclam/examples/ && \
284 ln -sf /var/lib/clamav/daily.cvd . && \
285 ln -sf /var/lib/clamav/main.cvd . )
288 ewarn "clamav[-freshclam] not installed" ; eend 0
291 if ! [ -r /etc/ld.so.nohwcap ] ; then
292 einfo "Creating /etc/ld.so.nohwcap"
293 touch /etc/ld.so.nohwcap
296 # installation of resolvconf in chroot *with* /proc
297 # is different from an installation without /proc,
298 # so make sure it is OK in any case; don't use /dev/shm
299 if [ -d /etc/resolvconf ] ; then
300 rm -rf /etc/resolvconf/run
301 mkdir /etc/resolvconf/run
302 touch /etc/resolvconf/run/enable-updates
303 mkdir /etc/resolvconf/run/interface
304 cat > /etc/resolvconf/run/resolv.conf << EOF
305 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
306 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
310 if [ -x /usr/bin/updatedb ] ; then
311 einfo "Updating locate-database"
312 mount -t proc none /proc
313 updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
317 ewarn "updatedb not installed" ; eend 0
320 einfo "Unmounting all filesystems"
324 ################################################################################
327 # list dangling symlinks: ls **/*(-@)
330 # find / \! -type l -perm -2000 -ls > audit/sgid-files
331 # find / \! -type l -perm -0002 -ls > audit/world-writeable-files
332 # find / \! -type l -perm -4000 -ls > audit/suid-files
333 # find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
334 # find / -perm -0777 -type d -ls > audit/writeable-dirs
335 # find / -size +3000k > audit/big_files.new
336 # find /all_filesystems -name ".. " -print -xdev | cat -vet
337 # find / -name ".*" -print -xdev | cat -v > audit/hidden-files
338 # find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
340 # list non-stripped files:
341 # file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
343 # Is software by grml-repos up2date?
344 # grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/grml.org_repos_._* | grep Package | awk '{print $2}' | xargs echo
347 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
348 ################################################################################
350 ## END OF FILE #################################################################