This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
acidify
executable file
·562 lines (510 loc) · 18 KB
/
acidify
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
#!/bin/bash
set -e
MAJVERSION=0
MINVERSION=4
RELVERSION=1
export PATH="~/bin:$PATH"
# Start the timer
START_TIME=$(date +%s)
# Command line arguments
ARCH=$(uname -m)
ACIDIFY_CMD=$(readlink -f $0)
ACIDIFY_DIR=$(dirname $ACIDIFY_CMD)
ACIDIFY_LINK=~/bin/acidify
command="${1}"
arg="${2}"
# Utility Functions
function load_acidify_config()
{
if [ -f ~/.acidify/config ]; then
source ~/.acidify/config
else
echo -en "Notice: Could not find configuration file. Using environmental or program defaults.\n" | color yellow
fi
DLJOBS=${DLJOBS:-4}
MANUFACTURER=${MANUFACTURER:-samsung}
DEVICE=${DEVICE:-galaxys4gmtd}
MODEL=${MODEL:-sgh-t959v}
LM_AOKP=${LM_AOKP:-"http://teamacid.github.com/manifests/$MODEL/AOKP/local_manifest.xml"}
LM_CM7=${LM_CM7:-"http://teamacid.github.com/manifests/$MODEL/CM7/local_manifest.xml"}
LM_CM9=${LM_CM9:-"http://teamacid.github.com/manifests/$MODEL/CM9/local_manifest.xml"}
GOOUSER=${GOOUSER:-TeamAcid}
ANDROID_ENV_DIR=${ANDROID_ENV_DIR:-${ANDROID_BUILD_TOP}}
}
function abort()
{
exit 1
}
function error()
{
echo -en "Error: ${*}" | color red
abort
}
function setbuildtype()
{
echo ${@} > $ANDROID_ENV_DIR/.acidify/buildtype || error "Could not write to $ANDROID_ENV_DIR/.acidify/buildtype !\n"
}
function getlocalmanifest()
{
local lm_url=""
case $buildtype in
AOKP) lm_url="$LM_AOKP";;
CM9) lm_url="$LM_CM9";;
CM7) lm_url="$LM_CM7";;
*) error "Invalid build type!\n";;
esac
if [ x"$lm_url" != x"" ]; then
message "Fetching $buildtype local manifest\n"
curl $lm_url > $ANDROID_ENV_DIR/.repo/local_manifest.xml
fi
}
function aptgetreq()
{
. /etc/lsb-release
case $DISTRIB_CODENAME in
precise|maya)
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl libc6-dev lib32ncurses5-dev x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386 schedtool \
pngcrush rsync libncurses5-dev
sudo ln -fs /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
;;
oneiric|lisa)
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline-gplv2-dev lib32z1-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc openjdk-6-jdk schedtool \
pngcrush rsync
sudo apt-get install libx11-dev:i386
;;
natty|katya)
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc openjdk-6-jdk schedtool pngcrush rsync
;;
maverick|julia)
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc openjdk-6-jdk schedtool pngcrush rsync
sudo ln -fs /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
;;
lucid|isadora)
sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc openjdk-6-jdk schedtool pngcrush rsync
;;
*)
error "Your version of Ubuntu is unsupported!\n"
;;
esac
}
function installreqpackages()
{
[[ -f /etc/lsb-release && -r /etc/lsb-release ]] && . /etc/lsb-release
case $DISTRIB_ID in
Ubuntu|LinuxMint) aptgetreq;;
*)
if [ x"$DISTRIB_ID" = x"" ]; then
DISTRIB_ID="Your system"
fi
error "$DISTRIB_ID is unsupported by this script!\n" \
"Refer to the building Android guide for $DISTRIB_ID\n" \
"to determine what packages you need.\n"
;;
esac
}
function gotoenv() {
if [ -z "$ANDROID_ENV_DIR" ]; then
cd $ANDROID_ENV_DIR
fi
}
function checkenv()
{
gotoenv
if [ -f $ANDROID_ENV_DIR/build/envsetup.sh ]; then
command -v brunch >/dev/null 2>&1 || . $ANDROID_ENV_DIR/build/envsetup.sh
else
error "Could not run envsetup.sh.\nHave you run acidify init yet?"
fi
}
function cleanenv()
{
gotoenv
if [ -f $ANDROID_ENV_DIR/build/envsetup.sh ]; then
checkenv
make clobber
fi
if [ -d $ANDROID_ENV_DIR/kernel/$MANUFACTURER/$DEVICE ]; then
cd $ANDROID_ENV_DIR/kernel/$MANUFACTURER/$DEVICE
make distclean
gotoenv
fi
if [ -d $ANDROID_ENV_DIR/android ]; then
message "Removing $ANDROID_ENV_DIR/android\n"
rm -rf $ANDROID_ENV_DIR/android
fi
if [ -d $ANDROID_ENV_DIR/platform_manifest ]; then
message "Removing $ANDROID_ENV_DIR/platform_manifest\n"
rm -rf $ANDROID_ENV_DIR/platform_manifest
fi
if [ -d $ANDROID_ENV_DIR/.repo/manifests ]; then
message "Removing $ANDROID_ENV_DIR/.repo/manifests\n"
rm -rf $ANDROID_ENV_DIR/.repo/manifests
fi
if [ -d $ANDROID_ENV_DIR/.repo/manifests.git ]; then
message "Removing $ANDROID_ENV_DIR/.repo/manifests.git\n"
rm -rf $ANDROID_ENV_DIR/.repo/manifests.git
fi
if [ -f $ANDROID_ENV_DIR/.repo/manifest.xml ]; then
message "Removing $ANDROID_ENV_DIR/.repo/manifest.xml\n"
rm -f $ANDROID_ENV_DIR/.repo/manifest.xml
fi
if [ -f $ANDROID_ENV_DIR/.repo/local_manifest.xml ]; then
message "Removing $ANDROID_ENV_DIR/.repo/local_manifest.xml\n"
rm -f $ANDROID_ENV_DIR/.repo/local_manifest.xml
fi
}
function color()
{
# make the color bold
local BOLD=1\;
function red {
COLOR=31
}
function green {
COLOR=32
}
function yellow {
COLOR=33
}
while (($#));
do
$1
shift
done
echo -en "\E["$BOLD""$COLOR"m"
cat
echo -en "\033[0m"
}
function message() {
# Piping the output in case we want to override the color
echo -en ${*} | color green
}
function initrepo(){
if [ x"$1" != x"" -a x"$2" != x"" -a x"$3" != x"" ]; then
local init_buildtype=$1
local init_repo_url=$2
local init_repo_branch=$3
setbuildtype "$init_buildtype"
cleanenv
message "Initializing repository\n"
repo init -u $init_repo_url -b $init_repo_branch
sync
message "Starting all projects on task branch $init_repo_branch\n"
message "This may cause issues with projects using\nnon-standard" \
"branch names (typically kernel projects). Make sure you\n" \
"checkout the appropriate branch as needed.\n"
repo start --all $init_repo_branch
else
error "You must supply all arguments to initrepo()\nPlease edit" \
"the script and try again.\n"
fi
}
function setbuildpath()
{
local wd=`pwd`
wd=${wd}
sed -i "s%\(ANDROID_ENV_DIR *= *\$\x7BANDROID_ENV_DIR:-\).*%\1`pwd`\x7D%" ~/.acidify/config
message "Build environment set to `pwd`\n"
}
function timer()
{
local end_time=$(date +%s)
local elapsed=$((end_time - START_TIME))
local e_hr=$((elapsed / 60 / 60))
local e_min=$(((elapsed / 60) % 60))
local e_sec=$((elapsed % 60))
printf "Elapsed Time: " | color yellow
[ $e_hr != 0 ] && printf "%d hr(s) " $e_hr | color yellow
[ $e_min != 0 ] && printf "%d min(s) " $e_min | color yellow
printf "%d sec(s)\n" $e_sec | color yellow
}
# Usable Functions
function setup()
{
mkdir -p ~/bin
message "Making Acidify available from any directory\n"
if [ ! -f $ACIDIFY_LINK ]; then
ln -s $ACIDIFY_CMD $ACIDIFY_LINK
fi
message "Installing required packages for building Android\n"
installreqpackages
message "Fetching the latest version of repo\n"
curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
chmod a+x ~/bin/repo
message "Your machine is ready to setup the Android build environment\n"
message "Please see http://source.android.com/source/initializing.html for\n"
message "instructions on setting up ADB and the udev rules required.\n"
}
function init()
{
command -v repo >/dev/null 2>&1 || error "You don't have the repo utility!\nRun 'acidify setup' to correct this.\n"
message "Attempting to initialize environment to build type $arg\n"
message "This WILL REMOVE ALL LOCAL CHANGES\n"
case $arg in
aokp)
init_buildtype="AOKP"
init_repo_url="https://github.com/AOKP/platform_manifest.git"
init_repo_branch="ics"
initrepo $init_buildtype $init_repo_url $init_repo_branch
setbuildpath
;;
cm7)
init_buildtype="CM7"
init_repo_url="https://github.com/CyanogenMod/android.git"
init_repo_branch="gingerbread"
initrepo $init_buildtype $init_repo_url $init_repo_branch
setbuildpath
$ANDROID_ENV_DIR/vendor/cyanogen/get-rommanager
;;
cm9)
init_buildtype="CM9"
init_repo_url="https://github.com/CyanogenMod/android.git"
init_repo_branch="ics"
initrepo $init_buildtype $init_repo_url $init_repo_branch
setbuildpath
$ANDROID_ENV_DIR/vendor/cm/get-prebuilts
;;
*)
error "That configuration does not exist!\n"
abort
;;
esac
}
function config()
{
checkenv
case $buildtype in
AOKP) lunch aokp_$DEVICE-userdebug;;
CM9) lunch cm_$DEVICE-eng;;
CM7) lunch cyanogen_$DEVICE-eng;;
*) error "Invalid build type!\n";;
esac
}
function build()
{
message "Building $buildtype\n"
checkenv
config
if [ "$buildtype" = "CM7" -a "$DEVICE" = "galaxys4gmtd" ]; then
$ANDROID_ENV_DIR/kernel/samsung/galaxys4gmtd/build.sh build
fi
mka bacon
if [ ! $? -eq 0 ]; then
error "mka ${build_argument} failed!\n"
fi
}
function clean()
{
if [ -d $ANDROID_ENV_DIR/kernel/$MANUFACTURER/$DEVICE ]; then
cd $ANDROID_ENV_DIR/kernel/$MANUFACTURER/$DEVICE
make distclean
fi
gotoenv
make clobber
}
function release()
{
clean
build
}
function deploy()
{
gotoenv
command -v adb >/dev/null 2>&1 || error "ADB is not installed and/or in your PATH, so I cannot deploy!\n"
local build_date=$(date -u +%Y%m%d)
local rm_zip_path
local local_zip_path
local remote_zip_path
case $buildtype in
AOKP)
# AOKP is annoying about naming its builds
# Someone that builds for AOKP should definitely fix this
AOKP_BUILD=6
device_build=$DEVICE"_milestone"
rm_zip_path=/sdcard/aokp_$DEVICE*.zip
local_zip_path=$ANDROID_ENV_DIR/out/target/product/$DEVICE/aokp_$device_build-$AOKP_BUILD.zip
remote_zip_path=/sdcard/aokp_$device_build-$AOKP_BUILD.zip
;;
CM9)
rm_zip_path=/sdcard/cm-9-*.zip
local_zip_path=$ANDROID_ENV_DIR/out/target/product/$DEVICE/cm-9-$build_date-UNOFFICIAL-$DEVICE.zip
remote_zip_path=/sdcard/cm-9-$build_date-UNOFFICIAL-$DEVICE.zip
;;
CM7)
rm_zip_path=/sdcard/cm-7-*.zip
local_zip_path=$ANDROID_ENV_DIR/out/target/product/$DEVICE/cm-7-$build_date-UNOFFICIAL-$DEVICE.zip
remote_zip_path=/sdcard/cm-7-$build_date-UNOFFICIAL-$DEVICE.zip
;;
*) error "Not a valid build type!\n";;
esac
if [ -f "$local_zip_path" ]; then
message "Waiting for your Android device to be detected...\n"
message "If this operation takes too long try unplugging and plugging your phone back in.\n"
adb wait-for-device
message "Removing old build(s)!\n"
adb shell rm "$rm_zip_path"
message "Pushing new build!\n"
adb push "$local_zip_path" "$remote_zip_path"
message "Operation completed (hopefully successfully).\n"
message "Rebooting to recovery...\n"
adb reboot recovery
else
error "Could not find the output zip file. Make sure you run a build first.\n"
fi
}
function upload()
{
gotoenv
local goodir=$(echo $buildtype | tr '[:upper:]' '[:lower:]')
local build_date=$(date -u +%Y%m%d)
local local_zip_path
local remote_zip_path
case $buildtype in
AOKP)
# AOKP is annoying about naming its builds
# Someone that builds for AOKP should definitely fix this
AOKP_BUILD=6
device_build=$DEVICE"_milestone"
local_zip_path=$ANDROID_ENV_DIR/out/target/product/$DEVICE/aokp_$device_build-$AOKP_BUILD.zip
remote_zip_path=$GOOUSER@upload.goo.im:/home/$GOOUSER/public_html/$goodir/
;;
CM9)
local_zip_path=$ANDROID_ENV_DIR/out/target/product/$DEVICE/cm-9-$build_date-UNOFFICIAL-$DEVICE.zip
remote_zip_path=$GOOUSER@upload.goo.im:/home/$GOOUSER/public_html/$goodir/
;;
CM7)
local_zip_path=$ANDROID_ENV_DIR/out/target/product/$DEVICE/cm-7-$build_date-UNOFFICIAL-$DEVICE.zip
remote_zip_path=$GOOUSER@upload.goo.im:/home/$GOOUSER/public_html/$goodir/
;;
*) error "Not a valid build type!\n";;
esac
if [ -f "$local_zip_path" ]; then
message "Uploading to goo.im\n"
message "If you upload fails, just run acidify upload again.\n"
message "The upload will continue from where it left off.\n"
rsync --partial --progress -e "ssh -p 2222" "$local_zip_path" "$remote_zip_path"
if [ $? -eq 0 ]; then
message "Uploaded latest build to goo.im\n"
else
error "The latest build failed to upload to goo.im !\n"
fi
else
error "Could not find the output zip file. Make sure you run a build first.\n"
fi
}
function sync()
{
getlocalmanifest
message "Syncing $buildtype changes with upstream\n"
repo sync -j$DLJOBS -d
}
function update()
{
message "Removing "
version
rm $ACIDIFY_DIR/acidify
message "Fetching newest version from Github\n"
curl https://raw.github.com/teamacid/acidify/master/acidify > $ACIDIFY_DIR/acidify
curl https://raw.github.com/teamacid/acidify/master/config.sample > $ACIDIFY_DIR/config.sample
chmod +x $ACIDIFY_DIR/acidify
message "Updated to "
$ACIDIFY_DIR/acidify version
message "You should examine the new config.sample as well, to see if your\n" \
"config needs to be modified further to support new features."
}
function flash()
{
message "This will flash the latest boot image via heimdall\n"
message "Make sure you're in download mode!\n"
command -v heimdall >/dev/null 2>&1 || error "heimdall-cli is not installed, so flashing cannot continue.\n"
if [ -f "$ANDROID_ENV_DIR/out/target/product/$DEVICE/boot.img" ]; then
message "Flashing boot image\n"
sudo heimdall flash --kernel "$ANDROID_ENV_DIR/out/target/product/$DEVICE/boot.img"
else
error "boot.img does not exist! You probably forgot to build it."
fi
}
function usage()
{
message "Usage: acidify [command] (build type)\n"
message "\n"
message "Commands:\n"
message "\tsetup\t\tFetches required packages in additon to repo for building Android\n"
message "\tinit\t\tInitializes the build environment to build the type specified in the argument\n"
message "\tsetenv\t\tSet configured Android build environment to the current working directory\n"
message "\tconfig\t\tConfigures the build environment for $DEVICE\n"
message "\tbuild\t\tBuilds a build for the $DEVICE\n"
message "\tclean\t\tCleans the build environment\n"
message "\trelease\t\tCompiles a clean build for the $DEVICE\n"
message "\tdeploy\t\tDeploys a new build to the device's SD card via adb\n"
message "\tupload\t\tUploads the latest build to goo.im\n"
message "\tsync\t\tSyncs the latest changes from upstream\n"
message "\tupdate\t\tUpdate acidify to the latest and greatest\n"
message "\tflash\t\tFlash the latest boot image via heimdall\n"
message "\n\n"
message "Available build types (case sensitive):\n"
message "\tcm7\t\tFor CyanogenMod 7\n"
message "\tcm9\t\tFor CyanogenMod 9\n"
message "\taokp\t\tFor Android Open Kang Project\n"
abort
}
function version()
{
message "Acidify version $MAJVERSION.$MINVERSION.$RELVERSION\n"
}
function main()
{
version
mkdir -p ~/.acidify
case $command in
setup) setup;;
init) init;;
setenv) setbuildpath;;
config) config;;
build) build;;
release) release;;
clean) clean;;
deploy) deploy;;
flash) flash;;
upload) upload;;
sync) sync;;
update) update;;
version) ;; # Leave this blank. Acidify prints its version on every run.
*) usage;;
esac
}
load_acidify_config
if [ x"${command}" = x"" ]; then
usage
fi
if [ x"${ARCH}" != x"x86_64" ]; then
error "Only 64-bit machines are supported!\n"
fi
if [ -f $ANDROID_ENV_DIR/.acidify/buildtype ]; then
buildtype=$(cat $ANDROID_ENV_DIR/.acidify/buildtype)
fi
main
if [ ! x"${command}" = x"version" -o x"${command}" = x"setenv" -o x"${command}" = x"" ]; then
timer
fi
# vi: ts=4:sw=4:sts=4:et:ai