post scripts for altering the filesystem for last-minute configuration tweaks
[build.git] / vbuild-fedora-mirror.sh
index 76aff71..48a84f4 100755 (executable)
 #!/bin/bash
 # this can help you create/update your fedora mirror
+# $Id$
 
 COMMAND=$(basename $0)
 
 dry_run=
+verbose=
+skip_core=
 root=/data/fedora/linux
 rsyncurl=rsync://mirrors.kernel.org/fedora
-#rsyncurl=rsync://fr.rpmfind.net/linux/fedora
-fcdistro=fc6
+eu_rsyncurl=rsync://ftp-stud.hs-esslingen.de/fedora/linux
+distroname=f8
 arch=i386
 
 
 function usage () {
-    echo "Usage: $COMMAND [-n] [-v] [-r root] [-u rsyncurl] [-f fcdistro] [-a arch]"
-    echo "Defaults to -r $root -u $rsyncurl -f $fcdistro -a $arch"
-    echo "Use vserver conventions for fcdistro, e.g. fc6 and f7"
+    echo "Usage: $COMMAND [-n] [-v] [-c] [-e] [-r root] [-u rsyncurl] [-f distroname] [-a arch]"
+    echo "Defaults to -r $root -u $rsyncurl -f $distroname -a $arch"
+    echo "Use vserver conventions for distroname, e.g. fc6 and f7"
+    echo "Options:"
+    echo " -n : dry run"
+    echo " -v : verbose"
+    echo " -c : skips core repository"
+    echo " -e : uses European mirror $eu_rsyncurl"
     exit 1
 }
 
-while getopts "nvr:u:f:a:h" opt ; do
+while getopts "nvcer:u:f:a:h" opt ; do
     case $opt in
-       n) dry_run=-n ;;
-       v) set -x ;;
+       n) dry_run=--dry-run ;;
+       v) verbose=--verbose ;;
+       c) skip_core=true ;;
+       e) rsyncurl=$eu_rsyncurl ;;
        r) root=$OPTARG ;;
        u) rsyncurl=$OPTARG ;;
-       f) fcdistro=$OPTARG ;;
+       f) distroname=$OPTARG ;;
        a) arch=$OPTARG ;;
        h|*) usage ;;
     esac
 done
 
-case $fcdistro in
+case $distroname in
     fc*[1-6])
-       findex=$(echo $fcdistro | sed -e s,fc,,g)
+       distroindex=$(echo $distroname | sed -e "s,fc,,g")
+       distro="Fedora Core"
+       ;;
+    f*[7-8])
+       distroindex=$(echo $distroname | sed -e "s,f,,g")
+       distro="Fedora"
+       ;;
+    centos*[4-5])
+       distroindex=$(echo $distroname | sed -e "s,centos,,g")
+       distro="CentOS"
        ;;
     *)
-       findex=$(echo $fcdistro | sed -e s,f,,g)
+       echo "Unknown redhat distribution $distroname - exiting"
+       RES=1
        ;;
 esac
 
-echo "root=$root"
-echo rsyncurl="$rsyncurl"
-echo "fcdistro=$fcdistro"
-echo "findex=$findex"
-echo "arch=$arch"
+excludelist="debug/ iso/ ppc/ source/"
+options="--archive --compress --delete --delete-excluded $dry_run $verbose"
+[ -n "$(rsync --help | grep no-motd)" ] && options="$options --no-motd"
+for e in $excludelist; do
+  options="$options --exclude $e"
+done
 
-case $findex in
-    2|4|6)
-       echo "============================== $findex core"
-       mkdir -p ${root}/core/$findex/$arch/os/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/$arch/os/ ${root}/core/$findex/$arch/os/
-       echo "============================== $findex updates"
-       mkdir -p  ${root}/core/updates/$findex/$arch/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
-       echo "============================== $findex extras"
-       mkdir -p ${root}/extras/$findex/$arch/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/extras/$findex/$arch/ ${root}/extras/$findex/$arch/
-       RES=0
-       ;;
-    7)
-       echo "============================== $findex core"
-       mkdir -p ${root}/core/$findex/$arch/os/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/Everything/$arch/os/ ${root}/core/$findex/$arch/os/
-       echo "============================== $findex updates"
-       mkdir -p ${root}/core/updates/$findex/$arch/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
-       RES=0
-       ;;
-    8)
-    # somehow the layout on my favorite mirror is different in 7 and 8, /Everything/ has gone 
-       echo "============================== $findex core"
-       mkdir -p ${root}/core/$findex/$arch/os/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/$findex/$arch/os/ ${root}/core/$findex/$arch/os/
-       echo "============================== $findex updates"
-       mkdir -p ${root}/core/updates/$findex/$arch/
-       rsync $dry_run -avz --delete --exclude debug/ ${rsyncurl}/core/updates/$findex/$arch/ ${root}/core/updates/$findex/$arch/
-       RES=0
+if [ -n "$verbose" ] ; then 
+    echo "root=$root"
+    echo "distro=$distroname"
+    echo "distroname=$distroname"
+    echo "distroindex=$distroindex"
+    echo "arch=$arch"
+    echo rsyncurl="$rsyncurl"
+    echo "rsync options=$options"
+fi
+
+RES=1
+paths=""
+case $distro in
+    [Ff]edora*)
+        case $distroindex in
+           2|4|6)
+               [ -z "$skip_core" ] && paths="core/$distroindex/$arch/os/"
+               paths="$paths core/updates/$distroindex/$arch/ extras/$distroindex/$arch/"
+               RES=0
+               ;;
+           7|8)
+               [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
+               paths="$paths updates/$distroindex/$arch/"
+               RES=0
+               ;;
+       esac
        ;;
-    *)
-       echo "Unknown fedora index $findex - exiting"
-       RES=1
+    
+    CentOS*)
+       case $distroindex in
+           5)
+               [ -z "$skip_core" ] && paths="$distroindex/os/$arch/"
+               paths="$paths $distroindex/updates/$arch/"
+               RES=0
+               ;;
+       esac
        ;;
+
 esac
 
+if [ "$RES" = 1 ] ; then
+    echo "$distro $distroindex currently unsupported - exiting"
+else
+    for repopath in $paths; do
+       echo "============================== $distro -> $distroindex $repopath"
+       [ -z "$dry_run" ] && mkdir -p ${root}/${repopath}
+       command="rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}"
+       echo $command
+       $command
+    done
+fi
+
 exit $RES