post scripts for altering the filesystem for last-minute configuration tweaks
[build.git] / vbuild-fedora-mirror.sh
index 5533985..48a84f4 100755 (executable)
@@ -1,27 +1,37 @@
 #!/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
-distroname=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 distroname] [-a arch]"
+    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) distroname=$OPTARG ;;
@@ -47,56 +57,65 @@ case $distroname in
        echo "Unknown redhat distribution $distroname - exiting"
        RES=1
        ;;
-
 esac
 
 excludelist="debug/ iso/ ppc/ source/"
-options="$dry_run -avz --delete --delete-excluded --no-motd"
-for e in $excludelist
-do
+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
 
-echo "root=$root"
-echo "distro=$distroname"
-echo "distroname=$distroname"
-echo "distroindex=$distroindex"
-echo "arch=$arch"
-echo rsyncurl="$rsyncurl"
-echo "rsync options=$options"
+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)
-               for repopath in core/$distroindex/$arch/os/ core/updates/$distroindex/$arch/ extras/$distroindex/$arch/
-                 do
-                 echo "============================== $distro -> $distroindex $repopath"
-                 mkdir -p ${root}/${repopath}
-                 rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}
-               done
+               [ -z "$skip_core" ] && paths="core/$distroindex/$arch/os/"
+               paths="$paths core/updates/$distroindex/$arch/ extras/$distroindex/$arch/"
                RES=0
                ;;
-
            7|8)
-               for repopath in releases/$distroindex/Everything/$arch/os/ updates/$distroindex/$arch/
-                 do
-                 echo "============================== $distro -> $distroindex $repopath"
-                 mkdir -p ${root}/${repopath}
-                 rsync $options ${rsyncurl}/${repopath} ${root}/${repopath}
-               done
+               [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
+               paths="$paths updates/$distroindex/$arch/"
                RES=0
                ;;
-           *)
-               echo "Unknown fedora index $distroindex - exiting"
-               RES=1
-               ;;
        esac
        ;;
-    *)
-       echo "$distro $distroindex currently unsupported - 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