#! /bin/bash #========================================================================== # Execute any hooks required for this segment # # Title: pbuilder-runhooks # Description User hooks for pbuilder package # Programmed by: Dale Amon # $HOOKDIR is set in /etc/pbuilderrc and contains a list of executable # programs or scripts. The type is only limited by what you expect will # be available in your chrooted environment after debootstrap has done # an initial install. The functions muxt be named in the format: # . Currently only X is defined; # scripts prefixed with X will be run just before the chroot environment # is exited and the base.tgz file is created or updated. # $BUILDPLACE is as used in pbuilder. When already inside chroot, this # routine can be called with $BUILDPLACE='' # TODO: * Are there any other executable backup types we should # filtered besides *~ and *.bak? # #========================================================================== hooks=tmp/hooks #========================================================================== # Set up fresh chroot'd hooks tmp script directory # function loadhooks () { if [ -z "$HOOKDIR" ]; then return ; fi if [ -d "$BUILDPLACE/$hooks" ]; then rm -rf "$BUILDPLACE/$hooks" fi if [ -d "$HOOKDIR" ]; then mkdir -p "$BUILDPLACE/$hooks" if ! cp -a "$HOOKDIR/"* "$BUILDPLACE/$hooks"; then echo "W: no hooks found on the hookdir" >&2 fi fi } #-------------------------------------------------------------------------- # Tidy up after ourselves. (Anything we leave behind ends up in base.tgz) # function unloadhooks () { if [ -z "$HOOKDIR" ]; then return ; fi if [ -d "$BUILDPLACE/$hooks" ]; then rm -rf "$BUILDPLACE/$hooks" else echo "E: Logic failure." >&2 fi } #-------------------------------------------------------------------------- # Execute every script found in the chroot'd target directory. We only # test for whether a file is executable because we have no idea what # the user had put in their dist. If they want PL/1 and ADA on the base # dist or have decided to use emacslisp for everything, it's their # problem. # # Args: Required prefix on hook fn name # Returns: none # function executehooks () { local prefix="$1" if [ -z "$HOOKDIR" ]; then return ; fi for fn in "$BUILDPLACE/$hooks/$prefix"[0-9][0-9]* ; do case "$fn" in "$BUILDPLACE/$hooks/$prefix"'[0-9][0-9]*') echo "W: no hooks of type ${prefix} found -- ignoring" >&2 ;; *~) echo "W: skipping an editor backup file $fn" >&2 ;; *.bak) echo "W: skipping a backup file $fn" >&2 ;; *) if [ -x "$fn" ]; then $CHROOTEXEC "$hooks/"$(basename "$fn") echo " -> user script $fn finished" else if [ -f "$fn" ]; then filetype=$(basename "$fn" ) echo "W: execute priv not set on file $filetype, not executing." >&2 else # Should it reach here ? This case should be caught in the above case. echo "W: no hooks of type ${prefix} found -- internal error in logic" >&2 fi fi ;; esac done } #--------------------------------------------------------------------------