#!/bin/bash
#
# upd-instroot
#
# Copyright (C) 2007, 2008 Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

ORIGDIR=`pwd`
DEBUG=""
ARCH=`uname -m`

while [ $# -gt 0 ]; do
    case $1 in
        --debug)
            DEBUG="--debug"
            shift
        ;;

        --arch)
            ARCH=$2
            shift; shift
        ;;

        --imgdir)
            DEST=$2
            shift; shift
        ;;

        # a filesystem tree to use as updates.  could be the output
        # of 'make install' from anaconda...
        --updates)
            UPDATES=$2
            shift; shift
        ;;

        --nogr)
            echo "*** DeprecationWarning: ignoring --nogr option." >&2
            shift
        ;;

        --mindir)
            echo "*** DeprecationWarning: ignoring --mindir option." >&2
            shift; shift
        ;;

        --stg2dir)
            echo "*** DeprecationWarning: please use --imgdir instead of --stg2dir." >&2
            shift; shift
        ;;

        *)
            yumconf=$1
            shift
        ;;
    esac
done

if [ -z "$yumconf" ]; then
    echo "upd-instroot: updates instimage from a Red Hat RPMS directory"
    echo "usage:        $0 [--debug] [--arch arch] [--imgdir imgdir] [yumconf]"
    exit 1
fi

if [ $ARCH = x86_64 -o $ARCH = s390x -o $ARCH = ppc64 ]; then
    LIBDIR=lib64
else
    LIBDIR=lib
fi

if [ -z "$DEST" ]; then
    DEST=`mktemp -d ${TMPDIR:-/tmp}/dest.XXXXXX`
fi

if [ ! -f $yumconf ]; then
    echo "Unable to find yum repo information!"
    exit 1
fi

. $(dirname $0)/buildinstall.functions

expandPackageSet() {
    YUMCONF=$1
    YUMDIR=$2
    RPMS=$3
    PKGDEST=$4
    KEEPFILES=$5

    [ -d $PKGDEST ] || die "ERROR: directory missing: $PKGDEST"

    [ -z "$DEBUG" ] && outlvl="--quiet" || outlvl="--verbose"

    yum $outlvl -c $YUMCONF -y --installroot=$YUMDIR install $RPMS 2>&1 || die "ERROR: could not install packages"

    if [ -n "$UPDATES" ]; then
        (cd $UPDATES; find) | (cd $UPDATES ; /bin/cpio --quiet -pmdu $YUMDIR)
    fi

    # figure out the theme to keep
    if [ -f $YUMDIR/etc/gtk-2.0/gtkrc ]; then
        gtktheme=$(grep "gtk-theme-name" $YUMDIR/etc/gtk-2.0/gtkrc | awk {'print $3;'} | sed -e 's/"//g')
        echo "usr/share/themes/$gtktheme" >> $KEEPFILES
        # find gtk engine needed
        for engine in `grep engine $YUMDIR/usr/share/themes/$gtktheme/gtk-2.0/gtkrc | grep -v ^# | awk {'print $2;'} | sed -e 's/"//g' | sort -u` ; do
            echo "usr/$LIBDIR/gtk-2.0/*/engines/*$engine*" >> $KEEPFILES
        done

        theme=$(grep "gtk-icon-theme-name" $YUMDIR/etc/gtk-2.0/gtkrc | awk {'print $3;'} | sed -e 's/"//g')
        while [ -n "$theme" ]; do
            echo "usr/share/icons/$theme" >> $KEEPFILES
            theme=$(grep Inherits $YUMDIR/usr/share/icons/$theme/index.theme | cut -d = -f 2)
        done

        cursortheme=$(grep "gtk-cursor-theme-name" $YUMDIR/etc/gtk-2.0/gtkrc | awk {'print $3;'} | sed -e 's/"//g')
        if [ -n "$cursortheme" ]; then
            echo "usr/share/icons/$cursortheme" >> $KEEPFILES
        fi
    fi

    echo `date` "Installing files"
    pushd $YUMDIR >/dev/null
    cat $KEEPFILES | while read spec ; do
        #Pull off path
        path=`echo "$spec" | sed 's,\([^[*\?]*\)/.*,\1,'`
        for filespec in `find ./$path -path "./$spec" 2> /dev/null` ; do
            if [ ! -e $filespec ]; then
                continue
            elif [ ! -d $filespec ]; then
                instFile $filespec $PKGDEST
            else
                for i in `find $filespec -type f 2> /dev/null` ; do instFile $i $PKGDEST ; done
                for i in `find $filespec -type l 2> /dev/null` ; do instFile $i $PKGDEST ; done
                for d in `find $filespec -type d 2> /dev/null` ; do instDir $d $PKGDEST ; done
            fi
        done
    done
    popd >/dev/null
}

die () {
    echo "$@"
    echo "Aborting instroot creation..."
    exit 1
}

setupSshd() {
    echo "sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin" \
    	>> $DEST/etc/passwd

    # enable root shell logins
    echo "root::14438:0:99999:7:::" >> $DEST/etc/shadow

    # enable 'install' account that starts anaconda on login
    echo "install:x:0:0:root:/root:/sbin/loader" >> $DEST/etc/passwd
    echo "install::14438:0:99999:7:::" >> $DEST/etc/shadow

    chmod 0400 $DEST/etc/shadow

    cat > $DEST/etc/pam.d/login << EOF
#%PAM-1.0
auth        required      pam_env.so
auth        sufficient    pam_unix.so likeauth nullok
auth        required      pam_deny.so
account     required      pam_unix.so
password    sufficient    pam_unix.so nullok use_authtok md5 shadow
password    required      pam_deny.so
session     required      pam_limits.so
session     required      pam_unix.so
EOF
    cp -f $DEST/etc/pam.d/login $DEST/etc/pam.d/sshd
    cp -f $DEST/etc/pam.d/login $DEST/etc/pam.d/remote

    mkdir -m 0700 -p $DEST/etc/ssh
    if [ "$ARCH" = "s390" -o "$ARCH" = "s390x" ]; then
        # key generation takes ages on s390, you really don't want this
        # for every installation attempt. These are NOT the keys of the
        # installed system!
        echo -n "Generating SSH1 RSA host key: "
        /usr/bin/ssh-keygen -q -t rsa1 -f $DEST/etc/ssh/ssh_host_key \
                            -C '' -N '' >&/dev/null
        echo
        echo -n "Generating SSH2 RSA host key: "
        /usr/bin/ssh-keygen -q -t rsa -f $DEST/etc/ssh/ssh_host_rsa_key \
                            -C '' -N '' >&/dev/null
        echo
        echo -n "Generating SSH2 DSA host key: "
        /usr/bin/ssh-keygen -q -t dsa -f $DEST/etc/ssh/ssh_host_dsa_key \
                            -C '' -N '' >&/dev/null
        echo
        (cd $DEST/etc/ssh; \
         chmod 600 ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; \
         chmod 644 ssh_host_key.pub ssh_host_rsa_key.pub ssh_host_dsa_key.pub; )
    fi

    cat > $DEST/etc/ssh/sshd_config.anaconda <<EOF
Port 22
HostKey /etc/ssh/ssh_host_key
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
PermitRootLogin yes
IgnoreRhosts yes
StrictModes yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd yes
XAuthLocation /sbin/xauth
KeepAlive yes
SyslogFacility AUTHPRIV
RSAAuthentication yes
PasswordAuthentication yes
PermitEmptyPasswords yes
PermitUserEnvironment yes
EOF
    chmod 600 $DEST/etc/ssh/sshd_config.anaconda
}

