spk view spk-mirror @ rev 95
spk-up: improve extra local package
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Fri May 25 16:42:10 2012 +0200 (2012-05-25) |
parents | f98429058c26 |
children | 7da09d0db03c |
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 31 " $file"
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 "Extra DB : "$(boldify $db)
69 echo "Extra URL : "$(cat $extradb/$db/mirror)
70 gettext "Packages :"; colorize 32 " $nb"
71 }
73 # Add a package to packages.* lists
74 addto_list() {
75 cd $pkgsdir
77 # We need ARCH set the get correct version.
78 ARCH=$(fgrep ARCH= /etc/slitaz/cook.conf | cut -d "\"" -f 2)
79 case "$ARCH" in
80 arm|x86_64) arch="-${ARCH}" ;;
81 esac
83 echo "$PACKAGE-${VERSION}${EXTRAVERSION}${arch}" >> packages.list
84 $CHECKSUM $(basename $pkg) >> packages.$SUM
85 #
86 # Add PACKED_SIZE UNPACKED_SIZE to know packages size before installing ???
87 # --> actually done via packages.txt. Use: ${VERSION}${EXTRAVERSION}${arch} ???
88 #
89 echo "$PACKAGE | ${VERSION}$EXTRAVERSION | $SHORT_DESC | $CATEGORY | $WEB_SITE" \
90 >> packages.desc
92 # packages.equiv is used by tazpkg install to check depends.
93 touch packages.equiv
94 for i in $PROVIDE; do
95 unset dest
96 echo $i | fgrep -q : && dest="${i#*:}:"
97 if grep -qs ^${i%:*}= packages.equiv; then
98 sed -i "s/^${i%:*}=/${i%:*}=${dest}$PACKAGE /" packages.equiv
99 else
100 echo "${i%:*}=${dest}$PACKAGE" >> packages.equiv
101 fi
102 done
103 # files.list provides a list of all packages files.
104 cat $tmpdir/files.list | sed s/^/"$PACKAGE: \0"/ >> $pkgsdir/files.list
105 cd - > /dev/null
106 }
108 #
109 # Commands
110 #
112 cmd=$1
113 [ -d "$cmd" ] && cmd=continue
115 case "$cmd" in
116 *usage|*help) usage ;;
117 http://*|ftp://|'continue') continue ;;
118 undigest)
119 echo "TODO: enable official undigest repo" ;;
120 ""|--list)
121 extra=0
122 excolor=32
123 newline
124 boldify "Mirror info"
125 separator
126 gettext "Main URL :"
127 boldify " $(cat $mirrorurl)"
128 if [ -f "$mirrors" ]; then
129 nb=$(cat $mirrors | wc -l)
130 gettext "Mirrors :"; colorize $excolor " $nb "
131 fi
132 if [ -d "$extradb" ]; then
133 extra=$(ls $extradb | wc -l)
134 fi
135 [ "$extra" != 0 ] || excolor=31
136 gettext "Extra :"; colorize $excolor " $extra"
137 separator
138 newline
139 if [ "$list" ]; then
140 boldify $(gettext "Official mirrors")
141 separator
142 cat $mirrors
143 separator && newline
144 if [ "$extra" != "0" ]; then
145 boldify $(gettext "Extra mirrors")
146 separator
147 cat $extradb/*/mirror
148 separator && newline
149 fi
150 fi
151 exit 0 ;;
152 esac
154 #
155 # Handle all urls
156 #
158 count=0
160 for url in $@
161 do
162 [ -d "$url" ] && url="dir:$url"
163 case "$url" in
164 http://*|ftp://|local)
165 [ "$count" == 0 ] && newline
166 count=$(($count + 1))
167 url="${url%/}/"
168 debug "checking: $url"
169 # Remove extra on --rm
170 if [ "$rm" ]; then
171 extra_db
172 if [ -d "$extradb/$db" ]; then
173 gettext "Removing extra mirror:"
174 echo -n " $(boldify $db)"
175 rm -rf $extradb/$db && status
176 else
177 gettext "Not an extra mirror:"; colorize 31 " $db"
178 fi
179 newline && continue
180 fi
181 # Official mirror
182 if fgrep -q "$url" $mirrors; then
183 gettext "Enabling: official mirror"; newline
184 gettext "Architecture:"; echo " $SLITAZ_ARCH"
185 # Handle arch type
186 case "$SLITAZ_ARCH" in
187 arm|x86_64) arch="$SLITAZ_ARCH/" ;;
188 i486) arch="/" ;;
189 esac
190 url=${url}packages/${SLITAZ_RELEASE}${arch}
191 echo "URL: $(boldify $url)"
192 echo "$url" > $mirrorurl
193 newline && continue
194 fi
195 # Extra mirror
196 extra_db
197 if [ -d "$extradb/$db" ]; then
198 gettext "Extra mirror already exist"; newline
199 extra_info $db
200 else
201 boldify $(gettext "Enabling: extra mirror")
202 separator
203 echo "URL: $(boldify $url)"
204 if ! check_mirror $url; then
205 continue
206 fi
207 mkdir -p $extradb/$db
208 echo "$url" > $extradb/$db/mirror
209 separator
210 gettext "New extra mirror is ready to use"; newline
211 fi
212 newline ;;
213 dir:*)
214 # Handle local mirror
215 dir=${url#dir:}
216 pkgsdir=${dir%/}
217 debug "dir: $dir"
218 nb=$(ls $pkgsdir/*.tazpkg 2>/dev/null | wc -l)
219 if [ "$nb" == 0 ]; then
220 gettext "No packages found in:"; boldify " $pkgsdir"
221 continue
222 fi
223 newline
224 gettext "Directory:"; boldify " $pkgsdir"
225 gettext "Packages :"; colorize 32 " $nb"
226 cd $pkgsdir
227 if [ ! "$nodb" ]; then
228 time=$(date +%s)
229 rm -f packages.* ID *.lzma
230 newline
231 boldify $(gettext "Creating packages lists")
232 separator
233 for pkg in $pkgsdir/*.tazpkg
234 do
235 gettext "Extracting data:"; echo -n " $(basename $pkg)"
236 mkdir -p $tmpdir
237 extract_receipt $tmpdir $pkg
238 extract_fileslist $tmpdir $pkg
239 source $tmpdir/receipt
240 addto_list && status
241 unset_receipt
242 rm -rf $tmpdir
243 done
244 # files.list.lzma
245 gettext "Compressing the files.list..."
246 lzma e files.list files.list.lzma
247 rm -f files.list
248 status
249 # ID
250 gettext "Creating uniq identity ID..."
251 $CHECKSUM packages.$SUM | cut -d ' ' -f 1 > ID
252 status
253 # Summary
254 separator
255 time=$(($(date +%s) - $time))
256 echo -n "$nb "
257 gettext "packages added in"
258 echo " ${time}s ("$(date "+%Y%m%d %H:%M")")"
259 fi
260 newline
261 # Handle --extra: Use local repo as extra mirror with symlinks
262 # to packages lists.
263 if [ "$extra" ]; then
264 boldify $(gettext "Enabling extra local mirror")
265 separator
266 db=$extradb/local
267 debug "database: $db"
268 mkdir -p $db && rm -f $db/*
269 echo "$pkgsdir/" > $db/mirror
270 for list in packages.*
271 do
272 echo -n $(gettext "Linking:") $list
273 ln -s $pkgsdir/$list $db/$list
274 status
275 done
276 gettext "Copying: ID (uniq identity)"
277 cp $pkgsdir/ID $db && status
278 separator && newline
279 fi ;;
280 --*) continue ;;
281 *)
282 [ "$count" == 0 ] && newline
283 count=$(($count + 1))
284 # Should we handle --rm also here ?
285 if [ -d "$extradb/$url" ]; then
286 extra_info $(basename $extradb/$url)
287 newline && continue
288 fi
289 gettext "Can't handle:"
290 colorize 31 " $url"; newline ;;
291 esac
292 done
294 exit 0