int install_rom_from_tar(char* filename)
{
    if (ui_key_pressed(KEY_SPACE)) {
	ui_print("Backing up before installing...\n");

	nandroid_backup("preinstall",BSD|PROGRESS);
    }

    ui_print("Attempting to install ROM from ");
    ui_print(filename);
    ui_print("...\n");
  
    char* argv[] = { "/sbin/nandroid-mobile.sh",
		     "--install-rom",
		     filename,
		     "--progress",
		     NULL };

    char* envp[] = { NULL };
  
    int status = runve("/sbin/nandroid-mobile.sh",argv,envp,1);
    if(!WIFEXITED(status) || WEXITSTATUS(status)!=0) {
	ui_printf_int("ERROR: install exited with status %d\n",WEXITSTATUS(status));
	return WEXITSTATUS(status);
    }
    else {
	ui_print("(done)\n");
    }
    ui_reset_progress();
    return 0;
}
Exemple #2
0
static int
cmd_backup_rom(const char *name, void *cookie, int argc, const char *argv[],
        PermissionRequestList *permissions)
{
    UNUSED(cookie);
    CHECK_WORDS();

    char* backup_name = NULL;
    char backup_path[PATH_MAX];
    switch(argc)
    {
        case 0:
            {
                char backup_path[PATH_MAX];
                nandroid_generate_timestamp_path(backup_path);
                backup_name = backup_path;
            }
            break;
        case 1:
            backup_name = argv[0];
            break;
        default:
            LOGE("Command %s requires zero or one argument\n", name);
            return 1;
    }

    return nandroid_backup(backup_name);
}
Exemple #3
0
int nandroid_main(int argc, char** argv) {
    load_volume_table();
    char backup_path[PATH_MAX];

    if (argc > 3 || argc < 2)
        return nandroid_usage();

    if (strcmp("backup", argv[1]) == 0) {
        if (argc != 2)
            return nandroid_usage();

        nandroid_generate_timestamp_path(backup_path);
        return nandroid_backup(backup_path);
    }

    if (strcmp("restore", argv[1]) == 0) {
        if (argc != 3)
            return nandroid_usage();
        return nandroid_restore(argv[2], 1, 1, 1, 1, 1, 0);
    }

    if (strcmp("dump", argv[1]) == 0) {
        if (argc != 3)
            return nandroid_usage();
        return nandroid_dump(argv[2]);
    }

    if (strcmp("undump", argv[1]) == 0) {
        if (argc != 3)
            return nandroid_usage();
        return nandroid_undump(argv[2]);
    }

    return nandroid_usage();
}
/*
 *nandroid_backup(backup_path);
 *
 *INTENT_BACKUP 
 *intent_backup(argc, NULL);
 */
static intentResult* intent_backup(int argc, char* argv[])
{
    return_intent_result_if_fail(argc == 1);
    int result ;
    result = nandroid_backup(argv[0]);
    assert_ui_if_fail(result == 0);
    return miuiIntent_result_set(result, NULL);
}
Exemple #5
0
void show_nandroid_menu()
{
    static char* headers[] = {  "Nandroid",
                                "",
                                NULL
    };

    static char* list[] = { "~~~> Go Back <~~~",
			    "Backup",
                            "Restore",
			    "Advanced Backup",
                            "Advanced Restore",
                            NULL
    };
for (;;)
    {

    int chosen_item = get_menu_selection(headers, list, 0);
    if (chosen_item == GO_BACK)
            break;
    switch (chosen_item)
    {
	case 0:
	    {
		return;
		break;
	    }
        case 1:
            {
                char backup_path[PATH_MAX];
                time_t t = time(NULL);
                struct tm *tmp = localtime(&t);
                if (tmp == NULL)
                {
                    struct timeval tp;
                    gettimeofday(&tp, NULL);
                    sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
                }
                else
                {
                    strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
                }
                nandroid_backup(backup_path);
		break;
            }
           
        case 2:
            show_nandroid_restore_menu();
            break;
        case 3:
            show_nandroid_advanced_backup_menu();
            break;
	case 4:
            show_nandroid_advanced_restore_menu();
            break;
    }
}
}
void process_volumes() {
    create_fstab();

    if (is_data_media()) {
        setup_data_media();
    }

    return;

    // dead code.
    if (device_flash_type() != BML)
        return;

    ui_print("Checking for ext4 partitions...\n");
    int ret = 0;
    ret = bml_check_volume("/system");
    ret |= bml_check_volume("/data");
    if (has_datadata())
        ret |= bml_check_volume("/datadata");
    ret |= bml_check_volume("/cache");
    
    if (ret == 0) {
        ui_print("Done!\n");
        return;
    }
    
    char backup_path[PATH_MAX];
    //time_t t = time(NULL);
    char backup_name[PATH_MAX];
    struct timeval tp;
    gettimeofday(&tp, NULL);
    sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec);
    if (target_sdcard == TARGET_INTERNAL_SDCARD) {
        sprintf(backup_path, INTERNAL_SDCARD_PATH "/clockworkmod/backup/%s", backup_name);
    } else {
        sprintf(backup_path, EXTERNAL_SDCARD_PATH "/clockworkmod/backup/%s", backup_name);
    }

    ui_set_show_text(1);
    ui_print("Filesystems need to be converted to ext4.\n");
    ui_print("A backup and restore will now take place.\n");
    ui_print("If anything goes wrong, your backup will be\n");
    ui_print("named %s. Try restoring it\n", backup_name);
    ui_print("in case of error.\n");

    nandroid_backup(backup_path);
    nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0);
    ui_set_show_text(0);
}
Value* BackupFn(const char* name, State* state, int argc, Expr* argv[]) {
    char* result = NULL;
    if (argc != 1) {
        return ErrorAbort(state, "%s() expects 1 args, got %d", name, argc);
    }
    char* path;
    if (ReadArgs(state, argv, 1, &path) < 0) {
        return NULL;
    }
    
    if (0 != nandroid_backup(path))
        return StringValue(strdup(""));
    
    return StringValue(strdup(path));
}
 void
preinstall_menu (char *filename)
{
   char *basename = strrchr (filename, '/') + 1;
  char install_string[PATH_MAX];

  strcpy (install_string, "Install ");
  strcat (install_string, basename);
   char *headers[] =
    { "Preinstall Menu", "Please make your selections.", " ", NULL
  };
   char *items[] =
    { "Abort Install", "Backup Before Install", "Wipe /data",
install_string, NULL
  };
  
#define ITEM_NO 		0
#define ITEM_BACKUP 	1
#define ITEM_WIPE 		2
#define ITEM_INSTALL 	3
  int chosen_item = -1;

  while (chosen_item != ITEM_BACK)
	  {
	    chosen_item =
	      get_menu_selection (headers, items, 1,
				  chosen_item < 0 ? 0 : chosen_item);
	    switch (chosen_item)
		    {
		    case ITEM_NO:
		      chosen_item = ITEM_BACK;
		      return;
		    case ITEM_BACKUP:
		      ui_print ("Backing up before installing...\n");
		      nandroid_backup ("preinstall", BDAS | PROGRESS);
		      break;
		    case ITEM_WIPE:
		      wipe_partition ("Are you sure?", "Yes - wipe DATA",
				       "data");
		      break;
		    case ITEM_INSTALL:
		      install_update_package (filename);
		      return;
		    }
	  }
}
void process_volumes() {
    create_fstab();

    if (is_data_media()) {
        setup_data_media();
    }

    return;

    // dead code.
    if (device_flash_type() != BML)
        return;

    ui_print("正在校验 EXT4 分区...\n");
    int ret = 0;
    ret = bml_check_volume("/system");
    ret |= bml_check_volume("/data");
    if (has_datadata())
        ret |= bml_check_volume("/datadata");
    ret |= bml_check_volume("/cache");
    
    if (ret == 0) {
        ui_print("校验完成!\n");
        return;
    }
    
    char backup_path[PATH_MAX];
    time_t t = time(NULL);
    char backup_name[PATH_MAX];
    struct timeval tp;
    gettimeofday(&tp, NULL);
    sprintf(backup_name, "before-ext4-convert-%d", tp.tv_sec);
    sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", backup_name);

    ui_set_show_text(1);
    ui_print("文件系统将会被转换为 EXT4格式.\n");
    ui_print("将会进行备份和恢复操作.\n");
    ui_print("如果出现错误你可以恢复\n");
    ui_print("文件名为%s的备份\n", backup_name);
    ui_print("在错误的情况下.\n");

    nandroid_backup(backup_path);
    nandroid_restore(backup_path, 1, 1, 1, 1, 1, 0);
    ui_set_show_text(0);
}
void show_nandroid_menu()
{
    static char* headers[] = {  "Nandroid",
                                "",
                                NULL 
    };

    static char* list[] = { "Backup", 
                            "Restore",
                            "Advanced Restore",
                            NULL
    };

    int chosen_item = get_menu_selection(headers, list, 0);
    switch (chosen_item)
    {
        case 0:
            {
                char backup_path[PATH_MAX];
                time_t t = time(NULL);
                struct tm *tmp = localtime(&t);
                if (tmp == NULL)
                {
                    struct timeval tp;
                    gettimeofday(&tp, NULL);
                    sprintf(backup_path, "/sdcard/ebrecovery/backup/%d", tp.tv_sec);
                }
                else
                {
                    strftime(backup_path, sizeof(backup_path), "/sdcard/ebrecovery/backup/%F.%H.%M.%S", tmp);
                }
                nandroid_backup(backup_path);
            }
            break;
        case 1:
            show_nandroid_restore_menu();
            break;
        case 2:
            show_nandroid_advanced_restore_menu(1);
            break;
    }
}
void show_nandroid_menu()
{
    static char* headers[] = {  "Backup and Restore",
                                "",
                                NULL
    };

    char* list[] = { "backup",
                            "restore",
                            "delete",
                            "advanced restore",
                            "free unused backup data",
                            "choose default backup format",
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL
    };

    char *other_sd = NULL;
    if (volume_for_path("/emmc") != NULL) {
        other_sd = "/emmc";
        list[6] = "backup to internal sdcard";
        list[7] = "restore from internal sdcard";
        list[8] = "advanced restore from internal sdcard";
        list[9] = "delete from internal sdcard";
    }
    else if (volume_for_path("/external_sd") != NULL) {
        other_sd = "/external_sd";
        list[6] = "backup to external sdcard";
        list[7] = "restore from external sdcard";
        list[8] = "advanced restore from external sdcard";
        list[9] = "delete from external sdcard";
    }
#ifdef RECOVERY_EXTEND_NANDROID_MENU
    extend_nandroid_menu(list, 10, sizeof(list) / sizeof(char*));
#endif

    for (;;) {
        int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
        if (chosen_item == GO_BACK)
            break;
        switch (chosen_item)
        {
            case 0:
                {
                    char backup_path[PATH_MAX];
                    time_t t = time(NULL);
                    struct tm *tmp = localtime(&t);
                    if (tmp == NULL)
                    {
                        struct timeval tp;
                        gettimeofday(&tp, NULL);
                        sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
                    }
                    else
                    {
                        strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
                    }
                    nandroid_backup(backup_path);
                    write_recovery_version();
                }
                break;
            case 1:
                show_nandroid_restore_menu("/sdcard");
                write_recovery_version();
                break;
            case 2:
                show_nandroid_delete_menu("/sdcard");
                write_recovery_version();
                break;
            case 3:
                show_nandroid_advanced_restore_menu("/sdcard");
                write_recovery_version();
                break;
            case 4:
                run_dedupe_gc(other_sd);
                break;
            case 5:
                choose_default_backup_format();
                break;
            case 6:
                {
                    char backup_path[PATH_MAX];
                    time_t t = time(NULL);
                    struct tm *timeptr = localtime(&t);
                    if (timeptr == NULL)
                    {
                        struct timeval tp;
                        gettimeofday(&tp, NULL);
                        if (other_sd != NULL) {
                            sprintf(backup_path, "%s/clockworkmod/backup/%d", other_sd, tp.tv_sec);
                        }
                        else {
                            break;
                        }
                    }
                    else
                    {
                        if (other_sd != NULL) {
                            char tmp[PATH_MAX];
                            strftime(tmp, sizeof(tmp), "clockworkmod/backup/%F.%H.%M.%S", timeptr);
                            // this sprintf results in:
                            // /emmc/clockworkmod/backup/%F.%H.%M.%S (time values are populated too)
                            sprintf(backup_path, "%s/%s", other_sd, tmp);
                        }
                        else {
                            break;
                        }
                    }
                    nandroid_backup(backup_path);
                }
                break;
            case 7:
                if (other_sd != NULL) {
                    show_nandroid_restore_menu(other_sd);
                }
                break;
            case 8:
                if (other_sd != NULL) {
                    show_nandroid_advanced_restore_menu(other_sd);
                }
                break;
            case 9:
                if (other_sd != NULL) {
                    show_nandroid_delete_menu(other_sd);
                }
                break;
            default:
#ifdef RECOVERY_EXTEND_NANDROID_MENU
                handle_nandroid_menu(10, chosen_item);
#endif
                break;
        }
    }
}
void show_nandroid_menu()
{
    static char* headers[] = {  "Nandroid",
                                "",
                                NULL
    };

    static char* list[] = { "Backup",
                            "Restore",
                            "Advanced Restore",
                            NULL
    };

#ifdef BOARD_HAS_SDCARD_INTERNAL
    int chosen_sdcard = -1;
#endif
    int chosen_item = get_menu_selection(headers, list, 0, 0);
    switch (chosen_item)
    {
        case 0:
            {
                char backup_path[PATH_MAX];
                char final_path[PATH_MAX];
                time_t t = time(NULL);
                struct tm *tmp = localtime(&t);
#ifdef BOARD_HAS_SDCARD_INTERNAL
                chosen_sdcard = show_sdcard_selection_menu();
                if (chosen_sdcard > -1)
                {
                    switch (chosen_sdcard) {
                        case 0:
                            sprintf(backup_path, "/sdcard");
                            break;
                        case 1:
                            sprintf(backup_path, "/sdcard-ext");
                            break;
                    }
                }
                else break;
#else
                sprintf(backup_path, "/sdcard");
#endif
#ifdef BOARD_HAS_WEBTOP
                static char* header[] = {  "Include webtop in backup?",
                                           "",
                                           NULL
                };

                static char* item[] = {  "Yes",
                                         "No",
                                         NULL
                };

                int skip_webtop = get_menu_selection(header, item, 0, 0);
                if (skip_webtop == GO_BACK) {
                    return;
                }
#endif
                if (tmp == NULL)
                {
                    struct timeval tp;
                    gettimeofday(&tp, NULL);
                    sprintf(final_path, "%s/clockworkmod/backup/%d", backup_path, tp.tv_sec);
                }
                else
                {
                    char tmp_path[PATH_MAX];
                    strftime(tmp_path, sizeof(tmp_path), "clockworkmod/backup/%F.%H.%M.%S", tmp);
                    sprintf(final_path, "%s/%s", backup_path, tmp_path);
                }
                nandroid_backup(final_path, backup_path, skip_webtop);
            }
            break;
        case 1:
#ifdef BOARD_HAS_SDCARD_INTERNAL
            chosen_sdcard = show_sdcard_selection_menu();
            if (chosen_sdcard > -1)
            {
                switch (chosen_sdcard) {
                    case 0:
                        show_nandroid_restore_menu("/sdcard");
                        break;
                    case 1:
                        show_nandroid_restore_menu("/sdcard-ext");
                        break;
                }
            }
            else break;
#else
            show_nandroid_restore_menu("/sdcard");
#endif
            break;
        case 2:
#ifdef BOARD_HAS_SDCARD_INTERNAL
            chosen_sdcard = show_sdcard_selection_menu();
            if (chosen_sdcard > -1)
            {
                switch (chosen_sdcard) {
                    case 0:
                        show_nandroid_advanced_restore_menu("/sdcard");
                        break;
                    case 1:
                        show_nandroid_advanced_restore_menu("/sdcard-ext");
                        break;
                }
            }
            else break;
#else
            show_nandroid_advanced_restore_menu("/sdcard");
#endif
            break;
    }
}
void show_nandroid_menu()
{
    static char* headers[] = {  "Nandroid",
                                "",
                                NULL
    };

    static char* list[] = { "backup to internal sdcard",
                            "restore from internal sdcard",
                            "advanced restore from internal sdcard",
                            "backup to external sdcard",
                            "restore from external sdcard",
                            "advanced restore from external sdcard",
                            NULL
    };

    if (volume_for_path("/emmc") == NULL || volume_for_path("/sdcard") == NULL && is_data_media())
        list[3] = NULL;

    int chosen_item = get_menu_selection(headers, list, 0, 0);
    switch (chosen_item)
    {
        case 0:
            {
                char backup_path[PATH_MAX];
                time_t t = time(NULL);
                struct tm *tmp = localtime(&t);
                if (tmp == NULL)
                {
                    struct timeval tp;
                    gettimeofday(&tp, NULL);
                    sprintf(backup_path, "/emmc/clockworkmod/backup/%d", tp.tv_sec);
                }
                else
                {
                    strftime(backup_path, sizeof(backup_path), "/emmc/clockworkmod/backup/%F.%H.%M.%S", tmp);
                }
                nandroid_backup(backup_path);
            }
            break;
        case 1:
            show_nandroid_restore_menu("/emmc");
            break;
        case 2:
            show_nandroid_advanced_restore_menu("/emmc");
            break;
        case 3:
            {
                char backup_path[PATH_MAX];
                time_t t = time(NULL);
                struct tm *tmp = localtime(&t);
                if (tmp == NULL)
                {
                    struct timeval tp;
                    gettimeofday(&tp, NULL);
                    sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
                }
                else
                {
                    strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
                }
                nandroid_backup(backup_path);
            }
            break;
        case 4:
            show_nandroid_restore_menu("/sdcard");
            break;
        case 5:
            show_nandroid_advanced_restore_menu("/sdcard");
            break;
    }
}
void show_nandroid_menu()
{
    static char* headers[] = {  "Nandroid",
                                "",
                                NULL
    };

    static char* list_internal[] = { "Backup to internal sdcard",
                                      "Restore from internal sdcard",
                                      "Advanced Restore from internal sdcard",
                                      "toggle target sdcard",
                                      NULL
    };
    static char* list_external[] = { "Backup to external sdcard",
                                      "Restore from external sdcard",
                                      "Advanced Restore from external sdcard",
                                      "toggle target sdcard",
                                      NULL
    };

	for (;;) {
		char* list;
		if (target_sdcard == TARGET_INTERNAL_SDCARD) {
			list = list_internal;
		} else {
			list = list_external;
		}
		int chosen_item = get_menu_selection(headers, list, 0, 0);
		switch (chosen_item)
		{
		    case 0:
		        {
		            char backup_path[PATH_MAX];
#ifdef RECOVERY_TZ_JPN
		            time_t t = time(NULL) + (60 * 60 * 9); // add 9 hours
#else
		            time_t t = time(NULL);
#endif
		            struct tm *tmp = localtime(&t);
		            if (tmp == NULL)
		            {
		                struct timeval tp;
		                gettimeofday(&tp, NULL);
		                if (target_sdcard == TARGET_INTERNAL_SDCARD) {
		                    sprintf(backup_path, INTERNAL_SDCARD_PATH "/clockworkmod/backup/%d", tp.tv_sec);
		                } else {
		                    sprintf(backup_path, EXTERNAL_SDCARD_PATH "/clockworkmod/backup/%d", tp.tv_sec);
		                }
		            }
		            else
		            {
		                if (target_sdcard == TARGET_INTERNAL_SDCARD) {
		                    strftime(backup_path, sizeof(backup_path), INTERNAL_SDCARD_PATH "/clockworkmod/backup/%F.%H.%M.%S", tmp);
		                } else {
		                    strftime(backup_path, sizeof(backup_path), EXTERNAL_SDCARD_PATH "/clockworkmod/backup/%F.%H.%M.%S", tmp);
		                }
		            }
		            nandroid_backup(backup_path);
		        }
		        return;
		    case 1:
		        show_nandroid_restore_menu();
		        break;
		    case 2:
		        show_nandroid_advanced_restore_menu();
		        break;
		    case 3:
		        toggle_targer_sdcard();
		        break;
		    default:
		        return;
		}
	}
}