PACKAGES="GConf2 NetworkManager NetworkManager-gnome ORBit2 acl anaconda
    anaconda-yum-plugins at-spi atk attr audit-libs bash bind-utils
    biosdevname bitmap-fonts-cjk
    btrfs-progs bzip2 bzip2-libs ca-certificates cairo cjkuni-uming-fonts
    comps-extras coreutils cpio cracklib cracklib-dicts cracklib-python
    cryptsetup-luks cyrus-sasl-lib db4 dbus dbus-python dbus-x11 dejavu-sans-fonts
    dejavu-sans-mono-fonts device-mapper device-mapper-libs
    device-mapper-multipath device-mapper-multipath-libs
    dhclient dmraid dmraid-libs
    dogtail dosfstools e2fsprogs e2fsprogs-libs echo-icon-theme ethtool
    elfutils-libelf expat fcoe-utils
    firstboot fontconfig fonts-ISO8859-2 freetype gail gawk gdb-gdbserver
    gdk-pixbuf gfs2-utils glib2 glibc-common gnome-python2-canvas gnome-python2-gconf
    gnome-themes gnome-themes-standard
    gobject-introspection gpm grep gtk2 gtk2-engines
    hdparm hwdata initscripts iproute iputils iscsi-initiator-utils
    jfsutils kbd kacst-farsi-fonts kacst-qurn-fonts kpartx keyutils-libs
    krb5-libs libICE libSM libX11 libXau
    libXaw libXcursor libXdmcp libXevie libXext libXfixes libXfont libXft
    libXi libXinerama libXmu libXpm libXrandr libXrender libXt libXtst
    libXxf86misc libacl libaio libart_lgpl libattr
    libbonobo libcanberra libcanberra-gtk2 libcurl libfontenc libidn libgcc
    libglade2 libgnomecanvas libgcrypt libgpg-error libjpeg libmlx4 libnl libogg
    libpng libselinux libselinux-python libsemanage
    libsemanage-python libsepol libssh2 libstdc++ libtdb libthai libtirpc 
    libtool-ltdl libuser
    libuser-python libvolume_id libvorbis libxcb libxkbfile libxml2 lklug-fonts
    lldpad
    lohit-assamese-fonts lohit-bengali-fonts lohit-gujarati-fonts lohit-hindi-fonts
    lohit-kashmiri-fonts lohit-kannada-fonts lohit-maithili-fonts lohit-marathi-fonts
    lohit-oriya-fonts lohit-punjabi-fonts lohit-sindhi-fonts lohit-tamil-fonts
    lohit-telugu-fonts lsof lvm2 madan-fonts mdadm
    metacity module-init-tools ncurses neon net-tools
    newt newt-python nfs-utils nspr nss nss-softokn ntfs-3g ntpdate
    openldap openssh openssh-server
    pam pango parted pciutils pcre psmisc
    pygtk2-libglade pykickstart pyparted python python-bugzilla python-decorator
    python-libs python-nss python-pyblock python-sqlite python-epdb
    python-urlgrabber python-volume_key pyxf86config rdate readline redhat-artwork
    reiserfs-utils report-config-default report-gtk report-newt rpm rpm-libs
    rpm-python rsyslog sed selinux-policy-targeted
    setup slang shared-mime-info smc-meera-fonts
    specspo sqlite startup-notification strace
    synaptics system-config-date
    system-config-keyboard ${brandpkgname}-logos ${brandpkgname}-release
    sysvinit-tools taipeifonts tcp_wrappers tcp_wrappers-libs
    tigervnc-server-minimal tigervnc-server-module tzdata
    udev un-core-dotum-fonts urw-fonts usbutils util-linux-ng
    vconfig vlgothic-fonts vim-minimal
    wget which wpa_supplicant xcb-util xkeyboard-config xfsprogs xorg-x11-xauth
    xorg-x11-drivers xorg-x11-font-utils xorg-x11-fonts-ethiopic
    xorg-x11-fonts-misc xorg-x11-server-utils
    xorg-x11-server-Xorg xorg-x11-xkb-utils xorg-x11-xfs yum
    yum-metadata-parser zenity zlib /etc/gtk-2.0/gtkrc"

if [ $ARCH = i386 ]; then
    PACKAGES="$PACKAGES glibc.i386 openssl.i386"
elif [ $ARCH = i586 ]; then
    PACKAGES="$PACKAGES glibc.i586 openssl.i586"
elif [ $ARCH = sparc -o $ARCH = sparcv9 -o $ARCH = sparc64 ]; then
    PACKAGES="$PACKAGES glibc.sparcv9 openssl.sparcv9"
else
    PACKAGES="$PACKAGES glibc openssl"
fi

if [ $ARCH = i386 -o $ARCH = i586 -o $ARCH = i686 -o $ARCH = x86_64 ]; then
    PACKAGES="$PACKAGES pcmciautils grub"
fi

if [ $ARCH = i386 -o $ARCH = i586 -o $ARCH = i686 -o $ARCH = x86_64 -o $ARCH = ia64 ]; then
    PACKAGES="$PACKAGES dmidecode efibootmgr"
