[PC-BSD Commits] r19927 - pcbsd/branches/9.1/src-sh/libsh

svn at pcbsd.org svn at pcbsd.org
Thu Oct 25 11:28:46 PDT 2012


Author: kris
Date: 2012-10-25 18:28:46 +0000 (Thu, 25 Oct 2012)
New Revision: 19927

Modified:
   pcbsd/branches/9.1/src-sh/libsh/functions.sh
Log:

MFC new get_mirror function, which when fully-implemented will allow us to
figure out a fresh & fast mirror without needing users to manually be setting
mirrors when one goes offline. 



Modified: pcbsd/branches/9.1/src-sh/libsh/functions.sh
===================================================================
--- pcbsd/branches/9.1/src-sh/libsh/functions.sh	2012-10-25 18:27:14 UTC (rev 19926)
+++ pcbsd/branches/9.1/src-sh/libsh/functions.sh	2012-10-25 18:28:46 UTC (rev 19927)
@@ -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