builds libnl and inotify-tools
[build.git] / vbuild-fedora-mirror.sh
index 855eadf..a178ff4 100755 (executable)
 #!/bin/bash
 # this can help you create/update your fedora mirror
+# $Id$
 
 COMMAND=$(basename $0)
+LOGDIR=/var/log/fedora-mirroring
+DATE=$(date '+%Y-%m-%d-%H-%M')
+LOG=${LOGDIR}/${DATE}.log
 
 dry_run=
-root=/data/fedora/linux
-rsyncurl=rsync://mirrors.kernel.org/fedora
-#rsyncurl=rsync://fr.rpmfind.net/linux/fedora
-distroname=fc6
-arch=i386
+verbose=
+log=
+skip_core=
+root=/mirror/
 
 
+us_fedora_url=rsync://mirrors.kernel.org/fedora
+# change this
+us_centos_url=rsync://mirrors.rit.edu/centos
+us_epel_url="us_epel_url-needs-to-be-defined"
+
+# this one is contaminated with the .~tmp~ thing
+
+eu_fedora_url=rsync://mirrors.ircam.fr/fedora-linux
+eu_centos_url=rsync://mirrors.ircam.fr/CentOS
+eu_epel_url=rsync://mirrors.ircam.fr/fedora-epel
+
+jp_fedora_url="jp_fedora_url-needs-to-be-defined"
+jp_centos_url="jp_centos_url-needs-to-be-defined"
+jp_epel_url="jp_epel_url-needs-to-be-defined"
+
+default_distroname=f8
+all_distronames="f8 f9 centos5.2 epel5"
+default_arch=i386
+all_archs="i386 x86_64"
+
+case $(hostname) in 
+    *.fr|*.de|*.uk)
+       fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ; epel_url=$eu_epel_url ;;
+    *.jp)
+       fedora_url=$jp_fedora_url ; centos_url=$jp_centos_url ; epel_url=$jp_epel_url ;;
+    *)
+       fedora_url=$us_fedora_url ; centos_url=$us_centos_url ; epel_url=$us_epel_url ;;
+esac
+
+function mirror_distro_arch () {
+    distroname=$1; shift
+    arch=$1; shift
+
+    distroname=$(echo $distroname | tr '[A-Z]' '[a-z]')
+    case $distroname in
+       fc*[1-6])
+           distroindex=$(echo $distroname | sed -e "s,fc,,g")
+           distro="Fedora Core"
+           rsyncurl=$fedora_url
+           ;;
+       f*[7-9])
+           distroindex=$(echo $distroname | sed -e "s,f,,g")
+           distro="Fedora"
+           rsyncurl=$fedora_url
+           ;;
+       centos[4-5]|centos[4-5].[0-9])
+           distroindex=$(echo $distroname | sed -e "s,centos,,g")
+           distro="CentOS"
+           rsyncurl=$centos_url
+           ;;
+       epel5)
+           distroindex=5
+           distro=epel
+           rsyncurl=$epel_url
+           ;;
+       *)
+           echo "WARNING -- Unknown distribution $distroname -- skipped"
+           return 1
+           ;;
+    esac
+
+    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
+
+    echo ">>>>>>>>>>>>>>>>>>>> root=$root distroname=$distroname arch=$arch rsyncurl=$rsyncurl"
+    [ -n "$verbose" ] && echo "rsync options=$options"
+
+    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|9)
+                   [ -z "$skip_core" ] && paths="releases/$distroindex/Everything/$arch/os/"
+                   paths="$paths updates/$distroindex/$arch/"
+                   # f8 and f9 have the additional newkey repo
+                   case $distroindex in 
+                       8|9) paths="$paths updates/$distroindex/${arch}.newkey/" ;;
+                   esac
+                   RES=0
+                   ;;
+           esac
+           localpath=fedora
+           ;;
+    
+       CentOS*)
+           case $distroindex in
+               5*)
+                   [ -z "$skip_core" ] && paths="$distroindex/os/$arch/"
+                   paths="$paths $distroindex/updates/$arch/"
+                   RES=0
+                   ;;
+           esac
+           localpath=centos
+           ;;
+
+       epel*)
+           case $distroindex in
+               5)
+                   paths="$paths $distroindex/$arch/"
+                   RES=0
+                   ;;
+           esac
+           localpath=epel
+           ;;
+
+    esac
+
+    if [ "$RES" = 1 ] ; then
+       echo "DISTRIBUTION $distro $distroindex CURRENTLY UNSUPPORTED - skipped"
+    else
+       for repopath in $paths; do
+           echo "===== $distro -> $distroindex $repopath"
+           [ -z "$dry_run" ] && mkdir -p ${root}/${localpath}/${repopath}
+           command="rsync $options ${rsyncurl}/${repopath} ${root}/${localpath}/${repopath}"
+           echo $command
+           $command
+       done
+    fi
+
+    echo "<<<<<<<<<<<<<<<<<<<< $distroname $arch"
+
+    return $RES 
+}
+
 function usage () {
-    echo "Usage: $COMMAND [-n] [-v] [-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 "Usage: $COMMAND [-n] [-v] [-c] [-r root] [-u|U rsyncurl] [-e|-j] [-f distroname|-F] [-a arch|-A]"
+    echo "Defaults to -r $root -f $default_distroname -a $default_arch"
+    echo "Default urls : $fedora_url $centos_url"
+    echo "Options:"
+    echo " -n : dry run"
+    echo " -v : verbose"
+    echo " -l : turns on autologging in $LOGDIR"
+    echo " -c : skips core repository"
+    echo " -r root (default is $root)"
+    echo " -u rsyncurl for fedora (default is $fedora_url)"
+    echo " -U rsyncurl for centos (default is $centos_url)"
+    echo " -s : uses standard (US) mirrors $us_fedora_url $us_centos_url"
+    echo " -e : uses European mirrors $eu_fedora_url $eu_centos_url"
+    echo " -j : uses Japanese mirrors $jp_fedora_url $jp_centos_url"
+    echo " -f distroname - use vserver convention, e.g. f8 or centos5"
+    echo " -F : for distroname in $all_distronames"
+    echo " -a arch - use yum convention"
+    echo " -A : for arch in $all_archs"
     exit 1
 }
 
