Dan McGhee wrote:
> <snip>
>
> <snip> ...enter a package name; e.g., 
> autoconf-2.64.tar.bz2, and, from that name, make a log directory 
> (autoconf-2.64-logs), give the source tree and variable name 
> (packagedir=autoconf-2.64), "untar" the archive and enter the source 
> tree directory ($packagedir).  This will be the first function in a 
> script that then configures, compiles and installs the package.
>
> Here's this little section:
>   
>> #! /bin/bash
>>
>> # Begin build_script_tests
>>
>> package=$@
>> packagedir=$(echo $package | sed 's/.tar.*//')
>>
>> # Make a log directory
>> mkdir -v $packagedir-logs
>>
>> # Decide which tar parameters to use and untar the package
>> [[ ${package} == *z ]] && tar -xzf $package
>> [[ ${package} == *2 ]] && tar -xjf $package
>>
>> # Enter source tree directory
>> cd $packagedir
>>
>> # End build_script_tests
>>     
> For autoconf, the invocation would be `./build_script_tests 
> autoconf-2.64.tar.bz2`   The problem appears to be in my test 
> constructs.  If I ran the script for autoconf, I would receive an error 
> something like:
>
> bash: [[ autoconf-2.64.tar.bz2 == *z  command not found.  It's similar 
> for the "gz."
>
>  From the "Advance Bash Scripting Guide:"
>
>   
>> The == comparison operator behaves differently within a 
>> double-brackets test than within single brackets.
>> [[ $a == z* ]]     # True if $a starts with an "z" (regex 
>> patternmatching).
>> [[ $a == "z*" ]] # True if $a is equal to z* (literal matching).
>> [ $a == z* ]       # File globbing and word splitting take place.
>> [ "$a" == "z*" ] # True if $a is equal to z* (literal matching).
>>     
> What I'm trying to do is "if $package ends in z, use tar -xzf.  If it 
> ends in 2, use tar -xjf.
>
> <lots of snipping>
>   

Rats! It's always something small, obvious and easily overlooked. For 
two days now, since I've been using bash history to invoke the script, 
I've entered autoconf-2.64,tar.bz2 and not autoconf-2.64.tar.bz2. 
Brother! Think I'll go play the piano.

This little script works for both *.gz and *.bz2 files. If anyone wants 
to use it, please do. The only problem comes when "untarring" an archive 
that doesn't create a directory with the package name. For example, 
vim-7.2.tar.bz2 creates "vim72." I can let the script abort, change 
$packagedir and let it run again.

But if someone can figure a way to "script around this," I sure would 
like to hear about it. I've been working on this for a couple of days 
and want to get started on my build.

Thanks,

Dan
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page

Reply via email to