Re: [OpenWrt-Devel] [PATCH] ipkg-make-index: replace awk calls with stat and cut (from coreutils)

2011-10-28 Thread Raphaël HUCK
Le Thu, 27 Oct 2011 17:03:05 +0200,
Florian Fainelli flor...@openwrt.org a écrit :

 On Thursday 27 October 2011 16:45:11 Raphaël HUCK wrote:
  Hi all,
  
  this patch replaces awk calls with stat and cut, which are both
  included in coreutils.
 
 Have you verified this works on BDS platforms, as well as MacOSX?

No, as I don't have a BSD or MacOS X system to test on.

And you're right to point this out, as stat -c %s doesn't work on
BSD, though cut  -d' ' -f1 seems to be fine.

I've been looking intensively through Linux, BSD, and MacOS X man
pages, and I've come to the conclusion that the best portable way to
get the size of a file is:

  $ wc -c  $FILE

I've updated my patch, it now uses wc (which is also in coreutils) and
doesn't need cut anymore.

Thanks!

-Raphaël
--- scripts/ipkg-make-index.sh.orig	2011-10-27 16:08:33.149886769 +0200
+++ scripts/ipkg-make-index.sh	2011-10-28 11:13:42.483519744 +0200
@@ -1,24 +1,25 @@
 #!/bin/sh
 set -e
 
-pkg_dir=$1
+pkg_dir=$1
 
-if [ -z $pkg_dir ] || [ ! -d $pkg_dir ]; then
+if [ -z ${pkg_dir} ] || [ ! -d ${pkg_dir} ]; then
 	echo Usage: ipkg-make-index package_directory 2
 	exit 1
 fi
 
-which md5sum /dev/null 21 || alias md5sum=md5
+which md5sum  /dev/null 21 || alias md5sum=md5
 
-for pkg in `find $pkg_dir -name '*.ipk' | sort`; do
-	echo Generating index for package $pkg 2
-	file_size=$(ls -l $pkg | awk '{print $5}')
-	md5sum=$(md5sum $pkg | awk '{print $1}')
+for pkg in $(find ${pkg_dir} -name '*.ipk' | sort); do
+	echo Generating index for package ${pkg} 2
+	file_size=$(wc -c  ${pkg})
+	md5sum=$(md5sum ${pkg} 2 /dev/null)
+	md5sum=${sum%% *}
 	# Take pains to make variable value sed-safe
-	sed_safe_pkg=`echo $pkg | sed -e 's/^\.\///g' -e 's/\\//\\//g'`
-	tar -xzOf $pkg ./control.tar.gz | tar xzOf - ./control | sed -e s/^Description:/Filename: $sed_safe_pkg\\
-Size: $file_size\\
-MD5Sum: $md5sum\\
+	sed_safe_pkg=$(echo ${pkg} | sed -e 's/^\.\///g' -e 's/\\//\\//g')
+	tar -xzOf ${pkg} ./control.tar.gz | tar xzOf - ./control | sed -e s/^Description:/Filename: ${sed_safe_pkg}\\
+Size: ${file_size}\\
+MD5Sum: ${md5sum}\\
 Description:/
 	echo 
 done
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [OpenWrt-Devel] [PATCH] ipkg-make-index: replace awk calls with stat and cut (from coreutils)

2011-10-27 Thread Florian Fainelli
On Thursday 27 October 2011 16:45:11 Raphaël HUCK wrote:
 Hi all,
 
 this patch replaces awk calls with stat and cut, which are both
 included in coreutils.

Have you verified this works on BDS platforms, as well as MacOSX?
-- 
Florian
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel