Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 1 | /* |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 2 | Copyright 2003 to 2017 TeamWin |
Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 18 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 19 | #define __STDC_FORMAT_MACROS 1 |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/vfs.h> |
| 25 | #include <unistd.h> |
| 26 | #include <vector> |
| 27 | #include <dirent.h> |
| 28 | #include <time.h> |
| 29 | #include <errno.h> |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 30 | #include <inttypes.h> |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 31 | #include <iostream> |
| 32 | #include <fstream> |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 33 | #include <sstream> |
| 34 | #include <string> |
| 35 | #include <iterator> |
| 36 | #include <algorithm> |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 37 | #include <sys/types.h> |
| 38 | #include <sys/wait.h> |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 39 | #include <zlib.h> |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 40 | |
| 41 | #include "twrp-functions.hpp" |
| 42 | #include "partitions.hpp" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 43 | #include "twcommon.h" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 44 | #include "openrecoveryscript.hpp" |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 45 | #include "progresstracking.hpp" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 46 | #include "variables.h" |
Dees_Troy | 4fc0024 | 2013-01-17 19:22:12 +0000 | [diff] [blame] | 47 | #include "adb_install.h" |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 48 | #include "data.hpp" |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 49 | #include "adb_install.h" |
| 50 | #include "fuse_sideload.h" |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 51 | #include "gui/gui.hpp" |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 52 | #include "gui/pages.hpp" |
| 53 | #include "orscmd/orscmd.h" |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 54 | #include "twinstall.h" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 55 | extern "C" { |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 56 | #include "gui/gui.h" |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 57 | #include "cutils/properties.h" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 58 | } |
| 59 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 60 | OpenRecoveryScript::VoidFunction OpenRecoveryScript::call_after_cli_command; |
| 61 | |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 62 | #define SCRIPT_COMMAND_SIZE 512 |
| 63 | |
| 64 | int OpenRecoveryScript::check_for_script_file(void) { |
bigbiff | 349ea55 | 2020-06-19 16:07:38 -0400 | [diff] [blame] | 65 | std::string logDir = TWFunc::get_log_dir(); |
| 66 | std::string orsFile; |
| 67 | if (logDir == DATA_LOGS_DIR) |
| 68 | orsFile = "/data/cache"; |
| 69 | else |
| 70 | orsFile = logDir; |
| 71 | orsFile += "/recovery/openrecoveryscript"; |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 72 | if (!PartitionManager.Mount_By_Path(orsFile, false)) { |
bigbiff | 349ea55 | 2020-06-19 16:07:38 -0400 | [diff] [blame] | 73 | LOGINFO("Unable to mount %s for OpenRecoveryScript support.\n", logDir.c_str()); |
| 74 | gui_msg(Msg(msg::kError, "unable_to_mount=Unable to mount {1}")(logDir.c_str())); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 75 | return 0; |
| 76 | } |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 77 | if (TWFunc::Path_Exists(orsFile)) { |
| 78 | LOGINFO("Script file found: '%s'\n", orsFile.c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 79 | // Copy script file to /tmp |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 80 | TWFunc::copy_file(orsFile, SCRIPT_FILE_TMP, 0755); |
| 81 | // Delete the file from cache |
| 82 | unlink(orsFile.c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 83 | return 1; |
| 84 | } |
| 85 | return 0; |
| 86 | } |
| 87 | |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 88 | int OpenRecoveryScript::copy_script_file(string filename) { |
| 89 | if (TWFunc::Path_Exists(filename)) { |
| 90 | LOGINFO("Script file found: '%s'\n", filename.c_str()); |
| 91 | if (filename == SCRIPT_FILE_TMP) |
| 92 | return 1; // file is already in the right place |
| 93 | // Copy script file to /tmp |
| 94 | TWFunc::copy_file(filename, SCRIPT_FILE_TMP, 0755); |
| 95 | // Delete the old file |
| 96 | unlink(filename.c_str()); |
| 97 | return 1; |
| 98 | } |
| 99 | return 0; |
| 100 | } |
| 101 | |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 102 | int OpenRecoveryScript::run_script_file(void) { |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 103 | int ret_val = 0, cindex, line_len, i, remove_nl, install_cmd = 0, sideload = 0; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 104 | char script_line[SCRIPT_COMMAND_SIZE], command[SCRIPT_COMMAND_SIZE], |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 105 | value[SCRIPT_COMMAND_SIZE], mount[SCRIPT_COMMAND_SIZE], |
| 106 | value1[SCRIPT_COMMAND_SIZE], value2[SCRIPT_COMMAND_SIZE]; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 107 | char *val_start, *tok; |
| 108 | |
Matt Mower | 06543e3 | 2017-01-06 15:25:26 -0600 | [diff] [blame] | 109 | FILE *fp = fopen(SCRIPT_FILE_TMP, "r"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 110 | if (fp != NULL) { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 111 | DataManager::SetValue(TW_SIMULATE_ACTIONS, 0); |
Dees_Troy | 6bdcbb1 | 2013-01-26 14:07:43 +0000 | [diff] [blame] | 112 | DataManager::SetValue("ui_progress", 0); // Reset the progress bar |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 113 | while (fgets(script_line, SCRIPT_COMMAND_SIZE, fp) != NULL && ret_val == 0) { |
| 114 | cindex = 0; |
| 115 | line_len = strlen(script_line); |
| 116 | if (line_len < 2) |
| 117 | continue; // there's a blank line or line is too short to contain a command |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 118 | //gui_print("script line: '%s'\n", script_line); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 119 | for (i=0; i<line_len; i++) { |
| 120 | if ((int)script_line[i] == 32) { |
| 121 | cindex = i; |
| 122 | i = line_len; |
| 123 | } |
| 124 | } |
| 125 | memset(command, 0, sizeof(command)); |
| 126 | memset(value, 0, sizeof(value)); |
| 127 | if ((int)script_line[line_len - 1] == 10) |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 128 | remove_nl = 2; |
| 129 | else |
| 130 | remove_nl = 1; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 131 | if (cindex != 0) { |
| 132 | strncpy(command, script_line, cindex); |
Matt Mower | e96c3c3 | 2014-09-19 12:14:37 -0500 | [diff] [blame] | 133 | LOGINFO("command is: '%s'\n", command); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 134 | val_start = script_line; |
| 135 | val_start += cindex + 1; |
bigbiff bigbiff | c03121d | 2013-09-09 19:14:35 -0400 | [diff] [blame] | 136 | if ((int) *val_start == 32) |
| 137 | val_start++; //get rid of space |
bigbiff bigbiff | 72e9554 | 2013-08-29 21:01:02 -0400 | [diff] [blame] | 138 | if ((int) *val_start == 51) |
| 139 | val_start++; //get rid of = at the beginning |
bigbiff bigbiff | a6c5f4e | 2013-09-17 20:01:14 -0400 | [diff] [blame] | 140 | if ((int) *val_start == 32) |
| 141 | val_start++; //get rid of space |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 142 | strncpy(value, val_start, line_len - cindex - remove_nl); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 143 | LOGINFO("value is: '%s'\n", value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 144 | } else { |
| 145 | strncpy(command, script_line, line_len - remove_nl + 1); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 146 | gui_print("command is: '%s' and there is no value\n", command); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 147 | } |
| 148 | if (strcmp(command, "install") == 0) { |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 149 | // Install Zip |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 150 | DataManager::SetValue("tw_action_text2", "Installing Zip"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 151 | ret_val = Install_Command(value); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 152 | install_cmd = -1; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 153 | } else if (strcmp(command, "wipe") == 0) { |
| 154 | // Wipe |
| 155 | if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) { |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 156 | PartitionManager.Wipe_By_Path("/cache"); |
dianlujitao | b76a73a | 2020-04-30 20:33:20 +0800 | [diff] [blame] | 157 | } else if (strcmp(value, "system") == 0 || strcmp(value, "/system") == 0 || strcmp(value, PartitionManager.Get_Android_Root_Path().c_str()) == 0) { |
| 158 | PartitionManager.Wipe_By_Path("/system"); |
Adrian DC | 0c6a626 | 2021-01-05 23:54:18 +0100 | [diff] [blame] | 159 | PartitionManager.Update_System_Details(); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 160 | } else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) { |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 161 | PartitionManager.Wipe_Dalvik_Cache(); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 162 | } else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) { |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 163 | PartitionManager.Factory_Reset(); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 164 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 165 | LOGERR("Error with wipe command value: '%s'\n", value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 166 | ret_val = 1; |
| 167 | } |
Adrian DC | 3b3bd12 | 2021-01-05 22:34:21 +0100 | [diff] [blame] | 168 | } else if (strcmp(command, "format") == 0) { |
| 169 | // Format |
| 170 | if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) { |
| 171 | PartitionManager.Format_Data(); |
| 172 | } else { |
| 173 | LOGERR("Error with format command value: '%s'\n", value); |
| 174 | ret_val = 1; |
| 175 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 176 | } else if (strcmp(command, "backup") == 0) { |
| 177 | // Backup |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 178 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@backing}")); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 179 | tok = strtok(value, " "); |
| 180 | strcpy(value1, tok); |
| 181 | tok = strtok(NULL, " "); |
| 182 | if (tok != NULL) { |
| 183 | memset(value2, 0, sizeof(value2)); |
| 184 | strcpy(value2, tok); |
| 185 | line_len = strlen(tok); |
| 186 | if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) { |
| 187 | if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) |
| 188 | remove_nl = 2; |
| 189 | else |
| 190 | remove_nl = 1; |
| 191 | } else |
| 192 | remove_nl = 0; |
| 193 | strncpy(value2, tok, line_len - remove_nl); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 194 | DataManager::SetValue(TW_BACKUP_NAME, value2); |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 195 | gui_msg(Msg("backup_folder_set=Backup folder set to '{1}'")(value2)); |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 196 | if (PartitionManager.Check_Backup_Name(value2, true, true) != 0) { |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 197 | ret_val = 1; |
| 198 | continue; |
| 199 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 200 | } else { |
| 201 | char empt[50]; |
| 202 | strcpy(empt, "(Current Date)"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 203 | DataManager::SetValue(TW_BACKUP_NAME, empt); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 204 | } |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 205 | ret_val = Backup_Command(value1); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 206 | } else if (strcmp(command, "restore") == 0) { |
| 207 | // Restore |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 208 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@restore}")); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 209 | PartitionManager.Mount_All_Storage(); |
bigbiff bigbiff | 56cf564 | 2016-08-19 17:43:45 -0400 | [diff] [blame] | 210 | DataManager::SetValue(TW_SKIP_DIGEST_CHECK_VAR, 0); |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 211 | char folder_path[512], partitions[512]; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 212 | |
| 213 | string val = value, restore_folder, restore_partitions; |
| 214 | size_t pos = val.find_last_of(" "); |
| 215 | if (pos == string::npos) { |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 216 | restore_folder = value; |
| 217 | partitions[0] = '\0'; |
| 218 | } else { |
| 219 | restore_folder = val.substr(0, pos); |
| 220 | restore_partitions = val.substr(pos + 1, val.size() - pos - 1); |
| 221 | strcpy(partitions, restore_partitions.c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 222 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 223 | strcpy(folder_path, restore_folder.c_str()); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 224 | LOGINFO("Restore folder is: '%s' and partitions: '%s'\n", folder_path, partitions); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 225 | gui_msg(Msg("restoring=Restoring {1}...")(folder_path)); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 226 | |
| 227 | if (folder_path[0] != '/') { |
| 228 | char backup_folder[512]; |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 229 | string folder_var; |
Ethan Yonker | d7adf29 | 2014-02-15 16:43:23 -0600 | [diff] [blame] | 230 | std::vector<PartitionList> Storage_List; |
| 231 | |
| 232 | PartitionManager.Get_Partition_List("storage", &Storage_List); |
| 233 | int listSize = Storage_List.size(); |
| 234 | for (int i = 0; i < listSize; i++) { |
| 235 | if (PartitionManager.Is_Mounted_By_Path(Storage_List.at(i).Mount_Point)) { |
| 236 | DataManager::SetValue("tw_storage_path", Storage_List.at(i).Mount_Point); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 237 | DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, folder_var); |
| 238 | sprintf(backup_folder, "%s/%s", folder_var.c_str(), folder_path); |
Ethan Yonker | d7adf29 | 2014-02-15 16:43:23 -0600 | [diff] [blame] | 239 | if (TWFunc::Path_Exists(backup_folder)) { |
| 240 | strcpy(folder_path, backup_folder); |
| 241 | break; |
| 242 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 243 | } |
| 244 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 245 | } else { |
| 246 | if (folder_path[strlen(folder_path) - 1] == '/') |
| 247 | strcat(folder_path, "."); |
| 248 | else |
| 249 | strcat(folder_path, "/."); |
| 250 | } |
| 251 | if (!TWFunc::Path_Exists(folder_path)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 252 | gui_msg(Msg(msg::kError, "locate_backup_err=Unable to locate backup '{1}'")(folder_path)); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 253 | ret_val = 1; |
| 254 | continue; |
| 255 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 256 | DataManager::SetValue("tw_restore", folder_path); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 257 | |
| 258 | PartitionManager.Set_Restore_Files(folder_path); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 259 | string Partition_List; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 260 | int is_encrypted = 0; |
| 261 | DataManager::GetValue("tw_restore_encrypted", is_encrypted); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 262 | DataManager::GetValue("tw_restore_list", Partition_List); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 263 | if (strlen(partitions) != 0) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 264 | string Restore_List; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 265 | |
| 266 | memset(value2, 0, sizeof(value2)); |
| 267 | strcpy(value2, partitions); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 268 | gui_msg(Msg("set_restore_opt=Setting restore options: '{1}':")(value2)); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 269 | line_len = strlen(value2); |
| 270 | for (i=0; i<line_len; i++) { |
dianlujitao | b76a73a | 2020-04-30 20:33:20 +0800 | [diff] [blame] | 271 | if ((value2[i] == 'S' || value2[i] == 's') && Partition_List.find("/system;") != string::npos) { |
| 272 | Restore_List += "/system;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 273 | gui_msg("system=System"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 274 | } else if ((value2[i] == 'D' || value2[i] == 'd') && Partition_List.find("/data;") != string::npos) { |
| 275 | Restore_List += "/data;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 276 | gui_msg("data=Data"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 277 | } else if ((value2[i] == 'C' || value2[i] == 'c') && Partition_List.find("/cache;") != string::npos) { |
| 278 | Restore_List += "/cache;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 279 | gui_msg("cache=Cache"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 280 | } else if ((value2[i] == 'R' || value2[i] == 'r') && Partition_List.find("/recovery;") != string::npos) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 281 | Restore_List += "/recovery;"; |
| 282 | gui_msg("recovery=Recovery"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 283 | } else if ((value2[i] == 'B' || value2[i] == 'b') && Partition_List.find("/boot;") != string::npos) { |
| 284 | Restore_List += "/boot;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 285 | gui_msg("boot=Boot"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 286 | } else if ((value2[i] == 'A' || value2[i] == 'a') && Partition_List.find("/and-sec;") != string::npos) { |
| 287 | Restore_List += "/and-sec;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 288 | gui_msg("android_secure=Android Secure"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 289 | } else if ((value2[i] == 'E' || value2[i] == 'e') && Partition_List.find("/sd-ext;") != string::npos) { |
| 290 | Restore_List += "/sd-ext;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 291 | gui_msg("sdext=SD-EXT"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 292 | } else if (value2[i] == 'M' || value2[i] == 'm') { |
bigbiff bigbiff | 56cf564 | 2016-08-19 17:43:45 -0400 | [diff] [blame] | 293 | DataManager::SetValue(TW_SKIP_DIGEST_CHECK_VAR, 1); |
| 294 | gui_msg("digest_check_skip=Digest check skip is on"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 298 | DataManager::SetValue("tw_restore_selected", Restore_List); |
| 299 | } else { |
| 300 | DataManager::SetValue("tw_restore_selected", Partition_List); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 301 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 302 | if (is_encrypted) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 303 | gui_err("ors_encrypt_restore_err=Unable to use OpenRecoveryScript to restore an encrypted backup."); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 304 | ret_val = 1; |
| 305 | } else if (!PartitionManager.Run_Restore(folder_path)) |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 306 | ret_val = 1; |
| 307 | else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 308 | gui_msg("done=Done."); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 309 | } else if (strcmp(command, "remountrw") == 0) { |
| 310 | ret_val = remountrw(); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 311 | } else if (strcmp(command, "mount") == 0) { |
| 312 | // Mount |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 313 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@mounting}")); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 314 | if (value[0] != '/') { |
| 315 | strcpy(mount, "/"); |
| 316 | strcat(mount, value); |
| 317 | } else |
| 318 | strcpy(mount, value); |
Chaosmaster | 3b3b634 | 2020-01-25 22:51:54 +0100 | [diff] [blame] | 319 | if (!strcmp(mount, "/system")) |
| 320 | strcpy(mount, PartitionManager.Get_Android_Root_Path().c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 321 | if (PartitionManager.Mount_By_Path(mount, true)) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 322 | gui_msg(Msg("mounted=Mounted '{1}'")(mount)); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 323 | } else if (strcmp(command, "unmount") == 0 || strcmp(command, "umount") == 0) { |
| 324 | // Unmount |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 325 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@unmounting}")); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 326 | if (value[0] != '/') { |
| 327 | strcpy(mount, "/"); |
| 328 | strcat(mount, value); |
| 329 | } else |
| 330 | strcpy(mount, value); |
Chaosmaster | 3b3b634 | 2020-01-25 22:51:54 +0100 | [diff] [blame] | 331 | if (!strcmp(mount, "/system")) |
| 332 | strcpy(mount, PartitionManager.Get_Android_Root_Path().c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 333 | if (PartitionManager.UnMount_By_Path(mount, true)) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 334 | gui_msg(Msg("unmounted=Unounted '{1}'")(mount)); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 335 | } else if (strcmp(command, "set") == 0) { |
| 336 | // Set value |
Ethan Yonker | 6511c4d | 2015-06-17 16:52:29 -0500 | [diff] [blame] | 337 | size_t len = strlen(value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 338 | tok = strtok(value, " "); |
| 339 | strcpy(value1, tok); |
Ethan Yonker | 6511c4d | 2015-06-17 16:52:29 -0500 | [diff] [blame] | 340 | if (len > strlen(value1) + 1) { |
| 341 | char *val2 = value + strlen(value1) + 1; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 342 | gui_msg(Msg("setting=Setting '{1}' to '{2}'")(value1)(val2)); |
Ethan Yonker | 6511c4d | 2015-06-17 16:52:29 -0500 | [diff] [blame] | 343 | DataManager::SetValue(value1, val2); |
| 344 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 345 | gui_msg(Msg("setting_empty=Setting '{1}' to empty")(value1)); |
Ethan Yonker | 6511c4d | 2015-06-17 16:52:29 -0500 | [diff] [blame] | 346 | DataManager::SetValue(value1, ""); |
| 347 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 348 | } else if (strcmp(command, "mkdir") == 0) { |
| 349 | // Make directory (recursive) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 350 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@making_dir1}")); |
| 351 | gui_msg(Msg("making_dir2=Making directory: '{1}'")(value)); |
that | f1408b3 | 2016-01-03 11:09:15 +0100 | [diff] [blame] | 352 | if (!TWFunc::Recursive_Mkdir(value)) { |
| 353 | // error message already displayed by Recursive_Mkdir |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 354 | ret_val = 1; |
| 355 | } |
| 356 | } else if (strcmp(command, "reboot") == 0) { |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 357 | if (strlen(value) && strcmp(value, "recovery") == 0) |
| 358 | TWFunc::tw_reboot(rb_recovery); |
| 359 | else if (strlen(value) && strcmp(value, "poweroff") == 0) |
| 360 | TWFunc::tw_reboot(rb_poweroff); |
| 361 | else if (strlen(value) && strcmp(value, "bootloader") == 0) |
| 362 | TWFunc::tw_reboot(rb_bootloader); |
| 363 | else if (strlen(value) && strcmp(value, "download") == 0) |
| 364 | TWFunc::tw_reboot(rb_download); |
mauronofrio | e9a49ef | 2018-10-03 13:38:16 +0200 | [diff] [blame] | 365 | else if (strlen(value) && strcmp(value, "edl") == 0) |
| 366 | TWFunc::tw_reboot(rb_edl); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 367 | else |
| 368 | TWFunc::tw_reboot(rb_system); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 369 | } else if (strcmp(command, "cmd") == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 370 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@running_command}")); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 371 | if (cindex != 0) { |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 372 | TWFunc::Exec_Cmd(value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 373 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 374 | LOGERR("No value given for cmd\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 375 | } |
| 376 | } else if (strcmp(command, "print") == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 377 | gui_print("%s\n", value); |
Dees_Troy | 4fc0024 | 2013-01-17 19:22:12 +0000 | [diff] [blame] | 378 | } else if (strcmp(command, "sideload") == 0) { |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 379 | // ADB Sideload |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 380 | DataManager::SetValue("tw_action_text2", gui_parse_text("{@sideload}")); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 381 | install_cmd = -1; |
| 382 | |
| 383 | int wipe_cache = 0; |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 384 | string result; |
| 385 | pid_t sideload_child_pid; |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 386 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 387 | gui_msg("start_sideload=Starting ADB sideload feature..."); |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 388 | ret_val = apply_from_adb("/", &sideload_child_pid); |
| 389 | if (ret_val != 0) { |
| 390 | if (ret_val == -2) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 391 | gui_err("need_new_adb=You need adb 1.0.32 or newer to sideload to this device."); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 392 | ret_val = 1; // failure |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 393 | } else if (TWinstall_zip(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache) == 0) { |
| 394 | if (wipe_cache) |
| 395 | PartitionManager.Wipe_By_Path("/cache"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 396 | } else { |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 397 | ret_val = 1; // failure |
Dees_Troy | 4fc0024 | 2013-01-17 19:22:12 +0000 | [diff] [blame] | 398 | } |
Adrian DC | 0c6a626 | 2021-01-05 23:54:18 +0100 | [diff] [blame] | 399 | PartitionManager.Update_System_Details(); |
Ethan Yonker | d83587d | 2015-01-03 16:54:18 -0600 | [diff] [blame] | 400 | sideload = 1; // Causes device to go to the home screen afterwards |
| 401 | if (sideload_child_pid != 0) { |
| 402 | LOGINFO("Signaling child sideload process to exit.\n"); |
| 403 | struct stat st; |
| 404 | // Calling stat() on this magic filename signals the minadbd |
| 405 | // subprocess to shut down. |
| 406 | stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); |
| 407 | int status; |
| 408 | LOGINFO("Waiting for child sideload process to exit.\n"); |
| 409 | waitpid(sideload_child_pid, &status, 0); |
| 410 | } |
Dees Troy | 28a85d2 | 2015-04-28 02:03:16 +0000 | [diff] [blame] | 411 | property_set("ctl.start", "adbd"); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 412 | gui_msg("done=Done."); |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 413 | } else if (strcmp(command, "fixperms") == 0 || strcmp(command, "fixpermissions") == 0 || strcmp(command, "fixcontexts") == 0) { |
| 414 | ret_val = PartitionManager.Fix_Contexts(); |
Ethan Yonker | aae6e8c | 2014-02-11 21:37:36 -0600 | [diff] [blame] | 415 | if (ret_val != 0) |
| 416 | ret_val = 1; // failure |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 417 | } else if (strcmp(command, "decrypt") == 0) { |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 418 | // twrp cmd cannot decrypt a password with space, should decrypt on gui |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 419 | if (*value) { |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 420 | string tmp = value; |
| 421 | std::vector<string> args = TWFunc::Split_String(tmp, " "); |
| 422 | |
| 423 | string pass = args[0]; |
| 424 | string userid = "0"; |
| 425 | if (args.size() > 1) |
| 426 | userid = args[1]; |
| 427 | |
| 428 | ret_val = PartitionManager.Decrypt_Device(pass, atoi(userid.c_str())); |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 429 | if (ret_val != 0) |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 430 | ret_val = 1; // failure |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 431 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 432 | gui_err("no_pwd=No password provided."); |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 433 | ret_val = 1; // failure |
Ethan Yonker | 03a42f6 | 2014-08-08 11:03:51 -0500 | [diff] [blame] | 434 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 435 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 436 | LOGERR("Unrecognized script command: '%s'\n", command); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 437 | ret_val = 1; |
| 438 | } |
| 439 | } |
| 440 | fclose(fp); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 441 | unlink(SCRIPT_FILE_TMP); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 442 | gui_msg("done_ors=Done processing script file"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 443 | } else { |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 444 | gui_msg(Msg(msg::kError, "error_opening_strerr=Error opening: '{1}' ({2})")(SCRIPT_FILE_TMP)( |
| 445 | strerror(errno))); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 446 | return 1; |
| 447 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 448 | |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 449 | if (install_cmd && DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && |
| 450 | DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 451 | gui_msg("injecttwrp=Injecting TWRP into boot image..."); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 452 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
| 453 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 454 | TWFunc::Exec_Cmd( |
| 455 | "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 456 | else { |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 457 | string injectcmd = |
| 458 | "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + |
| 459 | Boot->Actual_Block_Device; |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 460 | TWFunc::Exec_Cmd(injectcmd.c_str()); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 461 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 462 | gui_msg("done=Done."); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 463 | } |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 464 | if (sideload) |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 465 | ret_val = 1; // Forces booting to the home page after sideload |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 466 | return ret_val; |
| 467 | } |
| 468 | |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 469 | int OpenRecoveryScript::Insert_ORS_Command(string Command) { |
xiaolu | 38c3aa7 | 2015-05-26 22:55:18 +0800 | [diff] [blame] | 470 | ofstream ORSfile(SCRIPT_FILE_TMP, ios_base::app | ios_base::out); |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 471 | if (ORSfile.is_open()) { |
| 472 | //if (Command.substr(Command.size() - 1, 1) != "\n") |
| 473 | // Command += "\n"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 474 | LOGINFO("Inserting '%s'\n", Command.c_str()); |
xiaolu | 38c3aa7 | 2015-05-26 22:55:18 +0800 | [diff] [blame] | 475 | ORSfile << Command.c_str() << endl; |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 476 | ORSfile.close(); |
| 477 | return 1; |
| 478 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 479 | LOGERR("Unable to append '%s' to '%s'\n", Command.c_str(), SCRIPT_FILE_TMP); |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 480 | return 0; |
| 481 | } |
| 482 | |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 483 | int OpenRecoveryScript::Install_Command(string Zip) { |
| 484 | // Install zip |
| 485 | string ret_string; |
| 486 | int ret_val = 0, wipe_cache = 0; |
Ethan Yonker | d7adf29 | 2014-02-15 16:43:23 -0600 | [diff] [blame] | 487 | std::vector<PartitionList> Storage_List; |
| 488 | string Full_Path; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 489 | |
Ethan Yonker | aee144c | 2015-02-11 16:49:19 -0600 | [diff] [blame] | 490 | if (Zip.substr(0, 1) == "@") { |
| 491 | // This is a special file that contains a map of blocks on the data partition |
| 492 | Full_Path = Zip.substr(1); |
| 493 | if (!PartitionManager.Mount_By_Path(Full_Path, true) || !TWFunc::Path_Exists(Full_Path)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 494 | LOGINFO("Unable to install via mapped zip '%s'\n", Full_Path.c_str()); |
| 495 | gui_msg(Msg(msg::kError, "zip_err=Error installing zip file '{1}'")(Zip)); |
Ethan Yonker | aee144c | 2015-02-11 16:49:19 -0600 | [diff] [blame] | 496 | return 1; |
| 497 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 498 | LOGINFO("Installing mapped zip file '%s'\n", Full_Path.c_str()); |
| 499 | gui_msg(Msg("installing_zip=Installing zip file '{1}'")(Zip)); |
Ethan Yonker | aee144c | 2015-02-11 16:49:19 -0600 | [diff] [blame] | 500 | } else if (!TWFunc::Path_Exists(Zip)) { |
| 501 | PartitionManager.Mount_All_Storage(); |
| 502 | PartitionManager.Get_Partition_List("storage", &Storage_List); |
| 503 | int listSize = Storage_List.size(); |
| 504 | for (int i = 0; i < listSize; i++) { |
| 505 | if (PartitionManager.Is_Mounted_By_Path(Storage_List.at(i).Mount_Point)) { |
| 506 | Full_Path = Storage_List.at(i).Mount_Point + "/" + Zip; |
| 507 | if (TWFunc::Path_Exists(Full_Path)) { |
| 508 | Zip = Full_Path; |
| 509 | break; |
| 510 | } |
| 511 | Full_Path = Zip; |
| 512 | LOGINFO("Trying to find zip '%s' on '%s'...\n", Full_Path.c_str(), Storage_List.at(i).Mount_Point.c_str()); |
| 513 | ret_string = Locate_Zip_File(Full_Path, Storage_List.at(i).Mount_Point); |
| 514 | if (!ret_string.empty()) { |
| 515 | Zip = ret_string; |
| 516 | break; |
| 517 | } |
Ethan Yonker | d7adf29 | 2014-02-15 16:43:23 -0600 | [diff] [blame] | 518 | } |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 519 | } |
Ethan Yonker | aee144c | 2015-02-11 16:49:19 -0600 | [diff] [blame] | 520 | if (!TWFunc::Path_Exists(Zip)) { |
| 521 | // zip file doesn't exist |
| 522 | gui_print("Unable to locate zip file '%s'.\n", Zip.c_str()); |
| 523 | ret_val = 1; |
| 524 | } else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 525 | gui_msg(Msg("installing_zip=Installing zip file '{1}'")(Zip)); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 526 | } |
| 527 | |
Ethan Yonker | aee144c | 2015-02-11 16:49:19 -0600 | [diff] [blame] | 528 | ret_val = TWinstall_zip(Zip.c_str(), &wipe_cache); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 529 | if (ret_val != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 530 | gui_msg(Msg(msg::kError, "zip_err=Error installing zip file '{1}'")(Zip)); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 531 | ret_val = 1; |
| 532 | } else if (wipe_cache) |
| 533 | PartitionManager.Wipe_By_Path("/cache"); |
| 534 | |
| 535 | return ret_val; |
| 536 | } |
| 537 | |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 538 | string OpenRecoveryScript::Locate_Zip_File(string Zip, string Storage_Root) { |
| 539 | string Path = TWFunc::Get_Path(Zip); |
| 540 | string File = TWFunc::Get_Filename(Zip); |
| 541 | string pathCpy = Path; |
| 542 | string wholePath; |
| 543 | size_t pos = Path.find("/", 1); |
| 544 | |
| 545 | while (pos != string::npos) |
| 546 | { |
| 547 | pathCpy = Path.substr(pos, Path.size() - pos); |
Matt Mower | e96c3c3 | 2014-09-19 12:14:37 -0500 | [diff] [blame] | 548 | wholePath = pathCpy + File; |
Ethan Yonker | d7adf29 | 2014-02-15 16:43:23 -0600 | [diff] [blame] | 549 | LOGINFO("Looking for zip at '%s'\n", wholePath.c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 550 | if (TWFunc::Path_Exists(wholePath)) |
| 551 | return wholePath; |
Matt Mower | e96c3c3 | 2014-09-19 12:14:37 -0500 | [diff] [blame] | 552 | wholePath = Storage_Root + wholePath; |
Ethan Yonker | d7adf29 | 2014-02-15 16:43:23 -0600 | [diff] [blame] | 553 | LOGINFO("Looking for zip at '%s'\n", wholePath.c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 554 | if (TWFunc::Path_Exists(wholePath)) |
| 555 | return wholePath; |
| 556 | |
| 557 | pos = Path.find("/", pos + 1); |
| 558 | } |
| 559 | return ""; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | int OpenRecoveryScript::Backup_Command(string Options) { |
| 563 | char value1[SCRIPT_COMMAND_SIZE]; |
| 564 | int line_len, i; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 565 | string Backup_List; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 566 | |
| 567 | strcpy(value1, Options.c_str()); |
| 568 | |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 569 | DataManager::SetValue(TW_USE_COMPRESSION_VAR, 0); |
bigbiff bigbiff | 56cf564 | 2016-08-19 17:43:45 -0400 | [diff] [blame] | 570 | DataManager::SetValue(TW_SKIP_DIGEST_GENERATE_VAR, 0); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 571 | |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 572 | gui_msg("select_backup_opt=Setting backup options:"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 573 | line_len = Options.size(); |
| 574 | for (i=0; i<line_len; i++) { |
| 575 | if (Options.substr(i, 1) == "S" || Options.substr(i, 1) == "s") { |
dianlujitao | b76a73a | 2020-04-30 20:33:20 +0800 | [diff] [blame] | 576 | Backup_List += "/system;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 577 | gui_msg("system=System"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 578 | } else if (Options.substr(i, 1) == "D" || Options.substr(i, 1) == "d") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 579 | Backup_List += "/data;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 580 | gui_msg("data=Data"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 581 | } else if (Options.substr(i, 1) == "C" || Options.substr(i, 1) == "c") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 582 | Backup_List += "/cache;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 583 | gui_msg("cache=Cache"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 584 | } else if (Options.substr(i, 1) == "R" || Options.substr(i, 1) == "r") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 585 | Backup_List += "/recovery;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 586 | gui_msg("recovery=Recovery"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 587 | } else if (Options.substr(i, 1) == "1") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 588 | gui_print("%s\n", "Special1 -- No Longer Supported..."); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 589 | } else if (Options.substr(i, 1) == "2") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 590 | gui_print("%s\n", "Special2 -- No Longer Supported..."); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 591 | } else if (Options.substr(i, 1) == "3") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 592 | gui_print("%s\n", "Special3 -- No Longer Supported..."); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 593 | } else if (Options.substr(i, 1) == "B" || Options.substr(i, 1) == "b") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 594 | Backup_List += "/boot;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 595 | gui_msg("boot=Boot"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 596 | } else if (Options.substr(i, 1) == "A" || Options.substr(i, 1) == "a") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 597 | Backup_List += "/and-sec;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 598 | gui_msg("android_secure=Android Secure"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 599 | } else if (Options.substr(i, 1) == "E" || Options.substr(i, 1) == "e") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 600 | Backup_List += "/sd-ext;"; |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 601 | gui_msg("sdext=SD-EXT"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 602 | } else if (Options.substr(i, 1) == "O" || Options.substr(i, 1) == "o") { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 603 | DataManager::SetValue(TW_USE_COMPRESSION_VAR, 1); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 604 | gui_msg("compression_on=Compression is on"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 605 | } else if (Options.substr(i, 1) == "M" || Options.substr(i, 1) == "m") { |
bigbiff bigbiff | 56cf564 | 2016-08-19 17:43:45 -0400 | [diff] [blame] | 606 | DataManager::SetValue(TW_SKIP_DIGEST_GENERATE_VAR, 1); |
| 607 | gui_msg("digest_off=Digest Generation is off"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 608 | } |
| 609 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 610 | DataManager::SetValue("tw_backup_list", Backup_List); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 611 | if (!PartitionManager.Run_Backup(false)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 612 | gui_err("backup_fail=Backup Failed"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 613 | return 1; |
| 614 | } |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 615 | gui_msg("backup_complete=Backup Complete"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 616 | return 0; |
| 617 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 618 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 619 | // this is called by main() |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 620 | void OpenRecoveryScript::Run_OpenRecoveryScript(void) { |
| 621 | DataManager::SetValue("tw_back", "main"); |
| 622 | DataManager::SetValue("tw_action", "openrecoveryscript"); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 623 | DataManager::SetValue("tw_action_param", ""); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 624 | DataManager::SetValue("tw_has_action2", "0"); |
| 625 | DataManager::SetValue("tw_action2", ""); |
| 626 | DataManager::SetValue("tw_action2_param", ""); |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 627 | #ifdef TW_OEM_BUILD |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 628 | DataManager::SetValue("tw_action_text1", gui_lookup("running_recovery_commands", "Running Recovery Commands")); |
| 629 | DataManager::SetValue("tw_complete_text1", gui_lookup("recovery_commands_complete", "Recovery Commands Complete")); |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 630 | #else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 631 | DataManager::SetValue("tw_action_text1", gui_lookup("running_ors", "Running OpenRecoveryScript")); |
| 632 | DataManager::SetValue("tw_complete_text1", gui_lookup("ors_complete", "OpenRecoveryScript Complete")); |
Ethan Yonker | 89583ef | 2015-08-26 09:01:59 -0500 | [diff] [blame] | 633 | #endif |
| 634 | DataManager::SetValue("tw_action_text2", ""); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 635 | DataManager::SetValue("tw_has_cancel", 0); |
| 636 | DataManager::SetValue("tw_show_reboot", 0); |
Ethan Yonker | fd0439e | 2015-01-14 11:08:13 -0600 | [diff] [blame] | 637 | if (gui_startPage("action_page", 0, 1) != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 638 | LOGERR("Failed to load OpenRecoveryScript GUI page.\n"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 639 | } |
Dees_Troy | 6bdcbb1 | 2013-01-26 14:07:43 +0000 | [diff] [blame] | 640 | } |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 641 | |
| 642 | // this is called by the "openrecoveryscript" GUI action called via action page from Run_OpenRecoveryScript |
| 643 | int OpenRecoveryScript::Run_OpenRecoveryScript_Action() { |
| 644 | int op_status = 1; |
| 645 | // Check for the SCRIPT_FILE_TMP first as these are AOSP recovery commands |
| 646 | // that we converted to ORS commands during boot in recovery.cpp. |
| 647 | // Run those first. |
| 648 | int reboot = 0; |
| 649 | if (TWFunc::Path_Exists(SCRIPT_FILE_TMP)) { |
| 650 | gui_msg("running_recovery_commands=Running Recovery Commands"); |
| 651 | if (OpenRecoveryScript::run_script_file() == 0) { |
| 652 | reboot = 1; |
| 653 | op_status = 0; |
| 654 | } |
| 655 | } |
| 656 | // Check for the ORS file in /cache and attempt to run those commands. |
| 657 | if (OpenRecoveryScript::check_for_script_file()) { |
| 658 | gui_msg("running_ors=Running OpenRecoveryScript"); |
| 659 | if (OpenRecoveryScript::run_script_file() == 0) { |
| 660 | reboot = 1; |
| 661 | op_status = 0; |
| 662 | } |
| 663 | } |
| 664 | if (reboot) { |
| 665 | // Disable stock recovery reflashing |
| 666 | TWFunc::Disable_Stock_Recovery_Replace(); |
| 667 | usleep(2000000); // Sleep for 2 seconds before rebooting |
| 668 | TWFunc::tw_reboot(rb_system); |
| 669 | usleep(5000000); // Sleep for 5 seconds to allow reboot to occur |
| 670 | } else { |
| 671 | DataManager::SetValue("tw_page_done", 1); |
| 672 | } |
| 673 | return op_status; |
| 674 | } |
| 675 | |
| 676 | // this is called by the "twcmd" GUI action when a command is received via FIFO from the "twrp" command line tool |
| 677 | void OpenRecoveryScript::Run_CLI_Command(const char* command) { |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 678 | string tmp = command; |
| 679 | std::vector<string> parts = |
| 680 | TWFunc::Split_String(tmp, " "); // pats[0] is cmd, parts[1...] is args |
| 681 | string cmd_str = parts[0]; |
| 682 | |
| 683 | if (cmd_str == "runscript") { |
| 684 | if (parts.size() > 1) { |
| 685 | string filename = parts[1]; |
| 686 | if (OpenRecoveryScript::copy_script_file(filename) == 0) { |
| 687 | LOGINFO("Unable to copy script file\n"); |
| 688 | } else { |
| 689 | OpenRecoveryScript::run_script_file(); |
| 690 | } |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 691 | } else { |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 692 | LOGINFO("Missing parameter: script file name\n"); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 693 | } |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 694 | } else if (cmd_str == "get") { |
| 695 | if (parts.size() > 1) { |
| 696 | string varname = parts[1]; |
| 697 | string value; |
| 698 | DataManager::GetValue(varname, value); |
| 699 | gui_print("%s = %s\n", varname.c_str(), value.c_str()); |
| 700 | } else { |
| 701 | LOGINFO("Missing parameter: var name\n"); |
| 702 | } |
| 703 | } else if (cmd_str == "decrypt") { |
| 704 | // twrp cmd cannot decrypt a password with space, should decrypt on gui |
| 705 | if (parts.size() == 1) { |
| 706 | gui_err("no_pwd=No password provided."); |
| 707 | } else { |
| 708 | string pass = parts[1]; |
| 709 | string userid = "0"; |
| 710 | if (parts.size() > 2) |
| 711 | userid = parts[2]; |
| 712 | |
| 713 | gui_msg("decrypt_cmd=Attempting to decrypt data partition or user data via command line."); |
| 714 | if (PartitionManager.Decrypt_Device(pass, atoi(userid.c_str())) == 0) { |
| 715 | // set_page_done = 1; // done by singleaction_page anyway |
bigbiff | 349ea55 | 2020-06-19 16:07:38 -0400 | [diff] [blame] | 716 | std::string logDir = TWFunc::get_log_dir(); |
| 717 | if (logDir == DATA_LOGS_DIR) |
| 718 | logDir = "/data/cache"; |
| 719 | std::string orsFile = logDir + "/openrecoveryscript"; |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 720 | if (TWFunc::Path_Exists(orsFile)) { |
| 721 | Run_OpenRecoveryScript_Action(); |
| 722 | } |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 723 | } |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 724 | } |
| 725 | } else if (OpenRecoveryScript::Insert_ORS_Command(command)) { |
| 726 | OpenRecoveryScript::run_script_file(); |
| 727 | } |
| 728 | |
| 729 | // let the GUI close the output fd and restart the command listener |
| 730 | call_after_cli_command(); |
| 731 | LOGINFO("Done reading ORS command from command line\n"); |
| 732 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 733 | |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 734 | int OpenRecoveryScript::remountrw(void) |
| 735 | { |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 736 | bool remount_system = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path()); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 737 | int op_status; |
| 738 | TWPartition* Part; |
| 739 | |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 740 | if (!PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 741 | op_status = 1; // fail |
| 742 | } else { |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 743 | Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path()); |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 744 | if (Part) { |
| 745 | DataManager::SetValue("tw_mount_system_ro", 0); |
| 746 | Part->Change_Mount_Read_Only(false); |
| 747 | } |
| 748 | if (remount_system) { |
| 749 | Part->Mount(true); |
| 750 | } |
| 751 | op_status = 0; // success |
| 752 | } |
| 753 | |
| 754 | return op_status; |
| 755 | } |