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-* &>/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 $ROOTCMD rm -f /etc/apt/apt.conf.d/90grml-apt-proxy.conf
22 if [ -x $target/usr/sbin/localepurge ] ; then
23 echo "Running localepurge"
26 echo "Warning: localepurge not installed"
29 # revert dpkg-divert of hooks/instsoft.GRMLBASE, which is
30 # used to work around /etc/kernel/postinst.d/zz-update-grub failing
31 # inside openvz environment, see #597084
32 if $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/update-grub' ; then
33 echo "Undoing dpkg-divert of update-grub executable"
34 $ROOTCMD rm -f /usr/sbin/update-grub
35 $ROOTCMD dpkg-divert --rename --remove /usr/sbin/update-grub
38 # revert dpkg-divert of hooks/instsoft.GRMLBASE, which is
39 # used to work around a grub-probe<->openvz bug
40 if $ROOTCMD dpkg-divert --list | grep -q '/usr/sbin/grub-probe' ; then
41 echo "Undoing dpkg-divert of grub-probe executable"
42 $ROOTCMD rm -f /usr/sbin/grub-probe
43 $ROOTCMD dpkg-divert --rename --remove /usr/sbin/grub-probe
46 # revert udev workaround of hooks/updatebase.GRMLBASE
47 if grep -q 'updatebase.GRMLBASE' ${target}/etc/udev/kernel-upgrade 2>/dev/null ; then
48 echo "Removing /etc/udev/kernel-upgrade created by updatebase.GRMLBASE"
49 $ROOTCMD rm -f /etc/udev/kernel-upgrade
52 echo "Cleaning apt places"
53 $ROOTCMD apt-get check 2>/dev/null
54 $ROOTCMD dpkg --clear-avail
55 $ROOTCMD apt-cache gencaches 2>/dev/null
56 $ROOTCMD apt-get clean
58 rm -f $target/var/lib/dpkg/status-old $target/var/lib/dpkg/available-old
60 if ! [ -x $target/usr/bin/grep-dctrl ] ; then
61 echo "Warning: grep-dctrl not installed"
63 echo "Cleaning up /var/lib/dpkg/status"
64 if $ROOTCMD grep-dctrl -v -F Status "purge ok not-installed" \
65 /var/lib/dpkg/status > $target/var/lib/dpkg/status.new ; then
66 mv $target/var/lib/dpkg/status.new $target/var/lib/dpkg/status
67 chmod 644 $target/var/lib/dpkg/status
68 chown root:root $target/var/lib/dpkg/status
72 echo "Removing host ssh-keys"
73 rm -f $target/etc/ssh/*key*
75 echo "Removing dbus machine-id"
76 rm -f $target/var/lib/dbus/machine-id
78 if [ -d $target/var/spool/squid/ ] ; then
79 echo "Cleaning /var/spool/squid/0*"
80 rm -rf $target/var/spool/squid/0*
83 echo "Cleaning and removing some misc files and directories"
84 find $target/etc -type f -name *.pre_fcopy -delete
85 find $target/etc -type l -name *.pre_fcopy -delete
86 rm -rf --one-file-system $target/etc/sysconfig/* \
87 $target/etc/motd.dpkg-* $target/etc/auto.master.*dpkg* \
88 $target/etc/samba/*.SID $target/etc/samba/*.tdb \
89 $target/var/log/ksymoops/* \
90 $target/var/state/* $target/var/log/nessus/* \
91 $target/halt $target/reboot $target/ash.static \
92 $target/etc/dhcpc/*.info $target/etc/dhcpc/resolv* \
93 $target/etc/*passwd- $target/etc/*shadow- \
94 $target/etc/*group- $target/var/spool/postfix/maildrop/* \
95 $target/etc/*.old $target/etc/*.original \
96 $target/etc/lvm/.cache $target/etc/lvm/cache/.cache \
97 $target/etc/lvm/backup/* $target/tmp/* \
98 $target/var/tmp/* $target/var/backups/* \
99 $target/var/lib/mysql $target/var/log/lilo_log.* $target/core* \
100 $target/etc/blkid.tab
102 # remove only "temporary" or saved files in the given directories
104 for i in $(find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null); do
105 rm -f --one-file-system "$i"
109 # set all files in the given directories to a length of zero
111 for i in $(find "$@" -type f -size +0 -not -name \*.ini -not -path '*/fai/*' -not -name install_packages.list 2>/dev/null); do
116 echo "Removing possible leftovers from update-pciids runs"
117 rm -f "${target}"/wget-log*
119 echo "Cleaning log and cache directories"
120 nuke ${target}/var/log ${target}/var/cache
121 zero ${target}/var/account/pacct \
122 ${target}/var/cache/man \
123 ${target}/var/lib/games \
124 ${target}/var/lib/nfs \
125 ${target}/var/lib/xkb \
126 ${target}/var/local \
128 ${target}/var/mail/grml
130 # on /run we don't have to create it
131 if [ -d ${target}/var/run ] ; then
132 echo "Recreate empty utmp and wtmp"
133 :>${target}/var/run/utmp
134 :>${target}/var/run/wtmp
137 if ! [ -x $target/usr/sbin/update-ca-certificates ] ; then
138 echo "Warning: update-ca-certificates not installed"
140 echo "Updating ca-certificates"
141 $ROOTCMD update-ca-certificates
144 # regenerate ls.so.cache
145 if ! [ -x $target/sbin/ldconfig ] ; then
146 echo "Warning: ldconfig not installed"
148 echo "Updating ld.so.cache"
152 if ! [ -x $target/usr/bin/update-menus ] ; then
153 echo "Warning: update-menus not installed"
155 echo "Updating windowmanager menus"
156 $ROOTCMD update-menus -v
159 if ! [ -x $target/usr/bin/mandb ] ; then
160 echo "Warning: mandb not installed"
162 echo "Updating mandb"
164 $ROOTCMD man doesnotexist >/dev/null 2>&1 || true
167 if ! [ -d $target/var/lib/clamav/ ] ; then
168 echo "Warning: clamav[-freshclam] not installed"
170 echo "Cleaning /var/lib/clamav/"
171 $ROOTCMD rm -rf /var/lib/clamav/clamav-*
173 echo "Setting up daily.cvd and main.cvd symlinks"
174 if [ -f $target/var/lib/clamav/daily.cvd ] ; then
175 mkdir -p $target/usr/share/doc/clamav-freshclam/examples/
176 ln -sf /var/lib/clamav/daily.cvd $target/usr/share/doc/clamav-freshclam/examples/
177 ln -sf /var/lib/clamav/main.cvd $target/usr/share/doc/clamav-freshclam/examples/
181 if ! [ -r $target/etc/ld.so.nohwcap ] ; then
182 echo "Creating /etc/ld.so.nohwcap"
183 touch $target/etc/ld.so.nohwcap
186 if ! [ -d $target/etc/resolvconf ] ; then
187 echo "Warning: resolvconf not installed"
189 echo "Setting up resolvconf"
190 rm -f "${target}"/etc/resolvconf/resolv.conf.d/original
191 rm -f "${target}"/etc/resolv.conf
192 ln -s /run/resolvconf/resolv.conf "${target}"/etc/resolv.conf
195 # make sure we don't leak any mdadm configurations
196 # that are present on the build system to the live system
197 if [ -f "${target}/etc/mdadm/mdadm.conf" ] ; then
198 echo "Found /etc/mdadm/mdadm.conf, getting rid of any possible enabled ARRAY settings."
199 sed -i '/^ARRAY/d' "${target}/etc/mdadm/mdadm.conf"
202 if ! $ROOTCMD test -x /usr/bin/updatedb ; then
203 echo "Warning: updatedb not installed"
205 echo "Updating locate-database"
206 $ROOTCMD updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
209 if [ -r "${target}/etc/machine-id" ] ; then
210 echo "Removing /etc/machine-id generated by systemd"
211 rm -f "$target/etc/machine-id"
214 ## END OF FILE #################################################################
215 # vim:ft=sh expandtab ai tw=80 tabstop=4 shiftwidth=2