r3837 - jhalfs/trunk/BLFS/xsl

pierre at higgs.linuxfromscratch.org pierre at higgs.linuxfromscratch.org
Fri Nov 20 09:19:08 PST 2015


Author: pierre
Date: Fri Nov 20 09:19:08 2015
New Revision: 3837

Log:
Fortify unpacking in the scripts generated for BLFS, see ticket #1693

Modified:
   jhalfs/trunk/BLFS/xsl/scripts.xsl

Modified: jhalfs/trunk/BLFS/xsl/scripts.xsl
==============================================================================
--- jhalfs/trunk/BLFS/xsl/scripts.xsl	Thu Nov 19 22:15:24 2015	(r3836)
+++ jhalfs/trunk/BLFS/xsl/scripts.xsl	Fri Nov 20 09:19:08 2015	(r3837)
@@ -98,19 +98,30 @@
       </xsl:when>
       <xsl:when test="@role = 'installation'">
         <xsl:text>
-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&#xA;&#xA;</xsl:text>
+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&#xA;
+</xsl:text>
         <xsl:apply-templates select=".//screen | .//para/command"/>
         <xsl:if test="$sudo = 'y'">
           <xsl:text>sudo /sbin/</xsl:text>


More information about the alfs-log mailing list