2 # Filename: ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/98-clean-chroot
3 # Purpose: clean up chroot system
4 # Authors: grml-team (grml.org), (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 ################################################################################
12 if ! [ $(ls $target/boot/config-* 2>/dev/null) ] ; then
13 echo "No kernel config files (/boot/config-*) found. No kernel-image package installed?" >&2
17 echo "Creating ~/.zshrc"
18 touch $target/root/.zshrc
20 if [ -x $target/usr/sbin/localepurge ] ; then
21 echo "Running localepurge"
24 echo "Warning: localepurg not installed"
27 # find /var -name \*.pid
28 echo "Removing pid-files"
29 find $target/var/run -name \*.pid -exec rm {} \;
31 echo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
32 rm -f $target/var/lib/apt/lists/*Packages \
33 $target/var/lib/apt/lists/*Release \
34 $target/var/lib/apt/lists/*Sources \
35 $target/var/lib/apt/lists/*IndexDiff \
36 $target/var/lib/apt/lists/*.gpg \
37 $target/var/cache/apt-show-versions/* \
38 $target/var/cache/debconf/templates.dat-old \
39 $target/var/cache/apt/*.bin
40 $ROOTCMD apt-get check 2>/dev/null
41 $ROOTCMD dpkg --clear-avail
42 $ROOTCMD apt-cache gencaches 2>/dev/null
43 $ROOTCMD apt-get clean
45 rm -f $target/var/lib/dpkg/status-old $target/var/lib/dpkg/available-old
47 if ! [ -x $target/usr/bin/grep-dctrl ] ; then
48 echo "Warning: grep-dctrl not installed"
50 echo "Cleaning up /var/lib/dpkg/status"
51 if $ROOTCMD grep-dctrl -v -F Status "purge ok not-installed" \
52 /var/lib/dpkg/status > $target/var/lib/dpkg/status.new ; then
53 mv $target/var/lib/dpkg/status.new $target/var/lib/dpkg/status
54 chmod 644 $target/var/lib/dpkg/status
55 chown root:root $target/var/lib/dpkg/status
59 echo "Removing host ssh-keys"
60 rm -f $target/etc/ssh/*key*
62 if [ -d $target/var/spool/squid/ ] ; then
63 echo "Cleaning /var/spool/squid/0*"
64 rm -rf $target/var/spool/squid/0*
67 echo "Cleaning and removing some misc files and directories"
68 find $target/etc -type f -name *.pre_fcopy -delete
69 rm -rf $target/etc/sysconfig/* $target/etc/motd.dpkg-* $target/etc/auto.master.*dpkg* \
70 $target/etc/samba/*.SID $target/etc/samba/*.tdb \
71 $target/var/run/ $target/var/log/ksymoops/* $target/var/lock/* \
72 $target/var/state/* $target/var/log/nessus/* \
73 $target/halt $target/reboot $target/ash.static \
74 $target/etc/dhcpc/*.info $target/etc/dhcpc/resolv* \
75 $target/etc/*passwd- $target/etc/*shadow- \
76 $target/etc/*group- $target/var/spool/postfix/maildrop/* \
77 $target/etc/*.old $target/etc/*.original \
78 $target/etc/lvm/.cache $target/etc/lvm/cache/.cache \
79 $target/etc/lvm/backup/main $target/tmp/* \
80 $target/var/tmp/* $target/var/backups/* \
81 $target/var/lib/mysql $target/var/log/lilo_log.* $target/core*
83 # remove only "temporary" or saved files in the given directories
85 for i in $(find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null); do
90 # set all files in the given directories to a length of zero
92 for i in $(find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null); do
97 echo "Cleaning log and cache directories"
98 nuke ${target}/var/log ${target}/var/cache
99 zero ${target}/var/local ${target}/var/log \
100 ${target}/var/spool ${target}/var/lib/games \
101 ${target}/var/cache/man ${target}/var/lib/nfs \
102 ${target}/var/lib/xkb ${target}/var/mail/grml \
103 ${target}/var/account/pacct
105 # on /run we don't have to create it
106 if [ -d ${target}/var/run ] ; then
107 echo "Recreate empty utmp and wtmp"
108 :>${target}/var/run/utmp
109 :>${target}/var/run/wtmp
112 if ! [ -x $target/usr/sbin/update-ca-certificates ] ; then
113 echo "Warning: update-ca-certificates not installed"
115 echo "Updating ca-certificates"
116 $ROOTCMD update-ca-certificates
119 # regenerate ls.so.cache
120 if ! [ -x $target/sbin/ldconfig ] ; then
121 echo "Warning: ldconfig not installed"
123 echo "Updating ld.so.cache"
127 if [ -x $target/usr/bin/update-menus ] ; then
128 echo "Warning: update-menus not installed"
130 echo "Updating windowmanager menus"
131 $ROOTCMD update-menus -v
134 if ! [ -x $target/usr/bin/mandb ] ; then
135 echo "Warning: mandb not installed"
137 echo "Updating mandb"
139 $ROOTCMD man doesnotexist >/dev/null 2>&1 || true
142 if ! [ -d $target/var/lib/clamav/ ] ; then
143 echo "Warning: clamav[-freshclam] not installed"
145 echo "Cleaning /var/lib/clamav/"
146 rm -f $target/var/lib/clamav/clamav-*
148 echo "Setting up daily.cvd and main.cvd symlinks"
149 if [ -f $target/var/lib/clamav/daily.cvd ] ; then
150 mkdir -p $target/usr/share/doc/clamav-freshclam/examples/
151 ln -sf /var/lib/clamav/daily.cvd $target/usr/share/doc/clamav-freshclam/examples/
152 ln -sf /var/lib/clamav/main.cvd $target/usr/share/doc/clamav-freshclam/examples/
156 if ! [ -r $target/etc/ld.so.nohwcap ] ; then
157 echo "Creating /etc/ld.so.nohwcap"
158 touch $target/etc/ld.so.nohwcap
161 # installation of resolvconf in chroot *with* /proc
162 # is different from an installation without /proc,
163 # so make sure it is OK in any case
164 if ! [ -d $target/etc/resolvconf ] ; then
165 echo "Warning: resolvconf not installed"
167 echo "Setting up resolvconf"
168 if [ -L $target/etc/resolvconf/run ] ; then # resolvconf with /run
169 # /etc/resolvconf/run symlinks to /run/resolvconf
170 RESOLV_CONF=/run/resolvconf/
171 else # no /run present
172 RESOLV_CONF=/etc/resolvconf/run/
175 rm -rf ${target}/${RESOLV_CONF}
176 mkdir -p ${target}/${RESOLV_CONF}
178 touch ${target}/${RESOLV_CONF}/enable-updates
179 mkdir ${target}/${RESOLV_CONF}/interface
181 cat > ${target}/${RESOLV_CONF}/resolv.conf << EOF
182 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
183 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
187 if ! [ -x $target/usr/bin/updatedb ] ; then
188 echo "Warning: updatedb not installed"
190 echo "Updating locate-database"
191 $ROOTCMD updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
194 ## END OF FILE #################################################################
195 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2