-#!/bin/bash
-# Filename: /etc/grml/fai/grml/grml_cleanup_chroot
-# Purpose: clean up grml chroot
-# Authors: (c) Michael Prokop <mika@grml.org>
-# Bug-Reports: see http://grml.org/bugs/
-# License: This file is licensed under the GPL v2.
-################################################################################
-
-# misc stuff
- umask 022
- . /etc/grml/lsb-functions || exit 6
- [ -x /lib64 ] && GRML64=yes || GRML64=''
-
-# detect kernel version, assume newest kernel version
- KERNEL=$(ls -1 /lib/modules/ | sort -r -u | head -1)
-
-if [ -f /usr/share/fonts/X11/misc/artwiz-cursor.pcf.gz ] ; then
- if dpkg-divert --list artwiz-cursor | grep -q /usr/share/fonts/X11/misc/cursor.pcf.gz ; then
- eerror "Broken diversion of artwiz-cursor, see #341397, trying to fix it"
- ( cd /usr/share/fonts/X11/misc/ &&
- dpkg-divert --remove /usr/share/fonts/X11/misc/cursor.pcf.gz && mkfontdir )
- eend 0
- fi
-fi
-
-# start of main cleanup process...
-if ! [ -r /boot/config-"$KERNEL" ] ; then
- eerror "/boot/config-$KERNEL not available. \$KERNEL not set to correct value?"
- eend 1
- exit 9
-fi
-
-einfo "Preparing grml-system: $(cat /etc/grml_version)" ; eend 0
-
-einfo "Setting up /etc/motd.tail"
-echo "" > /etc/motd.tail ; eend 0
-
-einfo "Setting up /etc/modules: "
-cat>/etc/modules<<EOF
-# /etc/modules: kernel modules to load at boot time.
-#
-# This file should contain the names of kernel modules that are
-# to be loaded at boot time, one per line. Comments begin with
-# a \`#', and everything on the line after them are ignored.
-EOF
-echo "" >> /etc/modules
-grep '^[a-z]' /etc/grml/modules >> /etc/modules
-eend 0
-
-einfo "Setting up /etc/inittab"
-cp /etc/inittab.grml /etc/inittab
-eend $?
-
-if [ "$(dpkg --list | awk '/^rc/ { print $2}')" != '' ] ; then
- einfo "Purging removed packages"
- dpkg --purge $(dpkg --list | awk '/^rc/ { print $2}')
- eend $?
-fi
-
-if [ -x /usr/bin/make -a -r /usr/src/Makefile ] ; then
- einfo "Cleaning up /usr/src/linux-headers-$KERNEL"
- ( cd /usr/src
- VER=$(/bin/ls -d /usr/src/linux-headers-* | head -1)
- VER=${VER##/usr/src/linux-headers-}
- if [ -n "$VER" ] ; then
- VER=$VER make clean && \
- VER=$VER make symlinks
- else
- make clean && \
- make symlinks
- fi
- )
- eend $?
-fi
-
-einfo "Creating ~/.zshrc"
- touch ~/.zshrc
-eend $?
-
-if [ -d /usr/lib/valgrind/x86-linux/ ] ; then
- einfo "Stripping /usr/lib/valgrind/x86-linux/"
- strip --strip-unneeded /usr/lib/valgrind/x86-linux/*
- eend $?
-else
- ewarn "valgrind not installed" ; eend 0
-fi
-
-if [ -x /usr/sbin/localepurge ] ; then
- einfo "Running localepurge"
- localepurge ; eend $?
-else
- ewarn "localepurg not available" ; eend 0
-fi
-
-# find /var -name \*.pid
-einfo "Removing pid-files"
- find /var/run -name \*.pid -exec rm {} \;
-eend $?
-
-einfo "Removing /var/lib/apt/lists/*-stuff, dpkg-status-old and pkgcache.bin"
- rm -f /var/lib/apt/lists/*Packages
- rm -f /var/lib/apt/lists/*Release
- rm -f /var/lib/apt/lists/*Sources
- rm -f /var/lib/apt/lists/*IndexDiff
- rm -f /var/lib/apt/lists/*.gpg
- rm -f /var/cache/apt-show-versions/*
- rm -f /var/cache/debconf/templates.dat-old
- rm -f /var/cache/apt/*.bin
- apt-get check 2>/dev/null
- dpkg --clear-avail
- apt-cache gencaches 2>/dev/null
- rm -f /var/lib/dpkg/status-old
- rm -f /var/lib/dpkg/available-old
-eend $?
-
-if ifclass GRML_SMALL ; then
- einfo "Removing /var/cache/debconf/templates.dat"
- rm -f /var/cache/debconf/templates.dat
- eend $?
-
- einfo "Removing /usr/share/ssh/blacklist.*"
- rm -f /usr/share/ssh/blacklist.DSA-1024 /usr/share/ssh/blacklist.RSA-2048
- eend $?
-fi
-
-# get rid of large kernel modules:
-if ifclass GRML_SMALL ; then
- einfo "Identified grml-small, removing some very large kernel drivers:"
- if [ -r "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko" ] ; then
- einfo "Removing /lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
- rm -f "/lib/modules/${KERNEL}/kernel/fs/ocfs2/ocfs2.ko"
- eend $?
- fi
- if [ -d "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax/" ] ; then
- einfo "Removing /lib/modules/${KERNEL}/kernel/drivers/isdn/hisax"
- rm -rf "/lib/modules/${KERNEL}/kernel/drivers/isdn/hisax"
- eend $?
- fi
-fi
-
-if [ -x /usr/bin/grep-dctrl ] ; then
- einfo "Cleaning up /var/lib/dpkg/status"
- grep-dctrl -v -F Status "purge ok not-installed" /var/lib/dpkg/status > status.new && \
- cp status.new /var/lib/dpkg/status && chmod 644 /var/lib/dpkg/status && \
- chown root:root /var/lib/dpkg/status && rm status.new && eend 0 || eend 1
-else
- ewarn "Warning: /usr/bin/grep-dctrl not available."
-fi
-
-einfo "Removing x-server-conffiles"
- rm -f /etc/X11/xorg.conf /etc/X11/XF86Config-4 \
- /etc/X11/XF86Config /etc/XF86Config /etc/XF86Config-4
-eend $?
-
-einfo "Removing ssh-keys"
- rm -f /etc/ssh/*key*
-eend $?
-
-einfo "Removing unused/backup files"
- find / -name *~ -print0 | xargs -0 rm -f
-eend $?
-
-# remove only "temporary" or saved files in the given directories
-nuke(){
- for i in `find "$@" -name \*.gz -o -name \*.bz2 -o -name \*.0 2>/dev/null`; do
- rm -f "$i"
- done
-}
-
-# set all files in the given directories to a length of zero
-zero(){
- for i in `find "$@" -type f -size +0 -not -name \*.ini 2>/dev/null`; do
- :> "$i"
- done
-}
-
-#for i in `find /usr/*/man -name \*.\[0-9ln\]` ; do
-# [ -f "$i".gz -o -f "$i".bz2 ] && rm -f "$i"
-#done
-
-if [ -d /var/spool/squid/ ] ; then
- einfo "Cleaning /var/spool/squid/0*"
- rm -rf /var/spool/squid/0*
- eend $?
-else
- ewarn "update-ca-certificates not installed" ; eend 0
-fi
-
-# delete old dowloaded packages
-einfo "Running apt-get clean"
- apt-get clean
-eend $?
-
-if [ -x /usr/bin/nvi ] ; then
- if ! [ -d /var/tmp/vi.recover ] ; then
- einfo "Creating nvi /var/tmp directory"
- mkdir -p /var/tmp/vi.recover
- chown root:root /var/tmp/vi.recover
- chmod 1777 /var/tmp/vi.recover
- eend $?
- fi
-else
- ewarn "nvi not installed" ; eend 0
-fi
-
-if [ -x /sbin/depmod ] ; then
- if [ -r /lib/modules/$KERNEL ] ; then
- einfo "Updating modules.dep for kernel $KERNEL"
- depmod -ae -F /boot/System.map-"$KERNEL" "$KERNEL"
- eend $?
- fi
-else
- ewarn "depmod not installed" ; eend 0
-fi
-
-einfo "Cleaning and removing some misc files and directories"
- find /etc -type f -name *.pre_fcopy -delete
- rm -f /etc/sysconfig/* /etc/motd.dpkg-new /etc/auto.master.distrib.dpkg-new \
- /etc/samba/*.SID /etc/samba/*.tdb /dev/mouse* /dev/cdrom* /dev/cdwriter* \
- /var/run/*/* /var/run/* /var/log/ksymoops/* /var/lock/*/* /var/lock/* \
- /var/state/*/* /var/state/* /var/log/nessus/* \
- /halt /reboot /ash.static /etc/dhcpc/*.info /etc/dhcpc/resolv* \
- /etc/*passwd- /etc/*shadow- /etc/*group- /var/spool/postfix/maildrop/* \
- /etc/*.old /etc/*.original \
- /etc/lvm/.cache /etc/lvm/cache/.cache /etc/lvm/backup/main 2>/dev/null
- rm -rf /tmp/* /var/tmp/* /var/tmp/.* /var/backups/* /.ssh /root/.ssh /home/*/.ssh \
- /home/grml/* /home/grml/.??* /var/lib/texmf/ls-R /var/spool/texmf/ls-R \
- /var/lib/mysql /var/log/lilo_log.* /core* 2>/dev/null
- nuke /var/log /var/cache
- zero /var/local /var/log /var/spool \
- /var/lib/games /var/cache/man \
- /var/lib/nfs /var/lib/xkb \
- /var/mail/grml /var/account/pacct
- # Recreate empty utmp and wtmp
- :>/var/run/utmp
- :>/var/run/wtmp
-eend $?
-
-if [ -x /usr/sbin/update-ca-certificates ] ; then
- einfo "Updating ca-certificates"
- update-ca-certificates 1>/dev/null
- eend $?
-else
- ewarn "update-ca-certificates not installed" ; eend 0
-fi
-
-# regenerate module dependencies and ls.so.cache
-if [ -x /sbin/ldconfig ] ; then
- einfo "Updating ld.so.cache"
- ldconfig
- eend $?
-else
- ewarn "ldconfig not installed" ; eend 0
-fi
-
-if [ -x /usr/bin/update-menus ] ; then
- einfo "Updating windowmanager menus"
- update-menus -v
- eend $?
-else
- ewarn "update-menus not installed" ; eend 0
-fi
-
-if [ -x /usr/bin/mktexlsr ] ; then
- einfo "Updating texhash"
- mktexlsr
- eend $?
-else
- ewarn "mktexlsr not installed" ; eend 0
-fi
-
-if [ -x /usr/bin/mandb ] ; then
- einfo "Updating mandb"
- mandb -c
- man doesnotexist >/dev/null 2>&1
- eend $?
-else
- ewarn "mandb not installed" ; eend 0
-fi
-
-if [ -d /var/lib/clamav/ ] ; then
- einfo "Cleaning /var/lib/clamav/"
- rm -f /var/lib/clamav/clamav-* ; eend $?
- if [ -f /var/lib/clamav/daily.cvd ] ; then
- ( mkdir -p /usr/share/doc/clamav-freshclam/examples/ && \
- cd /usr/share/doc/clamav-freshclam/examples/ && \
- ln -sf /var/lib/clamav/daily.cvd . && \
- ln -sf /var/lib/clamav/main.cvd . )
- fi
-else
- ewarn "clamav[-freshclam] not installed" ; eend 0
-fi
-
-if ! [ -r /etc/ld.so.nohwcap ] ; then
- einfo "Creating /etc/ld.so.nohwcap"
- touch /etc/ld.so.nohwcap
-fi
-
-# installation of resolvconf in chroot *with* /proc
-# is different from an installation without /proc,
-# so make sure it is OK in any case
-if [ -d /etc/resolvconf ] ; then
- if [ -L /etc/resolvconf/run ] ; then # resolvconf with /run
- # /etc/resolvconf/run symlinks to /run/resolvconf
- rm -rf /run/resolvconf
- mkdir -p /run/resolvconf
- else # no /run present
- rm -rf /etc/resolvconf/run
- mkdir /etc/resolvconf/run
- fi
-
- touch /etc/resolvconf/run/enable-updates
- mkdir /etc/resolvconf/run/interface
- cat > /etc/resolvconf/run/resolv.conf << EOF
-# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
-# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
-EOF
-fi
-
-if [ -x /usr/bin/updatedb ] ; then
- einfo "Updating locate-database"
- updatedb --prunepaths='/tmp /usr/tmp /var/tmp /grml /root /proc /sys'
- eend $?
-else
- ewarn "updatedb not installed" ; eend 0
-fi
-
-################################################################################
-# MISC STUFF
-# ~~~~~~~~~~
-# list dangling symlinks: ls **/*(-@)
-#
-# Security-audit:
-# find / \! -type l -perm -2000 -ls > audit/sgid-files
-# find / \! -type l -perm -0002 -ls > audit/world-writeable-files
-# find / \! -type l -perm -4000 -ls > audit/suid-files
-# find / ( -perm 4000 -o -perm -2000 \) -exec ls -ld {} \;
-# find / -perm -0777 -type d -ls > audit/writeable-dirs
-# find / -size +3000k > audit/big_files.new
-# find /all_filesystems -name ".. " -print -xdev | cat -vet
-# find / -name ".*" -print -xdev | cat -v > audit/hidden-files
-# find / -name ".. " -print -xdev | cat -vet > audit/unusal-file-names
-#
-# list non-stripped files:
-# file /usr/sbin/* | grep -v ', stripped' | grep -v 'perl' | grep -v 'Bourne' | grep -v 'python' | grep -v 'symbolic link'
-#
-# Is software by grml-repos up2date?
-# grep-dctrl --field Maintainer 'Michael Prokop' /var/lib/apt/lists/* | grep Package | awk '{print $2}' | xargs echo
-################################################################################
-
-## END OF FILE #################################################################