On Mon, May 14, 2012 at 09:48:01PM +0430, Yasser Zamani wrote: > > cat > t.sh << EOF > if [ "$1" == "" ]; then > echo 'USAGE: t.bash [name]' > return > fi > FNAME=$(ls $1* | grep tar.xz) > if [ "$FNAME" == "" ]; then > FNAME=$(ls $1* | grep tar.gz) > if [ "$FNAME" == "" ]; then > FNAME=$(ls $1* | grep tar.bz2) > if [ "$FNAME" == "" ]; then > echo 'match not found!' > return > else > TARPARAM='-jxf' > EXT='.tar.bz2' > fi > else > TARPARAM='-zxf' > EXT='.tar.gz' > fi > else > TARPARAM='-Jxf' > EXT='.tar.xz' > fi
At the risk of straying into blfs-support territory: When you get to BLFS, you will find other variants - .tgz and .tbz2, and even .tar.lzma. Although I too still pass -j, -J, -z, and --lzma, any recent version of tar doesn't need these flags since it should be able to determine the compression automatically. Another problem happens is if your browser decides to keep the filename but decompress the contents, this will break - I've seen that sometimes with older versions of epiphany. In those circumstances, breakage is good (you can re-download for a smaller correctly-compressed file). Error-handling, and understanding the failure modes, is always the fun part of writing scripts ;-) > DIR=$(echo $FNAME | sed "s/$EXT//g") Usually works for packages in LFS, but for the wider world it's better to find out the name it will actually extract to. In my own scripts I use: DIRECTORY=`tar -tv $TARCMD -f ${PACKAGES}/${CURRENT} 2>/dev/null | \ head -n 1 | awk '{ print $6}' | sed s'@^./@@' | \ cut -d '/' -f 1` [note that I mostly avoid $(...), I prefer `...`] > echo `rm -fR $DIR` > echo `ls $1*` > echo `tar $TARPARAM $FNAME` > rm -vfR ut.sh > echo -e 'cd ..\necho `rm -fR '$DIR'`\necho `ls '$1'*`\nrm -vfR ut.sh' >> ut.sh > chmod 777 ut.sh > cd $DIR > EOF > chmod 777 t.sh > For your ut.sh you might find it easier to use "..." so that variables will be expanded. But I don't really like the approach of creating multiple functions on a package-by-package basis. Generally, 777 is not a good permission. Makes no difference if you have no other users, but 755 or 754 may be better. If there is a separate build dir (binutils, gcc, glibc) you also want to remove that if making a second attempt on a package. Have fun producing scripts that work for your uses. ĸen -- das eine Mal als Tragödie, das andere Mal als Farce -- http://linuxfromscratch.org/mailman/listinfo/lfs-support FAQ: http://www.linuxfromscratch.org/lfs/faq.html Unsubscribe: See the above information page