3 # altboot provides a simple bootmenu before init is beeing run.
4 # There are two default menu entries: "Normal boot" and "Single user mode"
5 # New menu entries can be created be putting files into /etc/altboot-menu.
8 test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!"
13 # Set some defaults in case altboot.cfg is missing
14 REAL_INIT="/sbin/init.sysvinit"
16 # Read default runlevel from inittab
17 INIT_RUNLEVEL="`cat /etc/inittab | sed -n "/^id\:/s/id\:\([0-9]\)\:.*$/\1/p"`"
18 test -z "$INIT_RUNLEVEL" && INIT_RUNLEVEL=5
21 2.6*) ALTBOOT_CFG_FILE="/etc/altboot-2.6.cfg";;
22 2.4*) ALTBOOT_CFG_FILE="/etc/altboot-2.4.cfg";;
23 *) echo "Warning: Unknown kernel [`uname -r`], using kernel 2.6 configuration!"
24 ALTBOOT_CFG_FILE="/etc/altboot-2.6.cfg";;
27 test -e "$ALTBOOT_CFG_FILE" && . "$ALTBOOT_CFG_FILE" || echo "WARNING: No $ALTBOOT_CFG_FILE found! Check your installation of Altboot!" > /dev/tty1
35 echo "ERROR: $1" >/dev/tty0
36 #exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
38 echo -e "\nPress <ENTER> to launch the altboot menu"
40 exec /sbin/init.altboot -force</dev/tty0 >/dev/tty0 2>&1
44 # This function prints the boot-menu
45 # $1: Directory containing the scripts for the menu-items
47 test -z "$1" && die "DEBUG: Parameter 1 is empty in show_menu"
49 echo -e "altboot v$VERSION\n"
55 # Build "m_entry" for scripts in /etc/altboot-menu
59 if ! test -d "$1/$file"
61 M_TITLE="`$1/$file title`"
62 if ! test -z "$M_TITLE"
65 # Keep a list of existing "modules" together with an index number
66 # This sure is ugly, but Busybox sh doesn't do arrays....
67 m_entry="`echo -e "$m_entry\n$cnt:$file\n"`"
68 echo -e "\t\t[$cnt] $M_TITLE"
74 # Display directories below /etc/altboot-menu as menu-item
75 # and add all scripts inside the directory to m_entry
80 M_TITLE="`basename "$1/$dir"`"
81 if ! test -z "$M_TITLE"
84 # Keep a list of existing "modules" together with an index number
85 # This sure is ugly, but Busybox sh doesn't do arrays....
86 m_entry="`echo -e "$m_entry\n$cnt:$dir:DIR\n"`"
87 echo -e "\t\t[$cnt] $M_TITLE"
93 if ! test -d "$1/$dir/$file"
95 M_TITLE="`$1/$dir/$file title`"
96 if ! test -z "$M_TITLE"
99 # Keep a list of existing "modules" together with an index number
100 # This sure is ugly, but Busybox sh doesn't do arrays....
101 m_entry="`echo -e "$m_entry\n$cnt:$dir/$file\n"`"
102 #echo -e "\t\t[$cnt] $M_TITLE"
117 echo "WARNING: $1 not found"
122 # This function is used to display the content of directories below
123 # /etc/altboot-menu as menu-items
125 dirname="`basename "$1"`"
127 d_entries="`echo "$m_entry"|grep "$dirname/"`"
129 # echo "[$d_entries]"
131 echo -e "\naltboot v$VERSION: $dirname menu\n"
134 for d_entry in $d_entries
136 d_entry_number="`echo "$d_entry"| sed -n "s/\(.*\)\:\(.*\)/\1/p"`"
137 d_entry_file="`echo "$d_entry"| sed -n "s/\(.*\)\:\(.*\)/\2/p"`"
138 d_entry_title="`$d_entry_file title`"
140 # echo "number: [$d_entry_number]"
141 # echo "file: [$d_entry_file]"
142 # echo "title: [$d_entry_title]"
144 echo -e "\t\t[$d_entry_number] $d_entry_title"
151 # Shows the timer and sets $launch_altboot to yes if a keypress was detected
153 if test "$TIMEOUT" != 0
156 mount -t proc proc /proc >/dev/null 2>&1
159 2.4*) key_ints="`cat /proc/interrupts | grep keyboard | awk '{print $2}'`";;
160 2.6*) key_ints="`cat /proc/interrupts | grep Spitzkbd`";;
164 echo -en "\n\nPlease press any key to launch altboot." > /dev/tty1
166 test -z "$TIMEOUT" && TIMEOUT="3"
169 while test "$cnt" != "$TIMEOUT"
173 2.4*) key_ints_now="`cat /proc/interrupts | grep keyboard | awk '{print $2}'`";;
174 2.6*) key_ints_now="`cat /proc/interrupts | grep Spitzkbd`";;
177 if test "$key_ints_now" != "$key_ints"
183 echo -n "." >/dev/tty1
191 # This function launches the selected menu item / script
192 # $1: Directory containing the scripts for the menu-items
194 test -z "$1" && die "Parameter 1 of launch_selection is empty!"
197 *) file="`echo "$m_entry"| sed -n "/$junk\:/s/^.*\:\(.*\)/\1/p"`"
199 # The selected menu-item points to a directory
200 if test "$file" = DIR
202 dir="`echo "$m_entry"| sed -n "/$junk\:/s/^.*\:\(.*\)\:\(.*\)/\1/p"`"
203 show_sub_menu /etc/altboot-menu/$dir >/dev/tty0
204 wait_for_input >/dev/tty0
205 launch_selection /etc/altboot-menu >/dev/tty0
208 if test "$file" = MAIN
210 show_sub_menu /etc/altboot-menu >/dev/tty0
211 wait_for_input >/dev/tty0
212 launch_selection /etc/altboot-menu >/dev/tty0
217 . $1/$file run "$file" >/dev/tty0
218 die "WARNING: Using failsafe shell" >/dev/tty0
230 # Do _not_ change the next few lines!
232 # This is required to work around an annoying busybox bug.
233 # Every key you press while this script runs will be
234 # picked up by the next "read $junk".
235 # So the next read would pick up the "any" key the user pressed
236 # above to launch the altboot menu.
239 # This filters an "<ENTER>" from the user as "any key"
240 ( while :; do read x< /dev/tty0 2>&1; done; ) > /dev/null 2>&1 &
245 echo -n "Please choose one of the above [$last_selection]: " </dev/tty0 > /dev/tty0 2>&1
246 read junk< /dev/tty0 2>&1
248 # This filters other chars the user may have used
249 junk="`echo "$junk" | sed -n "s/.*\([0-9]\)/\1/p"`"
251 if test "$junk" -lt "$cnt" -o "$junk" -eq "$cnt"
255 # Don't remount rw if the drive is already mounted rw
256 # Only helpful for testing / debugging
257 if test "`mount|sed -n "/\/dev\/root/s/.*(\(.*\))/\1/p"`" != "rw"
259 mount -o remount,rw / >/dev/null 2>&1
260 echo "$junk" > /etc/altboot.conf
261 mount -o remount,ro / >/dev/null 2>&1
263 echo "$junk" > /etc/altboot.conf
266 junk="$last_selection"
274 # * * * * * * This is the main function * * * * * *
276 if test "`runlevel`" != "unknown" -a "$1" != "-force"
278 echo "altboot: Using real init [$REAL_INIT] [$*] *" >/dev/tty1
280 # exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
283 # Boot original init if altboot is turned off
284 if test "$ENABLE_ALTBOOT" != "yes"
286 echo "altboot: Using real init [$REAL_INIT] **" >/dev/tty1
287 exec $REAL_INIT $INIT_RUNLEVEL
291 # Execute scripts in /etc/altboot.rc before doing anything else.
292 # Required in special situations, like booting spitz
293 RC_FILES=`ls /etc/altboot.rc | grep \.sh$`
295 for file in $RC_FILES
297 . /etc/altboot.rc/$file >/dev/tty1 2>&1 || echo "/etc/altboot.rc/$file failed!"
300 # Make sure altboots master password is set
301 set_password >/dev/tty0
303 test "$ASK_PW_ON_BOOT" = "yes" && verify_master_pw >/dev/tty0
306 # When started with -force, always print the menu
307 echo "$*" | grep -q -- "-force" && TIMEOUT=0
310 # This timeout works by reading /proc/interrupts to see if the keyboard interrupt
311 # increases while the timer is running. A TIMEOUT of 0 will always launch altboot.
312 run_timer >/dev/tty1 2>&1
318 if test "$launch_altboot" != yes
320 # last_selection is the previously selected menu item by the user
321 last_selection="`cat /etc/altboot.conf`" >/dev/null 2>&1
322 test -z "$last_selection" && last_selection="1"
324 echo "Booting last selection: [$last_selection]" >/dev/tty0
326 # Set up the wanna-be array of available menu entries and their numbers
327 show_menu /etc/altboot-menu >/dev/null
328 junk="$last_selection"
329 launch_selection /etc/altboot-menu >/dev/tty0
332 # Anything after this point will never be reached if $launch_altboot != yes
334 # Show the altboot menu
335 show_menu /etc/altboot-menu >/dev/tty0
337 # Load last selection for use as default if <ENTER> is pressed at the prompt
338 last_selection="`cat /etc/altboot.conf`" >/dev/null 2>&1
339 test -z "$last_selection" && last_selection="1"
341 # Ask the user which menu-item to use
342 wait_for_input >/dev/tty0
344 # This should _never_ happen.
347 echo "WARNING: Trying failsafe mode" >/dev/tty0
348 mount -o remount,rw / >/dev/tty0 2>&1
349 echo "Dumping environment to /altboot.env"
350 echo "$CURRENT_ENV" > /altboot.env
351 mount -o remount,ro / >/dev/tty0 2>&1
355 launch_selection /etc/altboot-menu >/dev/tty0
357 # Uhoh, something went terribly wrong if we reach this point!
358 die "WARNING: Failsafe fall-through activated. Spawning emergency shell"