Magellan Linux

Contents of /branches/mage-next/src/tools/up2date.in

Parent Directory Parent Directory | Revision Log Revision Log


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