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