#!/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 .
#
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
}
PACKAGES="GConf2 NetworkManager NetworkManager-gnome ORBit2 acl anaconda
anaconda-yum-plugins at-spi atk attr audit-libs bash 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 gpm grep gtk2 gtk2-engines
hdparm hwdata initscripts iproute iputils iscsi-initiator-utils
jfsutils 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 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 lvm2 madan-fonts mdadm
mesa-dri-drivers metacity module-init-tools ncurses neon net-tools
newt newt-python nfs-utils nspr nss nss-softokn ntfs-3g
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 readline redhat-artwork
reiserfs-utils report-config-default report-gtk report-newt rpm rpm-libs
rpm-python rsyslog sed selinux-policy-targeted
setup slang 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 telnet
tigervnc-server tigervnc-server-module tzdata
udev un-core-dotum-fonts urw-fonts usbutils util-linux-ng
vlgothic-fonts vim-minimal
wget 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 = x86_64 ]; then
PACKAGES="$PACKAGES pcmciautils grub"
fi
if [ $ARCH = i386 -o $ARCH = i586 -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 joe krb5-libs less man
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 = 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 = 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 <> $KEEPFILE <> $KEEPFILE < $KEEPFILERESCUE <> $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; mkdir -p $DEST/usr/sbin $DEST/var/lib $DEST/boot
ln -s /tmp $DEST/var/lib/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..."
# 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
rm -rf $YUMDIR
chown -R root:root $DEST
chmod -R a+rX-w $DEST
# Remove locales unused during the install
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;
}
' | 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
rm -f $DEST/locales $DEST/locales.list
# fixup joe links
if [ -d "$DESTDIR"/etc/joe ]; then
ln -fs jpicorc $DEST/etc/joe/picorc
ln -fs jpicorc $DEST/etc/joe/jnanorc
ln -fs jpicorc $DEST/etc/joe/nanorc
ln -fs jmacsrc $DEST/etc/joe/emacsrc
ln -fs jmacs $DEST/usr/bin/emacs
ln -fs jpico $DEST/usr/bin/pico
ln -fs jpico $DEST/usr/bin/nano
fi
# 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 < $DEST/etc/libuser.conf < ../../sbin/udevadm
for brokenlink in $(find $DEST/usr/{bin,sbin} -follow -lname '*') ; do
target="$(readlink $brokenlink)"
for pathbit in bin sbin; do
# if it starts with "../../sbin/", remove that
newtarget="${target##../../$pathbit/}"
# if we removed something, replace it with the proper path
if [ "$newtarget" != "$target" ]; then
# make it ../sbin/ instead
ln -sf "../$pathbit/$newtarget" "$brokenlink"
fi
done
done
# 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 = 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 $DEST/root $DEST/tmp
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
# 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