/var/lib/sorcery/modules/url_handlers/url_svn
1 #!/bin/bash
2 #---------------------------------------------------------------------
3 ##
4 ##=head1 SYNOPSIS
5 ##
6 ## Url handler functions for parsing subversion urls.
7 ##
8 ##=head1 SVN URL Format
9 ##
10 ## The source mage specific format is:
11 ##
12 ## svn://SVNURL:DIR_NAME
13 ## svn://SVNURL:DIR_NAME:REVISION_TAG
14 ##
15 ## It is exactly the same as a standard svn:// url, with additional
16 ## tokens at the end DIR_NAME and optional REVISITION_TAG
17 ##
18 ## The svn://SVNURL portion of the url will appear on the svn command
19 ## line as the url.
20 ##
21 ## The DIR_NAME will be the tail element of the SOURCE_DIRECTORY.
22 ##
23 ## In order to maintain compatibility with the original svn url format,
24 ## which uses http:// as the underlying protocol, a hint may be specified
25 ## named "old_svn_compat".
26 ##
27 ## For more details, see the SVN manual at
28 ## http://svnbook.red-bean.com/svnbook/ch03s04.html
29 ##
30 ##=head1 EXAMPLES
31 ##
32 ## Suppose we want to download the latest version of bmp-plugins
33 ## from svn. We'd use the following url:
34 ##
35 ## svn://svn.pld-linux.org/svn/bmp-plugins/trunk:bmp-plugins-svn
36 ##
37 ## If we want the 4474 revision number we would use the following url:
38 ##
39 ## svn://svn.pld-linux.org/svn/bmp-plugins/trunk:bmp-plugins-svn:4474
40 ##
41 ## svn repositories requiring passwords are not currently supported.
42 ##
43 ##=head1 COPYRIGHT
44 ##
45 ## Copyright 2004 by the Source Mage Team
46 ## Copyright 2005 by the Source Mage Team
47 ##
48 ##=head1 FUNCTIONS
49 ##
50 ##=over 4
51 ##
52 #---------------------------------------------------------------------
53
54 #---------------------------------------------------------------------
55 ##=item url_svn_crack <url>
56 ##
57 ## Parse the specified svn url.
58 ##
59 ## @Global URL
60 ## @Global SVN_ROOT
61 ## @Global SVN_MODULE
62 ## @Global SVN_TAG
63 ##
64 #---------------------------------------------------------------------
65 function url_svn_crack() {
66
67 URL=`url_strip_prefix "$1" svn`
68 SVN_ROOT=`echo $URL | sed "s#\(^[^/]*[^:]*\):.*#\1#"`
69 if list_find "$2" old_svn_compat; then
70 SVN_ROOT=http://$SVN_ROOT
71 else
72 SVN_ROOT=svn://$SVN_ROOT
73 fi
74 local SVN_MODULE_TAG=`echo $URL | sed "s#^[^/]*[^:]*\(.*\)#\1#"`
75 SVN_MODULE=`echo $SVN_MODULE_TAG | cut -d : -f2`
76 local SVN_TAGNAME=`echo $SVN_MODULE_TAG | cut -d : -f3`
77 SVN_TAG=${SVN_TAGNAME:=HEAD}
78
79 }
80
81 #---------------------------------------------------------------------
82 ##=item url_svn_is_valid <url>
83 ##
84 ## Ensure that all the fields that should be parsed out from a url
85 ## do indeed exist
86 #---------------------------------------------------------------------
87 function url_svn_is_valid() {
88 local URL SVN_ROOT SVN_MODULE SVN_TAG item
89 url_svn_crack $1
90 for item in URL SVN_ROOT SVN_MODULE SVN_TAG; do
91 if ! [[ ${!item} ]] ; then
92 return 1
93 fi
94 done
95 }
96
97 #---------------------------------------------------------------------
98 ##=item url_svn_hostname <url>
99 ##
100 ## Get the hostname of the url
101 ##
102 #---------------------------------------------------------------------
103 function url_svn_hostname() {
104 echo $1|sed 's#^svn://\([^/:]*\)[/:].*$#\1#'
105 }
106
107 #---------------------------------------------------------------------
108 ##=item url_svn_netselect <url>
109 ##
110 ## Gets a netselect type output for the url
111 ##
112 #---------------------------------------------------------------------
113 function url_svn_netselect() {
114 local tmp_hostname url_speed each
115
116 for each in "$@" ; do
117 tmp_hostname=$(url_svn_hostname $each)
118 # since we had to pull the url apart to give netselect
119 # something it can understand we'll just pretend like
120 # multiple A records wont exist for this host...
121 url_speed=$(netselect -s 1 $tmp_hostname 2>/dev/null|awk '{print $1}')
122 [[ -n $url_speed ]] && echo "$url_speed $each"
123 done
124 }
125
126 #---------------------------------------------------------------------
127 ##=back
128 ##
129 ##=head1 LICENSE
130 ##
131 ## This software is free software; you can redistribute it and/or modify
132 ## it under the terms of the GNU General Public License as published by
133 ## the Free Software Foundation; either version 2 of the License, or
134 ## (at your option) any later version.
135 ##
136 ## This software is distributed in the hope that it will be useful,
137 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
138 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139 ## GNU General Public License for more details.
140 ##
141 ## You should have received a copy of the GNU General Public License
142 ## along with this software; if not, write to the Free Software
143 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
144 ##
145 #---------------------------------------------------------------------