[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [PATCH] use dialog (when available) for shutdown/reboot message



Hi all,

Here comes the second update to the patch. I noticed that calling dialog
does not work after eject has already been called because dialog wants
to access some files on the file system. Therefore I added a one second
sleep before calling eject to give dialog a chance. Please see the
attached patch.
I would be glad if someone could comment on the patch.

Greetings

Ronny Standtke

-- 
Ronny Standtke                 Fachhochschule Nordwestschweiz
Dozent Medienpädagogik / ICT   Pädagogische Hochschule
Telefon: +41 32 627 92 47      Obere Sternengasse 7
Mobil  : +41 79 786 81 82      4502 Solothurn
diff --git a/debian/live-initramfs.init b/debian/live-initramfs.init
index 4cf767a..6b2f443 100644
--- a/debian/live-initramfs.init
+++ b/debian/live-initramfs.init
@@ -134,39 +134,68 @@ do_stop ()
 	if [ -z ${QUICKREBOOT} ]
 	then
 		# TODO: i18n
-		BOOT_DEVICE="$(get_boot_device)"
+		# determine current action (do we shutdown or reboot?)
+		# this info is used later for the messages prompted to the user
+		if [ "${RUNLEVEL}" = "0" ]
+		then
+			ACTION="Shutdown"
+			INFINITIVE="shutdown"
+			FUTURE="shut down"
+		elif [ "${RUNLEVEL}" = "6" ]
+		then
+			ACTION="Reboot"
+			INFINITIVE="reboot"
+			FUTURE="rebooted"
+		else
+			log_warning_msg "Unsupported runlevel!"
+		fi
 
+		BOOT_DEVICE="$(get_boot_device)"
 		if device_is_USB_flash_drive ${BOOT_DEVICE}
 		then
 			# do NOT eject USB flash drives!
 			# otherwise rebooting with most USB flash drives
 			# failes because they actually remember the
 			# "ejected" state even after reboot
-			MESSAGE="Please remove the USB flash drive"
+			MESSAGE="You may now savely remove the USB flash drive and"
 		else
 			# ejecting is a very good idea here
-			MESSAGE="Please remove the disc, close the the tray (if any)"
+			MESSAGE="Please remove the disc, close the the tray (if any) and"
 
 			if [ -x /usr/bin/eject ]
 			then
-				eject -p -m /live/image >/dev/null 2>&1
+				# dialog (below) needs a working system, therefore we
+				# wait for a second before calling eject
+				$(sleep 1; eject -p -m /live/image >/dev/null 2>&1)&
 			fi
 
 			[ "$prompt" ] || return 0
 		fi
+		PRESS_ENTER="press ENTER to ${INFINITIVE} the system"
 
 		stty sane < /dev/console
 
-		echo -n -e "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
+		if [ -x /usr/bin/dialog ]
+		then
+			MESSAGE="${MESSAGE} ${PRESS_ENTER}.\n\n(If you do nothing, the system will be automatically ${FUTURE} when the timer runs out.)"
+			dialog --nocancel --backtitle "${ACTION}" --ok-label "${ACTION}" --pause "${MESSAGE}" 15 40 30
+		else
+			echo -n -e "\n\n${MESSAGE}\n${PRESS_ENTER}:" > /dev/console
+			READX="true"
+		fi
 
 		if [ -x /sbin/usplash_write ]
 		then
 			/sbin/usplash_write "TIMEOUT 86400"
 			/sbin/usplash_write "TEXT-URGENT ${MESSAGE}"
 			/sbin/usplash_write "TEXT-URGENT and press ENTER to continue"
+			READX="true"
 		fi
 
-		read x < /dev/console
+		if [ -n "${READX}" ]
+		then
+			read x < /dev/console
+		fi
 	fi
 }
 

Reply to: