# HG changeset patch # User Christophe Lincoln # Date 1337361832 -7200 # Node ID 885b195a5d697612930f3ba664b1bc3b1f1cc79a # Parent 63fb720dc777143a1d15fcfb13766664c673eb84 libspk.sh and spk-add: better but not finished download function, spk: add option --get and command clean diff -r 63fb720dc777 -r 885b195a5d69 lib/libspk.sh --- a/lib/libspk.sh Fri May 18 06:36:19 2012 +0200 +++ b/lib/libspk.sh Fri May 18 19:23:52 2012 +0200 @@ -99,33 +99,61 @@ # Check if package is on main or extra mirror. mirrored_pkg() { local name=$1 - local find=$(grep "^$name |" $pkgsdesc $extradb/*/*.desc 2>/dev/null) - [ -n "$find" ] + #local find=$(grep "^$name |" $pkgsdesc $extradb/*/*.desc 2>/dev/null) + for desc in $(find $extradb $pkgsdesc -name packages.desc); do + if grep -q "^$name |" $desc; then + db=$(dirname $desc) + mirrored=$(grep "^$name |" $desc) + mirror=$(cat $db/mirror) + break + fi + done } # Download a file trying all mirrors -# Parameters: package/file +# Usage: file [url|path] # -# We should do much better here, give priority to extra, then try -# main mirror, then try others official mirrors. The case $file is -# not needed since we use same URL for list or packages. +# Priority to extra is done by mirrored_pkg wich try first to find the +# packages in extra mirror, then on official. # download() { local file=$1 - local mirror="$(cat $mirrorurl)" + local uri="${2%/}" + local pwd=$(pwd) [ "$quiet" ] && local quiet="-q" - case "$file" in - *.tazpkg) - [ "$quiet" ] || echo "URL: ${mirror%/}/" - gettext "Downloading:"; boldify " $file" - wget $quiet -c ${mirror%/}/$file - if [ ! -f "$file" ]; then - gettext "ERROR: Missing package:"; boldify "$package" - newline && exit 1 - fi ;; - ID|packages.*|files.list.lzma) - echo "TODO" ;; - esac + [ "$cache" ] && 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 + 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 + if [ -f "$pwd/$file" ]; then + echo "File exist: $pwd/$file" && return 0 + fi + wget $quiet -c $uri/$file -O $CACHE_DIR/$file + fi + # Be sure the file was fetched. + if [ ! -f "$pwd/$file" ] || [ ! -f "$CACHE_DIR/$file" ]; then + gettext "ERROR: Missing file:"; colorize "$file" 31 + newline && exit 1 + fi } # Return the full package name, search in all packages.desc and break when @@ -133,7 +161,6 @@ full_package() { for desc in $(find $extradb $pkgsdesc -name packages.desc); do local line="$(grep "^$1 |" $desc)" - local db=$(dirname $desc) if grep -q "^$1 |" $desc; then IFS="|" echo $line | busybox awk '{print $1 "-" $2 ".tazpkg"}' diff -r 63fb720dc777 -r 885b195a5d69 spk --- a/spk Fri May 18 06:36:19 2012 +0200 +++ b/spk Fri May 18 19:23:52 2012 +0200 @@ -6,7 +6,8 @@ # Copyright (C) SliTaz GNU/Linux - BSD License # Author: See AUTHORS files # -. /usr/lib/slitaz/libspk.sh +#. /usr/lib/slitaz/libspk.sh +. lib/libspk.sh # # Functions @@ -24,13 +25,17 @@ $(boldify $(gettext "Commands:")) info $(gettext "Display path, mirror and other stats") activity $(gettext "Display packages activities") + clean $(gettext "Clean cache and temporary files") $(boldify $(gettext "Options:")) --add $(gettext "Install packages if mirrored") --rm $(gettext "Remove installed packages") + --get $(gettext "Download packages specified on cmdline") --block $(gettext "Add packages to the blocked list") --unblock $(gettext "Remove packages from the blocked list") --log $(gettext "Show package install and upgrade log") + --cache $(gettext "Used with --get to download in cache") + --forced $(gettext "Force packages reinstall or download") --root= $(gettext "Set the root file system path") --debug $(gettext "Display some usefull debug information") @@ -72,17 +77,41 @@ cat $activity | tail -n $lines separator && newline exit 0 ;; + clean) + newline + boldify "Spk Clean" + separator + size=$(du -sh $CACHE_DIR | awk '{print $1}') + gettext "Cleaning cache:"; echo -n " $CACHE_DIR ($size)" + rm -rf $CACHE_DIR/* && status + gettext "Cleaning tmp :"; echo -n " $(dirname $tmpdir)" + rm -rf $(dirname $tmpdir) && status + separator && newline + exit 0 ;; esac # # Handle packages: spk package1 ... packageN # -debug "cmdline: $@" +#debug "cmdline: $@" count=0 for pkg in $@ do + # Handle general: --options + case " $@ " in + *\ --get\ *) + # We want: package-version.tazpkg + package_full=$(full_package $pkg) + mirrored_pkg $pkg + [ "$mirrored" ] || continue + [ "$count" == 0 ] && newline + count=$(($count + 1)) + download $package_full $mirror + unset mirrored mirror db + newline && continue ;; + esac # Installed ? if [ -d "$installed/$pkg" ]; then # Handle: --options @@ -130,7 +159,7 @@ separator cat $logdir/$pkg/up.log else - gettext "Any upgrade log for:"; boldify " $pkg" + colorize "$(gettext "Any upgrade log for:"; echo " $pkg")" 36 newline fi && continue ;; esac @@ -146,9 +175,9 @@ continue fi # Mirrored ? - mirrored=$(grep "^$pkg |" $pkgsdesc) + mirrored_pkg $pkg if [ "$mirrored" ]; then - # Handle: --options + # Handle mirrored: --options case " $@ " in *\ --add\ *) spk-add $pkg --count=$count @@ -167,6 +196,7 @@ separator && newline continue fi + unset mirrored # Skip options such as --confirm or unknow package case "$pkg" in --*) continue ;; diff -r 63fb720dc777 -r 885b195a5d69 spk-add --- a/spk-add Fri May 18 06:36:19 2012 +0200 +++ b/spk-add Fri May 18 19:23:52 2012 +0200 @@ -288,10 +288,10 @@ local package_name="$1" # Check if get-Package - if mirrored_pkg get-$package_name; then - package_name="get-$package_name" - exec=true - fi + #if mirrored_pkg get-$package_name; then + #package_name="get-$package_name" + #exec=true + #fi # Check if package is mirrored if ! mirrored_pkg $package_name; then @@ -302,25 +302,29 @@ # We want: package-version.tazpkg local package_full=$(full_package $package_name) - cd $CACHE_DIR || exit 1 - if [ -f "$package_full" ]; then - [ "$count" == 1 ] && newline - gettext "Using cache:"; colorize " ${package_full%.tazpkg}" 34 + #mirrored_pkg $package_name + debug "spk-add package: $package_name" + download "$package_full" $mirror - # 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 + #cd $CACHE_DIR || exit 1 + #if [ -f "$package_full" ]; then + #[ "$count" == 1 ] && newline + #gettext "Using cache:"; colorize " ${package_full%.tazpkg}" 34 - # Check that the package has the correct checksum - #if [ "$($CHECKSUM $package_full)" != "$(fgrep \" $package_full\" $pkgsmd5)" ]; then - # rm -f $package.tazpkg - # download "$package_full" + ## 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 - else - newline && 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 # Create package path early to avoid dependencies loop mkdir -p $tmpdir diff -r 63fb720dc777 -r 885b195a5d69 spk-mirror --- a/spk-mirror Fri May 18 06:36:19 2012 +0200 +++ b/spk-mirror Fri May 18 19:23:52 2012 +0200 @@ -153,7 +153,7 @@ do [ -d "$url" ] && url="dir:$url" case "$url" in - http://*|ftp://) + http://*|ftp://|local) [ "$count" == 0 ] && newline count=$(($count + 1)) url="${url%/}/"