cdd1a079280079c11d38db1802a63a0428c8a755
[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                 (readelf -d $file ; ldd $file ) |
18                 awk '/NEEDED/ { lib=substr($5,2,length($5)-2); LIBS[lib]=$5 } \
19                     /.*=>/ {if ( $1 in LIBS ) LIBS[$1]=$3 } END \
20                     { for (lib in LIBS) print LIBS[lib] }' |
21                 xargs stat --printf "%U:%G\n"
22         done|sort -u|tr -s '\n' ' '
23 }
24
25
26 sed -i "s/\(Last_Updated: \).*$/\1$(date +%c)/" ${pkgdir}/.project
27 sed -i s/"\(Deps: \).*$"/"\1$(upd_pkg_deps)"/ ${pkgdir}/.project
28 awk '/^CONTENTS:/ { print; exit; } {print}' ${pkgdir}/.project > ${pkgdir}/.projtmp
29 echo "--------" >> ${pkgdir}/.projtmp
30 list_package ${pkg} >> ${pkgdir}/.projtmp
31 mv ${pkgdir}/.projtmp ${pkgdir}/.project
32
33 # If we're root, chown the .project file
34 [[ $(id -u) -eq 0 ]] && chown -v ${pkg}:${pkg} ${pkgdir}/.project