From 310cf13f67c45a13224de8ea2e3d613aaabc5745 Mon Sep 17 00:00:00 2001 From: Geert Janssens Date: Thu, 22 Apr 2010 09:25:51 +0000 Subject: [PATCH] * Make sure wget downloads are stored with filenames not containing any html garbage (& and = signs as a result of http_get parameters). * Have wget_unpacked return the actual path where the files were unpacked via the _EXTRACT_UDIR env variable. In most cases this is simply the path that was requested, but sometimes, a tarball or zip file adds its own relative path. The _EXTRACT_UDIR variable will take this into account by analysing the contents of the tarball/zip file. These changes will be used in the revived cross-compile script. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19048 57a11ea4-9604-0410-9ed3-97b8803252fd --- packaging/win32/functions.sh | 42 ++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/packaging/win32/functions.sh b/packaging/win32/functions.sh index 7a04580826..e78d9ca8c1 100644 --- a/packaging/win32/functions.sh +++ b/packaging/win32/functions.sh @@ -50,35 +50,59 @@ function wpwd() { # usage: smart_wget URL DESTDIR function smart_wget() { _FILE=`basename $1` + # Remove url garbage from filename that would not be removed by wget + _UFILE=${_FILE##*=} _DLD=`unix_path $2` # If the file already exists in the download directory ($2) # then don't do anything. But if it does NOT exist then # download the file to the tmpdir and then when that completes # move it to the dest dir. - if [ ! -f $_DLD/$_FILE ] ; then + if [ ! -f $_DLD/$_UFILE ] ; then # If WGET_RATE is set (in bytes/sec), limit download bandwith if [ ! -z "$WGET_RATE" ] ; then wget --passive-ftp -c $1 -P $TMP_UDIR --limit-rate=$WGET_RATE else wget --passive-ftp -c $1 -P $TMP_UDIR fi - mv $TMP_UDIR/$_FILE $_DLD + mv $TMP_UDIR/$_FILE $_DLD/$_UFILE fi - LAST_FILE=$_DLD/$_FILE + LAST_FILE=$_DLD/$_UFILE } # usage: wget_unpacked URL DOWNLOAD_DIR UNPACK_DIR function wget_unpacked() { smart_wget $1 $2 - _UPD=`unix_path $3` - echo -n "Extracting ${LAST_FILE##*/} ... " + _EXTRACT_UDIR=`unix_path $3` + _EXTRACT_SUBDIR= + echo -n "Extracting $_UFILE ... " case $LAST_FILE in - *.zip) unzip -q -o $LAST_FILE -d $_UPD;; - *.tar.gz) tar -xzpf $LAST_FILE -C $_UPD;; - *.tar.bz2) tar -xjpf $LAST_FILE -C $_UPD;; - *) die "Cannot unpack file $LAST_FILE!";; + *.zip) + unzip -q -o $LAST_FILE -d $_EXTRACT_UDIR + _PACK_DIR=$(zipinfo -1 $LAST_FILE '*/*' 2>/dev/null | head -1) + ;; + *.tar.gz) + tar -xzpf $LAST_FILE -C $_EXTRACT_UDIR + _PACK_DIR=$(tar -ztf $LAST_FILE 2>/dev/null | head -1) + ;; + *.tar.bz2) + tar -xjpf $LAST_FILE -C $_EXTRACT_UDIR + _PACK_DIR=$(tar -jtf $LAST_FILE 2>/dev/null | head -1) + ;; + *) + die "Cannot unpack file $LAST_FILE!" + ;; esac + + # Get the path where the files were actually unpacked + # This can be a subdirectory of the requested directory, if the + # tarball or zipfile contained a relative path. + _PACK_DIR=$(echo "$_PACK_DIR" | sed 's,^\([^/]*\).*,\1,') + if (( ${#_PACK_DIR} > 3 )) # Skip the bin and lib directories from the test + then + _EXTRACT_SUBDIR=$(echo $_UFILE | sed "s,^\($_PACK_DIR\).*,/\1,;t;d") + fi + _EXTRACT_UDIR="$_EXTRACT_UDIR$_EXTRACT_SUBDIR" echo "done" }