fi

if [ $ARCH = ia64 ]; then
    # XXX this needs to switch to grub at some point...
    PACKAGES="$PACKAGES elilo"
fi

if [ $ARCH = s390 -o $ARCH = s390x ]; then
    PACKAGES="$PACKAGES bind-utils binutils coreutils findutils gzip
              initscripts iputils less libgcc login lsscsi modutils mount
              net-tools openssh-clients pam portmap
              s390utils sed strace tar xorg-x11-libs
              xorg-x11-xauth"
fi

if [ $ARCH = ppc -o $ARCH = ppc64 ]; then
    PACKAGES="$PACKAGES pcmciautils pdisk yaboot hfsutils kernel-bootwrapper"
fi

#
# stuff ONLY included for rescue mode
#
# these packages are combined with the PACKAGES for big stage 2
#
PACKAGESRESCUE="bzip2 bzip2-libs dump
                findutils ftp gzip iputils krb5-libs less man-db
                modutils mtools mt-st mtr net-tools smartmontools
                openssh openssh-clients pciutils rsh traceroute tar rsync
                device-mapper device-mapper-libs dmraid ntfsprogs samba-client
		firstaidkit firstaidkit-engine firstaidkit-plugin-passwd
                firstaidkit-plugin-xserver firstaidkit-gui
                firstaidkit-plugin-mdadm-conf firstaidkit-plugin-key-recovery
                volume_key"

if [ $ARCH = i386 -o $ARCH = i586 -o $ARCH = i686 -o $ARCH = x86_64 ]; then
  PACKAGESRESCUE="$PACKAGESRESCUE gpart grub firstaidkit-plugin-grub"
fi

#
# add bootloader for particular arch
#
if [ $ARCH = sparc -o $ARCH = sparcv9 -o $ARCH = sparc64 ]; then
    PACKAGES="$PACKAGES tilo silo"
fi

if [ $ARCH = i386 -o $ARCH = i586 -o $ARCH = i686 -o $ARCH = x86_64 ]; then
    PACKAGES="$PACKAGES syslinux memtest86+ grub"
fi

if [ $ARCH = alpha ]; then
    PACKAGES="$PACKAGES aboot"
fi

if [ $ARCH = ppc ]; then
    PACKAGES="$PACKAGES fbset yaboot ppc64-utils"
fi

