Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- usage() {
- cat <<EOF
- rh_iso_extract.sh [ options ]
- Valid options are:
- -h | --help This help
- -a | --arch The architecture to work with [ default i386 ]
- -d | --dest-dir The destination dir prefix [ default /var/ftp ]
- -i | --iso-dir The source iso dir prefix [ default /var/ftp ]
- -r | --release The release name [ default beta/null ]
- If you cannot loop mount a file on an NFS filesystem,
- e.g. 2.2.x kernel based systems, you should copy your
- iso images to a local directory and override the iso-dir
- and dest-dir defaults.
- e.g.
- # mkdir -p /mnt/scratch/ftp/pub/redhat/linux/RELEASE/en/iso/i386/
- # cp /var/ftp/pub/redhat/linux/RELEASE/en/iso/i386/*.iso \\
- /mnt/scratch/ftp/pub/redhat/linux/RELEASE/en/iso/i386/
- # rh_iso_extract.sh -i /mnt/scratch/ftp/pub -d /var/ftp/pub
- EOF
- exit 1
- }
- TEMP=`getopt -o ha:d:i:r: --long help,arch:,dest-dir:,iso-dir:,release: -n 'rh_iso_extract.sh' -- "$@"`
- eval set -- "$TEMP"
- while true ; do
- case "$1" in
- -h|--help) usage ;;
- -a|--arch)
- ARCH=$2
- shift 2
- ;;
- -d|--dest-dir)
- DESTPREFIX=$2
- shift 2
- ;;
- -i|--iso-dir)
- ISOPREFIX=$2
- shift 2
- ;;
- -r|--release)
- RELEASE=$2
- shift 2
- ;;
- --) shift ; break;;
- *) echo "Internal error!" ; exit 1;;
- esac
- done
- ### Begin config
- LOCAL_BASE_DIR=/var/ftp/pub
- LOCAL_DEST_DIR=/var/ftp/pub
- if [ "$ISOPREFIX" != "" ]; then
- LOCAL_BASE_DIR=$ISOPREFIX
- LOCAL_DEST_DIR=$ISOPREFIX
- fi
- if [ "$DESTPREFIX" != "" ]; then
- LOCAL_DEST_DIR=$DESTPREFIX
- fi
- if [ "$RELEASE" = "" ]; then
- RELEASE=beta/null
- fi
- RH_BASE_DIR=redhat/linux
- RELEASE_BASE_DIR=$LOCAL_BASE_DIR/$RH_BASE_DIR/$RELEASE
- RELEASE_DEST_DIR=$LOCAL_DEST_DIR/$RH_BASE_DIR/$RELEASE
- ISO_BASE_DIR=$RELEASE_BASE_DIR/en/iso
- OS_BASE_DIR=$RELEASE_DEST_DIR/en/os
- DOC_ISO_DIR=$ISO_BASE_DIR/doc
- DOC_DIR=$RELEASE_BASE_DIR/en/doc
- # where to mount the iso's
- MNTPNT=/mnt/cdrom
- # white space separated list of architectures
- ARCH_LIST="i386"
- if [ "$ARCH" != "" ]; then
- ARCH_LIST="$ARCH"
- fi
- echo DESTPREFIX=$DESTPREFIX
- echo ISOPREFIX=$ISOPREFIX
- echo RELEASE=$RELEASE
- echo ISO_BASE_DIR=$ISO_BASE_DIR
- echo OS_BASE_DIR=$OS_BASE_DIR
- echo ARCH_LIST=$ARCH_LIST
- # who will own the created files
- OWNER=rsync
- OWNER_GRP=rsync
- # whether to extract the doc iso as well: yes/no
- DO_DOC=no
- ### End config
- do_one_arch() {
- # Usage: do_one_arch arch
- arch=$1
- archdir=$OS_BASE_DIR/$arch
- arch_isodir=$ISO_BASE_DIR/$arch
- mkdir -p $archdir
- if ( ls $arch_isodir/*-$arch-*.iso > /dev/null 2>&1 ) ; then
- for disc in $arch_isodir/*-$arch-*.iso; do
- echo Expanding `basename $disc` ...
- mount -o loop $disc $MNTPNT
- if ( cd $MNTPNT && pax -rw ./* $archdir ); then
- umount $MNTPNT
- echo Done
- else
- umount $MNTPNT
- exit 1
- fi
- done
- else
- echo "Unable to find $arch_isodir/*-$arch-*.iso"
- fi
- }
- do_one_srpms() {
- # Usage: do_one_srpms arch
- arch=$1
- srpms_dir=$OS_BASE_DIR/$arch/SRPMS
- arch_isodir=$ISO_BASE_DIR/$arch
- mkdir -p $srpms_dir
- if ( ls $arch_isodir/*-SRPMS-*.iso > /dev/null 2>&1 ) ; then
- for disc in $arch_isodir/*-SRPMS-*.iso; do
- echo Expanding `basename $disc` ...
- mount -o loop $disc $MNTPNT
- if ( cd $MNTPNT/SRPMS && pax -rw ./* $srpms_dir ); then
- umount $MNTPNT
- echo Done
- else
- umount $MNTPNT
- exit 1
- fi
- done
- else
- echo "Unable to find $arch_isodir/*-SRPMS-*.iso"
- fi
- }
- do_docs() {
- # Usage: do_docs
- mkdir -p $DOC_DIR
- if ( ls ${DOC_ISO_DIR}/*-docs.iso ) ; then
- for disc in ${DOC_ISO_DIR}/*-docs.iso; do
- echo Expanding `basename $disc` ...
- mount -o loop $disc $MNTPNT
- if ( cd $MNTPNT && pax -rw ./* $DOC_DIR ); then
- umount $MNTPNT
- echo Done
- else
- umount $MNTPNT
- exit 1
- fi
- done
- else
- echo "Unable to find $arch_isodir/*-docs.iso"
- fi
- }
- clean_trans_tbl() {
- # Usage: clean_trans_tbl dir
- dir=$1
- echo "Removing TRANS.TBL files from $1"
- find $dir -type f -name TRANS.TBL | xargs rm -f
- }
- set_owner() {
- # Usage: set_owner dir
- dir=$1
- echo "Setting user/group ownership for $1"
- # Do this in 2 steps to be more portable between *NIX systems
- chown -R $OWNER $dir
- chgrp -R $OWNER_GRP $dir
- }
- if [ "$DO_DOC" = "yes" ]; then
- docdir=$DOC_DIR
- if [ -d $docdir ] ; then
- echo "Removing existing documentation in $docdir"
- rm -rf $docdir
- fi
- do_docs
- clean_trans_tbl $docdir
- set_owner $docdir
- fi
- for arch in $ARCH_LIST; do
- archdir=$OS_BASE_DIR/$arch
- if [ -d $archdir ] ; then
- echo "Removing existing distribution in $archdir"
- rm -rf $archdir
- fi
- do_one_arch $arch
- do_one_srpms $arch
- clean_trans_tbl $archdir
- set_owner $archdir
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement