Add TWFunc::Exec_Cmd() with no 'result' agrument
Signed-off-by: Vojtech Bocek <vbocek@gmail.com> Change-Id: Id8acff1ac9b3c7e4b562c80562a8ff42a1d132b9
This commit is contained in:
+10
-14
@@ -227,13 +227,12 @@ int GUIAction::flash_zip(std::string filename, std::string pageName, const int s
|
||||
|
||||
// Now, check if we need to ensure TWRP remains installed...
|
||||
struct stat st;
|
||||
string result;
|
||||
if (stat("/sbin/installTwrp", &st) == 0)
|
||||
{
|
||||
DataManager::SetValue("tw_operation", "Configuring TWRP");
|
||||
DataManager::SetValue("tw_partition", "");
|
||||
gui_print("Configuring TWRP...\n");
|
||||
if (TWFunc::Exec_Cmd("/sbin/installTwrp reinstall", result) < 0)
|
||||
if (TWFunc::Exec_Cmd("/sbin/installTwrp reinstall") < 0)
|
||||
{
|
||||
gui_print("Unable to configure TWRP with this kernel.\n");
|
||||
}
|
||||
@@ -759,7 +758,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
|
||||
if (wipe_cache)
|
||||
PartitionManager.Wipe_By_Path("/cache");
|
||||
string result;
|
||||
|
||||
if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
|
||||
operation_start("ReinjectTWRP");
|
||||
gui_print("Injecting TWRP into boot image...\n");
|
||||
@@ -768,10 +767,10 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
} else {
|
||||
TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
|
||||
if (Boot == NULL || Boot->Current_File_System != "emmc")
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash", result);
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
|
||||
else {
|
||||
string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device;
|
||||
TWFunc::Exec_Cmd(injectcmd, result);
|
||||
TWFunc::Exec_Cmd(injectcmd);
|
||||
}
|
||||
gui_print("TWRP injection complete.\n");
|
||||
}
|
||||
@@ -961,9 +960,8 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
if (simulate) {
|
||||
simulate_progress_bar();
|
||||
} else {
|
||||
string result;
|
||||
string cmd = "dd " + arg;
|
||||
TWFunc::Exec_Cmd(cmd, result);
|
||||
TWFunc::Exec_Cmd(cmd);
|
||||
}
|
||||
operation_end(0, simulate);
|
||||
return 0;
|
||||
@@ -1024,14 +1022,13 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
if (function == "cmd")
|
||||
{
|
||||
int op_status = 0;
|
||||
string result;
|
||||
|
||||
operation_start("Command");
|
||||
LOGINFO("Running command: '%s'\n", arg.c_str());
|
||||
if (simulate) {
|
||||
simulate_progress_bar();
|
||||
} else {
|
||||
op_status = TWFunc::Exec_Cmd(arg, result);
|
||||
op_status = TWFunc::Exec_Cmd(arg);
|
||||
if (op_status != 0)
|
||||
op_status = 1;
|
||||
}
|
||||
@@ -1082,13 +1079,12 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
if (function == "reinjecttwrp")
|
||||
{
|
||||
int op_status = 0;
|
||||
string result;
|
||||
operation_start("ReinjectTWRP");
|
||||
gui_print("Injecting TWRP into boot image...\n");
|
||||
if (simulate) {
|
||||
simulate_progress_bar();
|
||||
} else {
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash", result);
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
|
||||
gui_print("TWRP injection complete.\n");
|
||||
}
|
||||
|
||||
@@ -1175,7 +1171,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
} else {
|
||||
int wipe_cache = 0;
|
||||
int wipe_dalvik = 0;
|
||||
string result, Sideload_File;
|
||||
string Sideload_File;
|
||||
|
||||
if (!PartitionManager.Mount_Current_Storage(true)) {
|
||||
operation_end(1, simulate);
|
||||
@@ -1207,10 +1203,10 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */)
|
||||
} else {
|
||||
TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
|
||||
if (Boot == NULL || Boot->Current_File_System != "emmc")
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash", result);
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
|
||||
else {
|
||||
string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device;
|
||||
TWFunc::Exec_Cmd(injectcmd, result);
|
||||
TWFunc::Exec_Cmd(injectcmd);
|
||||
}
|
||||
gui_print("TWRP injection complete.\n");
|
||||
}
|
||||
|
||||
@@ -314,8 +314,7 @@ int OpenRecoveryScript::run_script_file(void) {
|
||||
} else if (strcmp(command, "cmd") == 0) {
|
||||
DataManager::SetValue("tw_action_text2", "Running Command");
|
||||
if (cindex != 0) {
|
||||
string status;
|
||||
TWFunc::Exec_Cmd(value, status);
|
||||
TWFunc::Exec_Cmd(value);
|
||||
} else {
|
||||
LOGERR("No value given for cmd\n");
|
||||
}
|
||||
@@ -364,14 +363,13 @@ int OpenRecoveryScript::run_script_file(void) {
|
||||
return 1;
|
||||
}
|
||||
if (install_cmd && DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
|
||||
string status;
|
||||
gui_print("Injecting TWRP into boot image...\n");
|
||||
TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
|
||||
if (Boot == NULL || Boot->Current_File_System != "emmc")
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash", status);
|
||||
TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
|
||||
else {
|
||||
string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device;
|
||||
TWFunc::Exec_Cmd(injectcmd.c_str(), status);
|
||||
TWFunc::Exec_Cmd(injectcmd.c_str());
|
||||
}
|
||||
gui_print("TWRP injection complete.\n");
|
||||
}
|
||||
|
||||
+22
-24
@@ -684,14 +684,13 @@ bool TWPartition::Get_Size_Via_df(bool Display_Error) {
|
||||
char command[255], line[512];
|
||||
int include_block = 1;
|
||||
unsigned int min_len;
|
||||
string result;
|
||||
|
||||
if (!Mount(Display_Error))
|
||||
return false;
|
||||
|
||||
min_len = Actual_Block_Device.size() + 2;
|
||||
sprintf(command, "df %s > /tmp/dfoutput.txt", Mount_Point.c_str());
|
||||
TWFunc::Exec_Cmd(command, result);
|
||||
TWFunc::Exec_Cmd(command);
|
||||
fp = fopen("/tmp/dfoutput.txt", "rt");
|
||||
if (fp == NULL) {
|
||||
LOGINFO("Unable to open /tmp/dfoutput.txt.\n");
|
||||
@@ -921,9 +920,8 @@ bool TWPartition::Mount(bool Display_Error) {
|
||||
Update_Size(Display_Error);
|
||||
|
||||
if (!Symlink_Mount_Point.empty()) {
|
||||
string Command, Result;
|
||||
Command = "mount '" + Symlink_Path + "' '" + Symlink_Mount_Point + "'";
|
||||
TWFunc::Exec_Cmd(Command, Result);
|
||||
string Command = "mount '" + Symlink_Path + "' '" + Symlink_Mount_Point + "'";
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1243,13 +1241,13 @@ bool TWPartition::Wipe_EXT23(string File_System) {
|
||||
return false;
|
||||
|
||||
if (TWFunc::Path_Exists("/sbin/mke2fs")) {
|
||||
string command, result;
|
||||
string command;
|
||||
|
||||
gui_print("Formatting %s using mke2fs...\n", Display_Name.c_str());
|
||||
Find_Actual_Block_Device();
|
||||
command = "mke2fs -t " + File_System + " -m 0 " + Actual_Block_Device;
|
||||
LOGINFO("mke2fs command: %s\n", command.c_str());
|
||||
if (TWFunc::Exec_Cmd(command, result) == 0) {
|
||||
if (TWFunc::Exec_Cmd(command) == 0) {
|
||||
Current_File_System = File_System;
|
||||
Recreate_AndSec_Folder();
|
||||
gui_print("Done.\n");
|
||||
@@ -1278,7 +1276,7 @@ bool TWPartition::Wipe_EXT4() {
|
||||
}
|
||||
#else
|
||||
if (TWFunc::Path_Exists("/sbin/make_ext4fs")) {
|
||||
string Command, result;
|
||||
string Command;
|
||||
|
||||
gui_print("Formatting %s using make_ext4fs...\n", Display_Name.c_str());
|
||||
Find_Actual_Block_Device();
|
||||
@@ -1295,7 +1293,7 @@ bool TWPartition::Wipe_EXT4() {
|
||||
}
|
||||
Command += " -a " + Mount_Point + " " + Actual_Block_Device;
|
||||
LOGINFO("make_ext4fs command: %s\n", Command.c_str());
|
||||
if (TWFunc::Exec_Cmd(Command, result) == 0) {
|
||||
if (TWFunc::Exec_Cmd(Command) == 0) {
|
||||
Current_File_System = "ext4";
|
||||
Recreate_AndSec_Folder();
|
||||
gui_print("Done.\n");
|
||||
@@ -1311,7 +1309,7 @@ bool TWPartition::Wipe_EXT4() {
|
||||
}
|
||||
|
||||
bool TWPartition::Wipe_FAT() {
|
||||
string command, result;
|
||||
string command;
|
||||
|
||||
if (TWFunc::Path_Exists("/sbin/mkdosfs")) {
|
||||
if (!UnMount(true))
|
||||
@@ -1320,7 +1318,7 @@ bool TWPartition::Wipe_FAT() {
|
||||
gui_print("Formatting %s using mkdosfs...\n", Display_Name.c_str());
|
||||
Find_Actual_Block_Device();
|
||||
command = "mkdosfs " + Actual_Block_Device;
|
||||
if (TWFunc::Exec_Cmd(command, result) == 0) {
|
||||
if (TWFunc::Exec_Cmd(command) == 0) {
|
||||
Current_File_System = "vfat";
|
||||
Recreate_AndSec_Folder();
|
||||
gui_print("Done.\n");
|
||||
@@ -1338,7 +1336,7 @@ bool TWPartition::Wipe_FAT() {
|
||||
}
|
||||
|
||||
bool TWPartition::Wipe_EXFAT() {
|
||||
string command, result;
|
||||
string command;
|
||||
|
||||
if (TWFunc::Path_Exists("/sbin/mkexfatfs")) {
|
||||
if (!UnMount(true))
|
||||
@@ -1347,7 +1345,7 @@ bool TWPartition::Wipe_EXFAT() {
|
||||
gui_print("Formatting %s using mkexfatfs...\n", Display_Name.c_str());
|
||||
Find_Actual_Block_Device();
|
||||
command = "mkexfatfs " + Actual_Block_Device;
|
||||
if (TWFunc::Exec_Cmd(command, result) == 0) {
|
||||
if (TWFunc::Exec_Cmd(command) == 0) {
|
||||
Recreate_AndSec_Folder();
|
||||
gui_print("Done.\n");
|
||||
return true;
|
||||
@@ -1404,7 +1402,7 @@ bool TWPartition::Wipe_RMRF() {
|
||||
}
|
||||
|
||||
bool TWPartition::Wipe_F2FS() {
|
||||
string command, result;
|
||||
string command;
|
||||
|
||||
if (TWFunc::Path_Exists("/sbin/mkfs.f2fs")) {
|
||||
if (!UnMount(true))
|
||||
@@ -1413,7 +1411,7 @@ bool TWPartition::Wipe_F2FS() {
|
||||
gui_print("Formatting %s using mkfs.f2fs...\n", Display_Name.c_str());
|
||||
Find_Actual_Block_Device();
|
||||
command = "mkfs.f2fs " + Actual_Block_Device;
|
||||
if (TWFunc::Exec_Cmd(command, result) == 0) {
|
||||
if (TWFunc::Exec_Cmd(command) == 0) {
|
||||
Recreate_AndSec_Folder();
|
||||
gui_print("Done.\n");
|
||||
return true;
|
||||
@@ -1534,7 +1532,7 @@ bool TWPartition::Backup_Tar(string backup_folder) {
|
||||
|
||||
bool TWPartition::Backup_DD(string backup_folder) {
|
||||
char back_name[255], backup_size[32];
|
||||
string Full_FileName, Command, result, DD_BS;
|
||||
string Full_FileName, Command, DD_BS;
|
||||
int use_compression;
|
||||
|
||||
sprintf(backup_size, "%llu", Backup_Size);
|
||||
@@ -1550,7 +1548,7 @@ bool TWPartition::Backup_DD(string backup_folder) {
|
||||
|
||||
Command = "dd if=" + Actual_Block_Device + " of='" + Full_FileName + "'" + " bs=" + DD_BS + "c count=1";
|
||||
LOGINFO("Backup command: '%s'\n", Command.c_str());
|
||||
TWFunc::Exec_Cmd(Command, result);
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
if (TWFunc::Get_File_Size(Full_FileName) == 0) {
|
||||
LOGERR("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str());
|
||||
return false;
|
||||
@@ -1560,7 +1558,7 @@ bool TWPartition::Backup_DD(string backup_folder) {
|
||||
|
||||
bool TWPartition::Backup_Dump_Image(string backup_folder) {
|
||||
char back_name[255];
|
||||
string Full_FileName, Command, result;
|
||||
string Full_FileName, Command;
|
||||
int use_compression;
|
||||
|
||||
TWFunc::GUI_Operation_Text(TW_BACKUP_TEXT, Display_Name, "Backing Up");
|
||||
@@ -1573,7 +1571,7 @@ bool TWPartition::Backup_Dump_Image(string backup_folder) {
|
||||
|
||||
Command = "dump_image " + MTD_Name + " '" + Full_FileName + "'";
|
||||
LOGINFO("Backup command: '%s'\n", Command.c_str());
|
||||
TWFunc::Exec_Cmd(Command, result);
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
if (TWFunc::Get_File_Size(Full_FileName) == 0) {
|
||||
// Actual size may not match backup size due to bad blocks on MTD devices so just check for 0 bytes
|
||||
LOGERR("Backup file size for '%s' is 0 bytes.\n", Full_FileName.c_str());
|
||||
@@ -1637,7 +1635,7 @@ bool TWPartition::Restore_Tar(string restore_folder, string Restore_File_System)
|
||||
}
|
||||
|
||||
bool TWPartition::Restore_DD(string restore_folder) {
|
||||
string Full_FileName, Command, result;
|
||||
string Full_FileName, Command;
|
||||
|
||||
TWFunc::GUI_Operation_Text(TW_RESTORE_TEXT, Display_Name, "Restoring");
|
||||
Full_FileName = restore_folder + "/" + Backup_FileName;
|
||||
@@ -1657,22 +1655,22 @@ bool TWPartition::Restore_DD(string restore_folder) {
|
||||
gui_print("Restoring %s...\n", Display_Name.c_str());
|
||||
Command = "dd bs=4096 if='" + Full_FileName + "' of=" + Actual_Block_Device;
|
||||
LOGINFO("Restore command: '%s'\n", Command.c_str());
|
||||
TWFunc::Exec_Cmd(Command, result);
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TWPartition::Restore_Flash_Image(string restore_folder) {
|
||||
string Full_FileName, Command, result;
|
||||
string Full_FileName, Command;
|
||||
|
||||
gui_print("Restoring %s...\n", Display_Name.c_str());
|
||||
Full_FileName = restore_folder + "/" + Backup_FileName;
|
||||
// Sometimes flash image doesn't like to flash due to the first 2KB matching, so we erase first to ensure that it flashes
|
||||
Command = "erase_image " + MTD_Name;
|
||||
LOGINFO("Erase command: '%s'\n", Command.c_str());
|
||||
TWFunc::Exec_Cmd(Command, result);
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
Command = "flash_image " + MTD_Name + " '" + Full_FileName + "'";
|
||||
LOGINFO("Restore command: '%s'\n", Command.c_str());
|
||||
TWFunc::Exec_Cmd(Command, result);
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1635,8 +1635,8 @@ int TWPartitionManager::Partition_SDCard(void) {
|
||||
if (!SDext->UnMount(true))
|
||||
return false;
|
||||
}
|
||||
string result;
|
||||
TWFunc::Exec_Cmd("umount \"$SWAPPATH\"", result);
|
||||
|
||||
TWFunc::Exec_Cmd("umount \"$SWAPPATH\"");
|
||||
Device = SDCard->Actual_Block_Device;
|
||||
// Just use the root block device
|
||||
Device.resize(strlen("/dev/block/mmcblkX"));
|
||||
@@ -1688,7 +1688,7 @@ int TWPartitionManager::Partition_SDCard(void) {
|
||||
gui_print("Removing partition table...\n");
|
||||
Command = "parted -s " + Device + " mklabel msdos";
|
||||
LOGINFO("Command is: '%s'\n", Command.c_str());
|
||||
if (TWFunc::Exec_Cmd(Command, result) != 0) {
|
||||
if (TWFunc::Exec_Cmd(Command) != 0) {
|
||||
LOGERR("Unable to remove partition table.\n");
|
||||
Update_System_Details();
|
||||
return false;
|
||||
@@ -1696,7 +1696,7 @@ int TWPartitionManager::Partition_SDCard(void) {
|
||||
gui_print("Creating FAT32 partition...\n");
|
||||
Command = "parted " + Device + " mkpartfs primary fat32 0 " + fat_str + "MB";
|
||||
LOGINFO("Command is: '%s'\n", Command.c_str());
|
||||
if (TWFunc::Exec_Cmd(Command, result) != 0) {
|
||||
if (TWFunc::Exec_Cmd(Command) != 0) {
|
||||
LOGERR("Unable to create FAT32 partition.\n");
|
||||
return false;
|
||||
}
|
||||
@@ -1704,7 +1704,7 @@ int TWPartitionManager::Partition_SDCard(void) {
|
||||
gui_print("Creating EXT partition...\n");
|
||||
Command = "parted " + Device + " mkpartfs primary ext2 " + fat_str + "MB " + ext_str + "MB";
|
||||
LOGINFO("Command is: '%s'\n", Command.c_str());
|
||||
if (TWFunc::Exec_Cmd(Command, result) != 0) {
|
||||
if (TWFunc::Exec_Cmd(Command) != 0) {
|
||||
LOGERR("Unable to create EXT partition.\n");
|
||||
Update_System_Details();
|
||||
return false;
|
||||
@@ -1714,7 +1714,7 @@ int TWPartitionManager::Partition_SDCard(void) {
|
||||
gui_print("Creating swap partition...\n");
|
||||
Command = "parted " + Device + " mkpartfs primary linux-swap " + ext_str + "MB " + swap_str + "MB";
|
||||
LOGINFO("Command is: '%s'\n", Command.c_str());
|
||||
if (TWFunc::Exec_Cmd(Command, result) != 0) {
|
||||
if (TWFunc::Exec_Cmd(Command) != 0) {
|
||||
LOGERR("Unable to create swap partition.\n");
|
||||
Update_System_Details();
|
||||
return false;
|
||||
@@ -1749,7 +1749,7 @@ int TWPartitionManager::Partition_SDCard(void) {
|
||||
Command = "mke2fs -t " + ext_format + " -m 0 " + SDext->Actual_Block_Device;
|
||||
gui_print("Formatting sd-ext as %s...\n", ext_format.c_str());
|
||||
LOGINFO("Formatting sd-ext after partitioning, command: '%s'\n", Command.c_str());
|
||||
TWFunc::Exec_Cmd(Command, result);
|
||||
TWFunc::Exec_Cmd(Command);
|
||||
}
|
||||
|
||||
Update_System_Details();
|
||||
|
||||
+2
-3
@@ -997,13 +997,12 @@ main(int argc, char **argv) {
|
||||
#ifdef TW_INCLUDE_INJECTTWRP
|
||||
// Back up TWRP Ramdisk if needed:
|
||||
TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
|
||||
string result;
|
||||
LOGI("Backing up TWRP ramdisk...\n");
|
||||
if (Boot == NULL || Boot->Current_File_System != "emmc")
|
||||
TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img", result);
|
||||
TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
|
||||
else {
|
||||
string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
|
||||
TWFunc::Exec_Cmd(injectcmd, result);
|
||||
TWFunc::Exec_Cmd(injectcmd);
|
||||
}
|
||||
LOGI("Backup of TWRP ramdisk done.\n");
|
||||
#endif
|
||||
|
||||
+32
-15
@@ -35,7 +35,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
/* Execute a command */
|
||||
int TWFunc::Exec_Cmd(string cmd, string &result) {
|
||||
int TWFunc::Exec_Cmd(const string& cmd, string &result) {
|
||||
FILE* exec;
|
||||
char buffer[130];
|
||||
int ret = 0;
|
||||
@@ -53,6 +53,28 @@ int TWFunc::Exec_Cmd(string cmd, string &result) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int TWFunc::Exec_Cmd(const string& cmd) {
|
||||
pid_t pid;
|
||||
int status;
|
||||
switch(pid = fork())
|
||||
{
|
||||
case -1:
|
||||
LOGERR("Exec_Cmd(): vfork failed!\n");
|
||||
return -1;
|
||||
case 0: // child
|
||||
execl("/sbin/sh", "sh", "-c", cmd.c_str(), NULL);
|
||||
_exit(127);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (TWFunc::Wait_For_Child(pid, &status, cmd) != 0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns "file.name" from a full /path/to/file.name
|
||||
string TWFunc::Get_Filename(string Path) {
|
||||
size_t pos = Path.find_last_of("/");
|
||||
@@ -130,21 +152,19 @@ void TWFunc::install_htc_dumlock(void) {
|
||||
}
|
||||
|
||||
void TWFunc::htc_dumlock_restore_original_boot(void) {
|
||||
string status;
|
||||
if (!PartitionManager.Mount_By_Path("/sdcard", true))
|
||||
return;
|
||||
|
||||
gui_print("Restoring original boot...\n");
|
||||
Exec_Cmd("htcdumlock restore", status);
|
||||
Exec_Cmd("htcdumlock restore");
|
||||
gui_print("Original boot restored.\n");
|
||||
}
|
||||
|
||||
void TWFunc::htc_dumlock_reflash_recovery_to_boot(void) {
|
||||
string status;
|
||||
if (!PartitionManager.Mount_By_Path("/sdcard", true))
|
||||
return;
|
||||
gui_print("Reflashing recovery to boot...\n");
|
||||
Exec_Cmd("htcdumlock recovery noreboot", status);
|
||||
Exec_Cmd("htcdumlock recovery noreboot");
|
||||
gui_print("Recovery is flashed to boot.\n");
|
||||
}
|
||||
|
||||
@@ -337,11 +357,10 @@ void TWFunc::check_and_run_script(const char* script_file, const char* display_n
|
||||
{
|
||||
// Check for and run startup script if script exists
|
||||
struct stat st;
|
||||
string result;
|
||||
if (stat(script_file, &st) == 0) {
|
||||
gui_print("Running %s script...\n", display_name);
|
||||
chmod(script_file, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
||||
TWFunc::Exec_Cmd(script_file, result);
|
||||
TWFunc::Exec_Cmd(script_file);
|
||||
gui_print("\nFinished running %s script.\n", display_name);
|
||||
}
|
||||
}
|
||||
@@ -738,12 +757,10 @@ int TWFunc::tw_chmod(const string& fn, const string& mode) {
|
||||
}
|
||||
|
||||
bool TWFunc::Install_SuperSU(void) {
|
||||
string status;
|
||||
|
||||
if (!PartitionManager.Mount_By_Path("/system", true))
|
||||
return false;
|
||||
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/xbin/su", status);
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/xbin/su");
|
||||
if (copy_file("/supersu/su", "/system/xbin/su", 0755) != 0) {
|
||||
LOGERR("Failed to copy su binary to /system/bin\n");
|
||||
return false;
|
||||
@@ -751,24 +768,24 @@ bool TWFunc::Install_SuperSU(void) {
|
||||
if (!Path_Exists("/system/bin/.ext")) {
|
||||
mkdir("/system/bin/.ext", 0777);
|
||||
}
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/bin/.ext/su", status);
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/bin/.ext/su");
|
||||
if (copy_file("/supersu/su", "/system/bin/.ext/su", 0755) != 0) {
|
||||
LOGERR("Failed to copy su binary to /system/bin/.ext/su\n");
|
||||
return false;
|
||||
}
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/xbin/daemonsu", status);
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/xbin/daemonsu");
|
||||
if (copy_file("/supersu/su", "/system/xbin/daemonsu", 0755) != 0) {
|
||||
LOGERR("Failed to copy su binary to /system/xbin/daemonsu\n");
|
||||
return false;
|
||||
}
|
||||
if (Path_Exists("/system/etc/init.d")) {
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/etc/init.d/99SuperSUDaemon", status);
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/etc/init.d/99SuperSUDaemon");
|
||||
if (copy_file("/supersu/99SuperSUDaemon", "/system/etc/init.d/99SuperSUDaemon", 0755) != 0) {
|
||||
LOGERR("Failed to copy 99SuperSUDaemon to /system/etc/init.d/99SuperSUDaemon\n");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/etc/install-recovery.sh", status);
|
||||
TWFunc::Exec_Cmd("/sbin/chattr -i /system/etc/install-recovery.sh");
|
||||
if (copy_file("/supersu/install-recovery.sh", "/system/etc/install-recovery.sh", 0755) != 0) {
|
||||
LOGERR("Failed to copy install-recovery.sh to /system/etc/install-recovery.sh\n");
|
||||
return false;
|
||||
@@ -997,4 +1014,4 @@ void TWFunc::Auto_Generate_Backup_Name() {
|
||||
}
|
||||
if (!mount_state)
|
||||
PartitionManager.UnMount_By_Path("/system", false);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@ public:
|
||||
static void Update_Intent_File(string Intent); // Updates intent file
|
||||
static int tw_reboot(RebootCommand command); // Prepares the device for rebooting
|
||||
static void check_and_run_script(const char* script_file, const char* display_name); // checks for the existence of a script, chmods it to 755, then runs it
|
||||
static int Exec_Cmd(string cmd, string &result); //execute a command and return the result as a string by reference
|
||||
static int Exec_Cmd(const string& cmd, string &result); //execute a command and return the result as a string by reference
|
||||
static int Exec_Cmd(const string& cmd); //execute a command
|
||||
static int removeDir(const string path, bool removeParent); //recursively remove a directory
|
||||
static int copy_file(string src, string dst, int mode); //copy file from src to dst with mode permissions
|
||||
static unsigned int Get_D_Type_From_Stat(string Path); // Returns a dirent dt_type value using stat instead of dirent
|
||||
|
||||
@@ -187,13 +187,12 @@ int main(int argc, char **argv) {
|
||||
#ifdef TW_INCLUDE_INJECTTWRP
|
||||
// Back up TWRP Ramdisk if needed:
|
||||
TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
|
||||
string result;
|
||||
LOGINFO("Backing up TWRP ramdisk...\n");
|
||||
if (Boot == NULL || Boot->Current_File_System != "emmc")
|
||||
TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img", result);
|
||||
TWFunc::Exec_Cmd("injecttwrp --backup /tmp/backup_recovery_ramdisk.img");
|
||||
else {
|
||||
string injectcmd = "injecttwrp --backup /tmp/backup_recovery_ramdisk.img bd=" + Boot->Actual_Block_Device;
|
||||
TWFunc::Exec_Cmd(injectcmd, result);
|
||||
TWFunc::Exec_Cmd(injectcmd);
|
||||
}
|
||||
LOGINFO("Backup of TWRP ramdisk done.\n");
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user