spk annotate spk-mirror @ rev 96

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