recovery-menu 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. if [ ! -x "$(which whiptail)" ]; then
  3. echo "Couldn't find whiptail, starting root shell instead of recovery menu."
  4. sulogin
  5. clear
  6. exit
  7. fi
  8. systemd-notify --ready || :
  9. # include gettext stuff
  10. . /lib/recovery-mode/l10n.sh
  11. # main
  12. READONLY=true
  13. while true; do
  14. unset items
  15. if [ "$READONLY" = "true" ]; then
  16. menu_text=$(eval_gettext "Recovery Menu (filesystem state: read-only)")
  17. else
  18. menu_text=$(eval_gettext "Recovery Menu (filesystem state: read/write)")
  19. fi
  20. items[c++]="resume"
  21. items[c++]=$(eval_gettext " Resume normal boot")
  22. for i in /lib/recovery-mode/options/*; do
  23. if [ -x "$i" ]; then
  24. name="`"$i" test`"
  25. if [ $? -eq 0 ]; then
  26. items[c++]="${i##*/}"
  27. items[c++]=" $name"
  28. fi
  29. fi
  30. done
  31. choice="$(whiptail --nocancel --menu "$menu_text" 18 70 10 \
  32. "${items[@]}" \
  33. 3>&1 1>&2 2>&3 3>&-)"
  34. if [ -z "$choice" ]; then
  35. continue
  36. fi
  37. if [ "$choice" = "resume" ]; then
  38. box_text=$(eval_gettext "You are now going to exit the recovery mode and continue the boot sequence. Please note that some graphic drivers require a full graphical boot and so will fail when resuming from recovery.
  39. If that's the case, simply reboot from the login screen and then perform a standard boot.")
  40. whiptail --msgbox "$box_text" 12 70
  41. clear
  42. touch /run/friendly_recovery.resume
  43. systemctl daemon-reload
  44. systemctl --no-block isolate default.target
  45. exit
  46. fi
  47. /lib/recovery-mode/options/$choice test mode >/dev/null 2>&1
  48. retval=$?
  49. # Hack for the fsck case (needs to be cosidered read/write only when
  50. # in read-only mode and read-only only when in read/write mode)
  51. if [ "$choice" = "fsck" ] && [ "$READONLY" = "false" ]; then
  52. retval=1
  53. fi
  54. case "$retval" in
  55. 0)
  56. # 0 => requires read/write
  57. if [ "$READONLY" = "true" ]; then
  58. box_text=$(eval_gettext "Continuing will remount your / filesystem in read/write mode and mount any other filesystem defined in /etc/fstab.
  59. Do you wish to continue?")
  60. whiptail --yesno "$box_text" 10 70 || continue
  61. if [ "$choice" = "fsck" ]; then
  62. FSCHECK="true"
  63. fi
  64. . /etc/default/rcS
  65. if [ -d /run/systemd/system ]; then
  66. [ "$FSCKFIX" = "yes" ] && fsck_mode="-y" || fsck_mode='-a'
  67. [ "$FSCHECK" = "true" ] || [ -f /forcefsck ] && fsck $fsck_mode
  68. systemctl start --job-mode=ignore-dependencies systemd-remount-fs.service
  69. mount -a
  70. else
  71. [ "$FSCHECK" = "true" ] || [ -f /forcefsck ] && force_fsck="--force-fsck"
  72. [ "$FSCKFIX" = "yes" ] && fsck_fix="--fsck-fix"
  73. mountall $force_fsck $fsck_fix --no-events
  74. fi
  75. rm -f /forcefsck
  76. if [ "$choice" = "fsck" ]; then
  77. echo ""
  78. echo $(eval_gettext "Finished, please press ENTER")
  79. read TMP
  80. fi
  81. READONLY=false
  82. fi
  83. ;;
  84. 1)
  85. # 1 => read-only only
  86. if [ "$READONLY" = "false" ]; then
  87. box_text=$(eval_gettext "The option you selected requires your filesystem to be in read-only mode. Unfortunately another option you selected earlier, made you exit this mode.
  88. The easiest way of getting back in read-only mode is to reboot your system.")
  89. whiptail --msgbox "$box_text" 12 70
  90. continue
  91. fi
  92. ;;
  93. 2)
  94. # 2 => works in all cases
  95. # nothing to do
  96. ;;
  97. esac
  98. export READONLY
  99. /lib/recovery-mode/options/$choice
  100. done