detect ability to use --format=gnu with tar
PATCH 1/1 detect ability to use --format=gnu with tar
From: Thomas Ingleby <[email protected]>
If opkg-build is being used on a platform not using GNU tar, format=gnu will necessarily work.
Thomas Ingleby (1):
opkg-build: add detection if using GNU tar.
opkg-build | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
Signature · 1 line
1.9.2
PATCH 1/1 opkg-build: add detection if using GNU tar.
From: Thomas Ingleby <[email protected]>
* Some options of GNU tar do not exist on other implementations
--- opkg-build | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
opkg-build +14 -3
@@ -159,6 +159,17 @@ ogargs="" outer=ar noclean=0 opkext=0 + +tarformat="" +#Probably not the best way to detect if running on a system without full GNU tar +set +e +tar --help | grep "format" &> /dev/null +if [ $? -eq 0 ] +then + tarformat="--format=gnu" +fi +set -e + usage="Usage: $0 [-c] [-C] [-O] [-o owner] [-g group] <pkg_directory> [<destination_directory>]" while getopts "cCg:ho:vO" opt; do case $opt in
@@ -233,8 +244,8 @@ tmp_dir=$dest_dir/IPKG_BUILD.$$ mkdir $tmp_dir echo $CONTROL > $tmp_dir/tarX -( cd $pkg_dir && tar $ogargs -X $tmp_dir/tarX -cz --format=gnu -f $tmp_dir/data.tar.gz . ) -( cd $pkg_dir/$CONTROL && tar $ogargs -cz --format=gnu -f $tmp_dir/control.tar.gz . ) +( cd $pkg_dir && tar $ogargs -X $tmp_dir/tarX -cz $tarformat -f $tmp_dir/data.tar.gz . ) +( cd $pkg_dir/$CONTROL && tar $ogargs -cz $tarformat -f $tmp_dir/control.tar.gz . ) rm $tmp_dir/tarX echo "2.0" > $tmp_dir/debian-binary
@@ -249,7 +260,7 @@ rm -f $pkg_file if [ "$outer" = "ar" ] ; then ( cd $tmp_dir && ar -crf $pkg_file ./debian-binary ./control.tar.gz ./data.tar.gz ) else - ( cd $tmp_dir && tar -cz --format=gnu -f $pkg_file ./debian-binary ./control.tar.gz ./data.tar.gz ) + ( cd $tmp_dir && tar -cz $tarformat -f $pkg_file ./debian-binary ./control.tar.gz ./data.tar.gz ) fi rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gz
Signature · 1 line
1.9.2
Re: [opkg-devel] [opkg-utils PATCH] opkg-build: add detection if using GNU tar.
Quoted 18 lines · On Mon, Jun 02, 2014 at 11:50:48AM +0100, [email protected] wrote:
From: Thomas Ingleby <[email protected]>
* Some options of GNU tar do not exist on other implementations
Signed-off-by Thomas Ingleby <[email protected]>--- opkg-build | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)opkg-build +1
-0@@ -159,6 +159,17 @@ ogargs="" outer=ar noclean=0 opkext=0 +
opkg-build ogargs="" · line 172
Quoted 10 lines
opkg-build +10
-0+tarformat="" +#Probably not the best way to detect if running on a system without full GNU tar +set +e +tar --help | grep "format" &> /dev/null +if [ $? -eq 0 ] +then + tarformat="--format=gnu" +fi +set -e +
I wouldn't trust that the word 'format' won't occur in some other context within the help output of tar. I'd search for '--format' instead, both bsdtar and gnu tar include that in the help output but busybox tar does not. The output of busybox tar also seems to be printed on stderr, so I'd include '2>&1' before the pipe.
You also shouldn't need the 'set +e' magic, if you move the command which could fail into the if statement then an error should not cause the script to abort. Maybe try something like:
if tar --help 2>&1 | grep -- --format > /dev/null; then ...
The rest of this looks good to me.
Quoted 30 lines
opkg-build +3
-3usage="Usage: $0 [-c] [-C] [-O] [-o owner] [-g group] <pkg_directory> [<destination_directory>]" while getopts "cCg:ho:vO" opt; do case $opt in@@ -233,8 +244,8 @@ tmp_dir=$dest_dir/IPKG_BUILD.$$ mkdir $tmp_dir echo $CONTROL > $tmp_dir/tarX -( cd $pkg_dir && tar $ogargs -X $tmp_dir/tarX -cz --format=gnu -f $tmp_dir/data.tar.gz . ) -( cd $pkg_dir/$CONTROL && tar $ogargs -cz --format=gnu -f $tmp_dir/control.tar.gz . ) +( cd $pkg_dir && tar $ogargs -X $tmp_dir/tarX -cz $tarformat -f $tmp_dir/data.tar.gz . ) +( cd $pkg_dir/$CONTROL && tar $ogargs -cz $tarformat -f $tmp_dir/control.tar.gz . ) rm $tmp_dir/tarX echo "2.0" > $tmp_dir/debian-binary@@ -249,7 +260,7 @@ rm -f $pkg_file if [ "$outer" = "ar" ] ; then ( cd $tmp_dir && ar -crf $pkg_file ./debian-binary ./control.tar.gz ./data.tar.gz ) else - ( cd $tmp_dir && tar -cz --format=gnu -f $pkg_file ./debian-binary ./control.tar.gz ./data.tar.gz ) + ( cd $tmp_dir && tar -cz $tarformat -f $pkg_file ./debian-binary ./control.tar.gz ./data.tar.gz ) fi rm $tmp_dir/debian-binary $tmp_dir/data.tar.gz $tmp_dir/control.tar.gzSignature · 6 lines
1.9.2 -- You received this message because you are subscribed to the Google Groups "opkg-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
Signature · 4 lines
Paul Barker Email: [email protected] http://www.paulbarker.me.uk