pbuilder-runhooks 3.27 KB
Newer Older
dancer's avatar
dancer committed
1 2 3 4 5 6 7
#! /bin/bash
#==========================================================================
# Execute any hooks required for this segment
#
# Title:         pbuilder-runhooks
# Description    User hooks for pbuilder package
# Programmed by: Dale Amon <amon@vnl.com>
8

dancer's avatar
dancer committed
9 10 11
# $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
12
# an initial install. The functions must be named in the format:
dancer's avatar
dancer committed
13 14 15
# <prefex><digit><digit><descriptive name>. 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.
16 17

# $BUILDPLACE is as used in pbuilder. When already inside chroot, this
18
# routine can be called with $BUILDPLACE='' (from pdebuild-internal)
19

dancer's avatar
dancer committed
20 21 22 23 24
# TODO:		* Are there any other executable backup types we should
#		  filtered besides *~ and *.bak?
#
#==========================================================================

dancer's avatar
dancer committed
25
hooks=tmp/hooks
dancer's avatar
dancer committed
26 27 28 29 30 31

#==========================================================================
# Set up fresh chroot'd hooks tmp script directory
# 

function loadhooks () {
32 33 34
    if [ -z "$HOOKDIR" ]; then
	return ;
    fi
dancer's avatar
dancer committed
35
    if [ -d "$BUILDPLACE/$hooks" ]; then
36 37 38
	rm -rf "$BUILDPLACE/$hooks"
    fi
    if [ -d "$HOOKDIR" ]; then
dancer's avatar
dancer committed
39
	mkdir -p "$BUILDPLACE/$hooks"
40
	if ! cp -aL "$HOOKDIR/"* "$BUILDPLACE/$hooks"; then
41
	    log "W: no hooks found in the hookdir '$HOOKDIR'"
42
	fi
43 44
    else
	log "W: hookdir $HOOKDIR does not exist, skipping"
dancer's avatar
dancer committed
45
    fi
dancer's avatar
dancer committed
46 47 48 49 50 51 52
}

#--------------------------------------------------------------------------
# Tidy up after ourselves. (Anything we leave behind ends up in base.tgz)
#

function unloadhooks () {
53 54 55
    if [ -z "$HOOKDIR" ]; then
	return ;
    fi
dancer's avatar
dancer committed
56 57 58
    if [ -d "$BUILDPLACE/$hooks" ]; then
	rm -rf "$BUILDPLACE/$hooks"
    else
59
	log "E: Logic failure."
dancer's avatar
dancer committed
60
    fi
dancer's avatar
dancer committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74
}

#--------------------------------------------------------------------------
# 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 () {
dancer's avatar
dancer committed
75
    local prefix="$1"
76 77 78
    if [ -z "$HOOKDIR" ]; then
	return ;
    fi
dancer's avatar
dancer committed
79
    for fn in "$BUILDPLACE/$hooks/$prefix"[0-9][0-9]* ; do
80
	case "$fn" in
dancer's avatar
+  
dancer committed
81
	    "$BUILDPLACE/$hooks/$prefix"'[0-9][0-9]*')
82
		log "W: no hooks of type ${prefix} found -- ignoring"
dancer's avatar
+  
dancer committed
83
		;;
dancer's avatar
dancer committed
84
	    *~)
85
		log "W: skipping an editor backup file $fn"
dancer's avatar
dancer committed
86
		;;
dancer's avatar
dancer committed
87
	    *.bak)
88
		log "W: skipping a backup file $fn"
dancer's avatar
dancer committed
89 90
		;;
	    *)	
91
		if [ -x "$fn" ]; then
92
		    log "I: user script $fn starting"
93
		    $CHROOTEXEC "/$hooks/"$(basename "$fn")
94
		    log "I: user script $fn finished"
dancer's avatar
dancer committed
95
		else
dancer's avatar
dancer committed
96 97
		    if [ -f "$fn" ]; then
			filetype=$(basename "$fn" ) 
98
			log "W: execute priv not set on file $filetype, not executing."
dancer's avatar
dancer committed
99
		    else
dancer's avatar
+  
dancer committed
100
			# Should it reach here ? This case should be caught in the above case.
101
			log "W: no hooks of type ${prefix} found -- internal error in logic"
dancer's avatar
dancer committed
102
		    fi
dancer's avatar
dancer committed
103 104 105 106
		fi  
	        ;;	
	esac
    done
dancer's avatar
dancer committed
107 108 109
}

#--------------------------------------------------------------------------