From 67992a05598e6010917da0143e933702fa162410 Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Fri, 20 Nov 2015 17:19:08 +0000 Subject: [PATCH] Fortify unpacking in the scripts generated for BLFS, see ticket #1693 --- BLFS/xsl/scripts.xsl | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/BLFS/xsl/scripts.xsl b/BLFS/xsl/scripts.xsl index 293229f..f1c1776 100644 --- a/BLFS/xsl/scripts.xsl +++ b/BLFS/xsl/scripts.xsl @@ -98,19 +98,30 @@ -if [ "${PACKAGE%.zip}" = "${PACKAGE}" ]; then - if [[ -e unpacked ]] ; then - UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'` - [[ -n $UNPACKDIR ]] && [[ -d $UNPACKDIR ]] && rm -rf $UNPACKDIR - fi - tar -xvf $PACKAGE > unpacked - UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'` -else - UNPACKDIR=${PACKAGE%.zip} - [[ -n $UNPACKDIR ]] && [[ -d $UNPACKDIR ]] && rm -rf $UNPACKDIR - unzip -d $UNPACKDIR ${PACKAGE} -fi -cd $UNPACKDIR +find . -maxdepth 1 -mindepth 1 -type d | xargs sudo rm -rf +case $PACKAGE in + *.tar.gz|*.tar.bz2|*.tar.xz|*.tgz) + tar -xvf $PACKAGE > unpacked + UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^./@@;s@/.*@@'` + ;; + *.zip) + zipinfo -1 $PACKAGE > unpacked + UNPACKDIR="$(sed 's@/.*@@' unpacked | uniq )" + if test $(wc -w <<< $UNPACKDIR) -eq 1; then + unzip $PACKAGE + else + UNPACKDIR=${PACKAGE%.zip} + unzip -d $UNPACKDIR $PACKAGE + fi + ;; + *) + UNPACKDIR=$PKG_DIR-build + mkdir $UNPACKDIR + cp $PACKAGE $UNPACKDIR + ;; +esac +cd $UNPACKDIR + sudo /sbin/