add backup_rom and restore_rom to amend scripts
This commit is contained in:
parent
13d8fccf50
commit
a9483087a0
45
commands.c
45
commands.c
@ -759,6 +759,45 @@ cmd_done(const char *name, void *cookie, int argc, const char *argv[],
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
switch(argc)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
backup_name = argv[0];
|
||||
break;
|
||||
default:
|
||||
LOGE("Command %s requires zero or one argument\n", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return do_nandroid_backup(backup_name);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_restore_rom(const char *name, void *cookie, int argc, const char *argv[],
|
||||
PermissionRequestList *permissions)
|
||||
{
|
||||
UNUSED(cookie);
|
||||
CHECK_WORDS();
|
||||
|
||||
if (argc != 1) {
|
||||
LOGE("Command %s requires exactly one argument\n", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return do_nandroid_restore(argv[0]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Function definitions
|
||||
*/
|
||||
@ -1122,6 +1161,12 @@ register_update_commands(RecoveryCommandContext *ctx)
|
||||
ret = registerCommand("done", CMD_ARGS_WORDS, cmd_done, (void *)ctx);
|
||||
if (ret < 0) return ret;
|
||||
|
||||
ret = registerCommand("backup_rom", CMD_ARGS_WORDS, cmd_backup_rom, (void *)ctx);
|
||||
if (ret < 0) return ret;
|
||||
|
||||
ret = registerCommand("restore_rom", CMD_ARGS_WORDS, cmd_restore_rom, (void *)ctx);
|
||||
if (ret < 0) return ret;
|
||||
|
||||
/*
|
||||
* Functions
|
||||
*/
|
||||
|
@ -325,16 +325,36 @@ system(const char *command)
|
||||
return (pid == -1 ? -1 : pstat);
|
||||
}
|
||||
|
||||
void do_nandroid_backup()
|
||||
int do_nandroid_backup(char* backup_name)
|
||||
{
|
||||
char cmd[PATH_MAX];
|
||||
if (NULL == backup_name)
|
||||
backup_name = "";
|
||||
sprintf(cmd, "/sbin/nandroid-mobile.sh backup /sdcard/clockworkmod/backup/ %s", backup_name);
|
||||
ui_print("Performing backup...\n");
|
||||
int ret = system("/sbin/nandroid-mobile.sh backup /sdcard/clockworkmod/backup/");
|
||||
int ret = system(cmd);
|
||||
if (ret != 0)
|
||||
{
|
||||
ui_print("Error while backing up! Error code: %d\n", ret);
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
ui_print("Backup complete.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int do_nandroid_restore(char* backup_path)
|
||||
{
|
||||
char* command[PATH_MAX];
|
||||
sprintf(command, "nandroid-mobile.sh restore %s", backup_path);
|
||||
ui_print("Performing restore...\n");
|
||||
int ret = system(command);
|
||||
if (ret != 0)
|
||||
{
|
||||
ui_print("Error while restoring!\n");
|
||||
return ret;
|
||||
}
|
||||
ui_print("Restore complete.\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void show_nandroid_restore_menu()
|
||||
@ -352,16 +372,7 @@ void show_nandroid_restore_menu()
|
||||
char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers);
|
||||
if (file == NULL)
|
||||
return;
|
||||
char* command[PATH_MAX];
|
||||
sprintf(command, "nandroid-mobile.sh restore %s", file);
|
||||
ui_print("Performing restore...\n");
|
||||
int ret = system(command);
|
||||
if (ret != 0)
|
||||
{
|
||||
ui_print("Error while restoring!\n");
|
||||
return;
|
||||
}
|
||||
ui_print("Restore complete.\n");
|
||||
do_nandroid_restore(file);
|
||||
}
|
||||
|
||||
void do_mount_usb_storage()
|
||||
@ -456,5 +467,5 @@ int amend_main(int argc, char** argv)
|
||||
if (register_update_commands(&ctx)) {
|
||||
LOGE("Can't install update commands\n");
|
||||
}
|
||||
return run_and_remove_extendedcommand(argv[1]);
|
||||
}
|
||||
return run_script(argv[1]);
|
||||
}
|
@ -16,11 +16,17 @@ get_allow_toggle_display();
|
||||
void
|
||||
ui_set_show_text(int value);
|
||||
|
||||
void
|
||||
int
|
||||
do_nandroid_backup();
|
||||
|
||||
int
|
||||
do_nandroid_restore();
|
||||
|
||||
void
|
||||
show_nandroid_restore_menu();
|
||||
|
||||
void
|
||||
do_mount_usb_storage();
|
||||
do_mount_usb_storage();
|
||||
|
||||
void
|
||||
show_choose_zip_menu();
|
||||
|
@ -171,7 +171,7 @@ case $1 in
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {backup|restore} [/path/to/nandroid/backup/]"
|
||||
echo "Usage: $0 {backup|restore} [/path/to/nandroid/backup/] [backupname]"
|
||||
echo "- backup will store a full system backup on /sdcard/nandroid"
|
||||
echo "- restore path will restore the last made backup for boot, system, recovery and data"
|
||||
exit 12
|
||||
@ -192,13 +192,18 @@ case $FAIL in
|
||||
3) echo "Error mounting sdcard read-write"; umount /system /data /sdcard; exit 15;;
|
||||
esac
|
||||
|
||||
TIMESTAMP="`date +%Y-%m-%d-%H%M`"
|
||||
if [ -z "$3" ]
|
||||
then
|
||||
BACKUPNAME="`date +%Y-%m-%d-%H%M`"
|
||||
else
|
||||
BACKUPNAME=$3
|
||||
fi
|
||||
BASEDIR=/sdcard/nandroid
|
||||
if [ ! -z "$2" ]; then
|
||||
BASEDIR=$2
|
||||
fi
|
||||
|
||||
DESTDIR=$BASEDIR/$TIMESTAMP
|
||||
DESTDIR=$BASEDIR/$BACKUPNAME
|
||||
if [ ! -d $DESTDIR ]; then
|
||||
mkdir -p $DESTDIR
|
||||
if [ ! -d $DESTDIR ]; then
|
||||
@ -297,6 +302,8 @@ echo "done"
|
||||
|
||||
# 8.
|
||||
echo "unmounting system, data and sdcard"
|
||||
sync
|
||||
sleep 2s
|
||||
umount /system
|
||||
umount /data
|
||||
umount /sdcard
|
||||
|
Loading…
Reference in New Issue
Block a user