-while getopts "nvr:u:f:a:h" opt ; do
-    case $opt in
-       n) dry_run=-n ;;
-       v) set -x ;;
-       r) root=$OPTARG ;;
-       u) rsyncurl=$OPTARG ;;
-       f) distroname=$OPTARG ;;
-       a) arch=$OPTARG ;;
-       h|*) usage ;;
-    esac
-done
-
-case $distroname in
-    fc*[1-6])
-       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"
-       ;;
-    *)
-       echo "Unknown redhat distribution $distroname - exiting"
-       RES=1
-       ;;
-
-esac
+function run () {
+    RES=0
+    for distroname in $distronames ; do 
+       for arch in $archs; do 
+           mirror_distro_arch "$distroname" "$arch" || RES=1
+       done
+    done
+    return $RES
+}
 
-excludelist="debug/ iso/ ppc/ opx"
-options="$dry_run -avz --delete --delete-excluded"
-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"
-
-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
-               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
-               RES=0
-               ;;
-           *)
-               echo "Unknown fedora index $distroindex - exiting"
-               RES=1
-               ;;
+function main () {
+    distronames=""
+    archs=""
+    while getopts "nvlcr:u:U:sejf:Fa:Ah" opt ; do
+       case $opt in
+           n) dry_run=--dry-run ;;
+           v) verbose=--verbose ;;
+           l) log=true ;;
+           c) skip_core=true ;;
+           r) root=$OPTARG ;;
+           u) fedora_url=$OPTARG ;;
+           U) centos_url=$OPTARG ;;
+           s) fedora_url=$us_fedora_url ; centos_url=$us_centos_url ;;
+           e) fedora_url=$eu_fedora_url ; centos_url=$eu_centos_url ;;
+           j) fedora_url=$jp_fedora_url ; centos_url=$jp_centos_url ;;
+           f) distronames="$distronames $OPTARG" ;;
+           F) distronames="$distronames $all_distronames" ;;
+           a) archs="$archs $OPTARG" ;;
+           A) archs="$archs $all_archs" ;;
+           h|*) usage ;;
        esac
-       ;;
-    *)
-       echo "$distro $distroindex currently unsupported - exiting"
-       RES=1
-       ;;
-esac
+    done
+    [ -z "$distronames" ] && distronames=$default_distroname
+    [ -z "$archs" ] && archs=$default_arch
+
+    # auto log : if specified
+    if [ -n "$log" ] ; then
+       mkdir -p $LOGDIR
+       run &> $LOG
+    else
+       run
+    fi
+    exit $?
+}
 
-exit $RES 
+main "$@"