/var/lib/sorcery/modules/url_handlers/url_smgl_tla

     1	#!/bin/bash
     2	## ----------------------------------------------------------------------------
     3	##
     4	##=head1 SYNOPSIS
     5	##
     6	## Url handler functions for parsing smgl's tla urls.
     7	##
     8	##=head1 DESCRIPTION
     9	##
    10	## This file contains functions for parsing tla urls.
    11	##
    12	##=head1 TLA URL Format
    13	##
    14	## There is no standard (that I know of) for tla urls so we use a
    15	## source mage specific format:
    16	##
    17	##      smgl_tla://location%archive%revision
    18	##
    19	## Location is an embedded url, this will be passed directly to tla.
    20	## Archive is the name of an archive, the format of this is defined by tla.
    21	## Revision is the category--branch--version[--patch] construct defined by
    22	## tla.
    23	##
    24	## For more details, see the tla manual at
    25	## http://www.gnu.org/software/gnu-arch/
    26	##
    27	##=head1 EXAMPLES
    28	##
    29	## Suppose we want to download the latest version of the emacs-wiki
    30	## scripts from tla.  We'd use the following url:
    31	##
    32	##      smgl_tla://http://sacha.free.net.ph/notebook/arch%sacha@free.net.ph--main%emacs-wiki--stable--1.0
    33	##
    34	## If we want the 1.0.13 release instead (i.e., patch level 13)
    35	## we would use the following url:
    36	##
    37	##      smgl_tla://http://sacha.free.net.ph/notebook/arch%sacha@free.net.ph--main%emacs-wiki--stable--1.0--patch-13
    38	##
    39	##=head1 COPYRIGHT
    40	##
    41	## Copyright 2005 the SourceMage Team
    42	##
    43	## ----------------------------------------------------------------------------
    44	
    45	
    46	# -----------------------------------------------------------------------------
    47	##=item url_smgl_tla_bucketize<url>
    48	##
    49	## Outputs "tla".
    50	# -----------------------------------------------------------------------------
    51	function url_smgl_tla_bucketize() {
    52	  echo tla
    53	}
    54	
    55	# -----------------------------------------------------------------------------
    56	##=item url_smgl_tla_crack <url>
    57	##
    58	## Parse the url
    59	##
    60	## @global URL
    61	## @global TLA_LOCATION
    62	## @global TLA_ARCHIVE
    63	## @global TLA_REVISION
    64	##
    65	# -----------------------------------------------------------------------------
    66	function url_smgl_tla_crack() {
    67	
    68	  URL=`url_strip_prefix "$1" smgl_tla`
    69	  TLA_LOCATION=`echo $URL|cut -d"%" -f1`
    70	  TLA_ARCHIVE=`echo $URL|cut -d"%" -f2`
    71	  TLA_REVISION=`echo $URL|cut -d"%" -f3`
    72	}
    73	
    74	
    75	# -----------------------------------------------------------------------------
    76	##=item url_smgl_tla_is_valid<url>
    77	##
    78	## Verifies the specified tla url exists.  Returns true for now...
    79	##
    80	# ----------------------------------------------------------------------------
    81	function url_smgl_tla_is_valid() {
    82	  local URL TLA_LOCATION TLA_ARCHIVE TLA_REVISION item
    83	  for item in URL TLA_LOCATION TLA_ARCHIVE TLA_REVISION; do
    84	    [[ ${!item} ]] || return 1
    85	  done
    86	}
    87	
    88	
    89	#---------------------------------------------------------------------
    90	##=item url_smgl_tla_hostname <url>
    91	##
    92	## Get the hostname of the url
    93	##
    94	#---------------------------------------------------------------------
    95	function url_smgl_tla_hostname() {
    96	  local P1=$(echo $1|cut -d"%" -f1)
    97	  echo $P1|sed 's#^.*://\([^/:]*\)[/:].*$#\1#'
    98	}
    99	
   100	#---------------------------------------------------------------------
   101	##=item url_svn_netselect <url>
   102	##
   103	## Gets a netselect type output for the url
   104	##
   105	#---------------------------------------------------------------------
   106	function url_smgl_tla_netselect() {
   107	  local tmp_hostname url_speed each
   108	
   109	  for each in $@ ; do
   110	    tmp_hostname=$(url_smgl_tla_hostname $each)
   111	    # since we had to pull the url appart to give netselect
   112	    # something it can understand we'll just pretend like
   113	    # multiple A records wont exist for this host...
   114	    url_speed=$(netselect -s 1 $tmp_hostname 2>/dev/null|awk '{print $1}')
   115	    [[ -n $url_speed ]] && echo "$url_speed $each"
   116	  done
   117	}
   118	
   119	
   120	#---------------------------------------------------------------------
   121	##=back
   122	##
   123	##=head1 LICENSE
   124	##
   125	## This software is free software; you can redistribute it and/or modify
   126	## it under the terms of the GNU General Public License as published by
   127	## the Free Software Foundation; either version 2 of the License, or
   128	## (at your option) any later version.
   129	##
   130	## This software is distributed in the hope that it will be useful,
   131	## but WITHOUT ANY WARRANTY; without even the implied warranty of
   132	## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   133	## GNU General Public License for more details.
   134	##
   135	## You should have received a copy of the GNU General Public License
   136	## along with this software; if not, write to the Free Software
   137	## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   138	##
   139	#---------------------------------------------------------------------