Prevent update-pkg-project from needlessly spamming stderr
authorSteve Youngs <steve@sxemacs.org>
Thu, 13 Mar 2014 00:52:41 +0000 (10:52 +1000)
committerSteve Youngs <steve@sxemacs.org>
Thu, 13 Mar 2014 00:52:41 +0000 (10:52 +1000)
* usr/lib/pkgusr/update-pkg-project (upd_pkg_deps): Prevent stderr
getting spammed.
(TIMESTAMP,DEPS): New.

Signed-off-by: Steve Youngs <steve@sxemacs.org>
usr/lib/pkgusr/update-pkg-project

index cdd1a07..feef549 100755 (executable)
@@ -6,27 +6,37 @@
 pkg="$1"
 
 if [ -z "${pkg}" ]; then
 pkg="$1"
 
 if [ -z "${pkg}" ]; then
-        pkg=$(whoami)
+    pkg=$(whoami)
 fi
 
 pkgdir=/usr/src/${pkg}
 
 upd_pkg_deps()
 {
 fi
 
 pkgdir=/usr/src/${pkg}
 
 upd_pkg_deps()
 {
-       for file in $(forall_direntries_from $pkg -type f -executable -readable); do
-               (readelf -d $file ; ldd $file ) |
-               awk '/NEEDED/ { lib=substr($5,2,length($5)-2); LIBS[lib]=$5 } \
+    for file in $(forall_direntries_from $pkg -type f -executable -readable); do
+       if readelf -d $file &>/dev/null && ldd $file &>/dev/null; then
+           (readelf -d $file ; ldd $file ) |
+           awk '/NEEDED/ { lib=substr($5,2,length($5)-2); LIBS[lib]=$5 } \
                     /.*=>/ {if ( $1 in LIBS ) LIBS[$1]=$3 } END \
                     { for (lib in LIBS) print LIBS[lib] }' |
                     /.*=>/ {if ( $1 in LIBS ) LIBS[$1]=$3 } END \
                     { for (lib in LIBS) print LIBS[lib] }' |
-               xargs stat --printf "%U:%G\n"
-       done|sort -u|tr -s '\n' ' '
+           xargs stat --printf "%U:%G\n"
+       fi
+    done|sort -u|tr -s '\n' ' '
 }
 
 }
 
+# Update deps and date
+TIMESTAMP=$(date +%c)
+DEPS=$(upd_pkg_deps)
+DEPS=${DEPS% }                 # trailing whitespace begone!
+sed -i -e "s/\(Last_Updated: \).*$/\1${TIMESTAMP}/" \
+    -e s/"\(Deps: \).*$"/"\1${DEPS}"/ ${pkgdir}/.project
 
 
-sed -i "s/\(Last_Updated: \).*$/\1$(date +%c)/" ${pkgdir}/.project
-sed -i s/"\(Deps: \).*$"/"\1$(upd_pkg_deps)"/ ${pkgdir}/.project
-awk '/^CONTENTS:/ { print; exit; } {print}' ${pkgdir}/.project > ${pkgdir}/.projtmp
+# Clear out old file list
+awk '/^CONTENTS:/ { print; exit; } {print}' \
+    ${pkgdir}/.project > ${pkgdir}/.projtmp
 echo "--------" >> ${pkgdir}/.projtmp
 echo "--------" >> ${pkgdir}/.projtmp
+
+# Add up to date file list
 list_package ${pkg} >> ${pkgdir}/.projtmp
 mv ${pkgdir}/.projtmp ${pkgdir}/.project
 
 list_package ${pkg} >> ${pkgdir}/.projtmp
 mv ${pkgdir}/.projtmp ${pkgdir}/.project