Last active
August 29, 2015 13:56
-
-
Save raidzero/9316297 to your computer and use it in GitHub Desktop.
Openbox pipe menu: grub2 reboot/hibernate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CHOICE=$1 | |
HIBERNATE=$2 | |
if [ "$CHOICE" == 9999 ]; then | |
STAYOFF="STAYOFF" | |
fi | |
if [ -z "$HIBERNATE" ]; then | |
#su raidzero -c '/home/raidzero/bin/sess.sh save' | |
kill `lsof | grep "/mnt/auto" | awk '{print $2}'` # stop all things using the fileserver | |
/etc/init.d/autofs stop | |
/etc/init.d/net.eth0 stop | |
killall audacious | |
RUNNING=`ps -ef | grep audacious | grep -v grep` | |
if [ -n $RUNNING ]; then | |
killall -9 auadacious | |
fi | |
fi | |
if [ "$CHOICE" == "SHUTDOWN" ]; then | |
/sbin/init 0 | |
exit | |
fi | |
if [ -z "$STAYOFF" ]; then | |
grub2-reboot $CHOICE | |
fi | |
if [ -z "$HIBERNATE" ]; then | |
echo "Rebooting." | |
/sbin/reboot | |
else | |
if [ -z "$STAYOFF" ]; then | |
MSG_STRING="Preparing to reboot, please wait." | |
else | |
MSG_STRING="Preparing to hibernate, please wait." | |
fi | |
env GTK2_RC_FILES=/home/raidzero/.themes/null-theme-green/gtk-2.0/gtkrc Xdialog --clear --title "Hibernating..." --infobox "$MSG_STRING" 6 40 4500 | |
/usr/local/sbin/hibernate $STAYOFF | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#this is dependent on /boot being mounted, otherwise no valid choices will be deteced, since the grub configuration cannt be read | |
#it also requires gksu, for gksudo (a GUI sudo prompt) | |
# grub.cfg needs to be readable also | |
NUMBER=`cat /boot/grub/grub.cfg | sed -n '/^menuentry/p' | sed 's/menuentry//g' | awk '{print $0 " ("NR")"'} | wc -l` | |
for i in `seq $NUMBER`; do | |
list[$i]=`cat /boot/grub/grub.cfg | sed -n '/^menuentry/p' | sed 's/menuentry //g' | awk '{print $0 " (record "NR")"'} | grep "record $i" | sed 's/(record .*)//g;s/ $//g' | cut -d "'" -f2` | |
done | |
HIBERNATE="$1" | |
if [ -z "$HIBERNATE" ]; then | |
TITLE="GRUB2 Reboot" | |
else | |
TITLE="GRUB2 Hibernate" | |
fi | |
cat <<EOFMENU | |
<openbox_pipe_menu> | |
<separator label="$TITLE"/> | |
<item label="$NUMBER choices:"/> | |
<separator/> | |
EOFMENU | |
for i in `seq $NUMBER`; do | |
let CHOICE=$i | |
echo "<item label=\"${list[$i]}\">" | |
echo "<action name=\"Execute\">" | |
echo "<execute>" | |
echo "gksudo ~/bin/grub2-reboot-do.sh $CHOICE $HIBERNATE" | |
echo "</execute>" | |
echo "</action>" | |
echo "</item>" | |
done | |
if [ -n "$HIBERNATE" ]; then | |
echo "<separator/>" | |
echo "<item label=\"Stay Off\">" | |
echo "<action name=\"Execute\">" | |
echo "<execute>" | |
echo "gksudo ~/bin/grub2-reboot-do.sh 9999 $HIBERNATE" | |
echo "</execute>" | |
echo "</action>" | |
echo "</item>" | |
fi | |
echo "</openbox_pipe_menu>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment