1 | #!/bin/sh |
---|
2 | |
---|
3 | tmpdir="$TMPDIR" |
---|
4 | if [ -z "${tmpdir}" ]; then tmpdir="$TEMP"; fi |
---|
5 | if [ -z "${tmpdir}" ]; then tmpdir="$TEMPDIR"; fi |
---|
6 | if [ -z "${tmpdir}" ]; then tmpdir="$TMP"; fi |
---|
7 | if [ -z "${tmpdir}" ]; then tmpdir="/tmp"; fi |
---|
8 | |
---|
9 | conffile="`mktemp -q "${tmpdir}/lol-bitten-XXXXXXXX" 2>/dev/null`" |
---|
10 | if [ "${conffile}" = "" ]; then |
---|
11 | conffile="`mktemp 2>/dev/null`" |
---|
12 | fi |
---|
13 | scriptfile="" |
---|
14 | builddir="${tmpdir}/lol-bitten-`whoami`" |
---|
15 | url="http://lolengine.net/builds" |
---|
16 | |
---|
17 | # |
---|
18 | # Utility functions |
---|
19 | # |
---|
20 | |
---|
21 | append() { |
---|
22 | echo "$*" >> "${conffile}" |
---|
23 | } |
---|
24 | |
---|
25 | cleanup() { |
---|
26 | rm -f "${conffile}" "${scriptfile}" |
---|
27 | rm -rf "${builddir}" |
---|
28 | } |
---|
29 | |
---|
30 | bailout() { |
---|
31 | cleanup |
---|
32 | # Exit gracefully |
---|
33 | exit 0 |
---|
34 | } |
---|
35 | |
---|
36 | trap bailout EXIT HUP INT QUIT ABRT KILL ALRM TERM |
---|
37 | |
---|
38 | # |
---|
39 | # Fork if necessary |
---|
40 | # |
---|
41 | |
---|
42 | if [ "$1" = "--forked" ]; then |
---|
43 | shift |
---|
44 | scriptfile="$1" |
---|
45 | shift |
---|
46 | else |
---|
47 | cp "$0" "${conffile}" |
---|
48 | chmod +x "${conffile}" |
---|
49 | exec "${conffile}" --forked "${conffile}" "$@" |
---|
50 | exit 0 |
---|
51 | fi |
---|
52 | |
---|
53 | # |
---|
54 | # Check for command line |
---|
55 | # |
---|
56 | |
---|
57 | if [ "$#" != 2 ]; then |
---|
58 | echo "Usage: run-bitten.sh <username> <password>" |
---|
59 | exit 1 |
---|
60 | fi |
---|
61 | |
---|
62 | # |
---|
63 | # Clean up working directory |
---|
64 | # |
---|
65 | cleanup |
---|
66 | if [ -e "${builddir}" ]; then |
---|
67 | echo "Error: cannot get rid of ${builddir}" |
---|
68 | exit 1 |
---|
69 | fi |
---|
70 | |
---|
71 | # |
---|
72 | # Operating system information |
---|
73 | # |
---|
74 | |
---|
75 | append "[os]" |
---|
76 | append "name = `uname -srmo 2>/dev/null || uname -srm`" |
---|
77 | append "version = 0" |
---|
78 | family="`uname -s | tr A-Z a-z`" |
---|
79 | case "$family" in |
---|
80 | mingw*) family="windows" ;; |
---|
81 | darwin*) family="osx" ;; |
---|
82 | esac |
---|
83 | append "family = $family" |
---|
84 | # This random token prevents HTTP conflicts when several instances |
---|
85 | # are run from the same machine. |
---|
86 | append "token = $$$RANDOM" |
---|
87 | append "" |
---|
88 | |
---|
89 | # |
---|
90 | # Hardware information |
---|
91 | # |
---|
92 | |
---|
93 | append "[machine]" |
---|
94 | name="`uname -n | tr A-Z a-z | sed 's/[.].*//'`" |
---|
95 | case "$name" in |
---|
96 | d*e*s*o*v*) name="putois" ;; |
---|
97 | esac |
---|
98 | append "name = $name" |
---|
99 | processor="`uname -m`" |
---|
100 | case "$processor" in |
---|
101 | x86_64) processor="amd64" ;; |
---|
102 | i*86) processor="i386" ;; |
---|
103 | esac |
---|
104 | # Windows defines a lot of crazy shit, try to make sense of it |
---|
105 | case "$PROCESSOR_ARCHITECTURE" in |
---|
106 | amd64|AMD64) processor="amd64" ;; |
---|
107 | x86|X86) processor="i386" ;; |
---|
108 | esac |
---|
109 | case "$PROCESSOR_ARCHITEW6432" in |
---|
110 | amd64|AMD64) processor="amd64" ;; |
---|
111 | x86|X86) processor="i386" ;; |
---|
112 | esac |
---|
113 | append "processor = $processor" |
---|
114 | append "" |
---|
115 | |
---|
116 | # |
---|
117 | # Authentication information |
---|
118 | # |
---|
119 | |
---|
120 | append "[authentication]" |
---|
121 | append "username = $1" |
---|
122 | append "password = $2" |
---|
123 | append "" |
---|
124 | |
---|
125 | # |
---|
126 | # Visual Studio configuration |
---|
127 | # |
---|
128 | |
---|
129 | # FIXME: we also need to check for the Visual Studio SDK |
---|
130 | append "[msvc]" |
---|
131 | if [ -n "$VS100COMNTOOLS" ]; then |
---|
132 | append "version = 10" |
---|
133 | elif [ -n "$VS110COMNTOOLS" ]; then |
---|
134 | append "version = 11" |
---|
135 | elif [ -n "$VS90COMNTOOLS" ]; then |
---|
136 | append "version = 9" |
---|
137 | fi |
---|
138 | append "" |
---|
139 | |
---|
140 | # |
---|
141 | # iOS development kit |
---|
142 | # |
---|
143 | |
---|
144 | append "[ios]" |
---|
145 | if [ -d "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" ]; then |
---|
146 | append "version = 6.1" |
---|
147 | fi |
---|
148 | append "" |
---|
149 | |
---|
150 | # |
---|
151 | # Xbox development kit |
---|
152 | # |
---|
153 | |
---|
154 | append "[xdk]" |
---|
155 | if [ -n "$XEDK" ]; then |
---|
156 | # FIXME: we don't know how to check the version |
---|
157 | append "version = 2.0.20675.0" |
---|
158 | fi |
---|
159 | append "" |
---|
160 | |
---|
161 | # |
---|
162 | # PS3 development kit |
---|
163 | # |
---|
164 | |
---|
165 | append "[ps3sdk]" |
---|
166 | # Try to "detect" the SNC compiler on Windows |
---|
167 | if [ -n "$SN_PS3_PATH" ]; then |
---|
168 | append "version = 410" |
---|
169 | fi |
---|
170 | # The setup is easier to detect on Linux |
---|
171 | if [ -f "$CELLSDK/version-SDK" ]; then |
---|
172 | append "version = $(cat "$CELLSDK/version-SDK")" |
---|
173 | fi |
---|
174 | append "" |
---|
175 | |
---|
176 | # |
---|
177 | # mingw32 / mingw-w64 |
---|
178 | # |
---|
179 | |
---|
180 | append "[mingw64]" |
---|
181 | if x86_64-w64-mingw32-g++ --version >/dev/null 2>&1; then |
---|
182 | append "version = $(x86_64-w64-mingw32-g++ --version | sed -ne 's/.*g++ *([^)]*) *//p')" |
---|
183 | fi |
---|
184 | append "" |
---|
185 | |
---|
186 | append "[mingw32]" |
---|
187 | if i686-w64-mingw32-g++ --version >/dev/null 2>&1; then |
---|
188 | append "version = $(i686-w64-mingw32-g++ --version | sed -ne 's/.*g++ *([^)]*) *//p')" |
---|
189 | fi |
---|
190 | append "" |
---|
191 | |
---|
192 | # |
---|
193 | # Android NDK |
---|
194 | # |
---|
195 | |
---|
196 | append "[ndk]" |
---|
197 | if [ "$family" != "windows" ]; then |
---|
198 | if [ -f "$ANDROID_NDK_ROOT/RELEASE.TXT" ]; then |
---|
199 | append "version = $(cat "$ANDROID_NDK_ROOT/RELEASE.TXT")" |
---|
200 | fi |
---|
201 | fi |
---|
202 | append "" |
---|
203 | |
---|
204 | # |
---|
205 | # Google NaCl SDK |
---|
206 | # |
---|
207 | |
---|
208 | append "[pepper]" |
---|
209 | if [ "$family" != "windows" ]; then |
---|
210 | if [ -d "$NACL_SDK_ROOT" ]; then |
---|
211 | pepper_version=0 |
---|
212 | for dir in "$NACL_SDK_ROOT/pepper_"*; do |
---|
213 | new_version="$(echo "$dir" | sed 's/.*_//')" |
---|
214 | if [ "$new_version" -gt "$pepper_version" ]; then |
---|
215 | pepper_version="$new_version" |
---|
216 | fi |
---|
217 | done |
---|
218 | if [ "$pepper_version" != 0 ]; then |
---|
219 | append "version = $pepper_version" |
---|
220 | fi |
---|
221 | fi |
---|
222 | fi |
---|
223 | append "" |
---|
224 | |
---|
225 | # |
---|
226 | # Raspberry Pi cross-compiler |
---|
227 | # |
---|
228 | |
---|
229 | append "[raspi]" |
---|
230 | if [ "$family" != "windows" ]; then |
---|
231 | if [ -d "$RASPI_SDK_ROOT/tools" ]; then |
---|
232 | append "version = 0" |
---|
233 | fi |
---|
234 | fi |
---|
235 | append "" |
---|
236 | |
---|
237 | # |
---|
238 | # Show what we just did here |
---|
239 | # |
---|
240 | |
---|
241 | cat "${conffile}" |
---|
242 | |
---|
243 | # |
---|
244 | # Fix system |
---|
245 | # |
---|
246 | |
---|
247 | if [ "$family" = "osx" ]; then |
---|
248 | # The version of Subversion shipped by Apple is antique; try to |
---|
249 | # use the one in /usr/local/bin instead. |
---|
250 | PATH="/usr/local/bin:$PATH" |
---|
251 | export PATH |
---|
252 | # HACK: the version of llvm-g++ shipped by Apple has an insane |
---|
253 | # memory leak; use clang++ instead. |
---|
254 | CC="clang" |
---|
255 | export CC |
---|
256 | CXX="clang++" |
---|
257 | export CXX |
---|
258 | fi |
---|
259 | |
---|
260 | # |
---|
261 | # Launch everything |
---|
262 | # |
---|
263 | |
---|
264 | while : ; do |
---|
265 | bitten-slave "$url" \ |
---|
266 | -f "${conffile}" \ |
---|
267 | --name "$name" \ |
---|
268 | --work-dir="${builddir}" |
---|
269 | rm -rf "${builddir}" |
---|
270 | sleep 10 |
---|
271 | done |
---|
272 | |
---|
273 | exit 0 |
---|
274 | |
---|