Prevent update-pkg-project from needlessly spamming stderr
[pkgusr] / usr / lib / pkgusr / update-pkg-project
1 #!/bin/bash
2
3 # Updates the timestamp and contents in a package's .project
4 # if $1 is null, update pkgusr's pkg
5
6 pkg="$1"
7
8 if [ -z "${pkg}" ]; then
9     pkg=$(whoami)
10 fi
11
12 pkgdir=/usr/src/${pkg}
13
14 upd_pkg_deps()
15 {
16     for file in $(forall_direntries_from $pkg -type f -executable -readable); do
17         if readelf -d $file &>/dev/null && ldd $file &>/dev/null; then
18             (readelf -d $file ; ldd $file ) |
19             awk '/NEEDED/ { lib=substr($5,2,length($5)-2); LIBS[lib]=$5 } \
20                     /.*=>/ {if ( $1 in LIBS ) LIBS[$1]=$3 } END \
21                     { for (lib in LIBS) print LIBS[lib] }' |
22             xargs stat --printf "%U:%G\n"
23         fi
24     done|sort -u|tr -s '\n' ' '
25 }
26
27 # Update deps and date
28 TIMESTAMP=$(date +%c)
29 DEPS=$(upd_pkg_deps)
30 DEPS=${DEPS% }                  # trailing whitespace begone!
31 sed -i -e "s/\(Last_Updated: \).*$/\1${TIMESTAMP}/" \
32     -e s/"\(Deps: \).*$"/"\1${DEPS}"/ ${pkgdir}/.project
33
34 # Clear out old file list
35 awk '/^CONTENTS:/ { print; exit; } {print}' \
36     ${pkgdir}/.project > ${pkgdir}/.projtmp
37 echo "--------" >> ${pkgdir}/.projtmp
38
39 # Add up to date file list
40 list_package ${pkg} >> ${pkgdir}/.projtmp
41 mv ${pkgdir}/.projtmp ${pkgdir}/.project
42
43 # If we're root, chown the .project file
44 [[ $(id -u) -eq 0 ]] && chown -v ${pkg}:${pkg} ${pkgdir}/.project