Magellan Linux

Contents of /branches/mage-next/src/up2date/common.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2591 - (show annotations) (download)
Tue Mar 4 08:35:27 2014 UTC (10 years, 3 months ago) by niro
File size: 2000 byte(s)
-split function into single includes
1 urlencode()
2 {
3 local uri="$@"
4
5 # fix percent (do this first!!)
6 uri=$(echo ${uri} | sed 's:%:%25:g')
7
8 # fix spaces
9 uri=$(echo ${uri} | sed 's:\ :%20:g')
10
11 # fix less than
12 uri=$(echo ${uri} | sed 's:<:%3C:g')
13
14 # fix greater than
15 uri=$(echo ${uri} | sed 's:>:%3E:g')
16
17 # fix pound
18 uri=$(echo ${uri} | sed 's:#:%23:g')
19
20 # fix curly brace left
21 uri=$(echo ${uri} | sed 's:{:%7B:g')
22
23 # fix curly brace right
24 uri=$(echo ${uri} | sed 's:}:%7D:g')
25
26 # fix square bracket left
27 uri=$(echo ${uri} | sed 's:\[:%5B:g')
28
29 # fix square bracket right
30 uri=$(echo ${uri} | sed 's:\]:%5D:g')
31
32
33 # return
34 echo "${uri}"
35 }
36
37 upsort()
38 {
39 local allversions="$@"
40 [[ -n ${allversions} ]] || die "upsort(): no versions given"
41
42 if [ -x ${MLIBDIR}/highestver ]
43 then
44 ${MLIBDIR}/highestver ${allversions}
45 else
46 for i in ${allversions}
47 do
48 echo "${i}"
49 done | sort -g | tac | head -n 1
50 fi
51 }
52
53 upsort_pipe()
54 {
55 local data
56 local versions
57
58 versions=""
59 while read data
60 do
61 versions+="${data} "
62 done
63
64 upsort ${versions}
65 }
66
67 tarballversions()
68 {
69 local suffix=bz2
70 local seperator="-"
71 [[ ! -z $1 ]] && suffix="$1"
72 local data
73 local version
74
75 [[ ! -z ${UP2SEPERATOR} ]] && seperator="${UP2SEPERATOR}"
76 [[ ${UP2SEPERATOR} = NULL ]] && seperator=""
77
78 case ${suffix} in
79 tbz2|tgz|zip)
80 if [[ ! -z ${UP2EXCLUDE} ]]
81 then
82 grep "\(\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/"
83 else
84 grep "\(\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.${suffix}\).*/\1/"
85 fi
86 ;;
87 *)
88 if [[ ! -z ${UP2EXCLUDE} ]]
89 then
90 grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | grep -v -- "${UP2EXCLUDE}" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/"
91 else
92 grep "\(\.tar\.${suffix}\)\(\$\|\#\)" | sed "s/.*${seperator}\(.*\)\(\.tar\.${suffix}\).*/\1/"
93 fi
94 ;;
95 esac
96 }
97
98 highesttarball()
99 {
100 tarballversions $@ | upsort_pipe
101 }
102
103 lasttarball()
104 {
105 tarballversions $@ | sed -n "$ p"
106 }
107
108 firsttarball()
109 {
110 tarballversions $@ | sed "q"
111 }