--- /root/mirrorselect.old 2003-02-27 18:07:41.000000000 -0500 +++ /root/mirrorselect.old 2003-02-27 18:17:44.000000000 -0500 @@ -29,8 +29,20 @@ ' fi +while getopts ":ahips:" opt +do + case $opt in + a ) echo "Using automatic mode."; MODE=auto;; + i ) echo "Using interactive mode."; MODE=user;; + p ) echo "Not changing config files."; NOUPDATE=1;; + s ) echo "Selecting $OPTARG servers."; SERVERS=$OPTARG;; + h ) ;; + * ) echo "Unimplemented option chosen.";; + esac +done + # if auto mode is set run netselect -if [ "${1}" = "-a" ] ; then +if [ "${MODE}" = "auto" ] ; then echo "Fetching server list from web" # nastiness, but it should work for now MIRROR_LIST=$((echo -e "GET /main/en/mirrors.xml HTTP/0.9\r\n\r\n" 1>&3 & cat 0<&3) 3<> /dev/tcp/gentoo.org/80 | \ @@ -42,15 +54,6 @@ CHECKLIST="${CHECKLIST} `echo $i | grep -v "("`" done - if [ "`echo ${2} | grep -e "^-s[01234567890]"`" ] ; then - SERVERS="${2}" - else - if [ "${2}" ] ; then - echo "${2} is an invalid option" - exit - fi - fi - #pick the mirror from list echo "Running netselect on serverlist, this may take a moment" CHOSEN=`netselect $SERVERS ${CHECKLIST} | awk -F" " '{ print $2 }'` @@ -59,7 +62,7 @@ MIRRORS="${MIRRORS} $i" done -elif [ "${1}" = "-i" ] ; then +elif [ "${MODE}" = "user" ] ; then # not auto mode, we'll run dialog based selection tool # change "mirror (loc)" to "mirror(loc)" for bash loop below MIRROR_LOCS=`echo $MIRROR_LIST | sed -e "s/ (/(/g"` @@ -94,6 +97,7 @@ else echo "mirrorselect usage (updated):" +echo "-p : output the selected mirrors to stdout instead of making changes" echo "-i : interactive mode, dialog based and static mirrorlist" echo "-a (-s) : auto mode, will retrieve live mirror list from web," echo " run netselect and choose the server(s) with best response times." @@ -121,6 +125,10 @@ echo "Selected: $MIRRORS" +if [ -n "$NOUPDATE" ] ; then + exit 0 +fi + # adjust settings in make.conf, all in one command to avoid complaints of make.conf being moved mv /etc/make.conf /etc/make.conf.old && cat /etc/make.conf.old | egrep -e "^[^#]*GENTOO_MIRRORS=[^ \t\n]" -v > /etc/make.conf && \ echo "GENTOO_MIRRORS=\"$MIRRORS\"" >> /etc/make.conf