Add check for make stuff to /etc/grml/fai/config/scripts/GRMLBASE/98-clean-chroot
[grml-live.git] / etc / grml / fai / grml / grml_cleanup_chroot
1 #!/bin/bash
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 ################################################################################
9
10 # misc stuff
11   umask 022
12   . /etc/grml/lsb-functions || exit 6
13   [ -x /lib64 ] && GRML64=yes || GRML64=''
14
15 # detect kernel version, assume newest kernel version
16   KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
17
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 )
23      eend 0
24   fi
25 fi
26
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?"
30   eend 1
31   exit 9
32 fi
33
34 einfo "Preparing grml-system: $(cat /etc/grml_version)" ; eend 0
35
36 einfo "Setting up /etc/motd.tail"
37 echo "" > /etc/motd.tail ; eend 0
38
39 einfo "Setting up /etc/modules: "
40 cat>/etc/modules<<EOF
41 # /etc/modules: kernel modules to load at boot time.
42 #
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.
46 EOF
47 echo "" >> /etc/modules
48 grep '^[a-z]' /etc/grml/modules >> /etc/modules
49 eend 0
50
51 einfo "Setting up /etc/inittab"
52 cp /etc/inittab.grml  /etc/inittab
53 eend $?
54
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 )
58    eend $?
59 fi
60
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
66     else
67        eerror "/usr/src/linux-headers-$KERNEL not found, exiting." ; eend 1
68        exit 10
69     fi
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"
72      eend 1
73      exit 10
74 else
75      ewarn "linux-headers-$KERNEL not installed." ; eend 0
76 fi
77
78 einfo "Creating ~/.zshrc"
79   touch ~/.zshrc
80 eend $?
81
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 $?
86 else
87   ewarn "ion3 not installed" ; eend 0
88 fi
89
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/*
93   eend $?
94 else
95   ewarn "valgrind not installed" ; eend 0
96 fi
97
98 if [ -x /usr/sbin/localepurge ] ; then
99   einfo "Running localepurge"
100   localepurge ; eend $?
101 else
102   ewarn "localepurg not available" ; eend 0
103 fi
104
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 $?
108 else
109   ewarn "backuppc not installed" ; eend 0
110 fi
111
112 # find /var -name \*.pid
113 einfo "Removing pid-files"
114   find /var/run -name \*.pid -exec rm {} \;
115 eend $?
116
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
122 eend $?
123
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
133   dpkg --clear-avail
134   apt-cache gencaches 2>/dev/null
135   rm -f /var/lib/dpkg/status-old
136   rm -f /var/lib/dpkg/available-old
137 eend $?
138
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
144 else
145    ewarn "Warning: /usr/bin/grep-dctrl not available."
146 fi
147
148 einfo "Copying original runlevel.conf to /etc/runlevel.conf"
149 cp /etc/runlevel.conf.livecd /etc/runlevel.conf
150 eend $?
151
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 
155 eend $?
156
157 einfo "Removing ssh-keys"
158   rm -f /etc/ssh/*key*
159 eend $?
160
161 # remove only "temporary" or saved files in the given directories
162 nuke(){
163   for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
164     rm -f "$i"
165   done
166 }
167
168 # set all files in the given directories to a length of zero
169 zero(){
170   for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
171     :> "$i"
172   done
173 }
174
175 #for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
176 #  [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
177 #done
178
179 if [ -d /var/spool/squid/ ] ; then
180   einfo "Cleaning /var/spool/squid/0*"
181   rm -rf /var/spool/squid/0*
182   eend $?
183 else
184   ewarn "update-ca-certificates not installed" ; eend 0
185 fi
186
187 # delete old dowloaded packages
188 einfo "Running apt-get clean"
189   apt-get clean
190 eend $?
191
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
198     eend $?
199   fi
200 else
201   ewarn "nvi not installed" ; eend 0
202 fi
203
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"
208     eend $?
209   fi
210 else
211   ewarn "depmod not installed" ; eend 0
212 fi
213
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
232   :>/var/run/utmp
233   :>/var/run/wtmp
234 eend $?
235
236 if [ -x /usr/sbin/update-ca-certificates ] ; then
237   einfo "Updating ca-certificates"
238   update-ca-certificates 1>/dev/null
239   eend $?
240 else
241   ewarn "update-ca-certificates not installed" ; eend 0
242 fi
243
244 # regenerate module dependencies and ls.so.cache
245 if [ -x /sbin/ldconfig ] ; then
246   einfo "Updating ld.so.cache"
247   ldconfig
248   eend $?
249 else
250   ewarn "ldconfig not installed" ; eend 0
251 fi
252
253 if [ -x /usr/bin/update-menus ] ; then
254   einfo "Updating windowmanager menus"
255   update-menus -v
256   eend $?
257 else
258   ewarn "update-menus not installed" ; eend 0
259 fi
260
261 if [ -x /usr/bin/mktexlsr ] ; then
262   einfo "Updating texhash"
263   mktexlsr
264   eend $?
265 else
266   ewarn "mktexlsr not installed" ; eend 0
267 fi
268
269 if [ -x /usr/bin/mandb ] ; then
270   einfo "Updating mandb"
271   mandb -c
272   man doesnotexist >/dev/null 2>&1
273   eend $?
274 else
275   ewarn "mandb not installed" ; eend 0
276 fi
277
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  . )
286   fi
287 else
288   ewarn "clamav[-freshclam] not installed" ; eend 0
289 fi
290
291 if ! [ -r /etc/ld.so.nohwcap ] ; then
292    einfo "Creating /etc/ld.so.nohwcap"
293    touch /etc/ld.so.nohwcap
294 fi
295
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
307 EOF
308 fi
309
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'
314   umount /proc
315   eend $?
316 else
317   ewarn "updatedb not installed" ; eend 0
318 fi
319
320 einfo "Unmounting all filesystems"
321   umount -a
322 eend $?
323
324 ################################################################################
325 # MISC STUFF
326 # ~~~~~~~~~~
327 # list dangling symlinks: ls **/*(-@)
328 #
329 # Security-audit:
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
339 #
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'
342 #
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 
345 #
346 # runlevel.conf:
347 # for file in /etc/init.d/* ; do grep $file -q /etc/runlevel.conf.hdinstall || echo $file not found ; done
348 ################################################################################
349
350 ## END OF FILE #################################################################