aboutsummaryrefslogtreecommitdiff
path: root/pbuilder-runhooks
blob: ee1e9c35cef4aac323e3a030fd7d722ad2f2748e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#! /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>
# Date:          $Date$ 
# Version:       $Revision$
#
# $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:
# <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.
#
# HISTORY:
# $Log$
# Revision 1.16  2003/11/16 07:08:54  dancer
# +	* THANKS: add
# +
# +	* pbuilder-runhooks: fix warning messages to be more correct, thanks
# +	to Daniel Martin.
# +
#
# Revision 1.15  2003/03/10 10:02:11  dancer
# +2003-03-10  Junichi Uekawa  <dancer@debian.org>
# +
# +	* pbuilder-satisfydepends: quote some strings... trying to be pedantic
# +
# +	* pbuilder-buildpackage-funcs: unset LOGNAME for when building with
# +	real root privilage.
# +	thanks Barak Pearlmutter <bap@cs.unm.edu>
# +
# +	* pbuilder.8: document X hooks which were previously undocumented.
# +
# +	* pbuilder-user-mode-linux (BUILDING_DSC_FILE): use readlink on real existing files.
# +	GNU "readlink -f " exits with an exit code of 1 when the file does not
# +	exist, debianutils readlink did not.
# +
# +	* pbuilder-runhooks (hooks): do not call readlink here,
# +	  since the file may not exist.
# +
# +	* pbuilder-checkparams (USE_PKGNAME_LOGFILE): use readlink on real existing files.
# +
# +	* pbuilder-buildpackage (PACKAGENAME): use readlink on real existing files.
# +
#
# Revision 1.14  2002/09/25 08:55:44  dancer
# +	* pbuilder-runhooks (hooks): do not error out if there are no hooks in the hookdir.
#
# Revision 1.13  2002/02/24 12:06:55  dancer
# release is ready, I've checked.
#
# Revision 1.12  2002/02/24 07:57:06  dancer
# added hooks support for pbuilder build target.
#
# Revision 1.11  2001/10/21 05:03:21  dancer
# fixing bugs related to runhooks, reported by Dale. Some serious logic disorder seems to be.
#
# Revision 1.10  2001/10/12 16:56:41  dancer
# changing the error message to warning, because these messages do not stop execution
#
# Revision 1.9  2001/10/12 16:31:18  dancer
# fixed my logical disorder.
#
# Revision 1.8  2001/10/12 15:54:32  dancer
# diff
#
# Revision 1.7  2001/09/27 11:04:54  dancer
# removing comment
#
# Revision 1.6  2001/09/27 11:03:56  dancer
# removing pushd and popd.
#
# Revision 1.5  2001/09/27 09:16:34  dancer
# fixing some serious typos .
#
# Revision 1.4  2001/09/27 08:20:58  dancer
# changing little bits to my liking, and hopefully removing any potentially dangerous bits.
#
# Revision 1.3  2001/09/27 07:13:04  dancer
# and even more reindentation.
#
# Revision 1.2  2001/09/27 07:12:51  dancer
# reindent etc.
#
# Revision 1.1  2001/09/27 07:10:47  dancer
# new file from dale amon.
#
# 20010925	Dale Amon <amon@vnl.com>
#		Created.
#		Thanks to Jens Ruehmkorf 
#		<ruehmkorf@informatik.uni-koeln.de>
#		for discussions and ideas.
#
# 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"
	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."
    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
	    *~)
		echo "W: skipping an editor backup file $fn"
		;;
	    *.bak)
		echo "W: skipping a backup file $fn"
		;;
	    *)	
		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."
		    else
			echo "W: no hooks of type ${prefix} found"
		    fi
		fi  
	        ;;	
	esac
    done
}

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