/var/lib/sorcery/modules/url_handlers/url_cvs
1 #!/bin/bash
2 #---------------------------------------------------------------------
3 ##
4 ##=head1 SYNOPSIS
5 ##
6 ## Url handler functions for grabbing cvs urls.
7 ##
8 ##=head1 DESCRIPTION
9 ##
10 ## This file contains functions for parsing cvs urls.
11 ##
12 ##=head1 CVS URL Format
13 ##
14 ## There is no standard (that I know of) for cvs urls so we use a
15 ## source mage specific format:
16 ##
17 ## cvs://CVSROOT:MODULE_NAME
18 ##
19 ## The above url will download the latest version of the specified
20 ## module (i.e., the HEAD revision). To specify a specific revision,
21 ## the following format can be used:
22 ##
23 ## cvs://CVSROOT:MODULE_NAME:REVISION_TAG
24 ##
25 ## The CVSROOT portion of the url may include information such as type of cvs
26 ## server, port number for the server, user name, password, cvs repository
27 ## directory, etc. The CVSROOT syntax is defined by cvs and is as follows:
28 ##
29 ## :method:[[user][:password]@]hostname[:[port]]/path/to/repository
30 ##
31 ## For more details, see the CVS manual at
32 ## http://www.cvshome.org/docs/manual/cvs.html
33 ##
34 ##=head1 EXAMPLES
35 ##
36 ## Suppose we want to download the latest version of the sorcery
37 ## scripts from cvs. We'd use the following url:
38 ##
39 ## cvs://:pserver:anonymous@mplayerhq.hu:/cvsroot/mplayer:main">main">main">main">main
40 ##
41 ## If we want the 1.0pre7 release instead (i.e., those files tagged with
42 ## 1_0pre7, we would use the following url:
43 ##
44 ## cvs://:pserver:anonymous@mplayerhq.hu:/cvsroot/mplayer:main">main">main">main">main:1_0pre7
45 ##
46 ## Some cvs repositories require passwords. One such repository is the
47 ## cvs repository for the ROOT package (an object-oriented data analysis
48 ## framework, see L<http://root.cern.ch/root/>). The CVSROOT, without the
49 ## password, would look like this:
50 ##
51 ## :pserver:cvs@root.cern.ch:/user/cvs
52 ##
53 ## The password for their cvs repository is I<cvs>. Adding the password would
54 ## make the CVSROOT look like this:
55 ##
56 ## :pserver:cvs:cvs@root.cern.ch:/user/cvs
57 ##
58 ## Thus, the full cvs url, including the password, would be:
59 ##
60 ## cvs://:pserver:cvs:cvs@root.cern.ch:/user/cvs:root
61 ##
62 ##=head1 COPYRIGHT
63 ##
64 ## Copyright 2002 by the Source Mage Team
65 ##
66 ##=head1 FUNCTIONS
67 ##
68 ##=over 4
69 ##
70 #---------------------------------------------------------------------
71
72 #---------------------------------------------------------------------
73 ##=item url_file_download <url>
74 ##
75 ## Parse the specified cvs url.
76 ##
77 ## @global URL
78 ## @global CVS_ROOT
79 ## @global CVS_MODULE
80 ## @global CVS_TAG
81 ##
82 #---------------------------------------------------------------------
83 function url_cvs_crack() {
84
85 URL=`url_strip_prefix "$1" cvs`
86 CVS_ROOT=`echo $URL | sed "s#\(^[^/]*[^:]*\):.*#\1#"`
87 local CVS_MODULE_TAG=`echo $URL | sed "s#^[^/]*[^:]*\(.*\)#\1#"`
88 CVS_MODULE=`echo $CVS_MODULE_TAG | cut -d : -f2`
89 local CVS_TAGNAME=`echo $CVS_MODULE_TAG | cut -d : -f3`
90 CVS_TAG=${CVS_TAGNAME:=HEAD}
91
92 }
93
94 #---------------------------------------------------------------------
95 ##=item url_cvs_is_valid <url>
96 ##
97 ## Ensure that all the fields that should be parsed out from a url
98 ## do indeed exist
99 #---------------------------------------------------------------------
100 function url_cvs_is_valid() {
101 local URL CVS_ROOT CVS_MODULE CVS_TAG item
102 url_cvs_crack $1
103 for item in URL CVS_ROOT CVS_MODULE CVS_TAG; do
104 if ! [[ ${!item} ]] ; then
105 return 1
106 fi
107 done
108 }
109
110 #---------------------------------------------------------------------
111 ##=item url_cvs_hostname <url>
112 ##
113 ## Get the hostname of the url
114 ##
115 #---------------------------------------------------------------------
116 function url_cvs_hostname() {
117 echo $1|sed 's/^[^@]*@\([^:]*\):.*$/\1/'
118 }
119
120 #---------------------------------------------------------------------
121 ##=item url_cvs_netselect <url>
122 ##
123 ## Gets a netselect type output for the url
124 ##
125 #---------------------------------------------------------------------
126 function url_cvs_netselect() {
127 local tmp_hostname url_speed each
128
129 for each in $@ ; do
130 tmp_hostname=$(url_cvs_hostname $each)
131 # since we had to pull the url appart to give netselect
132 # something it can understand we'll just pretend like
133 # multiple A records wont exist for this host...
134 url_speed=$(netselect -s 1 $tmp_hostname 2>/dev/null|awk '{print $1}')
135 [[ -n $url_speed ]] && echo "$url_speed $each"
136 done
137 }
138
139 #---------------------------------------------------------------------
140 ##=back
141 ##
142 ##=head1 LICENSE
143 ##
144 ## This software is free software; you can redistribute it and/or modify
145 ## it under the terms of the GNU General Public License as published by
146 ## the Free Software Foundation; either version 2 of the License, or
147 ## (at your option) any later version.
148 ##
149 ## This software is distributed in the hope that it will be useful,
150 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
151 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152 ## GNU General Public License for more details.
153 ##
154 ## You should have received a copy of the GNU General Public License
155 ## along with this software; if not, write to the Free Software
156 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
157 ##
158 #---------------------------------------------------------------------