1
#!/usr/bin/env /bin/bash
2
script=generate_modified
4
[ "${prog/*$script/$script}" = "$script" ] || {
5
echo "This script must not be sourced."
16
echo "If patch or script failed, check pre/ and post/ for current stage." ||
17
echo "Try setting DEBUG=1 to maintain pre/ and post/ staging."
25
die 5 "\n$SRC/ tree does not exist. Run 'make $SRC' to build the\n$SRC directory."
31
die 1 "$DST already exists. You must remove it before continuing."
34
echo "Building modified version in '$DST' directory:"
37
echo -n "Copying $DST from $SRC..."
38
cp -r ${SRC}* $DST || die $? "Copy failed."
41
(( DEBUG != 0 )) && rsync --delete -aprl $DST post/ > /dev/null
45
die 3 "$2 does not exist. Terminating."
46
echo -ne " + Applying: $2\n\t"
47
cat "$2" | while read command rest; do
49
"Commit:" | "Author:" | "")
51
*) echo "$command $rest"
57
patch -p1 -d $1 < "$2" > .patch.output || {
58
echo "-----patch failure output-----"
61
die 1 "$2 failed. Terminating."
63
[ -e .patch.output ] && rm .patch.output
69
die 3 "$2 does not exist. Terminating."
70
echo -ne " + Running: $2\n\t"
71
head -n 2 "$2" | tail -n 1 | sed -e 's,^#[[:space:]]*,,g' ||
74
$2 $1 || die 1 "$2 failed."
79
echo "Applying patches and scripts from pending/."
80
for i in pending/*; do
83
file=${i/%.patch/}.patch
84
[ "$file" == "$i" ] && {
86
[ -d pre ] && rm -rf pre
87
rsync --delete -aprl --exclude "*.orig" --exclude "*.rej" post/ pre/
91
do_patch $DST $file || die 3 "Patch failed."
96
[ "$file" == "$i" ] && [ -x "$i" ] && {
98
[ -d pre ] && rm -rf pre
99
rsync --delete -aprl --exclude "*.orig" --exclude "*.rej" post/ pre/
100
do_script post/ $file
106
echo " ! Skipping $i..."
109
(( DEBUG )) || exit 0
111
rsync --delete -avprl post/ $DST > /dev/null &&