#
# KEEPFILE is all files to keep from the packages in PACKAGES
#
# The files in this list define the install image used for all installation
# methods.
#
# The rescue mode of anaconda uses these files as well as those defined
# by KEEPFILERESCUE below.  The total size of this image should be
# under the size of the miniature CD used for the rescue CD (around 68MB).
#
KEEPFILE=${TMPDIR:-/tmp}/keepfile.$$
cat > $KEEPFILE <<EOF
$LIBDIR/dbus-1
$LIBDIR/libaio.so*
$LIBDIR/libfreebl3.so
$LIBDIR/libfreebl3.chk
$LIBDIR/libgcc_s*
$LIBDIR/libmultipath.so*
$LIBDIR/libnss_dns*
$LIBDIR/libnss_files*
$LIBDIR/libnssdbm3.so
$LIBDIR/libnssdbm3.chk
$LIBDIR/libsoftokn3.so
$LIBDIR/libsoftokn3.chk
$LIBDIR/libwrap*.so*
$LIBDIR/multipath/*
$LIBDIR/rsyslog/*
$LIBDIR/security/pam_*
bin/arch
bin/basename
bin/bash
bin/cat
bin/chgrp
bin/chmod
bin/chown
bin/cp
bin/cpio
bin/cut
bin/date
bin/dbus-daemon
bin/dbus-uuidgen
bin/dd
bin/df
bin/dmesg
bin/du
bin/echo
bin/env
bin/false
bin/fdisk*
bin/gawk
bin/*grep
bin/hostname
bin/ipcalc
bin/kill
bin/ln
bin/login
bin/ls
bin/mkdir
bin/mknod
bin/mktemp
bin/more
bin/mount
bin/mv
bin/ntfs-3g
bin/ps
bin/pwd
bin/rm
bin/rmdir
bin/rpm
bin/sed
bin/sleep
bin/sort
bin/sync
bin/touch
bin/true
bin/umount
bin/uname
bin/vi
boot/*.b
boot/bootlx
boot/efi/EFI/redhat/elilo.efi
boot/efi/EFI/redhat/grub.efi
boot/efika.forth
boot/memtest86*
etc/NetworkManager/VPN
etc/NetworkManager/NetworkManager.conf
etc/NetworkManager/dispatcher.d
etc/dbus-1/*
etc/dbus-1/system.d/*
etc/fb.modes
etc/fcoe
etc/fonts
etc/gconf
etc/group
etc/gtk-2.0/gtkrc*
etc/hosts
etc/im_palette.pal
etc/imrc
etc/iscsid.conf
etc/man_db.conf
etc/mke2fs.conf
etc/modprobe.d/libmlx4.conf
etc/netconfig
etc/nsswitch.conf
etc/pam.d/other
etc/pam.d/sshd
etc/pango
etc/passwd
etc/pcmcia
etc/pki/tls/certs/ca-bundle.crt
etc/polkit-1/localauthority.conf.d/*
etc/polkit-1/nullbackend.conf.d/*
etc/prelink.conf
etc/protocols
etc/rc.d/init.d/functions
etc/report.conf
etc/report.d/*
etc/rpm/macros.prelink
etc/security/limits.conf
etc/security/pam_env.conf
etc/selinux/targeted/policy/policy*
etc/selinux/targeted/contexts
etc/selinux/targeted/*conf
etc/selinux/targeted/seusers
etc/services
etc/shells
etc/sysconfig/network-scripts/network-functions*
etc/udev
etc/wpa_supplicant/wpa_supplicant.conf
etc/yum.repos.d/*
etc/yum/pluginconf.d/blacklist.conf
etc/yum/pluginconf.d/fedorakmod.conf
etc/yum/pluginconf.d/whiteout.conf
lib/terminfo
lib/udev
sbin/*gfs*
sbin/arping
sbin/badblocks
sbin/biosdevname
sbin/brcm_iscsiuio
sbin/blockdev
sbin/btrfsctl
sbin/btrfsck
sbin/cciss_id
sbin/clock
sbin/consoletype
sbin/cryptsetup
sbin/debugfs
sbin/debugreiserfs
sbin/dhclient
sbin/dhclient-script
sbin/dhcp6c
sbin/dosfslabel
sbin/dumpe2fs
sbin/fsadm
sbin/e2fsck
sbin/e2label
sbin/ethtool
sbin/fdisk
sbin/fsck
sbin/fsck.ext*
sbin/fsck.jfs
sbin/fsck.reiserfs
sbin/fsck.xfs
sbin/hdparm
sbin/hwclock
sbin/ifconfig
sbin/ip
sbin/iscsiadm
sbin/iscsid
sbin/iscsistart
sbin/jfs_tune
sbin/killall5
sbin/kpartx
sbin/ldconfig
sbin/load_policy
sbin/losetup
sbin/lspci
sbin/lvm*
sbin/mdadm
sbin/mdmon
sbin/mkdosfs
sbin/mke2fs
sbin/mkfs.btrfs
sbin/mkfs.ext*
sbin/mkfs.gfs2
sbin/mkfs.jfs
sbin/mkfs.msdos
sbin/mkfs.reiserfs
sbin/mkfs.vfat
sbin/mkfs.xfs
sbin/mkofboot
sbin/mkraid
sbin/mkreiserfs
sbin/mkswap
sbin/mount*
sbin/multipath
sbin/nologin
sbin/ofpath
sbin/parted
sbin/pcmcia-socket-startup
sbin/pdisk
sbin/probe
sbin/pidof
sbin/reiserfsck
sbin/reiserfstune
sbin/resize_reiserfs
sbin/resize2fs
sbin/rmmod
sbin/route
sbin/rsyslogd
sbin/setfiles
sbin/sfdisk
sbin/silo
sbin/swapoff
sbin/swapon
sbin/tune2fs
sbin/udev*
sbin/umount*
sbin/vconfig
sbin/wipefs
sbin/xfs_repair
sbin/xfsrestore
sbin/ybin
usr/include/python?.?/pyconfig*.h
usr/$LIBDIR/NetworkManager
usr/$LIBDIR/gconv
usr/$LIBDIR/gdk-pixbuf/loaders/*la*
usr/$LIBDIR/gdk-pixbuf/loaders/*png*
usr/$LIBDIR/gdk-pixbuf/loaders/*xpm*
usr/$LIBDIR/girepository-1.0
usr/$LIBDIR/gtk-2.0/*/engines/libclearlooks.so
usr/$LIBDIR/gtk-2.0/*/loaders/*la*
usr/$LIBDIR/gtk-2.0/*/loaders/*png*
usr/$LIBDIR/gtk-2.0/*/loaders/*xpm*
usr/$LIBDIR/gtk-2.0/immodules
usr/$LIBDIR/libuser/*
usr/$LIBDIR/pango
usr/$LIBDIR/python?.?
usr/$LIBDIR/libiscsi.so*
usr/$LIBDIR/libmetacity-private.so*
usr/$LIBDIR/libsqlite3.so*
usr/$LIBDIR/xorg/modules
usr/$LIBDIR/libfreebl3.so
usr/$LIBDIR/libfreebl3.chk
usr/$LIBDIR/libnss3.so
usr/$LIBDIR/libnssckbi.so
usr/$LIBDIR/libnssdbm3.so
usr/$LIBDIR/libnssdbm3.chk
usr/$LIBDIR/libnsspem.so
usr/$LIBDIR/libpolkit-backend-1.so.0.*
usr/$LIBDIR/libsmime3.so
usr/$LIBDIR/libsoftokn3.so
usr/$LIBDIR/libsoftokn3.chk
usr/$LIBDIR/libssl3.so
usr/$LIBDIR/.*.hmac
$LIBDIR/.libgcrypt*.hmac
usr/bin/[
usr/bin/Xorg
usr/bin/Xvnc
usr/bin/chattr*
usr/bin/chvt
usr/bin/clear
usr/bin/dbus-launch
usr/bin/du
usr/bin/eject
usr/bin/expr
usr/bin/gdbserver
usr/bin/gdialog
usr/bin/gdk-pixbuf-query-loaders*
usr/bin/gtk-query*
usr/bin/gtk-update-icon-cache*
usr/bin/hattrib
usr/bin/hcopy
usr/bin/head
usr/bin/hformat
usr/bin/hmount
usr/bin/humount
usr/bin/killall
usr/bin/logger
usr/bin/lsattr*
usr/bin/maketilo
usr/bin/md5sum
usr/bin/metacity
usr/bin/mkzimage
usr/bin/nm-connection-editor
usr/bin/nslookup
usr/bin/pango*
usr/bin/python
usr/bin/python?.?
usr/bin/rdate
usr/bin/readlink
usr/bin/reduce-font
usr/bin/setxkbmap
usr/bin/sha1sum
usr/bin/split
usr/bin/ssh-keygen
usr/bin/strace
usr/bin/syslinux
usr/bin/tac
usr/bin/tail
usr/bin/tee
usr/bin/tilo
usr/bin/top
usr/bin/tty
usr/bin/wc
usr/bin/udev*
usr/bin/uniq
usr/bin/vncconfig
usr/bin/vncpasswd
usr/bin/wget
usr/bin/which
usr/bin/xkbcomp
usr/bin/xrandr
usr/bin/zenity
usr/$LIBDIR/anaconda
usr/lib/kernel-wrapper
usr/lib/locale
usr/lib/python?.?
usr/lib/rpm/macros
usr/lib/rpm/rpmpopt
usr/lib/rpm/rpmrc
usr/share/X11/xorg.conf.d/*
usr/share/syslinux
usr/lib/yaboot
usr/lib/yum-plugins/blacklist.py*
usr/lib/yum-plugins/fedorakmod.py*
usr/lib/yum-plugins/whiteout.py*
usr/libexec/anaconda
usr/libexec/convertdb1
usr/libexec/fcoe/fcoe_edd.sh
usr/libexec/nm-crash-logger
usr/libexec/nm-dhcp-client.action
usr/libexec/nm-dispatcher.action
usr/libexec/polkit*
usr/sbin/NetworkManager
usr/sbin/addRamDisk
usr/sbin/anaconda
usr/sbin/build-locale-archive
usr/sbin/chroot
usr/sbin/dcbtool
usr/sbin/ddcprobe
usr/sbin/dmidecode
usr/sbin/efibootmgr
usr/sbin/fcoemon
usr/sbin/fbset
usr/sbin/fipvlan
usr/sbin/genhomedircon
usr/sbin/gptsync
usr/sbin/lldpad
usr/sbin/logpicker
usr/sbin/lsof
usr/sbin/lvm
usr/sbin/ntpdate
usr/sbin/prelink
usr/sbin/semodule
usr/sbin/showpart
usr/sbin/smartctl
usr/sbin/sshd
usr/sbin/.sshd.hmac
usr/sbin/wpa_passphrase
usr/sbin/wpa_supplicant
usr/sbin/wrapper
usr/sbin/xfs_admin
usr/sbin/xfs_check
usr/sbin/xfs_copy
usr/sbin/xfs_db
usr/share/polkit-1/actions/*
usr/share/X11/XKeysymDB
usr/share/X11/fonts/TTF/GohaTibebZemen.ttf
usr/share/X11/fonts/misc/6x13*
usr/share/X11/fonts/misc/cursor*
usr/share/X11/fonts/misc/fonts*
usr/share/X11/fonts/misc/olcursor*
usr/share/X11/locale
usr/share/X11/rgb*
usr/share/X11/xkb
usr/share/anaconda
usr/share/anaconda/anaconda.conf
usr/share/cracklib
usr/share/dbus-1
usr/share/fontconfig
usr/share/fonts/*/lklug.ttf
usr/share/fonts/lohit*/*
usr/share/fonts/*/lklug.ttf
usr/share/fonts/cjkuni*/uming*.ttc
usr/share/fonts/dejavu/DejaVuSans-Bold.ttf
usr/share/fonts/dejavu/DejaVuSans.ttf
usr/share/fonts/dejavu/DejaVuSansMono.ttf
usr/share/fonts/kacst/KacstFarsi.ttf
usr/share/fonts/kacst/KacstQurn.ttf
usr/share/fonts/madan/Madan.ttf
usr/share/fonts/un-core/UnDotum.ttf
usr/share/fonts/*/VL-Gothic-Regular.ttf
usr/share/fonts/smc/Meera*.ttf
usr/share/hwdata/MonitorsDB
usr/share/hwdata/pci.ids
usr/share/hwdata/usb.ids
usr/share/hwdata/videoaliases
usr/share/hwdata/videodrivers
usr/share/icons/hicolor/*/apps/nm-*
usr/share/icons/hicolor/index.theme
usr/share/locale/*/LC_MESSAGES/anaconda.mo
usr/share/locale/*/LC_MESSAGES/cracklib.mo
usr/share/locale/*/LC_MESSAGES/gtk20.mo
usr/share/locale/*/LC_MESSAGES/libc.mo
usr/share/locale/*/LC_MESSAGES/nm-applet.mo
usr/share/locale/*/LC_MESSAGES/parted.mo
usr/share/locale/*/LC_MESSAGES/redhat-dist.mo
usr/share/locale/*/LC_MESSAGES/system-config-date.mo
usr/share/locale/*/LC_MESSAGES/system-config-keyboard.mo
usr/share/locale/*/LC_MESSAGES/zenity.mo
usr/share/locale/locale.alias
usr/share/mime/mime.cache
usr/share/nm-applet/*
usr/share/pixmaps/comps/*.png
usr/share/pixmaps/gnome-default-dlg.png
usr/share/pixmaps/gnome-error.png
usr/share/pixmaps/gnome-info.png
usr/share/pixmaps/gnome-question.png
usr/share/pixmaps/gnome-warning.png
usr/share/pixmaps/no.xpm
usr/share/pixmaps/yes.xpm
usr/share/ppc64-utils
usr/share/python-meh/*
usr/share/system-config-date
usr/share/system-config-date/zonetab.py*
usr/share/system-config-keyboard
usr/share/terminfo/a/ansi
usr/share/terminfo/d/dumb
usr/share/terminfo/g/gnome
usr/share/terminfo/l/linux
usr/share/terminfo/s/screen
usr/share/terminfo/v/vt100
usr/share/terminfo/v/vt100-nav
usr/share/terminfo/v/vt102
usr/share/terminfo/v/vt320
usr/share/terminfo/v/vt320-w
usr/share/terminfo/x/xterm
usr/share/terminfo/x/xterm-color
usr/share/themes/Atlanta/metacity-1
usr/share/themes/Adwaita/*
usr/share/xorg/extramodes
usr/share/xorg/vesamodes
usr/share/zenity
usr/share/zoneinfo
var/lib/polkit-1
var/lib/dbus
var/lib/lldpad
var/run/dbus
EOF

if [ $ARCH = ppc -o $ARCH = ppc64 ]; then
    cat >> $KEEPFILE <<EOF
usr/$LIBDIR/kernel-wrapper/*
EOF
fi

if [ $ARCH = s390 -o $ARCH = s390x ]; then
    cat >> $KEEPFILE <<EOF
bin/basename
bin/cat
bin/chmod
bin/chown
bin/cp
bin/cut
bin/date
bin/dmesg
bin/echo
bin/find
bin/gzip
bin/ls
bin/mknod
bin/ping
bin/ping6
bin/ps
bin/sort
bin/tar
bin/vi
lib/modules/ibm
lib/s390-tools/lsznet.raw
lib/s390-tools/znetcontrolunits
lib/security
sbin/*_cio_free
sbin/arp
sbin/cio_ignore
sbin/cmsfscat
sbin/cmsfslst
sbin/dasdfmt
sbin/dasdinfo
sbin/dasdview
sbin/fdasd
sbin/lschp
sbin/lscss
sbin/lsdasd
sbin/lsqeth
sbin/lszfcp
sbin/portmap
sbin/qetharp
sbin/qetharp-2.6
sbin/qethconf
sbin/sysctl
usr/bin/dirname
usr/bin/expr
usr/bin/getopt
usr/bin/head
usr/bin/ldd
usr/bin/less
usr/bin/lsscsi
usr/bin/nslookup
usr/bin/printf
usr/bin/seq
usr/bin/scp
usr/bin/strace
usr/bin/tr
usr/bin/wc
usr/bin/xauth
usr/sbin/chreipl
usr/sbin/glibc_post_upgrade
usr/sbin/lsreipl
EOF
fi

# more dogtail stuff...
cat >> $KEEPFILE <<EOF
usr/$LIBDIR/gtk-2.0/modules/libatk-bridge.so
usr/$LIBDIR/gtk-2.0/modules/libgail.so
usr/libexec/bonobo-activation-server
usr/libexec/at-spi-registryd
usr/$LIBDIR/bonobo/servers
usr/libexec/gconfd-2
usr/$LIBDIR/GConf/2/libgconfbackend-xml.so
EOF

#
# KEEPFILERESCUE is all files to keep from the packages in PACKAGESRESCUE
#
# This defines the files in addition to KEEPFILE that make up
# the install images for NFS and CD/DVD based rescue mode installs.  This
# image is not loaded into memory so it can be considerably larger.
#
# NOTE: hd, ftp, and http rescue mode use and image based on KEEPFILE since
#       it has to be much smaller due to memory usage.
#
KEEPFILERESCUE=${TMPDIR:-/tmp}/keepfilerescue.$$
cat > $KEEPFILERESCUE <<EOF
bin/find
bin/gunzip
bin/gzip
bin/mt
bin/ping
bin/sync
bin/tar
bin/zcat
sbin/arp
sbin/blkid
sbin/depmod
sbin/dmraid
sbin/dmsetup
sbin/dump
sbin/ifconfig
sbin/insmod
sbin/lsmod
sbin/modinfo
sbin/modprobe
sbin/depmod
sbin/netstat
sbin/restore
sbin/rrestore
sbin/route
sbin/mount.cifs
sbin/umount.cifs
usr/bin/bunzip2
usr/bin/bzcat
usr/bin/bzip2
usr/bin/emacs
usr/bin/find
usr/bin/ftp
usr/bin/less
usr/bin/mattrib
usr/bin/mbadblocks
usr/bin/mcd
usr/bin/mcopy
usr/bin/mdel
usr/bin/mdeltree
usr/bin/mdir
usr/bin/mdu
usr/bin/mformat
usr/bin/minfo
usr/bin/mlabel
usr/bin/mmd
usr/bin/mmount
usr/bin/mmove
usr/bin/mpartition
usr/bin/mrd
usr/bin/mread
usr/bin/mren
usr/bin/mshowfat
usr/bin/mtools
usr/bin/mtype
usr/bin/mzip
usr/bin/open
usr/bin/rcp
usr/bin/rlogin
usr/bin/rsh
usr/bin/rsync
usr/bin/scp
usr/bin/sftp
usr/bin/shred
usr/bin/ssh
usr/bin/termidx
usr/bin/volume_key
usr/bin/xargs
usr/bin/ntfscat
usr/bin/ntfscluster
usr/bin/ntfscmp
usr/bin/ntfsdecrypt
usr/bin/ntfsdump_logfile
usr/bin/ntfsfix
usr/bin/ntfsinfo
usr/bin/ntfsls
usr/bin/ntfsmftalloc
usr/bin/ntfsmove
usr/bin/ntfstruncate
usr/bin/ntfswipe
usr/bin/firstaidkit
usr/sbin/lsusb
usr/sbin/mkntfs
usr/sbin/ntfsclone
usr/sbin/ntfscp
usr/sbin/ntfslabel
usr/sbin/ntfsresize
usr/sbin/ntfsundelete
usr/sbin/mtr
usr/sbin/smartctl
usr/sbin/traceroute
usr/$LIBDIR/firstaidkit/plugins/*
usr/bin/whiptail
usr/bin/firstaidkit-qs
EOF

if [ $ARCH = i386 -o $ARCH = i586 -o $ARCH = i686 -o $ARCH = x86_64 ]; then
    cat >> $KEEPFILERESCUE <<-EOF
sbin/grub
usr/bin/gpart
usr/share/grub
EOF
fi

echo "Assembling package list..."
RPMS="$PACKAGES $PACKAGESRESCUE"
[ -n "$DEBUG" ] && echo "RPMS are $RPMS"

rm -rf $DEST

# Create a bunch of empty directories that are important for a running system.
mkdir -p $DEST/boot
mkdir -p $DEST/dev
mkdir -p $DEST/etc/dhcp
mkdir -p $DEST/etc/modprobe.d
mkdir -p $DEST/firmware
mkdir -p $DEST/lib
mkdir -p $DEST/modules
mkdir -p $DEST/proc
mkdir -m 0700 $DEST/root
mkdir -p $DEST/selinux
mkdir -p $DEST/sys
mkdir -p $DEST/tmp
mkdir -p $DEST/usr/lib/rpm
mkdir -p $DEST/usr/sbin
mkdir -m 111 -p $DEST/var/empty/sshd
mkdir -p $DEST/var/lib/dbus
mkdir -p $DEST/var/lib/dhclient
mkdir -p $DEST/var/lib/rpm
mkdir -p $DEST/var/lock/rpm
mkdir -p $DEST/var/run
mkdir -p $DEST/var/run/dbus
mkdir -p $DEST/var/run/NetworkManager
mkdir -p $DEST/var/run/wpa_supplicant
mkdir -p $DEST/var/state

ln -s /tmp $DEST/var/lib/xkb
ln -s /tmp $DEST/var/state/xkb

#
# concat KEEPFILE and KEEPFILERESCUE lists
#
cat $KEEPFILERESCUE >> $KEEPFILE

echo `date` "Expanding packages..."
YUMDIR=${TMPDIR:-/tmp}/yumdir.$$
mkdir -p $YUMDIR/var/log
mkdir -p $YUMDIR/var/lib/yum

expandPackageSet $yumconf $YUMDIR "$RPMS" $DEST $KEEPFILE
echo `date` "Done Expanding packages..."

# Install the anaconda portions.
install -m 755 $DEST/usr/libexec/anaconda/auditd $DEST/sbin/auditd
install -m 755 $DEST/usr/$LIBDIR/anaconda/loader $DEST/sbin/loader
install -m 644 $DEST/usr/share/anaconda/loader.tr $DEST/etc/loader.tr

cp $DEST/usr/share/anaconda/raidstart-stub $DEST/usr/bin/raidstart
cp $DEST/usr/share/anaconda/raidstop-stub $DEST/usr/bin/raidstop
cp $DEST/usr/share/anaconda/list-harddrives-stub $DEST/usr/bin/list-harddrives
cp $DEST/usr/share/anaconda/loadkeys-stub $DEST/usr/bin/loadkeys
cp $DEST/usr/share/anaconda/restart-anaconda $DEST/usr/bin/restart-anaconda
mv $DEST/usr/$LIBDIR/python?.?/site-packages/pyanaconda/sitecustomize.py $DEST/usr/$LIBDIR/python?.?/site-packages

if [ $ARCH = "s390" -o $ARCH = "s390x" ]; then
    mv $DEST/usr/libexec/anaconda/shutdown $DEST/sbin
    mv $DEST/usr/share/anaconda/linuxrc.s390 $DEST/sbin/init
    ( cd $DEST/sbin && ln -sf init reboot && ln -sf init halt )
else
    mv $DEST/usr/$LIBDIR/anaconda/init $DEST/sbin/init
    ( cd $DEST/sbin && ln -s init reboot && ln -s init halt && ln -s init poweroff )

    install -m 644 $DEST/usr/share/anaconda/screenfont-$ARCH.gz $DEST/etc/screenfont.gz
fi

# Dogtail will check this
echo "Creating customized GConf2 settings for root"
mkdir -p $DEST/.gconf/desktop/gnome/interface
touch $DEST/.gconf/desktop/%gconf.xml
touch $DEST/.gconf/desktop/gnome/%gconf.xml
cat > $DEST/.gconf/desktop/gnome/interface/%gconf.xml <<EOF
<?xml version="1.0"?>
<gconf>
        <entry name="accessibility" mtime="1176200664" type="bool" value="true">
        </entry>
</gconf>
EOF

# anaconda needs to change a couple of the default gconf entries
GCONF_CONFIG_SOURCE="xml:readwrite:$DEST/etc/gconf/gconf.xml.defaults"
echo "Updating gconf at $GCONF_CONFIG_SOURCE"
gconf_update() {
    path=$1
    entry_type=$2
    value=$3
    CMD="gconftool-2 --direct --config-source=$GCONF_CONFIG_SOURCE -s -t $entry_type $path $value"
    $($CMD)
}
gconf_update /apps/metacity/general/button_layout string :
gconf_update /apps/metacity/general/action_right_click_titlebar string none
gconf_update /apps/metacity/window_keybindings/close string disabled
gconf_update /apps/metacity/global_keybindings/run_command_window_screenshot string disabled
gconf_update /apps/metacity/global_keybindings/run_command_screenshot string disabled

rm -rf $YUMDIR

chown -R root:root $DEST
chmod -R a+rX-w $DEST

# Some files need very particular permissions.
chmod 04755 $DEST/usr/libexec/polkit-1/polkit-agent-helper-1
chown root:dbus $DEST/$LIBDIR/dbus-1/dbus-daemon-launch-helper
chmod 04750 $DEST/$LIBDIR/dbus-1/dbus-daemon-launch-helper

# Remove locales unused during the install
install -m 644 $DEST/usr/share/anaconda/lang-table $DEST/etc/lang-table
localedef -c -i en_US -f UTF-8 --prefix $DEST en_US

cat $DEST/usr/share/anaconda/lang-table* | awk '
{ gsub("-", "", $4);
  print $4;
  print gensub(/\..*$/,"","",$4);
  print gensub(/_.*$/,"","",$4);
  if (split ($4, a, ".") > 1) {
    print gensub(/\..*$/,tolower("." a[2]),"",$4);
  };
  print $2;
}
' | grep -v Sotho | grep -v latarcyrhebsun16 | sed -e 's/latn/Latn/g' | LC_ALL=C sort -u > $DEST/locales
for p in lib share; do (
    cd $DEST/usr/$p/locale && {
        ls | grep -v locale.alias | grep -v locale-archive | LC_ALL=C sort > $DEST/locales.list
        LC_ALL=C comm -13 $DEST/locales $DEST/locales.list | xargs rm -rf
    }
); done

# Now shrink the locale-archive to contain just the minimum.
localedef --prefix $DEST --list-archive > $DEST/locales.glibc
LC_ALL=C unsupported="$(comm -13 $DEST/locales $DEST/locales.glibc)"
localedef --prefix $DEST --delete-from-archive $unsupported
mv $DEST/usr/lib/locale/locale-archive $DEST/usr/lib/locale/locale-archive.tmpl
/usr/sbin/chroot $DEST /usr/sbin/build-locale-archive

rm -f $DEST/locales $DEST/locales.list $DEST/locales.glibc

# fix up some links for man page related stuff
for file in nroff groff iconv geqn gtbl gpic grefer ; do
    ln -fs /mnt/sysimage/usr/bin/$file $DEST/usr/bin/$file
done

# create selinux config
if [ -e $DEST/etc/selinux/targeted ]; then
  cat > $DEST/etc/selinux/config <<EOF
SELINUX=permissive
SELINUXTYPE=targeted
EOF
fi

echo "Creating config files"
touch $DEST/etc/resolv.conf

# \EOF has a quote in the first character on purpose; see man bash on here documents
cat > $DEST/etc/rsyslog.conf <<\EOF
#### MODULES ####
$ModLoad imuxsock.so     # provides support for local system logging
$ModLoad imklog.so       # provides kernel logging support

$ModLoad imfile
$InputFileName /tmp/X.log
$InputFileTag xserver:
$InputFileStateFile xserver-statefile
$InputFileFacility local1
$InputRunFileMonitor
$InputFileName /tmp/anaconda-tb-all.log
$InputFileTag anaconda-tb:
$InputFileStateFile anaconda-tb-statefile
$InputFileFacility local1
$InputRunFileMonitor

#### GLOBAL DIRECTIVES ####
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

#### TEMPLATES ####

$template anaconda_tty4, "%syslogseverity-text:::uppercase% %programname%:%msg%\n"
$template anaconda_syslog, "%timestamp:8:$:date-rfc3164%,%timestamp:1:3:date-subseconds% %syslogseverity-text:::uppercase% %programname%:%msg%\n"
$template virtio_ForwardFormat, "<%PRI%>%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag:1:32%%msg:::sp-if-no-1st-sp%%msg%\n"

#### RULES ####
# log everything except anaconda-specific records from local1 (those are stored
# directly into files via python logging)
*.*;\
authpriv.none;\
local1.none             /tmp/syslog;anaconda_syslog
                        & /dev/tty4;anaconda_tty4

# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$ActionQueueMaxDiskSpace 1m     # space limit (use as much as possible)
$ActionQueueSaveOnShutdown off  # do not save messages to disk on shutdown
$ActionQueueType LinkedList     # run asynchronously
$ActionResumeRetryCount -1      # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
# ### end of the forwarding rule ###

EOF

cat > $DEST/etc/libuser.conf <<EOF
[defaults]
skeleton = /mnt/sysimage/etc/skel
mailspooldir = /mnt/sysimage/var/mail
crypt_style = md5
modules = files shadow
create_modules = files shadow
[files]
directory = /mnt/sysimage/etc
[shadow]
directory = /mnt/sysimage/etc
EOF

cat > $DEST/root/.profile <<EOF
PS1="[anaconda \u@\h \W]\\\\$ "
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/mnt/sysimage/sbin:/mnt/sysimage/usr/sbin:/mnt/sysimage/bin:/mnt/sysimage/usr/bin
export PATH PS1
EOF

cat > $DEST/root/.bash_history <<EOF
kill -USR2 \`cat /var/run/anaconda.pid\`
kill -HUP \`cat /var/run/anaconda.pid\`
udevadm info --export-db | less
tail -f /tmp/storage.log
echo b > /proc/sysrq-trigger
dmsetup table
multipath -d
HOME=/root chroot /mnt/sysimage bash -l -i
EOF

echo "Creating /etc/skel"
# libuser needs this when it creates sshpw users
mkdir -p $DEST/etc/skel

echo "Creating empty /etc/gshadow"
# libuser needs this when it creates sshpw users
touch $DEST/etc/gshadow

setupSshd

sed -i 's|\(installforallkernels\) = 0|\1 = 1|' $DEST/etc/yum/pluginconf.d/fedorakmod.conf

#
# Manual pages in rescue: We dont have man pages in the image, so we point everything (The pages
# and the man scripts to the /mnt/sysimage.  We want the man command to depend only on the
# man_db.conf file, so we don't use the $MANPATH env variable.  The executables stay unchanged as
# they will be soft links to /mnt/sysimage.
#
echo "Fixing up /etc/man_db.conf to point into /mnt/sysimage"

#
# Lets avoid the lines with MANPATH_MAP for now
#
sed -i "s,^MANPATH[^_MAP][ \t]*,&/mnt/sysimage," $DEST/etc/man_db.conf

#
# Lets change the lines with MANPATH_MAP.  Don't know how much of a difference this will make.
#
sed -i "s,^MANPATH_MAP[ \t]*[a-zA-Z0-9/]*[ \t]*,&/mnt/sysimage," $DEST/etc/man_db.conf

echo "Scrubbing tree..." "$DEST"

mv $DEST/etc/yum.repos.d $DEST/etc/anaconda.repos.d

rm -f $DEST/usr/$LIBDIR/libunicode-lite*
rm -f $DEST/usr/share/icons/*/icon-theme.cache
rm -f $DEST/usr/sbin/build-locale-archive

