diff --git a/README.md b/README.md
index dad843b..440bf64 100644
--- a/README.md
+++ b/README.md
@@ -1,44 +1,67 @@
-AABS
-==========
-Automated Android Build Script
-----------
-
-Getting started
-==========
-Download the minimal aabs-autorun script from GitHub
-
- git clone https://github.com/TeamNexus/aabs ./aabs/
- cp ./aabs/aabs.config.php ./aabs.config.php
- cp ./aabs/aabs.build.php ./aabs.build.php
- chmod +x ./aabs/aabs
-
-If you want to, you can edit the configs and build-operations
-to your needs. When you are finished, run "./aabs/aabs" and
-all devices and models available on the TeamNexus-repo will
-be built.
-
-Command Line-Options
-==========
-
- -d|--devices List of devices which should be built, seperated by a single space. Default: * to build all devices
- -r|--roms List of ROMs which should be built, seperated by a single space. Default: * to build all ROMs
- -S|--skip-sync Flag, which tells the build-system to skip "repo sync". Default: false
- -U|--skip-upload Flag, which tells the build-system to skip the build-uploads. Default: false
-
-License
-==========
-Automated Android Build Script - Simple and automated Android Build-Script
-Copyright (C) 2017 Lukas Berger
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see .
+AABS
+==========
+Automated Android Build Script
+----------
+
+Dependencies
+==========
+Minimal requirements: (Sync and build)
+
+ * System: bash, cd, cp, mkdir, rm, unzip, zip
+ * System: make, repo
+ * PHP 5.6
+ * PHP: Enabled `system` and `shell_exec`
+
+Recommended requirements: (Sync, build and patch)
+
+ * **Minimal requirements: (Sync and build) +**
+ * PHP: pcre-extension
+
+Recommended requirements: (Sync, build, patch and upload)
+
+ * **Recommended requirements: (Sync, build and patch) +**
+ * System: megacmd (https://mega.nz/cmd)
+ * PHP: ftp-extension (with SSL-support)
+ * PHP: sftp-extension
+
+Getting started
+==========
+Download AABS from the latest sources, copy the configuration
+and set correct permissions for the main executable.
+
+ git clone https://github.com/TeamNexus/aabs ./aabs/
+ cp ./aabs/aabs.config.php ./aabs.config.php
+ chmod +x ./aabs/aabs
+
+If you want to, you can edit the configs and build-operations
+to your needs. When you are finished, run "./aabs/aabs" and
+all devices and models available on the TeamNexus-repo will
+be built.
+
+Command Line-Options
+==========
+
+ -s, --skip-sync No synchronization of ROM-sources
+ -b, --skip-build Skips building the ROM
+ -u, --skip-patch Don't run let AABS-patcher run over the build
+ -u, --skip-upload Don't upload the ROM
+ -d, --devices Devices which should be built by AABS (Comma-separated, Have to be defined in aabs.build.php)
+ -r, --roms ROMS which should be built by AABS (Comma-separated, Have to be defined in aabs.build.php)
+
+License
+==========
+Automated Android Build Script - Simple and automated Android Build-Script
+Copyright (C) 2017 Lukas Berger
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
diff --git a/aabs b/aabs
index 45b5c0c..bb6c160 100755
--- a/aabs
+++ b/aabs
@@ -1,547 +1,22 @@
#!/usr/bin/php
$value) {
- switch ($key) {
- case "S":
- case "skip-sync":
- define("AABS_SKIP_SYNC", true);
- break;
+// include utilities
+include AABS_BASEDIR . "/core/utils.php";
- case "U":
- case "skip-upload":
- define("AABS_SKIP_UPLOAD", true);
- break;
-
- case "d":
- case "devices":
- define("AABS_DEVICES", $value . " ");
- break;
-
- case "r":
- case "roms":
- define("AABS_ROMS", $value . " ");
- break;
- }
- }
-
- if (is_file(dirname($argv[0]) . "/../aabs.config.php"))
- include dirname($argv[0]) . "/../aabs.config.php";
-
- include dirname($argv[0]) . "/aabs.config.php";
-
- if (!defined("AABS_SKIP_SYNC"))
- define("AABS_SKIP_SYNC", false);
-
- if (!defined("AABS_SKIP_UPLOAD"))
- define("AABS_SKIP_UPLOAD", false);
-
- if (!defined("AABS_DEVICES"))
- define("AABS_DEVICES", "*");
-
- if (!defined("AABS_ROMS"))
- define("AABS_ROMS", "*");
-
- if (is_file(dirname($argv[0]) . "/../aabs.build.php"))
- include dirname($argv[0]) . "/../aabs.build.php";
- else
- include dirname($argv[0]) . "/aabs.build.php";
-
- function aabs_sync($rom) {
- // check if sync is disabled
- if (AABS_SKIP_SYNC) {
- return;
- }
-
- // check if ROM is disabled
- if (AABS_ROMS != "*" && strpos(AABS_ROMS, "{$rom} ") === false) {
- return;
- }
-
- // check if ROM is supported
- __validate_rom($rom);
-
- $__assert = "";
- $__assert .= 'ret=$?' . "\n";
- $__assert .= 'if [ ! $ret -eq 0 ]; then' . "\n";
- $__assert .= "\t" . 'exit $ret' . "\n";
- $__assert .= 'fi' . "\n";
- $__assert .= "\n";
-
- $command = "";
- $command .= '#!/bin/bash' . "\n";
- $command .= "\n";
- $command .= 'cd "' . AABS_SOURCE_BASEDIR . "/{$rom}" . '"' . "\n" . $__assert;
- $command .= "\n";
- $command .= 'repo sync -c -d --force-sync --no-clone-bundle --jobs=' . AABS_SYNC_JOBS . "\n" . $__assert;
- $command .= "\n";
-
- __exec($command);
- }
-
- function aabs_build($rom, $device_prefix, $main_device, $targets_combinations) {
- // check if ROM is disabled
- if (AABS_ROMS != "*" && strpos(AABS_ROMS, "{$rom} ") === false) {
- return;
- }
-
- // check if device is disabled
- if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
- return;
- }
-
- // check if ROM is supported
- __validate_rom($rom);
-
- $output_match_path = "out/target/product/{$main_device}/" . __get_output_match($rom, $main_device);
-
- $__assert = "";
- $__assert .= 'ret=$?' . "\n";
- $__assert .= 'if [ ! $ret -eq 0 ]; then' . "\n";
- $__assert .= "\t" . 'exit $ret' . "\n";
- $__assert .= 'fi' . "\n";
- $__assert .= "\n";
-
- $command = "";
- $command .= '#!/bin/bash' . "\n";
- $command .= "\n";
- $command .= 'cd "' . AABS_SOURCE_BASEDIR . "/{$rom}" . '"' . "\n" . $__assert;
- $command .= "\n";
- $command .= 'rm -fv ' . $output_match_path . "\n" . $__assert;
- $command .= 'rm -fv ' . $output_match_path . '.bak' . "\n" . $__assert;
- $command .= "\n";
- $command .= 'export RR_BUILDTYPE=Unofficial' . "\n";
- $command .= 'export WITH_ROOT_METHOD="magisk"' . "\n";
- $command .= "\n";
- $command .= 'source build/envsetup.sh' . "\n";
- $command .= "\n";
- $command .= 'rm -fv "' . $output_match_path . '"' . "\n" . $__assert;
- $command .= 'rm -fv "' . $output_match_path . '.bak"' . "\n" . $__assert;
- $command .= "\n";
-
- foreach($targets_combinations as $device => $cmd) {
- // check if device is disabled
- if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
- continue;
- }
-
- $targets = isset($cmd['targets']) ? $cmd['targets'] : "bacon";
- $clobber = isset($cmd['clobber']) ? $cmd['clobber'] : false;
- $jobs = isset($cmd['jobs']) ? $cmd['jobs'] : AABS_BUILD_JOBS;
-
- $command .= 'lunch ' . $device_prefix . '_' . $device . '-userdebug' . "\n" . $__assert;
-
- if ($clobber) {
- $command .= 'make clobber -j' . $jobs . "\n" . $__assert;
- }
-
- $command .= 'make ' . $targets . ' -j' . $jobs . "\n" . $__assert;
- $command .= "\n";
- }
-
- __exec($command);
- }
-
- function aabs_patch($rom, $device, $targets = array( )) {
- if (is_array($device)) {
- $device_aliases = $device;
- $device = $device[0];
- }
-
- // check if ROM is disabled
- if (AABS_ROMS != "*" && strpos(AABS_ROMS, "{$rom} ") === false) {
- return;
- }
-
- // check if device is disabled
- if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
- return;
- }
-
- // check if ROM is supported
- __validate_rom($rom);
-
- $source_dir = AABS_SOURCE_BASEDIR . "/{$rom}";
- $output_dir = "{$source_dir}/out/target/product/{$device}";
- $output_name = trim(shell_exec("/bin/bash -c \"basename $output_dir/" . __get_output_match($rom, $device) . "\""), "\n\t");
- $output_path = "{$output_dir}/{$output_name}";
- $tmp = tempnam(sys_get_temp_dir(), 'aabs-patch-');
-
- if (is_file("$tmp"))
- unlink("$tmp");
-
- __mkdir("{$tmp}/");
- __mkdir("{$tmp}/patches/");
-
- __exec("unzip \"{$output_path}\" -d \"{$tmp}/\"");
-
- $script_targets = array( );
- foreach ($targets as $target_device => $target_options) {
- // check if device is disabled
- if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
- continue;
- }
-
- $target_out_dir = "{$source_dir}/out/target/product/{$target_device}";
- $target_patch_dir = "{$tmp}/patches/{$target_device}";
-
- if (!isset($script_targets[$target_device])) {
- $script_targets[$target_device] = array(
- 'boot' => false,
- 'system' => false
- );
- }
-
- __mkdir("{$target_patch_dir}");
-
- foreach ($target_options['files'] as $target_file) {
- if (is_array($target_file)) {
- $target_file_src = "{$source_dir}/{$target_file[0]}";
- $target_file_dst = "{$target_patch_dir}/{$target_file[1]}";
- } else {
- $target_file_src = "{$target_out_dir}/{$target_file}";
- $target_file_dst = "{$target_patch_dir}/{$target_file}";
- }
-
- if ($target_file_dst == "{$target_patch_dir}/boot.img")
- $script_targets[$target_device]['boot'] = true;
-
- if (strpos($target_file_dst, "{$target_patch_dir}/system/") === 0)
- $script_targets[$target_device]['system'] = true;
-
- $target_file_dirname = dirname($target_file_dst);
-
- __mkdir("{$target_file_dirname}");
- __exec("cp -f {$target_file_src} {$target_file_dst}");
- }
- }
-
- $updater_script_path = "{$tmp}/META-INF/com/google/android/updater-script";
- $updater_script = file_get_contents($updater_script_path);
-
- $updater_script_asserts = "";
- $updater_script_boot_asserts = "";
- $updater_script_boot = "";
- $updater_script_system_asserts = "";
- $updater_script_system = "";
-
- $updater_device_assert = "getprop(\"ro.product.device\") == \"%%\" || getprop(\"ro.build.product\") == \"%%\" || ";
-
- if (preg_match("/package_extract_file\(\"boot.img\", \"([^\"]*)\"\);/", $updater_script, $boot_device_match) == 0) {
- die("Failed to get path of BOOT block-device\n");
- }
-
- foreach ($script_targets as $target => $flags) {
- if ($flags['boot']) {
- $target_device_asserts = str_replace("%%", $target, $updater_device_assert);
- foreach ($targets[$target]['alias'] as $alias) {
- $target_device_asserts .= str_replace("%%", $alias, $updater_device_assert);
- }
-
- $target_device_asserts = substr($target_device_asserts, 0, strlen($target_device_asserts) - 4);
- $updater_script_boot_asserts .= $target_device_asserts . ' || ';
-
- $updater_script_boot .= "if {$target_device_asserts} then\n";
- $updater_script_boot .= "ui_print(\"[AABS] Injecting kernel for {$target}\");\n";
- $updater_script_boot .= "package_extract_file(\"patches/{$target}/boot.img\", \"{$boot_device_match[1]}\");\n";
- $updater_script_boot .= "endif;\n";
- }
-
- if ($flags['system']) {
- $target_device_asserts = str_replace("%%", $target, $updater_device_assert);
- foreach ($targets[$target]['alias'] as $alias) {
- $target_device_asserts .= str_replace("%%", $alias, $updater_device_assert);
- }
-
- $target_device_asserts = substr($target_device_asserts, 0, strlen($target_device_asserts) - 4);
- $updater_script_system_asserts .= $target_device_asserts . ' || ';
-
- $updater_script_system .= "if {$target_device_asserts} then\n";
- $updater_script_system .= "ui_print(\"[AABS] Injecting /system for {$target}\");\n";
- $updater_script_system .= "package_extract_dir(\"patches/{$target}/system\", \"/system\");\n";
- $updater_script_system .= "endif;\n";
- }
-
- $updater_script_asserts .= $target_device_asserts . ' || ';
- }
-
- if ($updater_script_boot_asserts != "") {
- $boot_flash_command = substr($boot_device_match[0], 0, strlen($boot_device_match[0]) - 1);
- $updater_script_boot_asserts = substr($updater_script_boot_asserts, 0, strlen($updater_script_boot_asserts) - 4);
-
- $updater_script_boot .= "if !({$updater_script_boot_asserts}) then\n";
- $updater_script_boot .= "ui_print(\"[AABS] Injecting default kernel\");\n";
- $updater_script_boot .= "{$boot_flash_command}\n";
- $updater_script_boot .= "endif;\n";
-
- $updater_script = str_replace($boot_device_match[0], $updater_script_boot, $updater_script);
- }
-
- if ($updater_script_system_asserts != "") {
- $system_unmount_pos = strrpos($updater_script, "unmount(\"/system\");");
- $updater_script_system_asserts = substr($updater_script_system_asserts, 0, strlen($updater_script_system_asserts) - 4);
-
- $updater_script =
- substr($updater_script, 0, $system_unmount_pos) .
- $updater_script_system . "\n" .
- "if !({$updater_script_system_asserts}) then\n" .
- "ui_print(\"[AABS] No need to inject /system\");\n" .
- "endif;\n" .
- substr($updater_script, $system_unmount_pos, strlen($updater_script) - $system_unmount_pos);
- }
-
- foreach ($device_aliases as $device_alias) {
- $updater_script_asserts = str_replace("%%", $device_alias, $updater_device_assert) . $updater_script_asserts;
- }
-
- $updater_script_asserts = substr($updater_script_asserts, 0, strlen($updater_script_asserts) - 4);
-
- $updater_script_assert_line = strpos($updater_script, "\n");
- $updater_script = substr($updater_script, $updater_script_assert_line);
-
- $updater_script =
- "if !({$updater_script_asserts}) then\n" .
- "ui_print(\"\");\n" .
- "ui_print(\"\");\n" .
- "ui_print(\" *****************************************\");\n" .
- "ui_print(\" ** **\");\n" .
- "ui_print(\" ** SORRY, BUT THIS BUILD DOESN'T **\");\n" .
- "ui_print(\" ** SUPPORT YOUR DEVICE **\");\n" .
- "ui_print(\" ** **\");\n" .
- "ui_print(\" *****************************************\");\n" .
- "ui_print(\"\");\n" .
- "ui_print(\"\");\n" .
- "endif;\n" .
- "assert({$updater_script_asserts});\n" .
- "ui_print(\" \");\n" .
- "ui_print(\" \");\n" .
- "ui_print(\" Prepared and patched with \");\n" .
- "ui_print(\" \");\n" .
- "ui_print(\" _______ _______ ______ ______\");\n" .
- "ui_print(\" (_______|_______|____ \ / _____)\");\n" .
- "ui_print(\" _______ _______ ____) | (____\");\n" .
- "ui_print(\" | ___ | ___ | __ ( \____ \\\\\");\n" .
- "ui_print(\" | | | | | | | |__) )_____) )\");\n" .
- "ui_print(\" |_| |_|_| |_|______/(______/\");\n" .
- "ui_print(\" \");\n" .
- "ui_print(\" https://github.com/TeamNexus/aabs\");\n" .
- "ui_print(\" \");\n" .
- "ui_print(\" \");\n" .
- "ui_print(\" *********************************\");\n" .
- "ui_print(\" ROM-Name: {$rom}\");\n" .
- "ui_print(\" Base-Device: {$device}\");\n" .
- "ui_print(\" Timestamp: " . date("Y-m-d H:i:s", AABS_START_TIME) . "\");\n" .
- "ui_print(\" *********************************\");\n" .
- "ui_print(\" \");\n" .
- $updater_script;
-
- file_put_contents($updater_script_path, $updater_script);
-
- __exec("mv {$output_path} {$output_path}.bak");
- __exec("cd {$tmp} && zip -r9 {$output_path} .");
- __exec("rm -rfv {$tmp}");
- }
-
- function aabs_upload($rom, $short_device, $device) {
- // check if uploading is disabled
- if (AABS_SKIP_UPLOAD) {
- return;
- }
-
- // check if ROM is supported
- __validate_rom($rom);
-
- // check if ROM is disabled
- if (AABS_ROMS != "*" && strpos(AABS_ROMS, "{$rom} ") === false) {
- return;
- }
-
- // check if device is disabled
- if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
- return;
- }
-
- $source_dir = AABS_SOURCE_BASEDIR . "/{$rom}";
- $output_dir = "{$source_dir}/out/target/product/{$device}";
- $output_name = trim(shell_exec("/bin/bash -c \"basename $output_dir/" . __get_output_match($rom, $device) . "\""), "\n\t");
- $output_path = "{$output_dir}/{$output_name}";
-
- $upload_dir = AABS_UPLOAD_DIR;
- $upload_dir_len = strlen($upload_dir);
- for ($i = 0; $i < $upload_dir_len; $i++) {
- if ($upload_dir[$i] == '%' && $i + 1 < $upload_dir_len) {
- $upload_dir = str_replace($upload_dir[$i] . $upload_dir[$i + 1], date($upload_dir[$i + 1], AABS_START_TIME), $upload_dir);
- $upload_dir_len = strlen($upload_dir);
- }
- }
- $upload_dir = str_replace("{ROM}", $rom, $upload_dir);
- $upload_dir = str_replace("{DEVICE}", $device, $upload_dir);
- $upload_dir = str_replace("{SHORT_DEVICE}", $short_device, $upload_dir);
-
- $upload_file = AABS_UPLOAD_FILE;
- $upload_file_len = strlen($upload_file);
- for ($i = 0; $i < $upload_file_len; $i++) {
- if ($upload_file[$i] == '%' && $i + 1 < $upload_file_len) {
- $upload_file = str_replace($upload_file[$i] . $upload_file[$i + 1], date($upload_file[$i + 1], AABS_START_TIME), $upload_file);
- $upload_file_len = strlen($upload_file);
- }
- }
- $upload_file = str_replace("{ROM}", $rom, $upload_file);
- $upload_file = str_replace("{DEVICE}", $device, $upload_file);
- $upload_file = str_replace("{SHORT_DEVICE}", $short_device, $upload_file);
-
- echo "\n";
- echo "\n";
-
- switch (AABS_UPLOAD_TYPE) {
- case "sftp":
-
- echo "Connecting to " . AABS_UPLOAD_HOST . ":" . AABS_UPLOAD_PORT . "...\n";
- if (!$ssh_conn = ssh2_connect(AABS_UPLOAD_HOST, AABS_UPLOAD_PORT))
- die("aabs_upload: failed to establish connection to " . AABS_UPLOAD_HOST . ":" . AABS_UPLOAD_PORT);
-
- echo "Authenicating...\n";
- if (!ssh2_auth_password($ssh_conn, AABS_UPLOAD_USER, AABS_UPLOAD_PASS))
- die("aabs_upload: failed to login to " . AABS_UPLOAD_HOST . ":" . AABS_UPLOAD_PORT . " (Using password: " . (AABS_UPLOAD_PASS == "" ? "no" : "yes") . ")");
-
- echo "Creating SFTP-session...\n";
- if (!$sftp_conn = ssh2_sftp($connection))
- die("aabs_upload: failed to create a SFTP-session");
-
- echo "Creating upload-directory...\n";
- if (!ssh2_exec($ssh_conn, "mkdir -p \"{$upload_dir}\""))
- die("aabs_upload: failed to create upload-directory");
-
- $remote_stream = @fopen("ssh2.sftp://$sftp_conn$upload_dir/.$upload_file", 'w');
- $local_stream = @fopen($output_path, 'r');
-
- if (!flock($local_stream, LOCK_SH))
- die("aabs_upload: failed to acquire lock for local file");
-
- $total = filesize($output_path);
- $current = 0;
-
- echo "\rUploading {$current} / {$total}...";
-
- while(!feof($local_stream)) {
- $buffer = fread($local_stream, 8192);
- fwrite($remote_stream, $buffer, strlen($buffer));
-
- $current += strlen($buffer);
- echo "\rUploading {$current} / {$total}...";
- }
- fflush($remote_stream);
-
- fclose($remote_stream);
- fclose($local_stream);
-
- echo "Make build visible...\n";
- if (!ssh2_exec($ssh_conn, "mv \"$upload_dir/.$upload_file\" \"$upload_dir/$upload_file\""))
- die("aabs_upload: failed to rename uploaded build-file");
-
- echo "\nFinished!";
- break;
-
- case "ftp":
-
- echo "Connecting to " . AABS_UPLOAD_HOST . ":" . AABS_UPLOAD_PORT . "...\n";
- if (!$ftp_conn = ftp_ssl_connect(AABS_UPLOAD_HOST, AABS_UPLOAD_PORT))
- die("aabs_upload: failed to establish connection to " . AABS_UPLOAD_HOST . ":" . AABS_UPLOAD_PORT);
-
- echo "Authenicating...\n";
- if (!ftp_login($ftp_conn, AABS_UPLOAD_USER, AABS_UPLOAD_PASS))
- die("aabs_upload: failed to login to " . AABS_UPLOAD_HOST . ":" . AABS_UPLOAD_PORT . " (Using password: " . (AABS_UPLOAD_PASS == "" ? "no" : "yes") . ")");
-
- echo "Switching to passive-mode...\n";
- if (!ftp_pasv($ftp_conn, true))
- die("aabs_upload: failed to switch to passive-mode");
-
- echo "Creating upload-directory...\n";
- if (!ftp_mksubdirs($ftp_conn, "/", $upload_dir))
- die("aabs_upload: failed to create upload-directory \"${upload_dir}\"");
-
- echo "Uploading...\n";
- if (!ftp_put($ftp_conn, "${upload_dir}/.${upload_file}", $output_path, FTP_BINARY))
- die("aabs_upload: failed to upload build to \"${upload_dir}/.${upload_file}\"");
-
- echo "Make build visible...\n";
- if (!ftp_rename($ftp_conn, "$upload_dir/.$upload_file", "$upload_dir/$upload_file"))
- die("aabs_upload: failed to rename uploaded build-file");
-
- echo "\nFinished!";
- break;
- }
-
- echo "\n";
- echo "\n";
- }
-
- function __mkdir($name) {
- if(!is_dir($name))
- __exec("mkdir -p {$name}");
- }
-
- function __exec($cmdline, $censoring = array( )) {
- $output = array( );
- $rc = 0;
- $dcmdline = $cmdline;
-
- if (strpos($cmdline, "\n") !== false) {
- $tempfile = tempnam(sys_get_temp_dir(), "aabs-exec-");
- file_put_contents($tempfile, $cmdline);
- chmod($tempfile, 0777);
- $dcmdline = $cmdline = "/bin/bash -c {$tempfile}";
- } else {
- foreach($censoring as $censor) {
- $dcmdline = str_replace($censor, "***", $dcmdline);
- }
- }
-
- echo "{$dcmdline}\n";
- system("{$cmdline}", $rc);
-
- if ($rc != 0) {
- die("Previous command failed with {$rc}\n");
- }
- }
-
- function __validate_rom($rom) {
- switch ($rom) {
- case "NexusOS":
- case "LineageOS":
- case "ResurrectionRemix":
- case "AOKP":
- return;
- }
-
- throw new Exception("Unsupported ROM: {$rom} (Supported: LineageOS, NexusOS, ResurrectionRemix, AOKP)");
- }
-
- function __get_output_match($rom, $device) {
- __validate_rom($rom);
-
- switch ($rom) {
- case "LineageOS":
- case "NexusOS":
- case "ResurrectionRemix":
- return "lineage_${device}-ota-*.zip";
- case "AOKP":
- return "aokp_${device}-ota-*.zip";
- }
- }
+// include remote-plugins
+include AABS_BASEDIR . "/remote/ftp.php";
+include AABS_BASEDIR . "/remote/sftp.php";
+include AABS_BASEDIR . "/remote/mega.php";
- // http://php.net/manual/en/function.ftp-mkdir.php#112399
- function ftp_mksubdirs($ftpcon, $ftpbasedir, $ftpath) {
- @ftp_chdir($ftpcon, $ftpbasedir);
- $parts = explode('/', $ftpath);
- foreach($parts as $part) {
- if(!@ftp_chdir($ftpcon, $part)) {
- @ftp_mkdir($ftpcon, $part);
- @ftp_chdir($ftpcon, $part);
- }
- }
- return true;
- }
+// include core-functions
+include AABS_BASEDIR . "/core/sync.php";
+include AABS_BASEDIR . "/core/build.php";
+include AABS_BASEDIR . "/core/patch.php";
+include AABS_BASEDIR . "/core/upload.php";
+
+// parse arguments, load configurations and start building
+include AABS_BASEDIR . "/core/core.php";
diff --git a/aabs.build.php b/aabs.build.php
index 2471ecc..98e99e4 100644
--- a/aabs.build.php
+++ b/aabs.build.php
@@ -1,59 +1,59 @@
- array(
- 'clobber' => AABS_SOURCE_CLOBBER,
- ),
- 'zeroltexx' => array(
- 'targets' => "bootimage",
- ),
- 'zerofltecan' => array(
- 'targets' => "bootimage audio.primary.universal7420_32 audio.primary.universal7420",
- ),
- 'zeroltecan' => array(
- 'targets' => "bootimage audio.primary.universal7420_32 audio.primary.universal7420",
- )
- ));
- aabs_patch($rom, array( "zerofltexx", "zeroflte" ), array(
- 'zeroltexx' => array(
- 'alias' => array( 'zerolte' ),
- 'files' => array(
- "boot.img",
- ),
- ),
- 'zerofltecan' => array(
- 'alias' => array( 'zerofltetmo', 'zerofltespr' ),
- 'files' => array(
- "boot.img",
- "system/lib/hw/audio.primary.universal7420.so",
- "system/lib64/hw/audio.primary.universal7420.so",
- array( "device/samsung/zerofltecan/configs/audio/mixer_paths_0.xml", "system/etc/mixer_paths_0.xml" ),
- ),
- ),
- 'zeroltecan' => array(
- 'alias' => array( 'zeroltetmo', 'zeroltespr' ),
- 'files' => array(
- "boot.img",
- "system/lib/hw/audio.primary.universal7420.so",
- "system/lib64/hw/audio.primary.universal7420.so",
- array( "device/samsung/zeroltecan/configs/audio/mixer_paths_0.xml", "system/etc/mixer_paths_0.xml" ),
- )
- ),
- ));
- aabs_upload($rom, "zero", "zerofltexx");
- }
+ array(
+ 'clobber' => AABS_SOURCE_CLOBBER,
+ ),
+ 'zeroltexx' => array(
+ 'targets' => "bootimage",
+ ),
+ 'zerofltecan' => array(
+ 'targets' => "bootimage audio.primary.universal7420_32 audio.primary.universal7420",
+ ),
+ 'zeroltecan' => array(
+ 'targets' => "bootimage audio.primary.universal7420_32 audio.primary.universal7420",
+ )
+ ));
+ aabs_patch($rom, array( "zerofltexx", "zeroflte" ), array(
+ 'zeroltexx' => array(
+ 'alias' => array( 'zerolte' ),
+ 'files' => array(
+ "boot.img",
+ ),
+ ),
+ 'zerofltecan' => array(
+ 'alias' => array( 'zerofltetmo', 'zerofltespr' ),
+ 'files' => array(
+ "boot.img",
+ "system/lib/hw/audio.primary.universal7420.so",
+ "system/lib64/hw/audio.primary.universal7420.so",
+ array( "device/samsung/zerofltecan/configs/audio/mixer_paths_0.xml", "system/etc/mixer_paths_0.xml" ),
+ ),
+ ),
+ 'zeroltecan' => array(
+ 'alias' => array( 'zeroltetmo', 'zeroltespr' ),
+ 'files' => array(
+ "boot.img",
+ "system/lib/hw/audio.primary.universal7420.so",
+ "system/lib64/hw/audio.primary.universal7420.so",
+ array( "device/samsung/zeroltecan/configs/audio/mixer_paths_0.xml", "system/etc/mixer_paths_0.xml" ),
+ )
+ ),
+ ));
+ aabs_upload($rom, "zero", "zerofltexx");
+ }
diff --git a/aabs.config.php b/aabs.config.php
index 8da07ec..810000c 100644
--- a/aabs.config.php
+++ b/aabs.config.php
@@ -1,113 +1,129 @@
- $cmd) {
+ // check if device is disabled
+ if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
+ continue;
+ }
+
+ $targets = isset($cmd['targets']) ? $cmd['targets'] : "bacon";
+ $clobber = isset($cmd['clobber']) ? $cmd['clobber'] : false;
+ $jobs = isset($cmd['jobs']) ? $cmd['jobs'] : AABS_BUILD_JOBS;
+
+ $command .= 'lunch ' . $device_prefix . '_' . $device . '-userdebug' . "\n" . $__assert;
+
+ if ($clobber) {
+ $command .= 'make clobber -j' . $jobs . "\n" . $__assert;
+ }
+
+ $command .= 'make ' . $targets . ' -j' . $jobs . "\n" . $__assert;
+ $command .= "\n";
+ }
+
+ __exec($command);
+}
\ No newline at end of file
diff --git a/core/core.php b/core/core.php
new file mode 100644
index 0000000..6c040a6
--- /dev/null
+++ b/core/core.php
@@ -0,0 +1,96 @@
+ $value) {
+ switch ($key) {
+ case "s":
+ case "skip-sync":
+ if (defined("AABS_SKIP_SYNC"))
+ goto help;
+
+ define("AABS_SKIP_SYNC", true);
+ break;
+
+ case "b":
+ case "skip-build":
+ if (defined("AABS_SKIP_UPLOAD"))
+ goto help;
+
+ define("AABS_SKIP_BUILD", true);
+ break;
+
+ case "p":
+ case "skip-patch":
+ if (defined("AABS_SKIP_PATCH"))
+ goto help;
+
+ define("AABS_SKIP_PATCH", true);
+ break;
+
+ case "u":
+ case "skip-upload":
+ if (defined("AABS_SKIP_UPLOAD"))
+ goto help;
+
+ define("AABS_SKIP_UPLOAD", true);
+ break;
+
+ case "d":
+ case "devices":
+ if (defined("AABS_SKIP_SYNC"))
+ goto help;
+
+ define("AABS_DEVICES", $value . " ");
+ break;
+
+ case "r":
+ case "roms":
+ if (defined("AABS_ROMS"))
+ goto help;
+
+ define("AABS_ROMS", $value . " ");
+ break;
+
+ default:
+help:
+ echo "aabs: invalid option \"{$key}\"\n";
+ echo "Usage: aabs [options]\n";
+ echo "Options:\n";
+ echo " -s, --skip-sync No synchronization of ROM-sources\n";
+ echo " -b, --skip-build Skips building the ROM\n";
+ echo " -u, --skip-patch Don't run let AABS-patcher run over the build\n";
+ echo " -u, --skip-upload Don't upload the ROM\n";
+ echo " -d, --devices Devices which should be built by AABS (Comma-separated, Have to be defined in aabs.build.php)\n";
+ echo " -r, --roms ROMS which should be built by AABS (Comma-separated, Have to be defined in aabs.build.php)\n";
+ echo "\n";
+ exit;
+ }
+}
+
+if (is_file(dirname($argv[0]) . "/../aabs.config.php"))
+ include dirname($argv[0]) . "/../aabs.config.php";
+
+include dirname($argv[0]) . "/aabs.config.php";
+
+if (!defined("AABS_SKIP_SYNC"))
+ define("AABS_SKIP_SYNC", false);
+
+if (!defined("AABS_SKIP_BUILD"))
+ define("AABS_SKIP_BUILD", false);
+
+if (!defined("AABS_SKIP_PATCH"))
+ define("AABS_SKIP_PATCH", false);
+
+if (!defined("AABS_SKIP_UPLOAD"))
+ define("AABS_SKIP_UPLOAD", false);
+
+if (!defined("AABS_DEVICES"))
+ define("AABS_DEVICES", "*");
+
+if (!defined("AABS_ROMS"))
+ define("AABS_ROMS", "*");
+
+if (is_file(dirname($argv[0]) . "/../aabs.build.php"))
+ include dirname($argv[0]) . "/../aabs.build.php";
+else
+ include dirname($argv[0]) . "/aabs.build.php";
diff --git a/core/patch.php b/core/patch.php
new file mode 100644
index 0000000..b6e2994
--- /dev/null
+++ b/core/patch.php
@@ -0,0 +1,211 @@
+ $target_options) {
+ // check if device is disabled
+ if (AABS_DEVICES != "*" && strpos(AABS_DEVICES, "{$device} ") === false) {
+ continue;
+ }
+
+ $target_out_dir = "{$source_dir}/out/target/product/{$target_device}";
+ $target_patch_dir = "{$tmp}/patches/{$target_device}";
+
+ if (!isset($script_targets[$target_device])) {
+ $script_targets[$target_device] = array(
+ 'boot' => false,
+ 'system' => false
+ );
+ }
+
+ __mkdir("{$target_patch_dir}");
+
+ foreach ($target_options['files'] as $target_file) {
+ if (is_array($target_file)) {
+ $target_file_src = "{$source_dir}/{$target_file[0]}";
+ $target_file_dst = "{$target_patch_dir}/{$target_file[1]}";
+ } else {
+ $target_file_src = "{$target_out_dir}/{$target_file}";
+ $target_file_dst = "{$target_patch_dir}/{$target_file}";
+ }
+
+ if ($target_file_dst == "{$target_patch_dir}/boot.img")
+ $script_targets[$target_device]['boot'] = true;
+
+ if (strpos($target_file_dst, "{$target_patch_dir}/system/") === 0)
+ $script_targets[$target_device]['system'] = true;
+
+ $target_file_dirname = dirname($target_file_dst);
+
+ __mkdir("{$target_file_dirname}");
+ __exec("cp -f {$target_file_src} {$target_file_dst}");
+ }
+ }
+
+ $updater_script_path = "{$tmp}/META-INF/com/google/android/updater-script";
+ $updater_script = file_get_contents($updater_script_path);
+
+ $updater_script_asserts = "";
+ $updater_script_boot_asserts = "";
+ $updater_script_boot = "";
+ $updater_script_system_asserts = "";
+ $updater_script_system = "";
+
+ $updater_device_assert = "getprop(\"ro.product.device\") == \"%%\" || getprop(\"ro.build.product\") == \"%%\" || ";
+
+ if (preg_match("/package_extract_file\(\"boot.img\", \"([^\"]*)\"\);/", $updater_script, $boot_device_match) == 0) {
+ die("Failed to get path of BOOT block-device\n");
+ }
+
+ foreach ($script_targets as $target => $flags) {
+ if ($flags['boot']) {
+ $target_device_asserts = str_replace("%%", $target, $updater_device_assert);
+ foreach ($targets[$target]['alias'] as $alias) {
+ $target_device_asserts .= str_replace("%%", $alias, $updater_device_assert);
+ }
+
+ $target_device_asserts = substr($target_device_asserts, 0, strlen($target_device_asserts) - 4);
+ $updater_script_boot_asserts .= $target_device_asserts . ' || ';
+
+ $updater_script_boot .= "if {$target_device_asserts} then\n";
+ $updater_script_boot .= "ui_print(\"[AABS] Injecting kernel for {$target}\");\n";
+ $updater_script_boot .= "package_extract_file(\"patches/{$target}/boot.img\", \"{$boot_device_match[1]}\");\n";
+ $updater_script_boot .= "endif;\n";
+ }
+
+ if ($flags['system']) {
+ $target_device_asserts = str_replace("%%", $target, $updater_device_assert);
+ foreach ($targets[$target]['alias'] as $alias) {
+ $target_device_asserts .= str_replace("%%", $alias, $updater_device_assert);
+ }
+
+ $target_device_asserts = substr($target_device_asserts, 0, strlen($target_device_asserts) - 4);
+ $updater_script_system_asserts .= $target_device_asserts . ' || ';
+
+ $updater_script_system .= "if {$target_device_asserts} then\n";
+ $updater_script_system .= "ui_print(\"[AABS] Injecting /system for {$target}\");\n";
+ $updater_script_system .= "package_extract_dir(\"patches/{$target}/system\", \"/system\");\n";
+ $updater_script_system .= "endif;\n";
+ }
+
+ $updater_script_asserts .= $target_device_asserts . ' || ';
+ }
+
+ if ($updater_script_boot_asserts != "") {
+ $boot_flash_command = substr($boot_device_match[0], 0, strlen($boot_device_match[0]) - 1);
+ $updater_script_boot_asserts = substr($updater_script_boot_asserts, 0, strlen($updater_script_boot_asserts) - 4);
+
+ $updater_script_boot .= "if !({$updater_script_boot_asserts}) then\n";
+ $updater_script_boot .= "ui_print(\"[AABS] Injecting default kernel\");\n";
+ $updater_script_boot .= "{$boot_flash_command}\n";
+ $updater_script_boot .= "endif;\n";
+
+ $updater_script = str_replace($boot_device_match[0], $updater_script_boot, $updater_script);
+ }
+
+ if ($updater_script_system_asserts != "") {
+ $system_unmount_pos = strrpos($updater_script, "unmount(\"/system\");");
+ $updater_script_system_asserts = substr($updater_script_system_asserts, 0, strlen($updater_script_system_asserts) - 4);
+
+ $updater_script =
+ substr($updater_script, 0, $system_unmount_pos) .
+ $updater_script_system . "\n" .
+ "if !({$updater_script_system_asserts}) then\n" .
+ "ui_print(\"[AABS] No need to inject /system\");\n" .
+ "endif;\n" .
+ substr($updater_script, $system_unmount_pos, strlen($updater_script) - $system_unmount_pos);
+ }
+
+ foreach ($device_aliases as $device_alias) {
+ $updater_script_asserts = str_replace("%%", $device_alias, $updater_device_assert) . $updater_script_asserts;
+ }
+
+ $updater_script_asserts = substr($updater_script_asserts, 0, strlen($updater_script_asserts) - 4);
+
+ $updater_script_assert_line = strpos($updater_script, "\n");
+ $updater_script = substr($updater_script, $updater_script_assert_line);
+
+ $updater_script =
+ "if !({$updater_script_asserts}) then\n" .
+ "ui_print(\"\");\n" .
+ "ui_print(\"\");\n" .
+ "ui_print(\" *****************************************\");\n" .
+ "ui_print(\" ** **\");\n" .
+ "ui_print(\" ** SORRY, BUT THIS BUILD DOESN'T **\");\n" .
+ "ui_print(\" ** SUPPORT YOUR DEVICE **\");\n" .
+ "ui_print(\" ** **\");\n" .
+ "ui_print(\" *****************************************\");\n" .
+ "ui_print(\"\");\n" .
+ "ui_print(\"\");\n" .
+ "endif;\n" .
+ "assert({$updater_script_asserts});\n" .
+ "ui_print(\" \");\n" .
+ "ui_print(\" \");\n" .
+ "ui_print(\" Prepared and patched with \");\n" .
+ "ui_print(\" \");\n" .
+ "ui_print(\" _______ _______ ______ ______\");\n" .
+ "ui_print(\" (_______|_______|____ \ / _____)\");\n" .
+ "ui_print(\" _______ _______ ____) | (____\");\n" .
+ "ui_print(\" | ___ | ___ | __ ( \____ \\\\\");\n" .
+ "ui_print(\" | | | | | | | |__) )_____) )\");\n" .
+ "ui_print(\" |_| |_|_| |_|______/(______/\");\n" .
+ "ui_print(\" \");\n" .
+ "ui_print(\" https://github.com/TeamNexus/aabs\");\n" .
+ "ui_print(\" \");\n" .
+ "ui_print(\" \");\n" .
+ "ui_print(\" *********************************\");\n" .
+ "ui_print(\" ROM-Name: {$rom}\");\n" .
+ "ui_print(\" Base-Device: {$device}\");\n" .
+ "ui_print(\" Timestamp: " . date("Y-m-d H:i:s", AABS_START_TIME) . "\");\n" .
+ "ui_print(\" *********************************\");\n" .
+ "ui_print(\" \");\n" .
+ $updater_script;
+
+ file_put_contents($updater_script_path, $updater_script);
+
+ __exec("mv {$output_path} {$output_path}.bak");
+ __exec("cd {$tmp} && zip -r9 {$output_path} .");
+ __exec("rm -rfv {$tmp}");
+}
\ No newline at end of file
diff --git a/core/sync.php b/core/sync.php
new file mode 100644
index 0000000..ab56057
--- /dev/null
+++ b/core/sync.php
@@ -0,0 +1,33 @@
+ array(
+ 'host' => AABS_UPLOAD_HOST,
+ 'port' => AABS_UPLOAD_PORT,
+ 'user' => AABS_UPLOAD_USER,
+ 'pass' => AABS_UPLOAD_PASS,
+ ),
+ );
+ break;
+
+ case "ftp":
+ $fn = "upload_to_ftp";
+ $params = array(
+ 'remote' => array(
+ 'host' => AABS_UPLOAD_HOST,
+ 'port' => AABS_UPLOAD_PORT,
+ 'user' => AABS_UPLOAD_USER,
+ 'pass' => AABS_UPLOAD_PASS,
+ ),
+ );
+ break;
+
+ case "mega":
+ $fn = "upload_to_mega";
+ $params = array(
+ 'remote' => array(
+ 'user' => AABS_UPLOAD_USER,
+ 'pass' => AABS_UPLOAD_PASS,
+ ),
+ );
+ break;
+ }
+
+ $params['output'] = array(
+ 'path' => $output_path,
+ 'dir' => $output_dir,
+ 'file' => $output_name,
+ );
+ $params['upload'] = array(
+ 'dir' => $upload_dir,
+ 'file' => $upload_file,
+ );
+
+ $fn($params);
+
+ echo "\nFinished!\n";
+ }
diff --git a/core/utils.php b/core/utils.php
new file mode 100644
index 0000000..a2118ac
--- /dev/null
+++ b/core/utils.php
@@ -0,0 +1,67 @@
+/dev/null 2>&1 || exit 1");
+
+ // login
+ $user = str_replace("\"", "\\\"", $user);
+ $pass = str_replace("\"", "\\\"", $pass);
+ __exec__allow_single_error("mega-login \"{$user}\" \"{$pass}\"", 202, array( $pass )); /* Allow "Already logged in."-error */
+
+ // rename output file
+ $new_output = $outputdir . '/' . $uploadfile;
+ __exec("mv {$output} {$new_output}");
+
+ // upload file
+ __exec("mega-put {$new_output} -c {$uploaddir}");
+
+ // rename it back
+ __exec("mv {$new_output} {$output}");
+}
diff --git a/remote/sftp.php b/remote/sftp.php
new file mode 100644
index 0000000..70779a0
--- /dev/null
+++ b/remote/sftp.php
@@ -0,0 +1,55 @@
+