| 1 | # Choose a Terminal (serial vs. graphical consle) from GRUB |
|---|
| 2 | |
|---|
| 3 | # Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net> |
|---|
| 4 | # Date: 2009-09-29 12:44:06-0400 |
|---|
| 5 | |
|---|
| 6 | # this is a grub config file that offers 5 alternating 1-second |
|---|
| 7 | # chances to hit ESC in either the serial console or the |
|---|
| 8 | # graphical console to select which console to use for grub. |
|---|
| 9 | |
|---|
| 10 | # it is ridiculously long right now because grub |
|---|
| 11 | # currently (2009-09-29) does not support any looping constructs, |
|---|
| 12 | # so i've pasted them all together within the ABSURD LOOP |
|---|
| 13 | # comments. |
|---|
| 14 | |
|---|
| 15 | # if looping constructs were possible, the ideal would be to have |
|---|
| 16 | # this cycle through all possible terminal_input and |
|---|
| 17 | # terminal_output choices (what if they don't match?) |
|---|
| 18 | |
|---|
| 19 | # You can load this file with a line in /boot/grub/grub.cfg like: |
|---|
| 20 | |
|---|
| 21 | # configfile /boot/grub/grub2-terminal-chooser |
|---|
| 22 | |
|---|
| 23 | insmod echo |
|---|
| 24 | insmod sleep |
|---|
| 25 | insmod test |
|---|
| 26 | insmod serial |
|---|
| 27 | serial --unit=0 --speed=115200 |
|---|
| 28 | |
|---|
| 29 | echo "checking for alternate inputs" |
|---|
| 30 | |
|---|
| 31 | ## BEGIN ABSURD LOOP |
|---|
| 32 | |
|---|
| 33 | if test $chosen_console == "" ; then |
|---|
| 34 | if terminal_input serial ; then true ; else |
|---|
| 35 | terminal serial |
|---|
| 36 | fi |
|---|
| 37 | if terminal_output serial ; then true ; else |
|---|
| 38 | terminal serial |
|---|
| 39 | fi |
|---|
| 40 | echo "hit ESC to use serial..." |
|---|
| 41 | if sleep --interruptible 1 ; then true; else |
|---|
| 42 | chosen_console=serial |
|---|
| 43 | fi |
|---|
| 44 | fi |
|---|
| 45 | |
|---|
| 46 | if test $chosen_console == "" ; then |
|---|
| 47 | if terminal_input console ; then true ; else |
|---|
| 48 | terminal console |
|---|
| 49 | fi |
|---|
| 50 | if terminal_output console ; then true ; else |
|---|
| 51 | terminal console |
|---|
| 52 | fi |
|---|
| 53 | echo "hit ESC to use graphical console..." |
|---|
| 54 | if sleep --interruptible 1 ; then true; else |
|---|
| 55 | chosen_console=console |
|---|
| 56 | fi |
|---|
| 57 | fi |
|---|
| 58 | |
|---|
| 59 | if test $chosen_console == "" ; then |
|---|
| 60 | if terminal_input serial ; then true ; else |
|---|
| 61 | terminal serial |
|---|
| 62 | fi |
|---|
| 63 | if terminal_output serial ; then true ; else |
|---|
| 64 | terminal serial |
|---|
| 65 | fi |
|---|
| 66 | echo "hit ESC to use serial..." |
|---|
| 67 | if sleep --interruptible 1 ; then true; else |
|---|
| 68 | chosen_console=serial |
|---|
| 69 | fi |
|---|
| 70 | fi |
|---|
| 71 | |
|---|
| 72 | if test $chosen_console == "" ; then |
|---|
| 73 | if terminal_input console ; then true ; else |
|---|
| 74 | terminal console |
|---|
| 75 | fi |
|---|
| 76 | if terminal_output console ; then true ; else |
|---|
| 77 | terminal console |
|---|
| 78 | fi |
|---|
| 79 | echo "hit ESC to use graphical console..." |
|---|
| 80 | if sleep --interruptible 1 ; then true; else |
|---|
| 81 | chosen_console=console |
|---|
| 82 | fi |
|---|
| 83 | fi |
|---|
| 84 | |
|---|
| 85 | if test $chosen_console == "" ; then |
|---|
| 86 | if terminal_input serial ; then true ; else |
|---|
| 87 | terminal serial |
|---|
| 88 | fi |
|---|
| 89 | if terminal_output serial ; then true ; else |
|---|
| 90 | terminal serial |
|---|
| 91 | fi |
|---|
| 92 | echo "hit ESC to use serial..." |
|---|
| 93 | if sleep --interruptible 1 ; then true; else |
|---|
| 94 | chosen_console=serial |
|---|
| 95 | fi |
|---|
| 96 | fi |
|---|
| 97 | |
|---|
| 98 | if test $chosen_console == "" ; then |
|---|
| 99 | if terminal_input console ; then true ; else |
|---|
| 100 | terminal console |
|---|
| 101 | fi |
|---|
| 102 | if terminal_output console ; then true ; else |
|---|
| 103 | terminal console |
|---|
| 104 | fi |
|---|
| 105 | echo "hit ESC to use graphical console..." |
|---|
| 106 | if sleep --interruptible 1 ; then true; else |
|---|
| 107 | chosen_console=console |
|---|
| 108 | fi |
|---|
| 109 | fi |
|---|
| 110 | |
|---|
| 111 | if test $chosen_console == "" ; then |
|---|
| 112 | if terminal_input serial ; then true ; else |
|---|
| 113 | terminal serial |
|---|
| 114 | fi |
|---|
| 115 | if terminal_output serial ; then true ; else |
|---|
| 116 | terminal serial |
|---|
| 117 | fi |
|---|
| 118 | echo "hit ESC to use serial..." |
|---|
| 119 | if sleep --interruptible 1 ; then true; else |
|---|
| 120 | chosen_console=serial |
|---|
| 121 | fi |
|---|
| 122 | fi |
|---|
| 123 | |
|---|
| 124 | if test $chosen_console == "" ; then |
|---|
| 125 | if terminal_input console ; then true ; else |
|---|
| 126 | terminal console |
|---|
| 127 | fi |
|---|
| 128 | if terminal_output console ; then true ; else |
|---|
| 129 | terminal console |
|---|
| 130 | fi |
|---|
| 131 | echo "hit ESC to use graphical console..." |
|---|
| 132 | if sleep --interruptible 1 ; then true; else |
|---|
| 133 | chosen_console=console |
|---|
| 134 | fi |
|---|
| 135 | fi |
|---|
| 136 | |
|---|
| 137 | if test $chosen_console == "" ; then |
|---|
| 138 | if terminal_input serial ; then true ; else |
|---|
| 139 | terminal serial |
|---|
| 140 | fi |
|---|
| 141 | if terminal_output serial ; then true ; else |
|---|
| 142 | terminal serial |
|---|
| 143 | fi |
|---|
| 144 | echo "hit ESC to use serial..." |
|---|
| 145 | if sleep --interruptible 1 ; then true; else |
|---|
| 146 | chosen_console=serial |
|---|
| 147 | fi |
|---|
| 148 | fi |
|---|
| 149 | |
|---|
| 150 | ## END ABSURD LOOP |
|---|
| 151 | |
|---|
| 152 | # else we default to using the graphical console: |
|---|
| 153 | |
|---|
| 154 | echo "using graphical console" |
|---|
| 155 | |
|---|
| 156 | if terminal_input console ; then true ; else |
|---|
| 157 | terminal console |
|---|
| 158 | fi |
|---|
| 159 | if terminal_output console ; then true ; else |
|---|
| 160 | terminal console |
|---|
| 161 | fi |
|---|
| 162 | |
|---|
| 163 | echo "using graphical console" |
|---|