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
41 echo "Cleaning apt places"
42 $ROOTCMD apt-get check 2>/dev/null
43 $ROOTCMD dpkg --clear-avail
44 $ROOTCMD apt-cache gencaches 2>/dev/null
45 $ROOTCMD apt-get clean
47 rm -f $target/var/lib/dpkg/status-old $target/var/lib/dpkg/available-old
49 if ! [ -x $target/usr/bin/grep-dctrl ] ; then
50 echo "Warning: grep-dctrl not installed"
52 echo "Cleaning up /var/lib/dpkg/status"
53 if $ROOTCMD grep-dctrl -v -F Status "purge ok not-installed" \
54 /var/lib/dpkg/status > $target/var/lib/dpkg/status.new ; then
55 mv $target/var/lib/dpkg/status.new $target/var/lib/dpkg/status
56 chmod 644 $target/var/lib/dpkg/status
57 chown root:root $target/var/lib/dpkg/status
61 echo "Removing host ssh-keys"
62 rm -f $target/etc/ssh/*key*
64 if [ -d $target/var/spool/squid/ ] ; then
65 echo "Cleaning /var/spool/squid/0*"
66 rm -rf $target/var/spool/squid/0*
69 echo "Cleaning and removing some misc files and directories"
70 find $target/etc -type f -name *.pre_fcopy -delete
71 rm -rf --one-file-system $target/etc/sysconfig/* \
72 $target/etc/motd.dpkg-* $target/etc/auto.master.*dpkg* \
73 $target/etc/samba/*.SID $target/etc/samba/*.tdb \
74 $target/var/run $target/var/log/ksymoops/* $target/var/lock/* \
75 $target/var/state/* $target/var/log/nessus/* \
76 $target/halt $target/reboot $target/ash.static \
77 $target/etc/dhcpc/*.info $target/etc/dhcpc/resolv* \
78 $target/etc/*passwd- $target/etc/*shadow- \
79 $target/etc/*group- $target/var/spool/postfix/maildrop/* \
80 $target/etc/*.old $target/etc/*.original \
81 $target/etc/lvm/.cache $target/etc/lvm/cache/.cache \
82 $target/etc/lvm/backup/main $target/tmp/* \
83 $target/var/tmp/* $target/var/backups/* \
84 $target/var/lib/mysql $target/var/log/lilo_log.* $target/core*
86 # remove only "temporary" or saved files in the given directories
88 for i in $(find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null); do
89 rm -f --one-file-system "$i"
93 # set all files in the given directories to a length of zero
95 for i in $(find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null); do
100 echo "Cleaning log and cache directories"
101 nuke ${target}/var/log ${target}/var/cache
102 zero ${target}/var/local ${target}/var/log \
103 ${target}/var/spool ${target}/var/lib/games \
104 ${target}/var/cache/man ${target}/var/lib/nfs \
105 ${target}/var/lib/xkb ${target}/var/mail/grml \
106 ${target}/var/account/pacct
108 # on /run we don't have to create it
109 if [ -d ${target}/var/run ] ; then
110 echo "Recreate empty utmp and wtmp"
111 :>${target}/var/run/utmp
112 :>${target}/var/run/wtmp
115 if ! [ -x $target/usr/sbin/update-ca-certificates ] ; then
116 echo "Warning: update-ca-certificates not installed"
118 echo "Updating ca-certificates"
119 $ROOTCMD update-ca-certificates
122 # regenerate ls.so.cache
123 if ! [ -x $target/sbin/ldconfig ] ; then
124 echo "Warning: ldconfig not installed"
126 echo "Updating ld.so.cache"
130 if [ -x $target/usr/bin/update-menus ] ; then
131 echo "Warning: update-menus not installed"
133 echo "Updating windowmanager menus"
134 $ROOTCMD update-menus -v
137 if ! [ -x $target/usr/bin/mandb ] ; then
138 echo "Warning: mandb not installed"
140 echo "Updating mandb"
142 $ROOTCMD man doesnotexist >/dev/null 2>&1 || true
145 if ! [ -d $target/var/lib/clamav/ ] ; then
146 echo "Warning: clamav[-freshclam] not installed"
148 echo "Cleaning /var/lib/clamav/"
149 rm -f $target/var/lib/clamav/clamav-*
151 echo "Setting up daily.cvd and main.cvd symlinks"
152 if [ -f $target/var/lib/clamav/daily.cvd ] ; then
153 mkdir -p $target/usr/share/doc/clamav-freshclam/examples/
154 ln -sf /var/lib/clamav/daily.cvd $target/usr/share/doc/clamav-freshclam/examples/
155 ln -sf /var/lib/clamav/main.cvd $target/usr/share/doc/clamav-freshclam/examples/
159 if ! [ -r $target/etc/ld.so.nohwcap ] ; then
160 echo "Creating /etc/ld.so.nohwcap"
161 touch $target/etc/ld.so.nohwcap
164 # installation of resolvconf in chroot *with* /proc
165 # is different from an installation without /proc,
166 # so make sure it is OK in any case
167 if ! [ -d $target/etc/resolvconf ] ; then
168 echo "Warning: resolvconf not installed"
170 echo "Setting up resolvconf"
171 if [ -L $target/etc/resolvconf/run ] ; then # resolvconf with /run
172 # /etc/resolvconf/run symlinks to /run/resolvconf
173 RESOLV_CONF=/run/resolvconf/
174 else # no /run present
175 RESOLV_CONF=/etc/resolvconf/run/
178 rm -rf ${target}/${RESOLV_CONF}
179 mkdir -p ${target}/${RESOLV_CONF}
181 touch ${target}/${RESOLV_CONF}/enable-updates
182 mkdir ${target}/${RESOLV_CONF}/interface
184 cat > ${target}/${RESOLV_CONF}/resolv.conf << EOF
185 # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
186 # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
190 if ! [ -x $target/usr/bin/updatedb ] ; then
191 echo "Warning: updatedb not installed"
193 echo "Updating locate-database"
194 $ROOTCMD updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
197 ## END OF FILE #################################################################
198 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2