From 29ee08162263dc202f04e3d956af152690e7ef09 Mon Sep 17 00:00:00 2001 From: Matteo Rossini Date: Sat, 19 Dec 2015 15:26:12 +0100 Subject: [PATCH] Version 1.6.0 - 19/Dec/2015 - Added CACHEUPDATE. You can now speedup the slackpkg update by caching metadata files. --- ChangeLog.txt | 4 ++ src/ChangeLog.txt | 4 ++ src/README | 20 +++++++++ src/slackpkgplus.sh | 75 +++++++++++++++++++++++++++++++++- src/slackpkgplus.x86.sample | 4 ++ src/slackpkgplus.x86_64.sample | 4 ++ 6 files changed, 110 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index cfbb8dd..7096946 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +Version 1.6.0 - 19/Dec/2015 + - Added CACHEUPDATE. You can now speedup the slackpkg update by caching + metadata files. + Version 1.5.2 - 18/Dec/2015 - Fixed a missed $ROOT - Added SHOWORDER option. It's a way to sort packages in dialog box to help diff --git a/src/ChangeLog.txt b/src/ChangeLog.txt index cfbb8dd..7096946 100644 --- a/src/ChangeLog.txt +++ b/src/ChangeLog.txt @@ -1,3 +1,7 @@ +Version 1.6.0 - 19/Dec/2015 + - Added CACHEUPDATE. You can now speedup the slackpkg update by caching + metadata files. + Version 1.5.2 - 18/Dec/2015 - Fixed a missed $ROOT - Added SHOWORDER option. It's a way to sort packages in dialog box to help diff --git a/src/README b/src/README index 1b469ed..68e0e2c 100644 --- a/src/README +++ b/src/README @@ -406,6 +406,23 @@ DOWNLOADCMD="aria2c -x 16 -s 16 --auto-file-renaming=false --allow-overwrite=tru if you have proxy add DOWNLOADCMD="aria2c --all-proxy=someproxy:8080 -x 16 -s 16 --auto-file-renaming=false --allow-overwrite=true -d / -o" +----- + +CACHEUPDATE Option + +By default 'slackpkg update' download all metadata files (CHECKSUMS.md5, PACKAGES.TXT, +MANIFEST.bz2). When you use many and or large repositories, this may take a lot of +time and in most cases there are no news or news just in only one repository. + +Enabling CACHEUPDATE slackpkg+ put a cache of metadatas in /var/lib/slackpkg/cache, +so everytime it just must to verify if there is a new version, otherwise it can use +the cached file. + +Note that it works only with http repositories and does not work with proxies. +It uses 'curl' to download file headers to check if there is a new version of +the file. + +Set CACHEUPDATE=on to enable it. Default is 'off' ----- @@ -455,6 +472,9 @@ SENSITIVE_SEARCH=off slackpkg search mplayer Note tha 'slackpkg install' still remains case sensitive, so you must use slackpkg install MPlayer +WARNING: do NOT run 'slackpkg search slackpkg' with SENSITIVE_SEARCH=on. It +may take a very lot of time! + ----- SHOWORDER diff --git a/src/slackpkgplus.sh b/src/slackpkgplus.sh index d6304dc..c908a62 100755 --- a/src/slackpkgplus.sh +++ b/src/slackpkgplus.sh @@ -21,6 +21,7 @@ if [ -e $CONF/slackpkgplus.conf ];then EXTDOWNLOADCMD=$DOWNLOADCMD EXTTAG_PRIORITY=$TAG_PRIORITY EXTSENSITIVE_SEARCH=$SENSITIVE_SEARCH + EXTCACHEUPDATE=$CACHEUPDATE . $CONF/slackpkgplus.conf @@ -33,6 +34,7 @@ if [ -e $CONF/slackpkgplus.conf ];then DOWNLOADCMD=${EXTDOWNLOADCMD:-$DOWNLOADCMD} TAG_PRIORITY=${EXTTAG_PRIORITY:-$TAG_PRIORITY} SENSITIVE_SEARCH=${EXTSENSITIVE_SEARCH:-$SENSITIVE_SEARCH} + CACHEUPDATE=${EXTCACHEUPDATE:-$CACHEUPDATE} USEBLACKLIST=true if [ "$USEBL" == "0" ];then @@ -51,7 +53,7 @@ if [ "$SLACKPKGPLUS" = "on" ];then - SPKGPLUS_VERSION="1.5.2" + SPKGPLUS_VERSION="1.6.0" VERSION="$VERSION / slackpkg+ $SPKGPLUS_VERSION" @@ -63,7 +65,16 @@ if [ "$SLACKPKGPLUS" = "on" ];then touch $WORKDIR/install.log fi + if [ "$CMD" == "update" ];then + ANSWER="Y" + fi + function cleanup(){ + if [ "$CMD" == "update" ];then + if [ "$ANSWER" != "Y" ] && [ "$ANSWER" != "y" ]; then + touch $WORKDIR/pkglist + fi + fi [ "$SPINNING" = "off" ] || tput cnorm if [ "$DELALL" = "on" ] && [ "$NAMEPKG" != "" ]; then rm $CACHEPATH/$NAMEPKG &>/dev/null @@ -960,6 +971,59 @@ function showlist() { } # END wgetdebug() + function cached_downloader(){ + local SRCURL + local CACHEFILE + local SRCBASE + SRCURL=$2 + SRCBASE=$(basename $SRCURL) + CACHEFILE=$(echo $SRCURL|md5sum|awk '{print $1}') + + case $SRCBASE in + CHECKSUMS.md5) TOCACHE=1 ;; + MANIFEST.bz2) TOCACHE=1 ;; + PACKAGES.TXT) TOCACHE=1 ;; + *) TOCACHE=0 ;; + esac + + if [ $TOCACHE -eq 1 ];then + echo + echo "=== check cache: $SRCURL ===" + echo -n "headers.. " + curl --location --head $SRCURL 2>/dev/null|grep -v ^Date:|sed 's/ //' > $TMPDIR/cache.head + echo "Url: $SRCURL" >> $TMPDIR/cache.head + grep -q "200 OK" $TMPDIR/cache.head || echo "Header or Url Invalid!!! (`date`)" + [ $VERBOSE -eq 3 ]&&cat $TMPDIR/cache.head|sed 's/^/ /' + if [ -e $CACHEDIR/$CACHEFILE -a -e $CACHEDIR/$CACHEFILE.head ];then + echo "Is cached.. " + [ $VERBOSE -eq 3 ]&&cat $CACHEDIR/$CACHEFILE.head|sed 's/^/ /' + if diff $CACHEDIR/$CACHEFILE.head $TMPDIR/cache.head >/dev/null;then + echo "Cache valid! If not please remove manually $CACHEDIR/$CACHEFILE !" + cp $CACHEDIR/$CACHEFILE $1 + return $? + fi + echo -n "Invalid.. " + rm -f $CACHEDIR/$CACHEFILE $CACHEDIR/$CACHEFILE.head + fi + echo "Download file.. " + $CACHEDOWNLOADER $1 $SRCURL + ERR=$? + if [ "$(ls -l $1 2>/dev/null|awk '{print $5}')" == "$(grep Content-Length: $TMPDIR/cache.head|awk '{print $2}')" ];then + echo "Caching it!" + cp $1 $CACHEDIR/$CACHEFILE + cp $TMPDIR/cache.head $CACHEDIR/$CACHEFILE.head + else + echo "NOT cacheable!" + fi + else + echo + echo "=== no caching for $SRCURL ===" + $CACHEDOWNLOADER $1 $SRCURL + ERR=$? + fi + return $ERR + + } # END cached_downloader() if [ ! -z "$DOWNLOADCMD" ];then DOWNLOADER="$DOWNLOADCMD" @@ -976,6 +1040,15 @@ function showlist() { fi fi + if [ "$CMD" == "update" -a "$CACHEUPDATE" == "on" ];then + CACHEDOWNLOADER=$DOWNLOADER + CACHEDIR=$WORKDIR/cache + mkdir -p $CACHEDIR + find $CACHEDIR -mtime +30 -exec rm -f {} \; + DOWNLOADER="cached_downloader" + fi + + # Global variable required by givepriority() # PRIORITYIDX=1 diff --git a/src/slackpkgplus.x86.sample b/src/slackpkgplus.x86.sample index d054077..3d91722 100644 --- a/src/slackpkgplus.x86.sample +++ b/src/slackpkgplus.x86.sample @@ -22,6 +22,10 @@ WGETOPTS="--timeout=20 --tries=2" # at /usr/doc/slackpkg+-*/README #DOWNLOADCMD="wget -O" +# Use the cache for metadata files (CHECKSUMS.md5,...). Enable it (on) to speedup the slackpkg update +# process by downloading just new files (see README). Disabled by default (off) +CACHEUPDATE=off + # Enable (on) / Disable (off) notification events (see notifymsg.conf) #ENABLENOTIFY=off diff --git a/src/slackpkgplus.x86_64.sample b/src/slackpkgplus.x86_64.sample index fa93091..92e10a5 100644 --- a/src/slackpkgplus.x86_64.sample +++ b/src/slackpkgplus.x86_64.sample @@ -30,6 +30,10 @@ WGETOPTS="--timeout=20 --tries=2" # at /usr/doc/slackpkg+-*/README #DOWNLOADCMD="wget -O" +# Use the cache for metadata files (CHECKSUMS.md5,...). Enable it (on) to speedup the slackpkg update +# process by downloading just new files (see README). Disabled by default (off) +CACHEUPDATE=off + # Enable (on) / Disable (off) notification events (see notifymsg.conf) #ENABLENOTIFY=off