spk view spk-mirror @ rev 68
bunch of improvments to download
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 18 21:24:30 2012 +0200 (2012-05-18) |
parents | 36c7fb7707d0 |
children | 0cb21eb5cf20 |
line source
1 #!/bin/sh
2 #
3 # Spk-mirror - Handle SliTaz packages mirrors. Read the README before
4 # adding or modifing any code in spk!
5 #
6 # Copyright (C) SliTaz GNU/Linux - BSD License
7 # Author: See AUTHORS files
8 #
9 . /usr/lib/slitaz/libspk.sh
11 # NOTE: I want to use 'extra' mirrors since we can add any extra mirror
12 # URL's and not only undigest. See also undigest command - Pankso
14 #
15 # Functions
16 #
18 # Help and usage
19 usage() {
20 name=$(basename $0)
21 cat << EOT
23 $(boldify $(gettext "Usage:")) $name [urls|info|--options]
25 $(gettext "Handle SliTaz packages mirrors")
27 $(boldify $(gettext "Options:"))
28 --list
29 --rm
30 --nodb
31 --extra
32 --debug
34 $(boldify $(gettext "Examples:"))
35 $name http://mirror.slitaz.org/
36 $name /path/to/packages --nodb --extra
38 EOT
39 exit 0
40 }
42 # Check if we have packages ID and lists on mirror.
43 check_mirror() {
44 for file in packages.list packages.$SUM packages.desc ID
45 do
46 gettext "Checking file:"; echo -n " $file"
47 if ! wget -q -s -T 6 ${1}${list} 2>/dev/null; then
48 newline
49 gettext "Unable to reach:"; colorize " $file" 31
50 newline && return 1
51 fi
52 status
53 done
54 }
56 # Get extra mirror DB path
57 extra_db() {
58 db=$(echo ${url#*://} | cut -d "/" -f1 )
59 debug "extra mirror: $url"
60 debug "extra DB: $db"
61 }
63 # Display info about an extra repo
64 extra_info() {
65 local db=$1
66 debug "extra DB: $extradb/$db"
67 nb=$(cat $extradb/$db/packages.$SUM 2>/dev/null | wc -l)
68 echo -n "Extra DB :"; boldify " $db"
69 echo -n "Extra URL :"; echo " $(cat $extradb/$db/mirror)"
70 gettext "Packages :"; colorize " $nb" 32
71 }
73 # Add a package to packages.* lists
74 addto_list() {
75 cd $pkgsdir
76 echo "$PACKAGE-${VERSION}${EXTRAVERSION}" >> packages.list
77 $CHECKSUM $(basename $pkg) >> packages.$SUM
78 #
79 # Add PACKED_SIZE UNPACKED_SIZE to know packages size
80 # before installing ??? --> actually done via packages.txt
81 #
82 cat >> packages.desc << EOT
83 $PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE
84 EOT
85 # packages.equiv is used by tazpkg install to check depends.
86 touch packages.equiv
87 for i in $PROVIDE; do
88 dest=""
89 echo $i | fgrep -q : && dest="${i#*:}:"
90 if grep -qs ^${i%:*}= packages.equiv; then
91 sed -i "s/^${i%:*}=/${i%:*}=${dest}$PACKAGE /" packages.equiv
92 else
93 echo "${i%:*}=${dest}$PACKAGE" >> packages.equiv
94 fi
95 done
96 # files.list provides a list of all packages files.
97 cat $tmpdir/files.list | sed s/^/"$PACKAGE: \0"/ >> $pkgsdir/files.list
98 }
100 #
101 # Commands
102 #
104 cmd=$1
105 [ -d "$cmd" ] && cmd=continue
107 case "$cmd" in
108 *usage|*help) usage ;;
109 http://*|ftp://|'continue') continue ;;
110 undigest)
111 echo "TODO: enable official undigest repo" ;;
112 ""|--list)
113 extra=0
114 excolor=32
115 newline
116 boldify "Mirror info"
117 separator
118 gettext "Main URL :"
119 boldify " $(cat $mirrorurl)"
120 if [ -f "$mirrors" ]; then
121 nb=$(cat $mirrors | wc -l)
122 gettext "Mirrors :"; colorize " $nb " $excolor
123 fi
124 if [ -d "$extradb" ]; then
125 extra=$(ls $extradb | wc -l)
126 fi
127 [ "$extra" != 0 ] || excolor=31
128 gettext "Extra :"; colorize " $extra" $excolor
129 separator
130 newline
131 if [ "$list" ]; then
132 boldify $(gettext "Official mirrors")
133 separator
134 cat $mirrors
135 separator && newline
136 if [ "$extra" != "0" ]; then
137 boldify $(gettext "Extra mirrors")
138 separator
139 cat $extradb/*/mirror
140 separator && newline
141 fi
142 fi
143 exit 0 ;;
144 esac
146 #
147 # Handle all urls
148 #
150 count=0
152 for url in $@
153 do
154 [ -d "$url" ] && url="dir:$url"
155 case "$url" in
156 http://*|ftp://|local)
157 [ "$count" == 0 ] && newline
158 count=$(($count + 1))
159 url="${url%/}/"
160 debug "checking: $url"
161 # Remove extra on --rm
162 if [ "$rm" ]; then
163 extra_db
164 if [ -d "$extradb/$db" ]; then
165 gettext "Removing extra mirror:"
166 echo -n " $(boldify "$db")"
167 rm -rf $extradb/$db && status
168 else
169 gettext "Not an extra mirror:"; colorize " $db" 31
170 fi
171 newline && continue
172 fi
173 # Official mirror
174 if fgrep -q "$url" $mirrors; then
175 gettext "Enabling: official mirror"; newline
176 gettext "Architecture:"; echo " $SLITAZ_ARCH"
177 # Handle arch type
178 case "$SLITAZ_ARCH" in
179 arm|x86_64) arch="$SLITAZ_ARCH/" ;;
180 i486) arch="/" ;;
181 esac
182 url=${url}packages/${SLITAZ_RELEASE}${arch}
183 echo "URL: $(boldify "$url")"
184 echo "$url" > $mirrorurl
185 newline && continue
186 fi
187 # Extra mirror
188 extra_db
189 if [ -d "$extradb/$db" ]; then
190 gettext "Extra mirror already exist"; newline
191 extra_info $db
192 else
193 boldify $(gettext "Enabling: extra mirror")
194 separator
195 echo "URL: $(boldify "$url")"
196 if ! check_mirror $url; then
197 continue
198 fi
199 mkdir -p $extradb/$db
200 echo "$url" > $extradb/$db/mirror
201 separator
202 gettext "New extra mirror is ready to use"; newline
203 fi
204 newline ;;
205 dir:*)
206 # Handle local mirror
207 dir=${url#dir:}
208 pkgsdir=${dir%/}
209 debug "dir: $dir"
210 nb=$(ls $pkgsdir/*.tazpkg 2>/dev/null | wc -l)
211 if [ "$nb" == 0 ]; then
212 gettext "No packages found in:"; boldify " $pkgsdir"
213 continue
214 fi
215 newline
216 gettext "Directory:"; boldify " $pkgsdir"
217 gettext "Packages :"; colorize " $nb" 32
218 cd $pkgsdir
219 if [ ! "$nodb" ]; then
220 time=$(date +%s)
221 rm -f packages.* ID *.lzma
222 newline
223 boldify $(gettext "Creating packages lists")
224 separator
225 for pkg in $pkgsdir/*.tazpkg
226 do
227 gettext "Extracting data:"; echo -n " $(basename $pkg)"
228 mkdir -p $tmpdir
229 extract_receipt $tmpdir $pkg
230 extract_fileslist $tmpdir $pkg
231 source $tmpdir/receipt
232 addto_list && status
233 unset_receipt
234 rm -rf $tmpdir
235 done
236 # files.list.lzma
237 gettext "Compressing the files.list..."
238 lzma e files.list files.list.lzma
239 rm -f files.list
240 status
241 # ID
242 gettext "Creating uniq identity ID..."
243 $CHECKSUM packages.$SUM | cut -d ' ' -f 1 > ID
244 status
245 # Summary
246 separator
247 time=$(($(date +%s) - $time))
248 echo -n "$nb "
249 gettext "packages added in"
250 echo " ${time}s ($(date "+%Y%m%d %H:%M"))"
251 fi
252 newline
253 # Handle --extra: Use local repo as extra mirror with symlinks
254 # to packages lists.
255 if [ "$extra" ]; then
256 boldify $(gettext "Enabling extra local mirror")
257 separator
258 db=$extradb/local
259 debug "database: $db"
260 mkdir -p $db && rm -f $db/*
261 echo "$pkgsdir/" > $db/mirror
262 for list in packages.*
263 do
264 gettext "Linking:"; echo -n " $list"
265 ln -s $pkgsdir/$list $db/$list
266 status
267 done
268 gettext "Copying: ID (uniq identity)"
269 cp $pkgsdir/ID $db && status
270 separator && newline
271 fi ;;
272 --*) continue ;;
273 *)
274 [ "$count" == 0 ] && newline
275 count=$(($count + 1))
276 # Should we handle --rm also here ?
277 if [ -d "$extradb/$url" ]; then
278 extra_info $(basename $extradb/$url)
279 newline && continue
280 fi
281 gettext "Can't handle:"
282 colorize " $url" 31 && newline ;;
283 esac
284 done
286 exit 0