#!/bin/bash # Copyright © 2010 - 2021 Steve Youngs. All rights reserved. # SPDX-License-Identifier: BSD-3-Clause # Author: Steve Youngs # Maintainer: Steve Youngs # Created: <2010-12-01> # Time-stamp: # Homepage: https://git.sxemacs.org/pkgusr # Keywords: pkgusr package-management tools ## This file is part of pkgusr ### Commentary: # # Updates the timestamp and contents in a package's .project # $1 -- package to update, if null current pkgusr # $2 -- '--subgroups' optional. Use if the package is split into # subgroups. # # All the work is done in list_package (see: list_package --help) ### Code pkg="$1" subgrps="$2" # Allow for 'update-pkg-project --subgroups' invocation # Hint: if it is not a pkgusr doing this the resulting error message # from list_package will set you straight. :) if [[ ${pkg} =~ ^--?subgroups$ ]]; then pkg=$(whoami) subgrps='--subgroups' fi # Allow for no cmdline opts if [ -z "${pkg}" ]; then pkg=$(whoami) fi pkgdir=/usr/src/${pkg} pkgawk=/usr/lib/pkgusr/pkgdeps.awk # Clear out old file list sed -i -n 1,/CONTENTS:/p ${pkgdir}/.project echo "--------" >> ${pkgdir}/.project # Update the mandb so we get up to date results # See /usr/lib/pkgusr/mandb and /etc/sudoers.d/99-pkgusr mandb # Re-populate .project (source'd to get at $AEXEC) source list_package ${pkg} ${subgrps} >> ${pkgdir}/.project # Find deps upd_pkg_deps() { # $AEXEC comes from list_package for file in ${AEXEC[@]}; do if readelf -d $file &>/dev/null && ldd $file &>/dev/null; then (readelf -d $file ; ldd $file ) | awk -f ${pkgawk} | xargs -r stat --printf "%U:%G\n" fi done | sort -u | tr -s '\n' ' ' } # Update Timestamp TIMESTAMP=$(date +%c) sed -i "s/\(Last_Updated: \).*$/\1${TIMESTAMP}/" ${pkgdir}/.project # Update Deps (a wee bit ugly in my eyes, sorry) DEPS=$(upd_pkg_deps) DEPS="Deps: ${DEPS% }" # trailing whitespace begone! sed -i -e /Deps:/d -e "/Web_Site/a ${DEPS}" ${pkgdir}/.project fmt -p Deps: ${pkgdir}/.project > ${pkgdir}/.project.fmt sed -i 's/^Deps:/ &/' ${pkgdir}/.project.fmt mv ${pkgdir}/.project{.fmt,} # If we're root, chown the .project file [[ $(id -u) -eq 0 ]] && chown -v ${pkg}:${pkg} ${pkgdir}/.project exit 0