# HG changeset patch # User Christophe Lincoln # Date 1337369070 -7200 # Node ID d1790128faac4c14470017717a78380cbb32e353 # Parent 885b195a5d697612930f3ba664b1bc3b1f1cc79a bunch of improvments to download diff -r 885b195a5d69 -r d1790128faac lib/libspk.sh --- a/lib/libspk.sh Fri May 18 19:23:52 2012 +0200 +++ b/lib/libspk.sh Fri May 18 21:24:30 2012 +0200 @@ -110,6 +110,23 @@ done } +# Check if the download was sane +check_download() { + debug "check_download: $file" + if ! tail -c 2k $file | fgrep -q 00000000TRAILER; then + gettext "Continuing download of:"; echo " $file" + download "$file" $mirror + fi + # Check that the package has the correct checksum + local msum=$(fgrep " $package_full" $pkgsmd5) + local sum=$($CHECKSUM $file) + debug "mirror $SUM : $msum" + debug "local $SUM : $sum" + if [ "$sum" != "$msum" ]; then + rm -f $file && download "$file" $mirror + fi +} + # Download a file trying all mirrors # Usage: file [url|path] # @@ -122,40 +139,52 @@ local pwd=$(pwd) [ "$quiet" ] && local quiet="-q" [ "$cache" ] && local pwd=$CACHE_DIR + [ "$get" ] || local pwd=$CACHE_DIR [ "$forced" ] && rm -f $pwd/$file debug "download file: $file" debug "DB: $db" # Local mirror ? End by cd to cache, we may be installind. If --get # was used we dl/copy in the current dir. if [ -f "$uri/$file" ]; then - [ "$quiet" ] || echo "URI: $uri/" - [ "$get" ] || pwd=$CACHE_DIR - gettext "Local mirror:"; boldify " $file" - gettext "Copying file to:"; colorize " $pwd" 34 + [ "$verbose" ] && echo "URI: $uri/" + gettext "Using local mirror:"; boldify " $file" + [ "$verbose" ] && (gettext "Copying file to:"; colorize " $pwd" 34) cp -f $uri/$file $pwd cd $pwd && return 0 fi # In cache ? Root can use --cache to set destdir. - cd $CACHE_DIR if [ -f "$CACHE_DIR/$file" ]; then gettext "Using cache:"; colorize " ${file%.tazpkg}" 34 return 0 else - [ "$quiet" ] || echo "URL: $uri/" - gettext "Downloading:"; boldify " $file" - gettext "Destination:"; colorize " $pwd" 34 + [ "$verbose" ] && echo "URL: $uri/" + if [ "$db" == "$PKGS_DB" ]; then + gettext "Using official mirror:" + else + gettext "Using extra mirror:" + fi + boldify " $file" + [ "$verbose" ] && (gettext "Destination:"; colorize " $pwd" 34) if [ -f "$pwd/$file" ]; then echo "File exist: $pwd/$file" && return 0 fi + # TODO: be a spider with wget -s to check if package is on mirror, + # if not try all official mirrors ? wget $quiet -c $uri/$file -O $CACHE_DIR/$file + cd $CACHE_DIR && check_download fi # Be sure the file was fetched. if [ ! -f "$pwd/$file" ] || [ ! -f "$CACHE_DIR/$file" ]; then - gettext "ERROR: Missing file:"; colorize "$file" 31 + gettext "ERROR: Missing file:"; colorize " $file" 31 newline && exit 1 fi } +# Unser var set by mirrored_pkg +unset_mirrored() { + unset mirrored mirror db pwd +} + # Return the full package name, search in all packages.desc and break when # first occurance is found: Usage: full_package pkgname full_package() { diff -r 885b195a5d69 -r d1790128faac spk --- a/spk Fri May 18 19:23:52 2012 +0200 +++ b/spk Fri May 18 21:24:30 2012 +0200 @@ -6,8 +6,8 @@ # Copyright (C) SliTaz GNU/Linux - BSD License # Author: See AUTHORS files # -#. /usr/lib/slitaz/libspk.sh -. lib/libspk.sh +. /usr/lib/slitaz/libspk.sh +#. lib/libspk.sh # # Functions @@ -109,7 +109,7 @@ [ "$count" == 0 ] && newline count=$(($count + 1)) download $package_full $mirror - unset mirrored mirror db + unset_mirrored newline && continue ;; esac # Installed ? diff -r 885b195a5d69 -r d1790128faac spk-add --- a/spk-add Fri May 18 19:23:52 2012 +0200 +++ b/spk-add Fri May 18 21:24:30 2012 +0200 @@ -294,7 +294,14 @@ #fi # Check if package is mirrored - if ! mirrored_pkg $package_name; then + #if ! mirrored_pkg $package_name; then + #gettext "Could not find package on mirror:" + #boldify " $package_name" && exit 1 + #fi + + # Check if package is mirrored + mirrored_pkg $package_name + if [ ! "$mirrored" ]; then gettext "Could not find package on mirror:" boldify " $package_name" && exit 1 fi @@ -302,29 +309,11 @@ # We want: package-version.tazpkg local package_full=$(full_package $package_name) - #mirrored_pkg $package_name + # Let fetch the package by download() + [ "$count" == 1 ] && newline debug "spk-add package: $package_name" download "$package_full" $mirror - - #cd $CACHE_DIR || exit 1 - #if [ -f "$package_full" ]; then - #[ "$count" == 1 ] && newline - #gettext "Using cache:"; colorize " ${package_full%.tazpkg}" 34 - - ## Check package download was finished - #if ! tail -c 2k $package_full | fgrep -q 00000000TRAILER; then - #gettext "Continuing download of:"; echo " $package_name" - #download "$package_full" - #fi - - ## Check that the package has the correct checksum - ##if [ "$($CHECKSUM $package_full)" != "$(fgrep \" $package_full\" $pkgsmd5)" ]; then - ## rm -f $package.tazpkg - ## download "$package_full" - ##fi - #else - #newline && download "$package_full" $mirror - #fi + cd $CACHE_DIR # Create package path early to avoid dependencies loop mkdir -p $tmpdir @@ -336,6 +325,7 @@ #[ "$exec" ] && chroot $root/ $package_name [ "$exec" ] && $package_name $root update_databases + unset_mirrored } # Install all missing deps of a package.