[PC-BSD Commits] r19926 - pcbsd/current/src-sh/libsh
svn at pcbsd.org
svn at pcbsd.org
Thu Oct 25 11:27:14 PDT 2012
Author: kris
Date: 2012-10-25 18:27:14 +0000 (Thu, 25 Oct 2012)
New Revision: 19926
Modified:
pcbsd/current/src-sh/libsh/functions.sh
Log:
Add new get_mirror() function
This will be used to lookup a PC-BSD mirror URL by region, which should
let us load-balance, and give the user a fresh and close mirror each
time they go to download something.
Can be overridden in /usr/local/etc/pcbsd.conf
Modified: pcbsd/current/src-sh/libsh/functions.sh
===================================================================
--- pcbsd/current/src-sh/libsh/functions.sh 2012-10-25 18:24:34 UTC (rev 19925)
+++ pcbsd/current/src-sh/libsh/functions.sh 2012-10-25 18:27:14 UTC (rev 19926)
@@ -5,6 +5,50 @@
# License: BSD
##############################################################
+PCBSD_ETCCONF="/usr/local/etc/pcbsd.conf"
+
+get_mirror() {
+
+ # Check if we already looked up a mirror we can keep using
+ if [ -n "$CACHED_PCBSD_MIRROR" ] ; then
+ VAL="$CACHED_PCBSD_MIRROR"
+ export VAL
+ return
+ fi
+
+ # Set the mirror URL
+ VAL="`cat ${PCBSD_ETCCONF} 2>/dev/null | grep 'PCBSD_MIRROR: ' | sed 's|PCBSD_MIRROR: ||g'`"
+ if [ -n "$VAL" ] ; then
+ echo "Using mirror: $VAL"
+ CACHED_PCBSD_MIRROR="$VAL"
+ export VAL CACHED_PCBSD_MIRROR
+ return
+ fi
+
+ echo "Getting regional mirror..."
+ . /etc/profile
+
+ # No URL? Lets get one from the master server
+ local mFile="${HOME}/.mirrorUrl.$$"
+ touch $mFile
+ fetch -o $mFile http://getmirror.pcbsd.org >/dev/null 2>/dev/null
+ VAL="`cat $mFile | grep 'URL: ' | sed 's|URL: ||g'`"
+ rm $mFile
+ if [ -n "$VAL" ] ; then
+ echo "Using mirror: $VAL"
+ CACHED_PCBSD_MIRROR="$VAL"
+ export VAL CACHED_PCBSD_MIRROR
+ return
+ fi
+
+ # Still no mirror? Lets try the PC-BSD FTP server...
+ VAL="ftp://ftp.pcbsd.org/pub/mirror"
+ CACHED_PCBSD_MIRROR="$VAL"
+ export VAL CACHED_PCBSD_MIRROR
+ echo "Using mirror: $VAL"
+ return
+}
+
# Function to download a file from remote using fetch
# Arg1 = Remote File URL
# Arg2 = Where to save file
More information about the Commits
mailing list