#! /bin/sh # This script uses cat2rsyncbatch to create rsync batch files to # re-create redundant iso files in a Fedora Core or similar GNU/Linux # distributions. The iso files considered redundant are SRPMS for # arches other than i386, as well as rescuecd and DVD images. # Copyright 2003, 2005 Alexandre Oliva # 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, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA case $1 in -n) dryrun=:; shift ;; esac relative_path () { ( # This script computes a relative pathname from $1 to $2 # They are assumed to not contain . or .. pathname components, # but if both directories exist and cd/pwd canonicalizes pathnames, # this shouldn't matter. PWD_CMD may be set to some pwd command that does. # Copyright 2003 Alexandre Oliva from=`(cd $1 > /dev/null && ${PWD_CMD-pwd} || echo $1) 2>/dev/null | sed 's,//*,/,g;s,/*$,,'` target=`(cd $2 > /dev/null && ${PWD_CMD-pwd} || echo $2) 2>/dev/null | sed 's,//*,/,g;s,/*$,,'` case $from in /* | "") ;; *) from=`${PWD_CMD-pwd}`/$from ;; esac case $target in /* | "") ;; *) target=`${PWD_CMD-pwd}`/$target ;; esac case $target in "$from" | "$from/"*) dots=`echo $from | sed s,.,.,g` echo $target | sed "s,^$dots/*,,;s,[^/]$,&/," exit 0 ;; esac case $from in "$target/"*) dots=`echo $target | sed s,.,.,g` echo $from/ | sed "s,^$dots/*,,;s,[^/]$,&/,;s,[^/]*/*,../,g;s,[^/]$,&/," exit 0 ;; esac prefix=`echo $from///$target | sed 's,\(\(/[^/]*\)*\).*///\1.*,\1,'` dots=`echo $prefix | sed s,.,.,g` from=`echo $from | sed "s,^$dots,,"` target=`echo $target | sed "s,^$dots,,"` from=`echo $from | sed 's,[^/][^/]*,..,g;s,.$,&/,'` echo ${from}$target/ ) } find "${@-.}" -name \*rescuecd.iso | while read f; do if test -f $f.sh; then echo $f.sh already exists, skipping $f >&2 continue fi if test -f $f.rsync.bz2; then echo $f.rsync.bz2 already exists, skipping $f >&2 continue fi dir=`dirname $f` name=`basename $f -rescuecd.iso` if test ! -f "$dir/$name-disc1.iso"; then echo $dir/$name-disc1.iso does not exist, skipping $f >&2 continue fi ( $dryrun cd `dirname $f` && $dryrun exec cat2rsyncbatch $name-rescuecd.iso $name-disc1.iso ) done find "${@-.}" -name \*-disc\?.iso ! -name \*SRPMS\* | while read f; do if test -f $f.sh; then echo $f.sh already exists, skipping $f >&2 continue fi if test -f $f.rsync.bz2; then echo $f.rsync.bz2 already exists, skipping $f >&2 continue fi dir=`dirname $f` name=`basename $f .iso` base=`echo $name | sed 's,-disc[0-9]*$,,'` if test ! -f "$dir/$base-DVD.iso"; then echo $dir/$name-DVD.iso does not exist, skipping $f >&2 continue fi ( $dryrun cd `dirname $f` && $dryrun exec cat2rsyncbatch $name.iso $base-DVD.iso ) done find "${@-.}" -name \*DVD.iso | while read f; do if test -f $f.sh; then echo $f.sh already exists, skipping $f >&2 continue fi if test -f $f.rsync.bz2; then echo $f.rsync.bz2 already exists, skipping $f >&2 continue fi dir=`dirname $f` name=`basename $f -DVD.iso` if test ! -f "$dir/$name-disc1.iso"; then echo $dir/$name-disc1.iso does not exist, skipping $f >&2 continue fi ( $dryrun cd `dirname $f` && $dryrun exec cat2rsyncbatch $name-DVD.iso $name-disc?.iso ) done find "${@-.}" -name \*SRPMS-disc1.iso | while read f; do case $f in *-i386-*) pat=s,i386,x86_64,g;; *-x86_64-*) pat=s,x86_64,i386,g;; *) continue ;; esac from=`echo $f | sed -e "$pat"` if test ! -f $from; then echo $from does not exist, skipping $f >&2 continue fi dir=`dirname $f` name=`basename $f -disc1.iso` if test -f $dir/$name.tar.sh; then echo $dir/$name.tar.sh already exists, skipping $f >&2 continue fi if test -f $dir/$name.tar.rsync.bz2; then echo $dir/$name.tar.rsync.bz2 already exists, skipping $f >&2 continue fi fromdir=`dirname $from` fromname=`basename $from -disc1.iso` fromdirrelative=`relative_path $dir $fromdir` ( $dryrun cd $dir $dryrun tar -cvf $name.tar $name-disc?.iso $dryrun exec cat2rsyncbatch $name.tar ${fromdirrelative}$fromname-disc?.iso rm -f $name.tar ) done