-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup-images
executable file
·126 lines (108 loc) · 2.5 KB
/
setup-images
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
#!/bin/bash
set -e
if [[ `id -u` != 0 ]]; then
echo "You MUST run this script as root."
exit 1
fi
SELFDIR=`dirname "$0"`
SELFDIR=`cd "$SELFDIR"; pwd`
source "$SELFDIR/library"
FINAL_STATE=6
function init_base_tgz()
{
local base_tgz
local distro
local arch
local maybe_linux32
base_tgz="$1"
distro="$2"
arch="$3"
maybe_linux32="$4"
status "Creating $base_tgz..."
$maybe_linux32 pbuilder create --basetgz "$base_tgz.initiating" \
--distribution $distro --architecture $arch \
--override-config --components "main universe"
mv "$base_tgz.initiating" "$base_tgz.1"
}
function modify_base_tgz()
{
local base_tgz="$1"
local platform="$2"
local maybe_linux32="$3"
local state="$4"
status "Installing necessary software in $base_tgz (step $state)..."
$maybe_linux32 pbuilder execute \
--basetgz "$base_tgz.$state" \
--save-after-login \
--bindmounts "$PASSENGER_AUTOBUILDER_ROOT" \
pbuilder-environment-installer \
"`cat pbuilder-environment`" \
"$platform" \
"$state"
local next_state="$state"
(( next_state++ ))
if [[ $next_state == $FINAL_STATE ]]; then
mv "$base_tgz.$state" "$base_tgz"
else
mv "$base_tgz.$state" "$base_tgz.$next_state"
fi
}
function get_base_tgz_state()
{
local base_tgz="$1"
local i
if [[ -f "$base_tgz" ]]; then
echo final
return
fi
for i in $(seq 1 $FINAL_STATE); do
if [[ -f "$base_tgz.$i" ]]; then
echo $i
return
fi
done
echo 0
}
function create_base_tgz()
{
local base_tgz="$1"
local distro="$2"
local arch="$3"
local platform="$4"
local maybe_linux32
if [[ $arch == i386 ]]; then
maybe_linux32=linux32
else
maybe_linux32=
fi
if [[ -f "$base_tgz" ]]; then
success "$base_tgz already exists"
return
fi
# Installation of the base.tgz is done in steps so that if one step fails (e.g.
# because of temporary internet failure), we don't have to redo everything.
local state=`get_base_tgz_state "$base_tgz"`
while [[ $state != final ]]; do
if [[ $state = 0 ]]; then
init_base_tgz "$base_tgz" "$distro" "$arch" "$maybe_linux32"
else
modify_base_tgz "$base_tgz" "$platform" "$maybe_linux32" "$state"
fi
state=`get_base_tgz_state "$base_tgz"`
done
}
only_one=
for arg in "$@"; do
case "$arg" in
--only-one)
only_one=1
;;
*)
echo "Invalid argument $arg"
exit 1
;;
esac
done
create_base_tgz "$PASSENGER_AUTOBUILDER_IMAGES_DIR/lucid-amd64.tgz" lucid amd64 ubuntu-10.04-x86_64
if [[ $only_one = 1 ]]; then exit; fi
create_base_tgz "$PASSENGER_AUTOBUILDER_IMAGES_DIR/lucid-i386.tgz" lucid i386 ubuntu-10.04-x86