find $DEST -type d | xargs chmod 755

cp $DEST/usr/share/doc/python-devel-*/gdbinit $DEST/.gdbinit

if [ -f $DEST/bin/bash ]; then
    rm -f $DEST/bin/ash
    ln -s bash $DEST/bin/sh
fi

if [ -f $DEST/bin/gawk ]; then
    ln -sf $DEST/bin/gawk awk
fi

( cd $DEST/etc && ln -sf /etc/rc.d/init.d init.d )
ln -sf /sbin/init $DEST/init
ln -sf /proc/mounts $DEST/etc/mtab

# copy bootloader files for sparc
if [ $ARCH = sparc -o $ARCH = sparcv9 -o $ARCH = sparc64 ]; then
    mkdir -p $DEST/usr/share/anaconda/boot
    [ -d $DEST/boot ] || die "ERROR: directory missing: $DEST/boot"
    (cd $DEST/boot; find -name "*.b") | (cd $DEST/boot; /bin/cpio --quiet -pdmu $DEST/usr/share/anaconda/boot)
fi

# copy bootloader file for ppc
if [ $ARCH = ppc -o $ARCH = ppc64 ]; then
    mkdir -p $DEST/usr/share/anaconda/boot
    cp -af $DEST/boot/efika.forth $DEST/usr/share/anaconda/boot
