This is not a problem with building LFS. I'm asking for help in the way
I want to do it.
I'm preparing for another build and over the years I have developed some
scripts to take care of the sometimes "drudge work" of "configure, make,
make install." With each build my script(s) get a little more
sophisticated (?). This time, I want to 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.
The problem I'm having is this. Some packages are *.tar.gz and others
are *.tar.bz2. I thought it would be easy to test for this and then
invoke tar with the appropriate command line parametes, but I can't get
it to work.
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.
I'm running Ubuntu 9.04 as host system--and I can't wait 'til I get my
LFS built because I hate it--and have bash-3.2.48. I think what I'm
trying to do is covered in that version. [rant] New 64-bit laptop and
lfs-livecd doesn't support my hardware.[/rant]
My hope is that someone can see the error (?) in the script or suggest
something that would do the same thing.
Thanks for the help.
Dan
--
http://linuxfromscratch.org/mailman/listinfo/lfs-support
FAQ: http://www.linuxfromscratch.org/lfs/faq.html
Unsubscribe: See the above information page