@@ -179,6 +179,7 @@ public class AppConsole : GLib.Object {
179179
180180 case " --scripted" :
181181 App . cmd_scripted = true ;
182+ App . cmd_confirm = true ;
182183 break ;
183184
184185 case " --yes" :
@@ -619,13 +620,15 @@ public class AppConsole : GLib.Object {
619620
620621 select_snapshot_for_restore();
621622
622- stdout. printf(" \n\n " );
623- log_msg(string . nfill(78 , ' *' ));
624- stdout. printf(_(" To restore with default options, press the ENTER key for all prompts!" ) + " \n " );
625- log_msg(string . nfill(78 , ' *' ));
626- stdout. printf(_(" \n Press ENTER to continue..." ));
627- stdout. flush();
628- stdin. read_line();
623+ if (! App . cmd_scripted) {
624+ stdout. printf(" \n\n " );
625+ log_msg(string . nfill(78 , ' *' ));
626+ stdout. printf(_(" To restore with default options, press the ENTER key for all prompts!" ) + " \n " );
627+ log_msg(string . nfill(78 , ' *' ));
628+ stdout. printf(_(" \n Press ENTER to continue..." ));
629+ stdout. flush();
630+ stdin. read_line();
631+ }
629632
630633 init_mounts();
631634
@@ -755,6 +758,12 @@ public class AppConsole : GLib.Object {
755758 return null ;
756759 }
757760
761+ if (App . cmd_scripted){
762+ log_error(_(" No snapshots selected. Use --snapshot to specify snapshots" ));
763+ App . exit_app(1 );
764+ return null ;
765+ }
766+
758767 log_msg(" " );
759768 log_msg(_(" Select snapshot" ) + " :\n " );
760769 list_snapshots(true );
@@ -877,6 +886,14 @@ public class AppConsole : GLib.Object {
877886 }
878887 }
879888
889+ if (App . cmd_scripted){
890+ dev = Device . get_device_by_name(default_device);
891+ if (dev == null ){
892+ log_error(_(" Failed to get device by name %s " ). printf(default_device));
893+ App . exit_app(1 );
894+ }
895+ }
896+
880897 // prompt user for device
881898 if (dev == null ){
882899 log_msg(" " );
@@ -987,20 +1004,29 @@ public class AppConsole : GLib.Object {
9871004 else {
9881005 if ((App . cmd_skip_grub == false ) && (App . reinstall_grub2 == false )){
9891006 log_msg(" " );
990-
991- int attempts = 0 ;
992- while ((App . cmd_skip_grub == false ) && (App . reinstall_grub2 == false )){
993- attempts++ ;
994- if (attempts > 3 ) { break ; }
995- stdout. printf(_(" Re-install GRUB2 bootloader?" ) + (grub_reinstall_default ? " (recommended)" : " " ) + " (y/n): " );
996- stdout. flush();
997- read_stdin_grub_install(grub_reinstall_default);
1007+
1008+ if (App . cmd_scripted) {
1009+ App . reinstall_grub2 = grub_reinstall_default;
1010+ }
1011+ else if (App . cmd_confirm){
1012+ // suppose that it would be as user would typed 'y' in read_stdin_grub_install
1013+ App . reinstall_grub2 = true ;
9981014 }
1015+ else {
1016+ int attempts = 0 ;
1017+ while ((App . cmd_skip_grub == false ) && (App . reinstall_grub2 == false )){
1018+ attempts++ ;
1019+ if (attempts > 3 ) { break ; }
1020+ stdout. printf(_(" Re-install GRUB2 bootloader?" ) + (grub_reinstall_default ? " (recommended)" : " " ) + " (y/n): " );
1021+ stdout. flush();
1022+ read_stdin_grub_install(grub_reinstall_default);
1023+ }
9991024
1000- if ((App . cmd_skip_grub == false ) && (App . reinstall_grub2 == false )){
1001- log_error(_(" Failed to get input from user in 3 attempts" ));
1002- log_msg(_(" Aborted." ));
1003- App . exit_app(0 );
1025+ if ((App . cmd_skip_grub == false ) && (App . reinstall_grub2 == false )){
1026+ log_error(_(" Failed to get input from user in 3 attempts" ));
1027+ log_msg(_(" Aborted." ));
1028+ App . exit_app(0 );
1029+ }
10041030 }
10051031 }
10061032 }
@@ -1012,41 +1038,51 @@ public class AppConsole : GLib.Object {
10121038 var device_list = list_grub_devices();
10131039 log_msg(" " );
10141040
1015- int attempts = 0 ;
1016- while (App . grub_device. length == 0 ){
1017-
1018- attempts++ ;
1019- if (attempts > 3 ) { break ; }
1041+ Device dev = null ;
10201042
1021- if (grub_device_default. length > 0 ){
1022- stdout. printf(" " +
1023- _(" [ENTER = Default (%s ), a = Abort]" ). printf(grub_device_default) + " \n\n " );
1043+ if (App . cmd_scripted){
1044+ dev = Device . get_device_by_name(grub_device_default);
1045+ if (dev == null ){
1046+ log_error(_(" Failed to get grub device by name %s " ). printf(grub_device_default));
1047+ App . exit_app(1 );
10241048 }
1049+ }
1050+ else {
1051+ int attempts = 0 ;
1052+ while (App . grub_device. length == 0 ){
1053+ attempts++ ;
1054+ if (attempts > 3 ) { break ; }
10251055
1026- stdout. printf(_(" Enter device name or number (a=Abort)" ) + " : " );
1027- stdout. flush();
1056+ if (grub_device_default. length > 0 ){
1057+ stdout. printf(" " +
1058+ _(" [ENTER = Default (%s ), a = Abort]" ). printf(grub_device_default) + " \n\n " );
1059+ }
10281060
1029- // TODO: provide option for default boot device
1061+ stdout. printf(_(" Enter device name or number (a=Abort)" ) + " : " );
1062+ stdout. flush();
10301063
1031- var list = new Gee .ArrayList<Device > ();
1032- foreach (var pi in App . partitions){
1033- if (pi. has_linux_filesystem()){
1034- list. add(pi);
1064+ var list = new Gee .ArrayList<Device > ();
1065+ foreach (var pi in App . partitions){
1066+ if (pi. has_linux_filesystem()){
1067+ list. add(pi);
1068+ }
10351069 }
1070+
1071+ dev = read_stdin_device(device_list, grub_device_default);
1072+ if (dev != null ) { continue ; }
10361073 }
1037-
1038- Device dev = read_stdin_device(device_list, grub_device_default);
1039- if (dev != null ) { App . grub_device = dev. device; }
1040- }
1041-
1042- log_msg(" " );
10431074
1044- if (App . grub_device. length == 0 ){
1045-
1046- log_error(_(" Failed to get input from user in 3 attempts" ));
1047- log_msg(_(" Aborted." ));
1048- App . exit_app(0 );
1075+ if (dev == null ){
1076+
1077+ log_error(_(" Failed to get input from user in 3 attempts" ));
1078+ log_msg(_(" Aborted." ));
1079+ App . exit_app(0 );
1080+ }
10491081 }
1082+
1083+ if (dev != null ) { App . grub_device = dev. device; }
1084+
1085+ log_msg(" " );
10501086 }
10511087
10521088 if ((App . reinstall_grub2) && (App . grub_device. length > 0 )){
0 commit comments