source: grass-addons/tools/module_svn_propset.sh

Last change on this file was 73933, checked in by neteler, 6 years ago

tools/module_svn_propset.sh: enable also .PDF (caps)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:mime-type set to text/x-sh
File size: 6.4 KB
Line 
1#!/bin/sh
2############################################################################
3#
4# TOOL: module_svn_propset.sh
5# AUTHOR: Hamish Bowman, Dunedin, New Zealand
6# PURPOSE: Looks at the files you pass it, tries to set svn props
7# automatically for the ones it knows
8# COPYRIGHT: (c) 2009-2013 Hamish Bowman, and the GRASS Development Team
9# This program is free software under the GNU General Public
10# License (>=v2). Read the file COPYING that comes with GRASS
11# for details.
12#
13#############################################################################
14# For a list of valid mime types see /etc/mime.types
15#
16
17if [ $# -lt 1 ] ; then
18 echo "USAGE: module_svn_propset.sh file1 [file2 file3 *.html]"
19 echo
20 exit 1
21fi
22
23if [ ! -x "`which svn`" ] ; then
24 echo "ERROR: Subversion not found, install it first" 1>&2
25 exit 1
26fi
27
28########
29
30# will only set if previously empty
31set_native_eol()
32{
33 if [ `svn proplist "$1" | grep -c 'svn:eol-style'` -eq 0 ] ; then
34 svn propset svn:eol-style "native" "$1"
35
36 fi
37}
38
39set_msdos_eol()
40{
41 if [ "`svn propget svn:eol-style "$1"`" = "native" ] ; then
42 svn propdel svn:eol-style "$1"
43 fi
44 if [ `svn proplist "$1" | grep -c 'svn:eol-style'` -eq 0 ] ; then
45 svn propset svn:eol-style "CRLF" "$1"
46 fi
47}
48
49set_mime_type()
50{
51 # remove generic default for images
52 if [ `echo "$2" | cut -f1 -d/` = "image" ] ; then
53 if [ "`svn propget svn:mime-type "$1"`" = "application/octet-stream" ] ; then
54 svn propdel svn:mime-type "$1"
55 fi
56 fi
57
58 if [ `svn proplist "$1" | grep -c 'svn:mime-type'` -eq 0 ] ; then
59 svn propset svn:mime-type "$2" "$1"
60 fi
61}
62
63# will only set if previously empty
64set_exe()
65{
66 if [ `svn proplist "$1" | grep -c 'svn:executable'` -eq 0 ] ; then
67 svn propset svn:executable "ON" "$1"
68 fi
69}
70
71# will only unset if previously set
72unset_exe()
73{
74 if [ `svn proplist "$1" | grep -c 'svn:executable'` -eq 1 ] ; then
75 svn propdel svn:executable "$1"
76 fi
77}
78
79# will only set if previously empty
80set_keywords()
81{
82 # check if set at all
83 if [ `svn proplist "$1" | grep -c 'svn:keywords'` -eq 0 ] ; then
84 svn propset svn:keywords "Author Date Id" "$1"
85 fi
86 # check if any keyword is missing
87 for keyword in Author Date Id ; do
88 if [ `svn proplist -v "$1" | grep -c "$keyword"` -eq 0 ] ; then
89 svn propset svn:keywords "Author Date Id" "$1"
90 fi
91 done
92}
93
94
95########
96#usually these are not stored in Svn, but fyi:
97# diff | patch ) svn propset svn:mime-type text/x-diff filenname
98
99apply_html()
100{
101 set_keywords "$1"
102 set_mime_type "$1" text/html
103 set_native_eol "$1"
104 unset_exe "$1"
105}
106
107apply_xml()
108{
109 # While given as "application" in /etc/mime.types, "text" is desired
110 # here due to the way SVN uses the mime type. See RFC 3023 and
111 # http://www.imc.org/ietf-xml-mime/mail-archive/msg00496.html
112 # Unfortunately SVN treats "application" as "binary" and then refuses
113 # to do text diffs. (same problem with PostScript)
114 set_mime_type "$1" text/xml
115 set_native_eol "$1"
116 unset_exe "$1"
117}
118
119apply_text()
120{
121 set_keywords "$1"
122 set_mime_type "$1" text/plain
123 set_native_eol "$1"
124 unset_exe "$1"
125}
126
127apply_makefile()
128{
129 set_mime_type "$1" text/x-makefile
130 set_native_eol "$1"
131 unset_exe "$1"
132}
133
134apply_shell_script()
135{
136 set_mime_type "$1" text/x-sh
137 set_native_eol "$1"
138 set_exe "$1"
139}
140
141apply_python_script()
142{
143 set_mime_type "$1" text/x-python
144 set_native_eol "$1"
145 #? set_exe "$1"
146}
147
148apply_perl_script()
149{
150 set_mime_type "$1" text/x-perl
151 set_native_eol "$1"
152 #? set_exe "$1"
153}
154
155apply_bat_script()
156{
157 # CHECKME: setting as an app/ might stop trac from trying diffs & previews
158 set_mime_type "$1" "text/x-bat"
159 set_msdos_eol "$1"
160 unset_exe "$1"
161}
162
163apply_C_code()
164{
165 set_mime_type "$1" text/x-csrc
166 set_native_eol "$1"
167 unset_exe "$1"
168}
169
170apply_C_header()
171{
172 set_mime_type "$1" text/x-chdr
173 set_native_eol "$1"
174 unset_exe "$1"
175}
176
177apply_Cpp_code()
178{
179 set_mime_type "$1" "text/x-c++src"
180 set_native_eol "$1"
181 unset_exe "$1"
182}
183
184apply_Fortran_code()
185{
186 set_mime_type "$1" text/x-fortran
187 set_native_eol "$1"
188 unset_exe "$1"
189}
190
191apply_image()
192{
193 set_mime_type "$1" "image/$2"
194 unset_exe "$1"
195}
196
197apply_pdf()
198{
199 set_mime_type "$1" "application/pdf"
200 unset_exe "$1"
201}
202
203apply_po()
204{
205 set_keywords "$1"
206 set_mime_type "$1" text/x-po
207 set_native_eol "$1"
208 unset_exe "$1"
209}
210
211apply_OBJ_code()
212{
213 svn propset svn:ignore "OBJ.*
214*.tmp.html" .
215}
216
217apply_Sql_code()
218{
219 set_mime_type "$1" text/x-sql
220 set_native_eol "$1"
221 unset_exe "$1"
222}
223
224apply_svg()
225{
226 set_mime_type "$1" "image/svg+xml"
227 set_native_eol "$1"
228 unset_exe "$1"
229}
230
231########
232
233
234for FILE in $* ; do
235 #echo "Processing <$FILE> ..."
236
237 if [ ! -e "$FILE" ] ; then
238 echo "ERROR: file not found <$FILE>"
239 continue
240 fi
241
242 if test -d "$FILE" ; then
243 DIRPREF=`echo "$FILE" | cut -d'.' -f1`
244 if [ "$DIRPREF" = "OBJ" ] ; then
245 apply_OBJ_code "$FILE"
246 fi
247 fi
248
249 FILE_SUFFIX=`echo "$FILE" | sed -e 's/^.*\.//'`
250 case "$FILE_SUFFIX" in
251 c)
252 apply_C_code "$FILE"
253 ;;
254 h)
255 apply_C_header "$FILE"
256 ;;
257 cc | cpp)
258 apply_Cpp_code "$FILE"
259 ;;
260 f | for | f77 | f90)
261 apply_Fortran_code "$FILE"
262 ;;
263 py)
264 apply_python_script "$FILE"
265 ;;
266 pl)
267 apply_perl_script "$FILE"
268 ;;
269 bat)
270 apply_bat_script "$FILE"
271 ;;
272 sh)
273 apply_shell_script "$FILE"
274 ;;
275 html)
276 apply_html "$FILE"
277 ;;
278 xml)
279 apply_xml "$FILE"
280 ;;
281 gxm)
282 apply_xml "$FILE"
283 ;;
284 pdf | PDF)
285 apply_pdf "$FILE"
286 ;;
287 png | jpg | jpeg | gif | bmp | xpm | xcf | ico)
288 if [ "$FILE_SUFFIX" = "jpg" ] ; then
289 FILE_SUFFIX="jpeg"
290 elif [ "$FILE_SUFFIX" = "svg" ] ; then
291 FILE_SUFFIX='svg+xml'
292 elif [ "$FILE_SUFFIX" = "xpm" ] ; then
293 FILE_SUFFIX='x-xpixmap'
294 elif [ "$FILE_SUFFIX" = "ico" ] ; then
295 FILE_SUFFIX='x-icon'
296 fi
297 apply_image "$FILE" "$FILE_SUFFIX"
298 ;;
299 txt | ascii | dox | md)
300 apply_text "$FILE"
301 ;;
302 po)
303 apply_po "$FILE"
304 ;;
305 rst)
306 apply_text "$FILE"
307 ;;
308 sql)
309 apply_Sql_code "$FILE"
310 ;;
311 svg)
312 apply_svg "$FILE"
313 ;;
314 *)
315 if [ "`basename $FILE`" = "Makefile" ] ; then
316 apply_makefile "$FILE"
317 elif [ "`basename $FILE`" = "README" ] || [ "`basename $FILE`" = "TODO" ] ; then
318 apply_text "$FILE"
319 elif [ `file "$FILE" | grep -c "shell script\|sh script"` -eq 1 ] ; then
320 apply_shell_script "$FILE"
321 else
322 if test ! -d "$FILE" ; then
323 echo "WARNING: unknown file type <$FILE>"
324 fi
325 fi
326 ;;
327 esac
328done
Note: See TracBrowser for help on using the repository browser.