-
Notifications
You must be signed in to change notification settings - Fork 35
/
titanium.sh
executable file
·435 lines (356 loc) · 15.1 KB
/
titanium.sh
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#!/bin/bash
# Utility script to start Titanium Mobile project from the command line.
PROJECT_ROOT=${PROJECT_ROOT:-../}
APP_DEVICE=${DEVICE_TYPE}
TI_SDK_VERSION=`cat tiapp.xml | grep "<sdk-version>" | sed -e "s/<\/*sdk-version>//g"`
TI_SDK_HIGHEST_VERSION=`ls ~/library/Application\ Support/titanium/mobilesdk/osx | tail -1`
IOS_SDK_VERSION=`cat tiapp.xml | grep "<ios-version>" | sed -e "s/[ \t]*<\/*ios-version>//g"`
TI_DIR="Library/Application Support/Titanium"
BUILD_TYPE=${BUILD_TYPE}
TESTFLIGHT_ENABLED=${testflight}
HOCKEY_ENABLED=${hockey}
APK_ONLY=${apkonly}
RELEASE_NOTES=${notes}
IPHONE_DEV_CERT=${cert}
PROVISIONING_PROFILE_NAME=${profile_file}
BUILD_ACTION=${action}
PROFILE_TYPE=iphone_dev_name
PACKAGE_APP=false
NO_COLOR=${no_color}
function pretty_print {
if [ $NO_COLOR ]
then
exec perl -pe ''
else
exec perl -pe 's/^\[DEBUG\].*$/\e[35m$&\e[0m/g;s/^\[INFO\].*$/\e[36m$&\e[0m/g;s/^\[WARN\].*$/\e[33m$&\e[0m/g;s/^\[ERROR\].*$/\e[31m$&\e[0m/g;'
fi
}
[[ -z "$ANDROID_SDK_PATH" ]] && ANDROID_SDK_PATH="${HOME}/Android"
# if no platform is set, use iphone as a default
if [ "${APP_DEVICE}" == "" ]; then
APP_DEVICE="iphone"
fi
# only install|adhoc are supported as install actions
if [ ! "${BUILD_ACTION}" == "install" ] && [ ! "${BUILD_ACTION}" == "adhoc" ]; then
echo ""
echo "[WARN] Only action=install and action=adhoc are supported. Choosing action=install." >&2
echo ""
BUILD_ACTION="install"
fi
if [ "${BUILD_ACTION}" == "adhoc" ]; then
PROFILE_TYPE=iphone_dist_name
fi
# provisioning profile name must be specified
if [ "${PROVISIONING_PROFILE_NAME}" == "" ]; then
echo ""
echo "[WARN] Defaulting profile_file to 'development'." >&2
echo ""
PROVISIONING_PROFILE_NAME="development"
fi
# Make sure an SDK version is set
if [[ -z "$TI_SDK_VERSION" ]]; then
if [[ -n "$tisdk" ]]; then
TI_SDK_VERSION="${tisdk}"
elif [ ! "${TI_SDK_HIGHEST_VERSION}" == "" ]; then
TI_SDK_VERSION="${TI_SDK_HIGHEST_VERSION}"
else
echo ""
echo "[ERROR] <sdk-version> is not defined in tiapp.xml, please define it, or add a tisdk argument to your command." >&2
echo ""
exit 1
fi
fi
if [[ -n "$TITANIUM_PATH" ]]; then
TI_DIR="$TITANIUM_PATH"
else
# Look all over for a titanium install
search_locations=(
"${HOME}/Library/Application Support/Titanium"
"/Library/Application Support/Titanium"
"${HOME}/.titanium"
)
for d in "${search_locations[@]}"; do
if [[ -d "${d}/mobilesdk/osx/${TI_SDK_VERSION}" ]]; then
echo "[DEBUG] Found Titanium SDK for ${TI_SDK_VERSION} at $d"
TI_DIR="$d"
break
fi
done
fi
# Both iOS and Android SDKs are linked in this directory
TI_ASSETS_DIR="${TI_DIR}/mobilesdk/osx/${TI_SDK_VERSION}"
if [[ -d "$TI_ASSETS_DIR" ]]; then
echo "[DEBUG] Titanium SDK ${TI_SDK_VERSION} found..."
else
echo "[ERROR] Titanium SDK for ${TI_SDK_VERSION} not found. You could try setting TITANIUM_PATH." >&2
exit 1
fi
# iPhone settings
if [ "${iphone}" == "" ]; then
if [ "${IOS_SDK_VERSION}" == "" ]; then
iphone="6.0"
else
iphone="${IOS_SDK_VERSION}"
fi
fi
TI_IPHONE_DIR="${TI_ASSETS_DIR}/iphone"
TI_IPHONE_BUILD="${TI_IPHONE_DIR}/builder.py"
# Android settings
if [ "${android}" == "" ]; then
android="titanium_2_WVGA854"
fi
TI_ANDROID_DIR="${TI_ASSETS_DIR}/android"
TI_ANDROID_BUILD="${TI_ANDROID_DIR}/builder.py"
# Get APP parameters from current tiapp.xml
APP_ID=`cat tiapp.xml | grep "<id>" | sed -e "s/<\/*id>//g"`
APP_NAME=`cat tiapp.xml | grep "<name>" | sed -e "s/<\/*name>//g"`
APP_NAME=$(echo ${APP_NAME// /})
if [ "APP_ID" == "" ] || [ "APP_NAME" == "" ]; then
echo "[ERROR] Could not obtain APP parameters from tiapp.xml file (does the file exist?)." >&2
exit 1
fi
# build commands based on the platform
if [ ${APP_DEVICE} == "iphone" -o ${APP_DEVICE} == "ipad" ]; then
# Run the app in the simulator
if [ "${BUILD_TYPE}" == "" ]; then
if [ "$(ps -Ac | egrep -i 'iPhone Simulator' | awk '{print $1}')" ]; then
killall "iPhone Simulator"
fi
echo "'${TI_IPHONE_BUILD}' run '${PROJECT_ROOT}/' ${iphone} ${APP_ID} '${APP_NAME}' ${APP_DEVICE}"
bash -c "'${TI_IPHONE_BUILD}' run '${PROJECT_ROOT}/' ${iphone} ${APP_ID} '${APP_NAME}' ${APP_DEVICE}" \
| pretty_print
# Build an IPA and load it through iTunes
else
bash -c "'${TI_IPHONE_DIR}/prereq.py' package" | \
while read prov
do
temp_iphone_dev_names=`echo $prov | python -c 'import json,sys;obj=json.loads(sys.stdin.read());print obj["'"$PROFILE_TYPE"'"]'| sed 's/ u//g' | sed 's/\[u//g' | sed 's/\[//g'| sed 's/\]//g'| sed "s/\ '//g"| sed "s/\'//g"`
IFS=,
IPHONE_DEV_NAMES=(${temp_iphone_dev_names//,iphone_dev_name:/})
if [ "${IPHONE_DEV_CERT}" == '' ] || [ $IPHONE_DEV_CERT -ge ${#IPHONE_DEV_NAMES[@]} ] ; then
dev_name_count=0
echo
echo "*****************************************************************************************************************"
echo "Please re-run the build command using a 'cert' flag, with the value set to the index of one of the certs below..."
for dev_name in "${IPHONE_DEV_NAMES[@]}"
do
echo "[${dev_name_count}] ${dev_name}"
dev_name_count=`expr $dev_name_count + 1`
done
echo "*****************************************************************************************************************"
echo
exit
fi
SIGNING_IDENTITY=${IPHONE_DEV_NAMES[$IPHONE_DEV_CERT]}
PROVISIONING_PROFILE="${PROJECT_ROOT}/certs/${PROVISIONING_PROFILE_NAME}.mobileprovision"
if [ ! -r 'certs/'$PROVISIONING_PROFILE_NAME'.mobileprovision' ];then
echo "You must have a file called ${PROVISIONING_PROFILE_NAME} to build for device..."
exit
fi
DATE=$( /bin/date +"%Y-%m-%d" )
echo "'${TI_IPHONE_DIR}/provisioner.py' '${PROVISIONING_PROFILE}'"
echo "Loading provisioning profile..."
bash -c "'${TI_IPHONE_DIR}/provisioner.py' '${PROVISIONING_PROFILE}'" | \
while read line
do
temp_array=(${line//{\"uuid\": \"/})
UUID=${temp_array[0]//\"/}
echo "'${TI_IPHONE_BUILD}' $BUILD_ACTION ${iphone} '${PROJECT_ROOT}/' $(echo $APP_ID) '$(echo $APP_NAME)' '$(echo $UUID | sed -e "s/uuid: //g")' '${SIGNING_IDENTITY}' '$(echo ${APP_DEVICE})'"
bash -c "'${TI_IPHONE_BUILD}' $BUILD_ACTION ${iphone} '${PROJECT_ROOT}/' $(echo $APP_ID) '$(echo $APP_NAME)' '$(echo $UUID | sed -e "s/uuid: //g")' '${SIGNING_IDENTITY}' '$(echo ${APP_DEVICE})'" | \
while read build_log
do
MAY_SYNC=0
if [ $BUILD_ACTION == "install" ] && [ "${build_log}" == '[INFO] iTunes sync initiated' ]; then
MAY_SYNC=1
BUILD_LOCATION="Debug-iphoneos"
elif [ $BUILD_ACTION == "adhoc" ] && [[ "${build_log}" =~ 'PackageApplication' ]]; then
MAY_SYNC=1
BUILD_LOCATION="Release-iphoneos"
SIGNING_IDENTITY="iPhone Distribution: $SIGNING_IDENTITY"
PACKAGE_APP=true
fi
if [ $MAY_SYNC -eq 1 ]; then
echo "[INFO] Done building app..."\
| pretty_print
APP="${PROJECT_ROOT}/build/iphone/build/$BUILD_LOCATION/$(echo $APP_NAME).app"
# Check if TestFlight or Hockey deploy was mandated
if [ $TESTFLIGHT_ENABLED ] || [ $HOCKEY_ENABLED ]; then
PACKAGE_APP=true
fi
if [ $PACKAGE_APP ]; then
echo "[INFO] Creating .ipa from compiled app"\
| pretty_print
if [ -f /tmp/$(echo $APP_NAME).ipa ]; then
/bin/rm "/tmp/$(echo $APP_NAME).ipa"
fi
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${APP}" -o "/tmp/$(echo $APP_NAME).ipa" --sign "${SIGNING_IDENTITY}" --embed "${PROVISIONING_PROFILE}" | \
while read package_log
do
DATE=$( /bin/date +"%Y-%m-%d" )
done
fi
if [ $TESTFLIGHT_ENABLED ]; then
API_TOKEN=`cat tiapp.xml | grep "<tf_api>" | sed -e "s/<\/*tf_api>//g"`
API_TOKEN=$(echo ${API_TOKEN// /})
TEAM_TOKEN=`cat tiapp.xml | grep "<tf_token>" | sed -e "s/<\/*tf_token>//g"`
TEAM_TOKEN=$(echo ${TEAM_TOKEN// /})
if [ "${API_TOKEN}" == '' -o "${TEAM_TOKEN}" == '' ]; then
echo "[ERROR] Testflight API key (tf_api) and Testflight team token (tf_token) must be defined in your tiapp.xml to upload with testflight"\
| pretty_print
exit 0
fi
echo "[INFO] Preping to upload to TestFlight..."\
| pretty_print
echo "[INFO] Uploading .ipa to TestFlight..." \
| pretty_print
if [ "${RELEASE_NOTES}" == '' ]; then
RELEASE_NOTES='Build uploaded automatically from MakeTi.'
fi
/usr/bin/curl "http://testflightapp.com/api/builds.json" \
-F file=@"/tmp/$(echo $APP_NAME).ipa" \
-F api_token=${API_TOKEN} \
-F notify="True" \
-F replace="True" \
-F team_token=${TEAM_TOKEN} \
-F distribution_lists=`cat tiapp.xml | grep "<tf_dist>" | sed -e "s/<\/*tf_dist>//g"` \
-F notes="${RELEASE_NOTES}" | \
while read upload_log
do
DATE=$( /bin/date +"%Y-%m-%d" )
done
fi
if [ $HOCKEY_ENABLED ]; then
API_TOKEN=`cat tiapp.xml | grep "<hockey_api>" | sed -e "s/<\/*hockey_api>//g"`
API_TOKEN=$(echo ${API_TOKEN// /})
APP_ID=`cat tiapp.xml | grep "<hockey_id>" | sed -e "s/<\/*hockey_id>//g"`
APP_ID=$(echo ${APP_ID// /})
if [ "${API_TOKEN}" == '' -o "${APP_ID}" == '' ]; then
echo "[ERROR] HockeyApp API key (hockey_api) and HockeyApp app ID (hockey_id) must be defined in your tiapp.xml to upload with HockeyApp"\
| pretty_print
exit 0
fi
echo "[INFO] Preping to upload to HockeyApp..."\
| pretty_print
echo "[INFO] Uploading .ipa to HockeyApp..." \
| pretty_print
if [ "${RELEASE_NOTES}" == '' ]; then
RELEASE_NOTES='Build uploaded automatically from MakeTi.'
fi
/usr/bin/curl \
-F "status=2" \
-F "notify=1" \
-F "notes=${RELEASE_NOTES}" \
-F "notes_type=0" \
-F "ipa=@/tmp/$(echo $APP_NAME).ipa" \
-H "X-HockeyAppToken: ${API_TOKEN}" \
https://rink.hockeyapp.net/api/2/apps/${APP_ID}/app_versions | \
while read upload_log
do
DATE=$( /bin/date +"%Y-%m-%d" )
done
fi
else
echo ${build_log} \
| pretty_print
fi
done
done
done
fi
elif [ ${APP_DEVICE} == "android" ]; then
if [[ -d "$ANDROID_SDK_PATH" ]]; then
echo "[ERROR] Android SDK not found. Did you set your ANDROID_SDK_PATH environemnt variable?" >&2
exit 127
fi
# Run the app in the simulator
if [ ${APK_ONLY} ]; then
bash -c "'${TI_ANDROID_BUILD}' build '${APP_NAME}' '${ANDROID_SDK_PATH}' '${PROJECT_ROOT}/' ${APP_ID} ${android}" \
| pretty_print
elif [ "${BUILD_TYPE}" == "" ]; then
# Check for Android Virtual Device (AVD)
if [ "$(ps -Ac | egrep -i 'emulator-arm' | awk '{print $1}')" ]; then
bash -c "'${TI_ANDROID_BUILD}' simulator '${APP_NAME}' '${ANDROID_SDK_PATH}' '${PROJECT_ROOT}/' ${APP_ID} ${android} && adb logcat | grep Ti" \
| pretty_print
else
echo "[ERROR] Could not find a running emulator."
echo "[ERROR] Run this command in a separate terminal session: ${ANDROID_SDK_PATH}/tools/emulator-arm -avd ${android}"
exit 0
fi
else
list_called="false"
device_found="false"
bash -c "${ANDROID_SDK_PATH}/platform-tools/adb devices" | \
while read adb_output
do
if [ $HOCKEY_ENABLED ]; then
bash -c "'${TI_ANDROID_BUILD}' build '${APP_NAME}' '${ANDROID_SDK_PATH}' '${PROJECT_ROOT}/' ${APP_ID} ${android}" | \
while read build_log
do
echo "${build_log}" \
| pretty_print
if [[ "$build_log" == *zipalign* ]]; then
sleep 2
echo "APK is now located in: ${PROJECT_ROOT}/build/android/bin/app.apk"
API_TOKEN=`cat tiapp.xml | grep "<hockey_api>" | sed -e "s/<\/*hockey_api>//g"`
API_TOKEN=$(echo ${API_TOKEN// /})
APP_ID=`cat tiapp.xml | grep "<hockey_android_id>" | sed -e "s/<\/*hockey_android_id>//g"`
APP_ID=$(echo ${APP_ID// /})
if [ "${API_TOKEN}" == '' -o "${APP_ID}" == '' ]; then
echo "[ERROR] HockeyApp API key (hockey_api) and HockeyApp app ID (hockey_android_id) must be defined in your tiapp.xml to upload with HockeyApp"\
| pretty_print
exit 0
fi
echo "[INFO] Preping to upload to HockeyApp..."\
| pretty_print
APP="${PROJECT_ROOT}/build/android/bin/app.apk"
echo "[INFO] Uploading .ipa to HockeyApp..." \
| pretty_print
if [ "${RELEASE_NOTES}" == '' ]; then
RELEASE_NOTES='Build uploaded automatically from MakeTi.'
fi
echo "${APP_ID}"
/usr/bin/curl \
-F "status=2" \
-F "notify=1" \
-F "notes=${RELEASE_NOTES}" \
-F "notes_type=0" \
-F "ipa=@$(echo $APP)" \
-H "X-HockeyAppToken: ${API_TOKEN}" \
https://rink.hockeyapp.net/api/2/apps/${APP_ID}/app_versions
fi
done
elif [ "${list_called}" == "True" ]; then
if [ "${adb_output}" == "" ]; then
if [ "${device_found}" == "false" ]; then
echo "[ERROR] Could not find an attached android device with development mode enabled." >&2
exit 0
fi
fi
device_found="True"
bash -c "'${TI_ANDROID_BUILD}' install '${APP_NAME}' '${ANDROID_SDK_PATH}' '${PROJECT_ROOT}/' ${APP_ID} ${android}" \
| pretty_print
break
fi
if [ "${adb_output}" == "List of devices attached" ]; then
list_called="True"
fi
done
fi
elif [ ${APP_DEVICE} == "web" ]; then
# Web settings
TI_WEB_DIR="${TI_ASSETS_DIR}/mobileweb"
# make sure this SDK has mobileweb
if [ -d "${TI_WEB_DIR}" ]; then
echo "[DEBUG] Mobileweb is installed..."
else
echo "[ERROR] This Ti SDK does not support mobileweb... "
exit 1
fi
bash -c "'/usr/bin/python' '${TI_ASSETS_DIR}/mobileweb/builder.py' '${PROJECT_ROOT}' 'development'" \
| pretty_print
echo "Files are now located in '${PROJECT_ROOT}/build/mobileweb/' Copy to a webserver and launch index.html in a web browser" >&2
# bash -c "open '${PROJECT_ROOT}/build/mobileweb/index.html'"
else
echo "[ERROR] platform ${APP_DEVICE} is not supported!" >&2
echo ${APP_DEVICE}
fi