#!/bin/bash ORIGDIR=`pwd` if [ -z "$1" ]; then echo "upd-instroot: updates instimage from a Red Hat RPMS directory" echo "usage: $0 [templatedir] [instroot]" exit 1 fi if [ ! -d $1 ]; then if [ -z "$ARCH" ]; then echo "ARCH must be set" >&2 exit 1 fi LATEST="latest --arch $ARCH" fi PACKAGEDIR=$1 if [ -z "$ARCH" ]; then ARCH=`rpm -qp --qf "%{ARCH}" $PACKAGEDIR/anaconda-runtime*.rpm` fi NEEDGR=yes if [ $ARCH = ia64 ]; then NEEDGR="" fi prunePackageList() { PACKAGEPATH=$1 PACKAGES="$2" if [ -n "$LATEST" ]; then $LATEST $PACKAGEPATH $PACKAGES if [ $? != 0 ]; then $LATEST $PACKAGEPATH $PACKAGES >&2 kill -9 $$ fi return fi PATTERN="" PACKAGEFILES="" for PKG in $PACKAGES; do PATTERN="${PATTERN:+${PATTERN}|}(^$PKG )" PACKAGEFILES="$PACKAGEFILES $(ls $PACKAGEPATH/${PKG}*{${ARCH},noarch}.rpm 2>/dev/null)" done # gtk+, enough said PATTERN=$(echo $PATTERN | sed 's,[\+\*],\\&,g') PACKAGEFILES=$(ls $PACKAGEFILES | sort -u) rpm --qf "%{NAME} $PACKAGEPATH/%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n" \ -qp $PACKAGEFILES | egrep "$PATTERN" | sed 's/.* //' } expandPackageSet() { RPMS=$1 PKGDEST=$2 KEEPFILE=$3 for n in $RPMS; do echo -ne "\rExpanding packages..." $(basename $n) if [ $(rpm -qp --qf '%{NAME}' $n) = "glibc" ] ; then GLIBC=$n fi rpm2cpio $n | (cd $PKGDEST; cpio -E $KEEPFILE --quiet -iumd) echo -ne "\rExpanding packages..." "$(basename $n | sed 's/./ /g')" done } if [ -z "$2" ]; then DEST=/tmp/upd-instroot else DEST=$2 fi if [ -z "$3" ]; then DESTGR=/tmp/upd-instroot else DESTGR=$3 fi rm -rf $DEST $DESTGR mkdir -p $DEST mkdir -p $DESTGR PACKAGES="glibc setup openssl python newt libtermcap zlib ash kon2 e2fsprogs util-linux raidtools popt mount procps rpm XFree86 Xconfigurator anaconda anaconda-runtime kudzu-devel kudzu db3 rpm-python bzip2 dosfstools pciutils" if [ $ARCH = i386 ]; then PACKAGES="$PACKAGES kernel-pcmcia-cs" fi # xpm is missing # Some packages are listed twice, but that's okay PACKAGESGR="anaconda XFree86-libs imlib libpng libtiff libjpeg XFree86-S3 XFree86-SVGA XFree86-75dpi-fonts XFree86-ISO8859-2-75dpi-fonts glib gtk+ XFree86-ISO8859-9-75dpi-fonts esound audiofile gnome-libs XFree86-100dpi-fonts XFree86-ISO8859-2 XFree86-ISO8859-9 XFree86-xfs e2fsprogs fileutils glibc rsh less ftp readline gzip popt specspo util-linux rpm rpm-devel open grep net-tools traceroute tar procps textutils sed ncurses bash cpio mt-st iputils sh-utils XFree86-cyrillic-fonts XFree86 Xconfigurator pygnome pygtk pygtk-libglade pygnome-libglade pygnome-applet pygnome-capplet gdk-pixbuf XFree86-KOI8-R XFree86-KOI8-R-75dpi-fonts pciutils" if [ -z "$NEEDGR" ]; then PACKAGESGR="bash" fi if [ $ARCH != ia64 ]; then PACKAGES="$PACKAGES db1 db2" PACKAGESGR="$PACKAGESGR mtools pine modutils" fi if [ $ARCH = sparc ]; then PACKAGESGR="$PACKAGESGR XFree86-3DLabs XFree86-Mach64 tilo silo" fi if [ $ARCH = i386 ]; then PACKAGESGR="$PACKAGESGR XFree86-3DLabs XFree86-8514 XFree86-AGX XFree86-FBDev XFree86-I128 XFree86-Mach32 XFree86-Mach64 XFree86-Mach8 XFree86-Mono XFree86-P9000 XFree86-S3 XFree86-S3V XFree86-SVGA XFree86-VGA16 XFree86-W32 syslinux" fi if [ $ARCH = alpha ]; then PACKAGESGR="$PACKAGESGR XFree86-3DLabs XFree86-Mono XFree86-P9000 XFree86-S3 XFree86-SVGA aboot" fi KEEPFILE=/tmp/keepfile.$$ cat > $KEEPFILE <> $KEEPFILEGR <> $KEEPFILEGR <<-EOF usr/X11R6/lib/X11/fonts/100dpi/cour* usr/X11R6/lib/X11/fonts/100dpi/helv* usr/X11R6/lib/X11/fonts/100dpi/tim* usr/X11R6/lib/X11/fonts/100dpi/fonts* usr/share/fonts/ISO8859-2/100dpi/cour* usr/share/fonts/ISO8859-2/100dpi/helv* usr/share/fonts/ISO8859-2/100dpi/tim* usr/share/fonts/ISO8859-2/100dpi/fonts* EOF fi echo "Assembling package list..." RPMS=$(prunePackageList $PACKAGEDIR "$PACKAGES") RPMSGR=$(prunePackageList $PACKAGEDIR "$PACKAGESGR") rm -rf $DEST; mkdir -p $DEST/usr/sbin rm -rf $DESTGR; mkdir -p $DESTGR/usr/sbin $DESTGR/var/lib ln -s /tmp $DESTGR/var/lib/xkb for file in $KEEPFILE $KEEPFILEGR; do cat $file | awk '{print $1 "\n./" $1}' > $file- mv -f $file- $file done echo -n "Expanding packages..." expandPackageSet "$RPMS" $DEST $KEEPFILE (cd $DEST; tar cSpf - .) | (cd $DESTGR; tar xSpf -) expandPackageSet "$RPMSGR" $DESTGR $KEEPFILEGR echo -e "\rExpanding packages..." if [ -f $DEST/usr/share/doc/kon2*/terminfo.kon ]; then tic $DEST/usr/share/doc/kon2*/terminfo.kon -o $DEST/usr/share/terminfo tic $DEST/usr/share/doc/kon2*/terminfo.kon -o $DESTGR/usr/share/terminfo rm $DEST/usr/share/doc/kon2*/terminfo.kon fi echo "retrieving timezones" TZDIR=/tmp/glibc-timezone-$$ mkdir -p $TZDIR/usr/share/zoneinfo rpm2cpio $GLIBC | (cd $TZDIR; cpio --quiet -iumd usr/share/zoneinfo ./usr/share/zoneinfo ./usr/share/zoneinfo/* usr/share/zoneinfo/*) (cd $TZDIR; tar cSpf - $TIMEZONES) | (cd $DEST; tar xSpf -) (cd $TZDIR; tar cSpf - $TIMEZONES) | (cd $DESTGR; tar xSpf -) rm -rf $TZDIR chown -R root:root $DEST $DESTGR chmod -R a+rX-w $DEST $DESTGR if [ $ARCH = sparc ]; then rm -f $DESTGR/usr/X11R6/bin/XF86_VGA16 fi # Remove locales unused during the install cat $DESTGR/usr/lib/anaconda/lang-table* | awk ' { print $5; print gensub(/\..*$/,"","",$5); print gensub(/_.*$/,"","",$5); if (split ($5, a, "\.") > 1) { print gensub(/\..*$/,tolower("." a[2]),"",$5); }; } ' | LC_ALL=C sort -u > $DESTGR/locales for p in lib share; do ( cd $DESTGR/usr/$p/locale && { ls | grep -v locale.alias | LC_ALL=C sort > $DESTGR/locales.list LC_ALL=C comm -13 $DESTGR/locales $DESTGR/locales.list | xargs rm -rf } ); done rm -f $DESTGR/locales $DESTGR/locales.list # Remove unneeded XFree86 modules rm -rf $DESTGR/usr/X11R6/lib/modules/dri rm -f $DESTGR/usr/X11R6/lib/modules/extensions/lib{GLcore,glx,pex5}* echo "Running mkfontdir..." if [ -n "$NEEDGR" ]; then for I in $DESTGR/usr/X11R6/lib/X11/fonts/* $DESTGR/usr/share/fonts/ISO8859-2/* $DESTGR/usr/share/fonts/ISO8859-9/*; do /usr/X11R6/bin/mkfontdir $I done fi rm -f $KEEPFILE $KEEPFILEGR echo -n "Scrubbing trees..." for p in $DEST $DESTGR; do echo -n -e "\rScrubbing trees..." "$p" ln -s ../lib/anaconda/raidstart-stub $p/usr/bin/raidstart ln -s ../lib/anaconda/raidstop-stub $p/usr/bin/raidstop mv $p/usr/sbin/anaconda $p/usr/bin/anaconda mv $p/usr/sbin/anaconda-runrescue $p/usr/bin/anaconda-runrescue mv $p/usr/lib/anaconda-runtime/lib* $p/usr/lib mv $p/usr/lib/anaconda-runtime/collage $p/usr/bin find $p -type d | xargs chmod 755 if [ -f $p/bin/bash ]; then rm -f $p/bin/ash ln -s bash $p/bin/sh else ln -s ash $p/bin/sh fi (cd $p/bin; find) | (cd $p/bin; /bin/cpio --quiet -pdmu $p/usr/bin) (cd $p/sbin; find) | (cd $p/sbin; /bin/cpio --quiet -pdmu $p/usr/sbin) rm -rf $p/bin rm -rf $p/sbin # copy bootloader files for sparc if [ $ARCH = sparc -a $p = $DESTGR ]; then mkdir -p $p/usr/lib/anaconda-runtime/boot (cd $p/boot; find -name "*.b") | (cd $p/boot; /bin/cpio --quiet -pdmu $p/usr/lib/anaconda-runtime/boot) fi # copy bootloader file for alpha if [ $ARCH = alpha -a $p = $DESTGR ]; then mkdir -p $p/usr/lib/anaconda-runtime/boot cp -af $p/boot/bootlx $p/usr/lib/anaconda-runtime/boot fi rm -rf $p/boot $p/home $p/root $p/tmp find $p -name "*.a" | grep -v "usr/X11R6/lib/modules" | xargs rm -rf (cd /usr/share/zoneinfo; find . -type f -or -type l | grep '^./[A-Z]' | sort | sed 's/^..//' | gzip -9) > $p/usr/lib/timezones.gz if [ -x /usr/bin/runroot ]; then REALPATH=`(cd $p; /bin/pwd)` runroot dist-7.0 --onlyone --arch $ARCH "cd $REALPATH\; usr/lib/anaconda-runtime/scrubtree $REALPATH" else $p/usr/lib/anaconda-runtime/scrubtree $p fi echo -n -e "\rScrubbing trees..." "$(echo $p | sed 's/./ /g')" done echo -e "\nCompressing .mo files in stage2 images..." if [ -d $DEST/usr/share/locale ]; then for i in `find $DEST/usr/share/locale -name anaconda.mo`; do gzip -9 $i mv -f $i.gz $i done fi echo "Patching python library..." # always use passive mode for ftp installs cd $DEST/usr/lib/python1.5 patch -p0 > /dev/null < python1.5.cgz rm -rf python1.5 find anaconda | cpio --quiet -H crc -o | gzip -9 > anaconda.cgz rm -rf anaconda ls libnewt* libslang* | cpio --quiet -H crc -o | gzip -9 > slang-newt.cgz rm -f libnewt* libslang* cd $DEST/usr/bin echo python1.5 | cpio --quiet -H crc -o | gzip -9 > python1.5.cgz /bin/rm -f python python1.5 /bin/ln -s python1.5 python mv anaconda anaconda.real mv $DEST/usr/lib/anaconda-runtime/anaconda-stub anaconda cd $DEST/lib ls libcom* libcrypt* libdl* libe2p* libext2* libm* libnss* libnsl* \ libpthread* libss* libtermcap* libuuid* \ | cpio --quiet -H crc -o | gzip -9 > libs.cgz rm -f libcom* libcrypt* libdl* libe2p* libext2* libm* libnss* libnsl* \ libpthread* libss* libtermcap* libuuid* cd $DEST/usr find X11R6 | cpio --quiet -H crc -o | gzip -9 > X11R6.cgz rm -rf X11R6 cd $DEST/usr/sbin ls [a-r]* | cpio --quiet -H crc -o | gzip -9 > sbin.cgz rm -f [a-r]* rm -rf $DEST/usr/lib/anaconda-runtime if [ -n "$NEEDGR" ]; then cd $ORIGDIR $DESTGR/usr/lib/anaconda-runtime/checkcards.py $DESTGR/usr/share/kudzu/pcitable $DESTGR/usr/X11R6/lib/X11/Cards fi