/var/lib/sorcery/modules/url_handlers/url_git

     1	#!/bin/bash
     2	#---------------------------------------------------------------------
     3	##
     4	##=head1 SYNOPSIS
     5	##
     6	## Url handler functions for downloading git urls
     7	##
     8	##=head1 DESCRIPTION
     9	##
    10	## This file contains functions for downloading and verifying
    11	## git urls.  This file uses the "git" program.
    12	##
    13	##=head1 COPYRIGHT
    14	##
    15	## Copyright 2002 by the Source Mage Team
    16	##
    17	##=head1 FUNCTIONS
    18	##
    19	##=over 4
    20	##
    21	#---------------------------------------------------------------------
    22	
    23	#---------------------------------------------------------------------
    24	##=item url_git_crack <url>
    25	##
    26	## Parse the specified git url.
    27	##
    28	## @Global URL
    29	## @Global GIT_ROOT
    30	## @Global GIT_DIRECTORY
    31	## @Global GIT_TAG
    32	##
    33	#---------------------------------------------------------------------
    34	function url_git_crack() {
    35	
    36	  URL=`url_strip_prefix "$1" git`
    37	  GIT_ROOT=`echo $URL | sed "s#\(^[^/]*[^:]*\):.*#\1#"`
    38	  GIT_ROOT=git://$GIT_ROOT
    39	  local GIT_DIRECTORY_TAG=`echo $URL | sed "s#^[^/]*[^:]*\(.*\)#\1#"`
    40	  GIT_DIRECTORY=`echo $GIT_DIRECTORY_TAG | cut -d : -f2`
    41	  local GIT_TAGNAME=`echo $GIT_DIRECTORY_TAG | cut -d : -f3`
    42	  GIT_TAG=${GIT_TAGNAME:=master}
    43	
    44	}
    45	
    46	#---------------------------------------------------------------------
    47	##=item url_git_bucketize <url>
    48	##
    49	## echoes the download handler - git
    50	##
    51	#---------------------------------------------------------------------
    52	function url_git_bucketize() {
    53	  echo git
    54	}
    55	
    56	#---------------------------------------------------------------------
    57	##=item url_git_verify <url>
    58	##
    59	## Verifies the specified git url.  Returns true if the url exists
    60	## OR if the url is an empty string.
    61	##
    62	#---------------------------------------------------------------------
    63	function url_git_verify() {
    64	  local URL GIT_ROOT item
    65	  url_git_crack $1
    66	  for item in URL GIT_ROOT; do
    67	    if ! [[ ${!item} ]] ; then
    68	      return 1
    69	    fi
    70	  done
    71	}
    72	
    73	#---------------------------------------------------------------------
    74	##=item url_<prefix>_hostname <url>
    75	##
    76	## Gets the hostname out of the url
    77	#---------------------------------------------------------------------
    78	function url_git_hostname() {
    79	  echo $1|sed 's:^.*//\([^/]*\).*$:\1:'
    80	}
    81	
    82	#---------------------------------------------------------------------
    83	##=item url_git_netselect <url>
    84	##
    85	## Gets a netselect type output for the url
    86	##
    87	#---------------------------------------------------------------------
    88	function url_git_netselect() {
    89	  local tmp_hostname url_speed each
    90	
    91	  for each in "$@" ; do
    92	    tmp_hostname=$(url_git_hostname $each)
    93	    # since we had to pull the url apart to give netselect
    94	    # something it can understand we'll just pretend like
    95	    # multiple A records wont exist for this host...
    96	    url_speed=$(netselect -s 1 $tmp_hostname 2>/dev/null|awk '{print $1}')
    97	    [[ -n $url_speed ]] && echo "$url_speed $each"
    98	  done
    99	}
   100	
   101	
   102	#---------------------------------------------------------------------
   103	##=back
   104	##
   105	##=head1 LICENSE
   106	##
   107	## This software is free software; you can redistribute it and/or modify
   108	## it under the terms of the GNU General Public License as published by
   109	## the Free Software Foundation; either version 2 of the License, or
   110	## (at your option) any later version.
   111	##
   112	## This software is distributed in the hope that it will be useful,
   113	## but WITHOUT ANY WARRANTY; without even the implied warranty of
   114	## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   115	## GNU General Public License for more details.
   116	##
   117	## You should have received a copy of the GNU General Public License
   118	## along with this software; if not, write to the Free Software
   119	## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   120	##
   121	#---------------------------------------------------------------------