fi

# copy bootloader file for alpha
if [ $ARCH = alpha ]; then
    mkdir -p $DEST/usr/share/anaconda/boot
    cp -af $DEST/boot/bootlx $DEST/usr/share/anaconda/boot
fi

# copy bootloader files for ia64
if [ $ARCH = ia64 ]; then
    mkdir -p $DEST/usr/share/anaconda/boot
    cp -af $DEST/boot/efi/EFI/redhat//* $DEST/usr/share/anaconda/boot
fi

# copy bootloader files for i386/x86_64
if [ $ARCH = i386 -o $ARCH = i586 -o $ARCH = i686 -o $ARCH = x86_64 ]; then
    mkdir -p $DEST/usr/share/anaconda/boot
    cp -af $DEST/boot/memtest* $DEST/usr/share/anaconda/boot
fi

rm -rf $DEST/boot $DEST/home

# Remove a bunch of stuff we don't want in the final image.
find $DEST -name "*.a" | grep -v kernel-wrapper/wrapper.a | xargs rm -rf
find $DEST -name "lib*.la" |grep -v "usr/$LIBDIR/gtk-2.0" | xargs rm -rf
for i in $DEST/lib/udev/rules.d/*generator* ; do
    [[ "$i" =~ net-generator ]] || rm -f $i
done

# nuke some python stuff we don't need
for d in idle distutils bsddb lib-old hotshot doctest.py pydoc.py site-packages/japanese site-packages/japanese.pth ; do
    rm -rf $DEST/$d
done

$DEST/usr/libexec/anaconda/scrubtree $DEST

echo "Creating debug dir"
mkdir -p $DEST/usr/lib/debug
mkdir -p $DEST/usr/src/debug

find $DEST -name "*.py" | while read fn; do
    rm -f ${fn}o
    rm -f ${fn}c
    ln -sf /dev/null ${fn}c
done

# some python stuff we don't need for install image
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/distutils/
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/lib-dynload/japanese
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/encodings/
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/compiler/
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/email/test/
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/curses/
rm -rf $DEST/usr/$LIBDIR/python?.?/site-packages/pydoc.py
