spk view spk-mirror @ rev 131

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