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