-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathautobuild-with-pbuilder
executable file
·125 lines (109 loc) · 2.58 KB
/
autobuild-with-pbuilder
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
#!/bin/bash
set -e
SELFDIR=`dirname "$0"`
SELFDIR=`cd "$SELFDIR"; pwd`
source "$SELFDIR/library"
source "$PASSENGER_AUTOBUILDER_CONFIG_DIR/signing"
function cleanup()
{
local pids=`jobs -p`
if [[ "$pids" != "" ]]; then
set +e
kill $pids
fi
}
function usage()
{
echo "Usage: ./autobuild-with-pbuilder GIT_URL NAME [--only-one] [--tag=TAG] [--dry-run]"
}
function sign()
{
for F in "$@"; do
status "Signing $F"
rm -f "$F.asc"
if [[ "$SIGNING_METHOD" = "local" ]]; then
gpg --batch --armor --local-user "$SIGNING_KEY" --detach-sign \
--passphrase-fd 3 "$F" 3<<<"$SIGNING_KEY_PASSWORD"
elif [[ "$SIGNING_METHOD" = "remote" ]]; then
signature=`$SIGNING_SSH_COMMAND < "$F"`
echo "$signature" > "$F.asc"
else
echo "Invalid signing method $SIGNING_METHOD. Please check $PASSENGER_AUTOBUILDER_CONFIG_DIR/signing."
exit 1
fi
done
}
function perform()
{
local base_tgz
local arch
local platform
base_tgz="$1"
arch="$2"
platform="$3"
local maybe_linux32
if [[ $arch == i386 ]]; then
maybe_linux32=linux32
else
maybe_linux32=
fi
local bindmounts
if [[ -e /etc/vagrant_box_build_time ]]; then
bindmounts="$PASSENGER_AUTOBUILDER_ROOT $PASSENGER_AUTOBUILDER_APP_DIR"
else
bindmounts="$PASSENGER_AUTOBUILDER_ROOT"
fi
status "Performing build: $platform"
local result_file="$PASSENGER_AUTOBUILDER_RUN_DIR/result-$$.txt"
$maybe_linux32 sudo /usr/sbin/pbuilder execute \
--basetgz "$base_tgz" \
--bindmounts "$bindmounts" \
-- \
"$PASSENGER_AUTOBUILDER_APP_DIR/autobuild-bootstrap-in-pbuilder" \
"$PASSENGER_AUTOBUILDER_APP_DIR" \
"$name" "$platform" \
"--git-url=$git_url" \
"--result-file=$result_file" \
"--timeout=2700" \
"${extra_args[@]}"
if [[ -f "$result_file" ]]; then
local generated_files=`cat "$result_file"`
rm -f "$result_file"
status "Signing output files for platform $platform"
sign $generated_files
fi
}
trap cleanup EXIT
git_url="$1"
name="$2"
only_one=
extra_args=()
shift
shift
for arg in "$@"; do
case "$arg" in
--only-one)
only_one=1
;;
--tag=* | --branch=* | --dry-run | --create-release-symlink)
extra_args+=("$arg")
;;
*)
echo "Invalid argument $arg"
exit 1
;;
esac
done
if [[ "$git_url" = "" || "$name" = "" ]]; then
usage
exit 1
fi
umask u=rwx,g=rx,o=rx
perform "$PASSENGER_AUTOBUILDER_IMAGES_DIR/lucid-amd64.tgz" amd64 linux-x86_64
if [[ "$only_one" != "" ]]; then exit; fi
perform "$PASSENGER_AUTOBUILDER_IMAGES_DIR/lucid-i386.tgz" i386 linux-x86
if [[ -e "$PASSENGER_AUTOBUILDER_CONFIG_DIR/s3" ]]; then
status "Syncing to S3"
"$PASSENGER_AUTOBUILDER_APP_DIR/sync_to_s3"
fi
success "All done!"