Magellan Linux

Contents of /trunk/pkgtools/up2date.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3112 - (show annotations) (download) (as text)
Fri Mar 15 11:30:25 2019 UTC (5 years, 1 month ago) by niro
File MIME type: application/x-sh
File size: 28588 byte(s)
-include mage.rc/rc.global, added utf8encode() function and use it, use upsort() and tarball functions for better version detection and added a bunch of small fixes
1 #!/bin/bash
2
3 source /usr/lib/mage/mage4.functions.sh
4 source /usr/lib/mage/smage2.functions.sh
5 source /etc/mage.rc.global
6 source /etc/mage.rc
7
8 # timeout in seconds
9 LYNX_CONNECT_TIMEOUT=10
10 LYNX_READ_TIMEOUT=10
11 #LYNX_OPTIONS="-pauth=user:pass"
12
13 ## only for tests -> normally in /etc/rc.d/init.d/functions
14 COLRED="\033[1;6m\033[31m"
15 COLGREEN="\033[1;6m\033[32m"
16 COLYELLOW="\033[1;6m\033[33m"
17 COLBLUE="\033[1;6m\033[34m"
18 COLMAGENTA="\033[1;6m\033[35m"
19 COLWHITE="\033[1;6m\033[37m"
20 COLGRAY="\033[0;6m\033[37m"
21 COLBOLD="\033[1m"
22 COLDEFAULT="\033[0m"
23
24 if [[ ${NOCOLORS} = true ]]
25 then
26 COLRED=""
27 COLGREEN=""
28 COLYELLOW=""
29 COLBLUE=""
30 COLMAGENTA=""
31 COLWHITE=""
32 COLGRAY=""
33 COLBOLD=""
34 COLDEFAULT=""
35 fi
36
37 die() { echo "Error: $@"; exit 1; }
38
39 #sminclude() { true; }
40 #msetfeature() { true; }
41 #mqueryfeature() { true; }
42 #haskell_enable_feature() { true; }
43 #haskell_disable_feature() { true; }
44
45 SILENT=1
46 FVERBOSE=off
47
48 utf8encode()
49 {
50 iconv --from-code=ISO_8859-15 --to-code=UTF-8 $@
51 }
52
53 urlencode()
54 {
55 local uri="$@"
56
57 # fix percent (do this first!!)
58 uri=$(echo ${uri} | sed 's:%:%25:g')
59
60 # fix spaces
61 uri=$(echo ${uri} | sed 's:\ :%20:g')
62
63 # fix less than
64 uri=$(echo ${uri} | sed 's:<:%3C:g')
65
66 # fix greater than
67 uri=$(echo ${uri} | sed 's:>:%3E:g')
68
69 # fix pound
70 uri=$(echo ${uri} | sed 's:#:%23:g')
71
72 # fix curly brace left
73 uri=$(echo ${uri} | sed 's:{:%7B:g')
74
75 # fix curly brace right
76 uri=$(echo ${uri} | sed 's:}:%7D:g')
77
78 # fix square bracket left
79 uri=$(echo ${uri} | sed 's:\[:%5B:g')
80
81 # fix square bracket right
82 uri=$(echo ${uri} | sed 's:\]:%5D:g')
83
84
85 # return
86 echo "${uri}"
87 }
88
89 upsort()
90 {
91 local allversions="$@"
92 [[ -n ${allversions} ]] || die "upsort(): no versions given"
93
94 if [ -x /home/tjoke/archlinux_version/highestver ]
95 then
96 /home/tjoke/archlinux_version/highestver ${allversions}
97 else
98 for i in ${allversions}
99 do
100 echo "${i}"
101 done | sort -g | tac | head -n 1
102 fi
103 }
104
105 upsort_pipe()
106 {
107 local data
108 local versions
109
110 versions=""
111 while read data
112 do
113 versions+="${data} "
114 done
115
116 upsort ${versions}
117 }
118
119 #highesttarball()
120 #{
121 # local suffix=bz2
122 # local seperator="-"
123 # [[ ! -z $1 ]] && suffix="$1"
124 # local data
125 # local version
126 #
127 # [[ ! -z ${UP2SEPERATOR} ]] && seperator="${UP2SEPERATOR}"
128 # [[ ${UP2SEPERATOR} = NULL ]] && seperator=""
129 #
130 # case ${suffix} in
131 # tbz2|tgz|zip)
132 # if [[ ! -z ${UP2EXCLUDE} ]]
133 # then
134 # grep "\(\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/" | upsort_pipe
135 # else
136 # grep "\(\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/" | upsort_pipe
137 # fi
138 # ;;
139 # *)
140 # if [[ ! -z ${UP2EXCLUDE} ]]
141 # then
142 # grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/" | upsort_pipe
143 # else
144 # grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/" | upsort_pipe
145 # fi
146 # ;;
147 # esac
148 #}
149
150 #lasttarball()
151 #{
152 # local suffix=bz2
153 # local seperator="-"
154 # [[ ! -z $1 ]] && suffix="$1"
155 #
156 # [[ ! -z ${UP2SEPERATOR} ]] && seperator="${UP2SEPERATOR}"
157 # [[ ${UP2SEPERATOR} = NULL ]] && seperator=""
158 #
159 # case ${suffix} in
160 # tbz2|tgz|zip)
161 # if [[ ! -z ${UP2EXCLUDE} ]]
162 # then
163 # grep "\(\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed -n "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/;$ p"
164 # else
165 # grep "\(\.${suffix}\)\(\$\|\#\)" | sed -n "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/;$ p"
166 # fi
167 # ;;
168 # *)
169 # if [[ ! -z ${UP2EXCLUDE} ]]
170 # then
171 # grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed -n "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/;$ p"
172 # else
173 # grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | sed -n "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/;$ p"
174 # fi
175 # ;;
176 # esac
177 #}
178
179 #firsttarball()
180 #{
181 # local suffix=bz2
182 # local seperator="-"
183 # [[ ! -z $1 ]] && suffix="$1"
184 #
185 # [[ ! -z ${UP2SEPERATOR} ]] && seperator="${UP2SEPERATOR}"
186 # [[ ${UP2SEPERATOR} = NULL ]] && seperator=""
187 #
188 # case ${suffix} in
189 # tbz2|tgz|zip)
190 # if [[ ! -z ${UP2EXCLUDE} ]]
191 # then
192 # grep "\(\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/;q"
193 # else
194 # grep "\(\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/;q"
195 # fi
196 # ;;
197 # *)
198 # if [[ ! -z ${UP2EXCLUDE} ]]
199 # then
200 # grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/;q"
201 # else
202 # grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/;q"
203 # fi
204 # ;;
205 # esac
206 #}
207
208 tarballversions()
209 {
210 local suffix=bz2
211 local seperator="-"
212 [[ ! -z $1 ]] && suffix="$1"
213 local data
214 local version
215
216 [[ ! -z ${UP2SEPERATOR} ]] && seperator="${UP2SEPERATOR}"
217 [[ ${UP2SEPERATOR} = NULL ]] && seperator=""
218
219 case ${suffix} in
220 tbz2|tgz|zip)
221 if [[ ! -z ${UP2EXCLUDE} ]]
222 then
223 grep "\(\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/"
224 else
225 grep "\(\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/"
226 fi
227 ;;
228 *)
229 if [[ ! -z ${UP2EXCLUDE} ]]
230 then
231 grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/"
232 else
233 grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/"
234 fi
235 ;;
236 esac
237 }
238
239 highesttarball()
240 {
241 tarballversions $@ | upsort_pipe
242 }
243
244 lasttarball()
245 {
246 tarballversions $@ | sed -n "$ p"
247 }
248
249 firsttarball()
250 {
251 tarballversions $@ | sed "q"
252 }
253
254 updatecmd()
255 {
256 local uppver
257 local useragent
258 [[ ! -z ${UP2USERAGENT} ]] && useragent="-useragent '${UP2USERAGENT}'"
259
260 uppver=$(lynx ${LYNX_OPTIONS} -connect_timeout=${LYNX_CONNECT_TIMEOUT} -read_timeout=${LYNX_READ_TIMEOUT} -dump "${useragent}" $@ | utf8encode)
261 if [[ $? -ne 0 ]]
262 then
263 echo "Error connecting '$@'"
264 sleep 1
265 return 1
266 fi
267
268 if [[ ! -z ${UP2SUBSTITUTE} ]]
269 then
270 echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g"
271 else
272 echo "${uppver}"
273 fi
274 }
275
276 updatecmd_gnu()
277 {
278 local pname=$1
279 local archive
280 local tarball
281
282 [[ -z ${pname} ]] && die "give me a \$PNAME"
283 [[ ! -z $2 ]] && archive="$2"
284
285 tarball="${pname}"
286 [[ ! -z ${UP2TARBALL} ]] && tarball="${UP2TARBALL}"
287
288 # remove 'latest' tarball too
289 updatecmd "http://ftp.gnu.org/gnu/${pname}" | grep "${tarball}-" | sed '/latest/d' | highesttarball "${archive}"
290 }
291
292 updatecmd_sourceforge_old()
293 {
294 local projectname="$1"
295 local pname="$2"
296 local check_deep_release_id="$3"
297 local archive
298 local uri
299 local group_id
300 local package_link_id
301 local package_id
302 local package_name
303 local release_link_id
304 local release_id
305
306 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
307 [[ -z ${pname} ]] && pname="${projectname}"
308 case ${check_deep_release_id} in
309 deep|release_id|releaseid) check_deep_release_id="true" ;;
310 esac
311 [[ ! -z $4 ]] && archive="$4"
312
313 # project home uri
314 uri="http://sourceforge.net/projects/${projectname}"
315 group_id=$(updatecmd ${uri} | grep showfiles | sed 's/.*=\(.*\)/\1/;s/#downloads$//;q')
316
317 # showfiles.php uri with group_id to get the latest files
318 uri="http://sourceforge.net/project/showfiles.php?group_id=${group_id}"
319
320 package_link_id=$(updatecmd ${uri} | grep "\[.*\]${pname} \[.*\].*Release.*" | sed "s/.*\[\(.*\)\]${pname}.*/\1/")
321 package_id=$(updatecmd ${uri} | grep "${package_link_id}\..*showfiles.*" | sed 's/.*package_id=\(.*\)/\1/')
322
323 # debug
324 #echo group_id=${group_id}
325 #echo package_link_id=${package_link_id}
326 #echo package_id=${package_id}
327
328 uri="http://sourceforge.net/project/showfiles.php?group_id=${group_id}&package_id=${package_id}"
329 package_name=$(updatecmd "${uri}" | grep -m1 'Latest \[.*\]' | sed 's/.*]\(.*\) \[.*\].*/\1/')
330
331 if [[ ${check_deep_release_id} = true ]]
332 then
333 # showfiles.php uri with group_id and package to get the latest released files
334 uri="http://sourceforge.net/project/showfiles.php?group_id=${group_id}&package_id=${package_id}"
335 release_link_id=$(updatecmd ${uri} | grep ".*Latest.*\[.*\]${package_name} \[.*\].*" | sed "s/.*\[\(.*\)\]${package_name}.*/\1/")
336 release_id=$(updatecmd "${uri}" | grep "${release_link_id}\..*showfiles.*" | sed 's/.*release_id=\(.*\)/\1/')
337
338 # debug
339 #echo package_name=${package_name}
340 #echo release_link_id=${release_link_id}
341 #echo release_id=${release_id}
342
343 uri="http://sourceforge.net/project/showfiles.php?group_id=${group_id}&package_id=${package_id}&release_id=${release_id}"
344 case ${archive} in
345 tbz2|tgz)
346 updatecmd "${uri}" | grep "\(\.${suffix}\)" | sed -n "s/.*-\(.*\)\(\.${suffix}\).*/\1/;$ p"
347 ;;
348 *)
349 updatecmd "${uri}" | grep "\(\.tar\.${archive}\)" | sed -n "s/.*-\(.*\)\(\.tar\.${archive}\).*/\1/;$ p"
350 ;;
351 esac
352 else
353 echo "${package_name}"
354 fi
355 }
356
357 # new layout
358 updatecmd_sourceforge2()
359 {
360 local projectname="$1"
361 local pname="$2"
362 local suffix
363 local uri
364 local package_link_id
365 local package_seperator="-"
366 local excluded
367
368 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
369 [[ -z ${pname} ]] && pname="${projectname}"
370 [[ ! -z $3 ]] && package_seperator="$3"
371
372 # project home uri
373 uri="http://sourceforge.net/projects/${projectname}/files"
374 # list of file suffixes, which should be excluded
375 excluded='(.asc|.md5)'
376 # package file names has always the date and time at the end <---------|
377 #package_link_id=$(updatecmd ${uri} | egrep -v ${excluded} | grep -v .md5 | grep -m1 "${pname}${package_seperator}[0-9].* [0-9]" | sed "s/.*\[\(.*\)\]${pname}.*/\1/")
378 package_link_id=$(updatecmd ${uri} | egrep -v ${excluded} | grep -m1 "${pname}${package_seperator}[0-9].* [0-9]" | sed "s/.*\[\(.*\)\].*/\1/")
379 echo DEBUG1:${package_link_id}
380
381 # get the suffix
382 suffix=$(updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${pname}.*\(\..*\)/\1/")
383 # echo "DEBUG2:${suffix}"
384
385 case ${suffix} in
386 .tbz2|.tgz|.zip|.rar)
387 #updatecmd ${uri} | grep -m1 "${pname}.*${suffix}" #| sed "s/.*${pname}\(.*\)${suffix}.*/\1/;s/-/_/g;s/_//1"
388 updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${pname}\(.*\)${suffix}.*/\1/;s/-/_/g;s/_//1"
389 ;;
390 *)
391 #updatecmd ${uri} | grep -m1 "${pname}.*.tar${suffix}" | sed "s/.*${pname}\(.*\).tar${suffix}.*/\1/;s/-/_/g;s/_//1"
392 updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${pname}\(.*\).tar${suffix}.*/\1/;s/-/_/g;s/_//1"
393 ;;
394 esac
395 }
396
397 # new layout, only newest
398 updatecmd_sourceforge_latest()
399 {
400 local projectname="$1"
401 local pname="$2"
402 local suffix
403 local uri
404 local package_link_id
405 local package_seperator="-"
406 local excluded
407 local deep="no"
408 local filename
409 local uppver
410
411 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
412 [[ -z ${pname} ]] && pname="${projectname}"
413 [[ ! -z $3 ]] && package_seperator="$3"
414 if [[ ! -z $4 ]]
415 then
416 deep="yes"
417 filename="$4"
418 fi
419
420 # project home uri
421 uri="http://sourceforge.net/projects/${projectname}/files"
422 # list of file suffixes, which should be excluded
423 excluded='(.asc|.md5)'
424 # package file names has always the date and time at the end <---------|
425 # package_link_id=$(updatecmd ${uri} | sed -n '/Newest Files/,/All Files/p' | grep -v ${excluded} | grep -m1 "${pname}${package_seperator}[0-9].* [0-9]" | sed "s/.*\[\(.*\)\].*/\1/")
426 package_link_id=$(updatecmd ${uri} | grep -A1 'Newest Files' | sed -n "s/.*\[\(.*\)\].*${pname}${package_seperator}.*/\1/;$ p")
427 # if [[ ${deep} = yes ]]
428 # then
429 # #package_link_id=$(updatecmd ${uri} | sed -n "/${pname}.*Subscribe.*/,/.*Subscribe.*/p" | sed -n "/${filename}.*Release Notes.*/,/.*Release Notes/p" | grep -v ${excluded} | grep -m1 ".*${package_seperator}[0-9].* [0-9]" | sed "s/.*\[\(.*\)\].*/\1/")
430 # package_link_id=$(updatecmd ${uri} | sed -n "/${pname}.*Subscribe.*/,/.*Subscribe.*/p" | sed -n "/${filename}.*Release Notes.*/,/.*Release Notes/p" | grep -v ${excluded} | grep -m1 "${pname}\ \[.*\]" | sed "s/.*\[\(.*\)\].*/\1/")
431 # else
432 # #package_link_id=$(updatecmd ${uri} | sed -n "/${pname}.*Subscribe.*/,/.*Subscribe.*/p" | grep -v ${excluded} | grep -m1 ".*${package_seperator}[0-9].* [0-9]" | sed "s/.*\[\(.*\)\].*/\1/")
433 # #package_link_id=$(updatecmd ${uri} | sed -n "/${pname}.*Subscribe.*/,/.*Subscribe.*/p" | grep -v ${excluded} | grep -m1 "${pname}\ \[.*\]" | sed "s/.*\[\(.*\)\].*/\1/")
434 # package_link_id=$(updatecmd ${uri} | grep -A1 'Newest Files' | sed -n "s/.*\[\(.*\)\].*${pname}${package_seperator}.*/\1/;$ p")
435 # fi
436 # #echo DEBUG1:${package_link_id}
437
438 # get the suffix
439 #suffix=$(updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${pname}.*\(\..*\)\/download/\1/")
440 suffix=$(updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*\(\..*\)\/download/\1/")
441 #echo "DEBUG2:${suffix}"
442
443 case ${suffix} in
444 .tbz2|.tgz|.zip|.rar|.7z)
445 #updatecmd ${uri} | grep -m1 "${pname}.*${suffix}" #| sed "s/.*${pname}\(.*\)${suffix}.*/\1/;s/-/_/g;s/_//1"
446 #updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${pname}\(.*\)${suffix}.*/\1/;s/-/_/g;s/_//1"
447 #updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${package_seperator}\(.*\)${suffix}.*/\1/;s/-/_/g;s/_//1"
448 uppver=$(updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${package_seperator}\([0-9].*\)${suffix}.*/\1/;s/-/_/g;s/_//1")
449 ;;
450 *)
451 #updatecmd ${uri} | grep -m1 "${pname}.*.tar${suffix}" | sed "s/.*${pname}\(.*\).tar${suffix}.*/\1/;s/-/_/g;s/_//1"
452 #updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${package_seperator}\(.*\).tar${suffix}.*/\1/;s/-/_/g;s/_//1"
453 uppver=$(updatecmd -listonly ${uri} | grep "\ ${package_link_id}\." | sed "s/.*${package_seperator}\([0-9].*\).tar${suffix}.*/\1/;s/-/_/g;s/_//1")
454 ;;
455 esac
456
457 if [[ ! -z ${UP2SUBSTITUTE} ]]
458 then
459 echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g"
460 else
461 echo "${uppver}"
462 fi
463 }
464
465
466 # new layout, only newest
467 updatecmd_sourceforge_lala()
468 {
469 local projectname="$1"
470 local pname="$2"
471 local suffix
472 local uri
473 local opts
474 local package_link_id
475 local package_seperator="-"
476 local excluded
477 local deep="no"
478 local filename="${pname}"
479 local uppver
480
481 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
482 [[ -z ${pname} ]] && pname="${projectname}"
483 if [[ ! -z $3 ]]
484 then
485 case $3 in
486 null|NULL) package_seperator='' ;;
487 *) package_seperator="$3" ;;
488 esac
489 fi
490 if [[ ! -z $4 ]]
491 then
492 deep="yes"
493 filename="$4"
494 else
495 filename="${pname}"
496 fi
497
498 # special opts like sort date asc
499 if [[ ! -z ${UP2OPTS} ]]
500 then
501 opts="${UP2OPTS}"
502 else
503 opts='?sort=date&sortdir=asc'
504 fi
505 # project home uri # urlencode $pname
506 uri="http://sourceforge.net/projects/${projectname}/files/$(urlencode ${pname})${opts}"
507 # list of file suffixes, which should be excluded
508 excluded='(.asc|.md5|.exe|.txt|.sign|.rpm|.html|.7z|.dmg)'
509 package_link_id=$(updatecmd "${uri}" | grep "\[.*\]${filename}${package_seperator}" | egrep -v ${excluded} | sed -n "s/.*\[\(.*\)\].*${filename}${package_seperator}.*/\1/;$ p")
510
511 # get the suffix
512 suffix=$(updatecmd -listonly "${uri}" | grep "\ ${package_link_id}\." | sed "s/.*\(\..*\)\/download/\1/")
513 #echo "DEBUG2:${suffix}"
514
515 case ${suffix} in
516 .tbz2|.tgz|.zip|.rar|.7z)
517 uppver=$(updatecmd -listonly "${uri}" | grep "\ ${package_link_id}\." | sed "s/.*${package_seperator}\([0-9].*\)${suffix}.*/\1/;s/-/_/g;s/_//1")
518 ;;
519 *)
520 uppver=$(updatecmd -listonly "${uri}" | grep "\ ${package_link_id}\." | sed "s/.*${package_seperator}\([0-9].*\).tar${suffix}.*/\1/;s/-/_/g;s/_//1")
521 ;;
522 esac
523
524 if [[ ! -z ${UP2SUBSTITUTE} ]]
525 then
526 echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g"
527 else
528 echo "${uppver}"
529 fi
530 }
531
532 # new layout, only newest
533 updatecmd_sourceforge_ftp_dir()
534 {
535 local projectname="$1"
536 local pname="$2"
537 local modifier="$3"
538 local uppver
539
540 # mesh works, kent not
541 #local mirror="http://mesh.dl.sourceforge.net"
542 local mirror="http://garr.dl.sourceforge.net"
543
544 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
545 [[ -z ${pname} ]] && pname="${projectname}"
546 case ${modifier} in
547 date-asc) modifier='?C=M;O=A' ;;
548 date-desc) modifier='?C=M;O=D' ;;
549 name) modifier='' ;;
550 *) modifier='' ;;
551 esac
552
553 # urlencode everything
554 projectname=$(urlencode ${projectname})
555 pname=$(urlencode ${pname})
556
557 if [[ ! -z ${UP2EXCLUDE} ]]
558 then
559 uppver=$(updatecmd "${mirror}/project/${projectname}/${pname}/${modifier}" | grep -v -- "${UP2EXCLUDE}" | grep '[DIR].*\[[0-9].*\/' | sed -n 's/.*[0-9]\]\(.*\)\/.*/\1/;$ p')
560 else
561 uppver=$(updatecmd "${mirror}/project/${projectname}/${pname}/${modifier}" | grep '[DIR].*\[[0-9].*\/' | sed -n 's/.*[0-9]\]\(.*\)\/.*/\1/;$ p')
562 fi
563
564 if [[ ! -z ${UP2SUBSTITUTE} ]]
565 then
566 echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g"
567 else
568 echo "${uppver}"
569 fi
570 }
571
572 # needs app-text/xmlstarlet
573 updatecmd_sourceforge()
574 {
575 local projectname="$1"
576 local subprojectname="$2"
577 local archive="$3"
578 local uri
579 local project_id
580 local tarballname
581 local seperator
582 local rss_limit=50
583 local tarballprefix
584 local uppver
585 local allver
586
587 if [[ -z ${archive} ]] && [[ -n ${subprojectname} ]]
588 then
589 case ${subprojectname} in
590 xz|gz|bz2|tbz|tbz2|txz|tgz|zip|rar|7z|jar)
591 archive="${subprojectname}"
592 unset subprojectname
593 ;;
594 esac
595 fi
596
597 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
598 [[ -z ${subprojectname} ]] && subprojectname="${projectname}"
599 if [[ -z ${tarballname} ]]
600 then
601 if [[ ${subprojectname} != ${projectname} ]]
602 then
603 tarballname="${subprojectname}"
604 else
605 tarballname="${projectname}"
606 fi
607 fi
608 [[ -z ${seperator} ]] && seperator="-"
609 [[ -z ${archive} ]] && archive="bz2"
610
611 # overrides
612 [[ ! -z ${UP2TARBALL} ]] && tarballname="${UP2TARBALL}"
613 [[ ! -z ${UP2SEPERATOR} ]] && seperator="${UP2SEPERATOR}"
614 [[ ${UP2SEPERATOR} = NULL ]] && seperator=""
615
616 uri="http://sourceforge.net/projects/${projectname}"
617 # project_id=$(updatecmd ${uri} | grep project-id | sed -e 's:.*project-id/::;s:/.*::')
618 # rss_uri="http://sourceforge.net/api/file/index/project-id/${project_id}/mtime/desc/limit/${rss_limit}/rss"
619 rss_uri="${uri}/rss?path=/"
620
621 case ${archive} in
622 bz2|gz|xz) tarballprefix=".tar.${archive}" ;;
623 archive-bz2|archive-gz|archive-xz) tarballprefix=".${archive/archive-/}" ;;
624 tbz|tbz2|txz|tgz|zip|rar|7z|jar) tarballprefix=".${archive}" ;;
625 *) tarballprefix=".${archive}" ;;
626 esac
627
628 if [[ -x $(type -P xml) ]]
629 then
630 allver=$(updatecmd ${rss_uri} | xml sel -T -t -m //item -v title -n)
631 else
632 allver=$(updatecmd ${rss_uri})
633 fi
634
635 if [[ ! -z ${UP2EXCLUDE} ]]
636 then
637 allver=$(echo "${allver}" | grep -v -- "${UP2EXCLUDE}")
638 fi
639
640 allver=$(echo "${allver}" | grep "/${subprojectname}.*/${tarballname}${seperator}.*${tarballprefix}" | sed -e "s:.*${tarballname}${seperator}::;s:${tarballprefix}.*::")
641 #uppver=$(echo "${allver}" | sort -g | tac | head -n 1)
642 #uppver=$(echo "${allver}" | sort -n | tac | head -n 1)
643 uppver=$(upsort "${allver}")
644
645 if [[ ! -z ${UP2SUBSTITUTE} ]]
646 then
647 echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g"
648 else
649 echo "${uppver}"
650 fi
651 }
652
653 updatecmd_berlios()
654 {
655 local projectname="$1"
656 local pname="$2"
657 local uri
658 local group_id
659
660 [[ -z ${projectname} ]] && die "give me a \$PROJECTNAME"
661 [[ -z ${pname} ]] && pname="${projectname}"
662
663 uri="http://developer.berlios.de/projects/${projectname}"
664 group_id=$(updatecmd "${uri}" | grep showfiles | sed 's/.*group_id=\(.*\)&.*/\1/;q')
665
666 # debug
667 # echo group_id=${group_id}
668 # echo package_link_id=${package_link_id}
669 # echo package_id=${package_id}
670
671 uri="http://developer.berlios.de/project/showfiles.php?group_id=${group_id}"
672 updatecmd "${uri}" | grep -A3 "^${pname}$" | sed -n 's/.*\[.*]\(.*\) .*[0-9]-.*/\1/;$ p'
673 }
674
675 updatecmd_freedesktop()
676 {
677 local pname=$1
678 local archive
679 local subdir
680 local tarballname
681
682 [[ -z ${pname} ]] && die "give me a \$PNAME"
683 [[ ! -z $2 ]] && archive="$2"
684 [[ ! -z ${UP2SUBDIR} ]] && subdir="/${UP2SUBDIR}"
685 tarballname="${pname}"
686 [[ ! -z ${UP2TARBALL} ]] && tarballname="${UP2TARBALL}"
687
688 # exclude rc versions!
689 updatecmd "http://${pname}.freedesktop.org/releases${subdir}" | grep ${tarballname}- | grep -v rc[0-9] | highesttarball "${archive}"
690 }
691
692 updatecmd_xorg()
693 {
694 local pname=$1
695 local subdir
696 local tarballname
697 local pcat
698
699 [[ -z ${pname} ]] && die "give me a \$PNAME"
700 [[ ! -z $2 ]] && archive="$2"
701 tarballname="${pname}-"
702 if [[ ! -z ${PCAT} ]]
703 then
704 pcat="${PCAT}"
705 else
706 pcat="${PCATEGORIE}"
707 fi
708 subdir="$(echo ${pcat} | sed -e 's:x11-::' -e 's:media-::' -e 's/\(.*\)s$/\1/')"
709 [[ ! -z ${UP2SUBDIR} ]] && subdir="${UP2SUBDIR}"
710 [[ ! -z ${UP2TARBALL} ]] && tarballname="${UP2TARBALL}"
711
712 updatecmd "http://xorg.freedesktop.org/archive/individual/${subdir}/?C=M;O=A" | grep "/${tarballname}" | highesttarball "${archive}"
713 }
714
715 updatecmd_perl()
716 {
717 local pname=$1
718 local archive
719 local uppver
720
721 [[ -z ${pname} ]] && die "give me a \$PNAME"
722 [[ ! -z $2 ]] && archive="$2"
723
724 uppver=$(updatecmd "http://search.cpan.org/dist/${pname}/" | lasttarball "${archive}")
725
726 if [[ ! -z ${UP2SUBSTITUTE} ]]
727 then
728 echo "${uppver}" | sed "s:${UP2SUBSTITUTE}::g"
729 else
730 echo "${uppver}"
731 fi
732 }
733
734 updatecmd_pypi()
735 {
736 local pname="$1"
737 local archive="$2"
738 local uppver
739 # local fullarchive
740 # local tarball=
741 # local seperator
742
743 [[ -z ${pname} ]] && die "give me a \$PNAME"
744 [[ -z ${archive} ]] && die "give me a \$ARCHIVE"
745
746 # case ${archive} in
747 # gz|bz2) fullarchive=".tar.${archive}" ;;
748 # *) fullarchive=".${archive}" ;;
749 # esac
750
751 # tarball="${pname}"
752 # seperator="-"
753 # [[ -z ${UP2TARBALL} ]] || tarball="${UP2TARBALL}"
754 # [[ -z ${UP2SEPERATOR} ]] || seperator="${UP2SEPERATOR}"
755
756 # we cannot sort with C=M;O=A
757 # uppver=$(updatecmd -listonly https://pypi.python.org/packages/source/${pname:0:1}/${pname}/ | grep ${tarball} | grep ${fullarchive} | sed "s:.*${tarball}${seperator}\(.*\)${fullarchive}:\1:")
758 uppver=$(updatecmd https://pypi.python.org/pypi/${pname}/ | grep "/source/${pname:0:1}/${pname}/" | highesttarball ${archive})
759 #uppver=$(updatecmd -listonly https://pypi.python.org/pypi/${pname}/ | grep ${tarball} | grep ${fullarchive} | sed "s:.*${tarball}${seperator}\(.*\)${fullarchive}:\1:")
760
761 upsort ${uppver}
762 }
763
764 updatecmd_gnome()
765 {
766 local uri
767 local pname="$1"
768 local mode="$2"
769 local appmajor
770
771
772 [[ -z ${pname} ]] && die "give me a \$PNAME"
773
774 case ${mode} in
775 devel|--devel) mode="devel" ;;
776 *) mode="normal" ;;
777 esac
778
779 uri="http://ftp.gnome.org/pub/GNOME/sources/${pname}"
780 if [[ ${mode} = devel ]]
781 then
782 appmajor=$(updatecmd "${uri}"/?C=N\;O=D | grep '/' | sed -ne 's|.*]\(.*\)/.*|\1|' -e '1 p')
783 else
784 appmajor=$(updatecmd "${uri}"/?C=N\;O=D | grep '[0-9]\.[0-9]*[02468]/' | sed -ne 's|.*]\(.*\)/.*|\1|' -e '1 p')
785 fi
786
787 updatecmd ${uri}/${appmajor}/ | grep ]LA | sed 's/.*S-\([0-9\.]*\).*/\1/' | upsort_pipe
788 }
789
790 updatecmd_xfce()
791 {
792 local uri
793 local pname="$1"
794 local archive
795 local subdir
796
797 [[ -z ${pname} ]] && die "give me a \$PNAME"
798 [[ ! -z $2 ]] && archive="$2"
799 if [[ -n ${UP2SUBDIR} ]]
800 then
801 subdir="${UP2SUBDIR}"
802 else
803 subdir="xfce"
804 fi
805
806 uri="http://archive.xfce.org/src/${subdir}/${pname}"
807 if [[ ${UP2OPTS} = unstable ]]
808 then
809 #updatecmd ${uri}/$(updatecmd "${uri}"/?C=N\;O=D | grep '[0-9]\.[0-9]/' | sed -ne 's|.*]\(.*\)/.*|\1|' -e '1 p')/?C=M\;O=A | lasttarball "${archive}"
810 updatecmd ${uri}/$(updatecmd -nolist "${uri}" | grep '[0-9]\.[0-9]*[0-9]/' | sed -e 's|.*]\(.*\)/.*|\1|' | upsort_pipe)/ | highesttarball "${archive}"
811 else
812 #updatecmd ${uri}/$(updatecmd "${uri}"/?C=N\;O=D | grep '[0-9]\.[0-9]*[02468]/' | sed -ne 's|.*]\(.*\)/.*|\1|' -e '1 p')/?C=M\;O=A | lasttarball "${archive}"
813 updatecmd ${uri}/$(updatecmd -nolist "${uri}" | grep '[0-9]\.[0-9]*[02468]/' | sed -e 's|.*]\(.*\)/.*|\1|' | upsort_pipe)/ | highesttarball "${archive}"
814 fi
815 }
816
817 updatecmd_google()
818 {
819 local uri
820 local pname="$1"
821 local archive
822
823 [[ -z ${pname} ]] && die "give me a \$PNAME"
824 [[ ! -z $2 ]] && archive="$2"
825
826 uri="http://code.google.com/p/${pname}/downloads/list"
827 updatecmd --listonly "${uri}" | grep ${pname}- | firsttarball "${archive}"
828 }
829
830 updateme()
831 {
832 local smage="$1"
833 local ONLY_PRINT_UPSTREAM
834
835 if [[ $1 = --upstream ]] || [[ $1 = -u ]]
836 then
837 if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]]
838 then
839 echo "you must give me a smagefile."
840 exit 1
841 fi
842 ONLY_PRINT_UPSTREAM=1
843 smage="$2"
844 fi
845
846 local PNAME
847 local PCATEGORIE
848 local PCAT
849 local PVER
850 local UP2DATE
851 local UP2URI
852 local UP2PVER
853 local UP2TARBALL
854 local UP2SUBDIR
855 local UP2SUBSTITUTE
856 local UP2USERAGENT
857 local UP2EXCLUDE
858 local UP2SEPERATOR
859 local UP2OPTS
860 local UPSTREAM_PVER
861 #
862 # PNAME="$(get_value_from_magefile PNAME ${smage})"
863 # PCATEGORIE="$(get_value_from_magefile PCATEGORIE ${smage})"
864 # PCAT="$(get_value_from_magefile PCAT ${smage})"
865 # PVER="$(get_value_from_magefile PVER ${smage})"
866 # UP2PVER="$(get_value_from_magefile UP2PVER ${smage})"
867 # UP2TARBALL="$(get_value_from_magefile UP2TARBALL ${smage})"
868 # UP2SUBDIR="$(get_value_from_magefile UP2SUBDIR ${smage})"
869 # UP2SUBSTITUTE="$(get_value_from_magefile UP2SUBSTITUTE ${smage})"
870 # UP2USERAGENT="$(get_value_from_magefile UP2USERAGENT ${smage})"
871 # UP2EXCLUDE="$(get_value_from_magefile UP2EXCLUDE ${smage})"
872 # UP2SEPERATOR="$(get_value_from_magefile UP2SEPERATOR ${smage})"
873 # UP2OPTS="$(get_value_from_magefile UP2OPTS ${smage})"
874 smagesource "${smage}"
875
876 [[ -z ${UP2PVER} ]] && UP2PVER="${PVER}"
877
878 UP2DATE=$(get_value_from_magefile UP2DATE ${smage})
879
880 if [[ -z ${UP2DATE} ]]
881 then
882 #echo "\$UP2DATE is empty, skipping ..."
883 #continue
884 :
885 fi
886
887 #echo "UP2DATE=${UP2DATE}"
888 #read
889 UPSTREAM_PVER=$(eval "${UP2DATE}")
890 if [[ ${ONLY_PRINT_UPSTREAM} = 1 ]]
891 then
892 echo "${UPSTREAM_PVER}"
893 else
894 # [[ ${UP2PVER} = ${UPSTREAM_PVER} ]] && echo -e "${PNAME}: ${COLGREEN}'${UP2PVER}' = '${UPSTREAM_PVER}'${COLDEFAULT}"
895 # #[[ ${UP2PVER} != ${UPSTREAM_PVER} ]] && echo "${PNAME}: '${UP2PVER}' != '${UPSTREAM_PVER}'"
896 # [[ ${UP2PVER} < ${UPSTREAM_PVER} ]] && echo -e "${PNAME}: ${COLRED}'${UP2PVER}' < '${UPSTREAM_PVER}'${COLDEFAULT}"
897 # [[ ${UP2PVER} > ${UPSTREAM_PVER} ]] && echo -e "${PNAME}: ${COLYELLOW}'${UP2PVER}' > '${UPSTREAM_PVER}'${COLDEFAULT}"
898 local retval
899 retval=$(/home/tjoke/archlinux_version/vercomp "${UP2PVER}" "${UPSTREAM_PVER}")
900 [ ${retval} -eq 0 ] && echo -e "${PNAME}: ${COLGREEN}'${UP2PVER}' = '${UPSTREAM_PVER}'${COLDEFAULT}"
901 [ ${retval} -lt 0 ] && echo -e "${PNAME}: ${COLRED}'${UP2PVER}' < '${UPSTREAM_PVER}'${COLDEFAULT}"
902 [ ${retval} -gt 0 ] && echo -e "${PNAME}: ${COLYELLOW}'${UP2PVER}' > '${UPSTREAM_PVER}'${COLDEFAULT}"
903 fi
904 }
905
906 updateall()
907 {
908 #local REPOS
909 local PACKAGE
910 local smage
911 local repo
912 local UP2DATE_SLEEP_COUNT=0
913 local UP2DATE_SLEEP_TIMEOUT=0
914 local ONLY_PRINT_UPSTREAM=0
915
916 : ${REPOS="/home/tjoke/svn/smage/trunk/core /home/tjoke/svn/smage/trunk/extras /home/tjoke/svn/smage/trunk/nonfree /home/tjoke/svn/smage/trunk/todo"}
917 # REPOS="/home/tjoke/svn/smage/trunk/core /home/tjoke/svn/smage/trunk/extras"
918 # REPOS="/home/tjoke/svn/smage/trunk/core"
919 # PACKAGE="glibc-nptl"
920 # PACKAGE="autoconf21"
921 PACKAGE="*"
922 [[ ! -z $1 ]] && PACKAGE="$1"
923
924 if [[ $1 = --upstream ]] || [[ $1 = -u ]]
925 then
926 if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]]
927 then
928 echo "you must give me a smagefile."
929 exit 1
930 fi
931 updateme $1 $2
932 return 0
933 fi
934
935 ##############################################################################
936 # recurse all depends if requested
937 #
938 if [[ $1 = --depend ]] || [[ $1 = -d ]]
939 then
940 if [[ -z $2 ]] || [[ ${2##*.} != smage2 ]]
941 then
942 echo "you must give me a smagefile."
943 exit 1
944 fi
945
946 SMAGEFILE="$2"
947 PACKAGE="$(magename2pname ${SMAGEFILE})"
948
949 echo "processing '${SMAGEFILE}' ..."
950 echo "running dependency checks for package '${PACKAGE}'..."
951
952 DEPEND=$(get_value_from_magefile DEPEND ${SMAGEFILE})
953 SDEPEND=$(get_value_from_magefile SDEPEND ${SMAGEFILE})
954
955 declare -i c=0
956 while read sign dep
957 do
958 case ${dep} in
959 "") continue;;
960 esac
961
962 # sleep every 15 packages for 5 seconds
963 (( c++ ))
964 if [[ ${c} -eq ${UP2DATE_SLEEP_COUNT} ]]
965 then
966 declare -i c=0
967 echo "DEBUG: Sleep Count (${UP2DATE_SLEEP_COUNT}x) reached, sleeping for ${UP2DATE_SLEEP_TIMEOUT} seconds ..."
968 sleep ${UP2DATE_SLEEP_TIMEOUT}
969 fi
970 #echo "debug: ${dep}"
971 updateme "$(dep2pname ${dep})"
972 done << EOF
973 ${DEPEND}
974 ${SDEPEND}
975 EOF
976 fi
977 #
978 # eof recurse
979 ##############################################################################
980
981 for repo in ${REPOS}
982 do
983 # exclude not existing
984 [[ ${PACKAGE} != \* ]] && [[ ! -d ${repo}/${PACKAGE} ]] && continue
985
986 declare -i c=0
987 for smage in ${repo}/${PACKAGE}/*.smage2
988 do
989 updateme ${smage}
990
991 # sleep every 15 packages for 5 seconds
992 (( c++ ))
993 if [[ ${c} -eq ${UP2DATE_SLEEP_COUNT} ]]
994 then
995 declare -i c=0
996 echo "DEBUG: Sleep Count (${UP2DATE_SLEEP_COUNT}x) reached, sleeping for ${UP2DATE_SLEEP_TIMEOUT} seconds ..."
997 sleep ${UP2DATE_SLEEP_TIMEOUT}
998 fi
999 done
1000 done
1001 }
1002
1003 updateall $@

Properties

Name Value
svn:executable *