#!/bin/bash ORIGDIR=`pwd` COMPONENT="" if [ "$1" == "--comp" ]; then COMPONENT=$2 shift; shift fi if [ -z "$1" ]; then echo "upd-instroot: updates instimage from a Red Hat RPMS directory" echo "usage: $0 --comp [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 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 KEEPFILES=$3 for n in $RPMS; do echo -ne "\rExpanding packages..." $(basename $n) if [ $(rpm -qp --qf '%{NAME}' $n) = "glibc-common" ] ; then GLIBC=$n fi rpm2cpio $n | (cd $PKGDEST; cpio -E $KEEPFILES --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 glibc-common setup openssl python python2 newt libtermcap zlib ash kon2 e2fsprogs util-linux raidtools popt mount procps rpm XFree86 Xconfigurator anaconda anaconda-runtime kudzu-devel kudzu db3 rpm-python2.2 bzip2 bzip2-libs dosfstools pciutils reiserfs-utils parted busybox-anaconda rpm-python anaconda-help" if [ $ARCH = i386 ]; then PACKAGES="$PACKAGES kernel-pcmcia-cs lilo" fi if [ $ARCH = ia64 ]; then PACKAGES="$PACKAGES elilo slang" fi # xpm is missing # Some packages are listed twice, but that's okay PACKAGESGR="anaconda XFree86-libs imlib libpng libpng10 libtiff libjpeg XFree86-S3 XFree86-SVGA XFree86-75dpi-fonts XFree86-ISO8859-2-75dpi-fonts glib2 gtk2 XFree86-ISO8859-9-75dpi-fonts esound audiofile libgnome XFree86-100dpi-fonts XFree86-ISO8859-2 XFree86-ISO8859-9 XFree86-xfs e2fsprogs fileutils glibc glibc-common 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 gnome-python2 pygtk2 gdk-pixbuf XFree86-KOI8-R XFree86-KOI8-R-75dpi-fonts pciutils pam reiserfs-utils atk pango freetype gnome-python2-canvas libgnomecanvas libart_lgpl libzvt gnome-python2-zvt anaconda-images" if [ -z "$NEEDGR" ]; then PACKAGESGR="bash" fi PACKAGES="$PACKAGES db1 db2" if [ $ARCH != ia64 ]; then 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 if [ $ARCH = ia64 ]; then PACKAGESGR="$PACKAGESGR elilo slang" 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 /usr/X11R6/bin/mkfontdir -p /usr/X11R6/lib/X11/fonts/encodings/ -e $DESTGR/usr/X11R6/lib/X11/fonts/encodings $DESTGR/usr/X11R6/lib/X11/fonts/* $DESTGR/usr/share/fonts/ISO8859-2/* $DESTGR/usr/share/fonts/ISO8859-9/* rm -f $DESTGR/usr/X11R6/bin/mkfontdir fi echo "Getting pango modules" if [ -n "$NEEDGR" ]; then if [ -x /usr/bin/runroot -a -n "$COMPONENT" ]; then REALPATH=`(cd $DESTGR; /bin/pwd | sed 's,/md1/,/,g')` runroot $COMPONENT --onlyone --arch $ARCH "LD_LIBRARY_PATH=/usr/X11R6/lib:$LD_LIBRARY_PATH /usr/sbin/chroot $REALPATH /usr/bin/pango-querymodules 2> $REALPATH/etc/pango/pango.modules" else /usr/sbin/chroot $DESTGR /usr/bin/pango-querymodules > $DESTGR/etc/pango/pango.modules fi rm -f $DESTGR/usr/bin/pango-querymodules fi echo "Getting gtk2 input method modules" if [ -n "$NEEDGR" ]; then if [ -x /usr/bin/runroot -a -n "$COMPONENT" ]; then REALPATH=`(cd $DESTGR; /bin/pwd | sed 's,/md1/,/,g')` runroot $COMPONENT --onlyone --arch $ARCH "LD_LIBRARY_PATH=/usr/X11R6/lib:$LD_LIBRARY_PATH /usr/sbin/chroot $REALPATH /usr/bin/gtk-query-immodules-2.0 2> $REALPATH/etc/gtk-2.0/gtk.immodules" else /usr/sbin/chroot $DESTGR /usr/bin/gtk-query-immodules-2.0 > $DESTGR/etc/gtk-2.0/gtk.immodules fi rm -f $DESTGR/usr/bin/gtk-query-immodules-2.0 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 ln -s ../lib/anaconda/losetup-stub $p/usr/bin/losetup ln -s ../lib/anaconda/pump-stub $p/usr/bin/pump mv $p/usr/sbin/anaconda $p/usr/bin/anaconda 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 # copy bootloader files for ia64 if [ $ARCH = ia64 -a $p = $DESTGR ]; then mkdir -p $p/usr/lib/anaconda-runtime/boot cp -af $p/boot/efi/* $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 find $p -name "lib*.la" | xargs rm -rf for f in newt popt rpm rpmio; do rm -f $p/usr/lib/lib$f.so done (cd $p/lib; rm -f libnss_files.so.1 libnss_dns.so.1) (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 -a -n "$COMPONENT" ]; then REALPATH=`(cd $p; /bin/pwd | sed 's,/md1/,/,g')` runroot $COMPONENT --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 if [ $ARCH = "alpha" ]; then rm -rf $DEST/usr/share/locale rm -rf $DEST/usr/lib/locale fi echo "Patching python library..." # always use passive mode for ftp installs cd $DEST/usr/lib/python2.2 patch -p0 > /dev/null <