108 lines
4.4 KiB
Bash
Executable file
108 lines
4.4 KiB
Bash
Executable file
#!/bin/sh
|
|
# speedwm-shutdwon
|
|
# This simple script uses $RUNLAUNCHER to ask the user what action they want to perform.
|
|
#
|
|
# NOTE: You must either permit nopass for poweroff and reboot commands for your user or simply enable nopass entirely!!
|
|
|
|
case "$RUNLAUNCHER" in
|
|
"") RUNLAUNCHER=dmenu ;;
|
|
esac
|
|
|
|
case "$TERMINAL" in
|
|
"") TERMINAL=st ;;
|
|
esac
|
|
|
|
HAVE_GRID="true"
|
|
if [ -e "$HOME/.config/speedwm-de/global/config" ]; then
|
|
. $HOME/.config/speedwm-de/global/config
|
|
else
|
|
mkdir -p $HOME/.config/speedwm-de/global
|
|
printf "HAVE_GRID=$HAVE_GRID # Whether or not to use the Grid argument. If you do not have the dmenu grid patch, set this to false. Doing so will disable grid." > $HOME/.config/speedwm-de/global/config
|
|
fi
|
|
|
|
if [ "$HAVE_GRID" = "true" ]; then
|
|
GRIDNUM="1"
|
|
fi
|
|
|
|
if [ "$HAVE_GRID" = "true" ]; then
|
|
GRIDARG="-g"
|
|
fi
|
|
|
|
if [ -e "/usr/share/speedwm-bindir" ]; then
|
|
BINDIR=$(cat /usr/share/speedwm-bindir)
|
|
else
|
|
BINDIR="/usr/bin/"
|
|
fi
|
|
|
|
EXPORTDIR=$HOME/.config/speedwm-de/powermenu
|
|
mkdir -p $EXPORTDIR
|
|
|
|
ls ${BINDIR}sudo && PERM=sudo
|
|
ls ${BINDIR}doas && PERM=doas
|
|
ls ${BINDIR}rootdo && PERM=rootdo
|
|
|
|
case "$PERM" in
|
|
"") PERM=su ;;
|
|
esac
|
|
|
|
COL_NORMAL_TEXT_NORMAL="#ffffff"
|
|
COL_NORMAL_TEXT_SELECTED="#ffffff"
|
|
COL_NORMAL_BACKGROUND_NORMAL="#333333"
|
|
COL_NORMAL_BACKGROUND_SELECTED="#222222"
|
|
COL_WARNING_TEXT_NORMAL="#ffffff"
|
|
COL_WARNING_TEXT_SELECTED="#000000"
|
|
COL_WARNING_BACKGROUND_NORMAL="#DC143C"
|
|
COL_WARNING_BACKGROUND_SELECTED="#8b0000"
|
|
LOCK_TEXT=""
|
|
|
|
# Load config if available and override settings
|
|
if [ -e "$EXPORTDIR/config" ]; then
|
|
. $EXPORTDIR/config
|
|
else
|
|
printf "COL_NORMAL_TEXT_NORMAL=$COL_NORMAL_TEXT_NORMAL # Text color for not selected options (Regular prompt)" > $EXPORTDIR/config
|
|
printf "\nCOL_NORMAL_TEXT_SELECTED=$COL_NORMAL_TEXT_SELECTED # Text color for selected option (Regular prompt)" >> $EXPORTDIR/config
|
|
printf "\nCOL_NORMAL_BACKGROUND_NORMAL=$COL_NORMAL_BACKGROUND_NORMAL # Background color for not selected options (Regular prompt)" >> $EXPORTDIR/config
|
|
printf "\nCOL_NORMAL_BACKGROUND_SELECTED=$COL_NORMAL_BACKGROUND_SELECTED # Background color for selected option (Regular prompt)" >> $EXPORTDIR/config
|
|
printf "\nCOL_WARNING_TEXT_NORMAL=$COL_WARNING_TEXT_NORMAL # Text color for not selected options (Warning prompt)" >> $EXPORTDIR/config
|
|
printf "\nCOL_WARNING_TEXT_SELECTED=$COL_WARNING_TEXT_SELECTED # Text color for selected option (Warning prompt)" >> $EXPORTDIR/config
|
|
printf "\nCOL_WARNING_BACKGROUND_NORMAL=$COL_WARNING_BACKGROUND_NORMAL # Background color for not selected options (Warning prompt)" >> $EXPORTDIR/config
|
|
printf "\nCOL_WARNING_BACKGROUND_SELECTED=$COL_WARNING_BACKGROUND_SELECTED # Background color for selected option (Warning prompt)" >> $EXPORTDIR/config
|
|
printf "\nPERM=$PERM # Root access tool (sudo, doas, etc.). Must support nopass for poweroff and reboot commands." >> $EXPORTDIR/config
|
|
printf "\nLOCK_TEXT=$LOCK_TEXT # Text to display on the lock screen" >> $EXPORTDIR/config
|
|
fi
|
|
|
|
case "$LOCK_TEXT" in
|
|
"") MESSAGEFLAG="" ;;
|
|
esac
|
|
|
|
MOREOPTS() {
|
|
USER_OPT3=$(printf "Restart speedwm\nEnd task\nspeedwm command\nUpdate speedwm\n.." | $RUNLAUNCHER -l 4 $GRIDARG $GRIDNUM -p "What do you want to do?" -nb "$COL_NORMAL_BACKGROUND_NORMAL" -sb "$COL_NORMAL_BACKGROUND_SELECTED" -nf "$COL_NORMAL_TEXT_NORMAL" -sf "$COL_NORMAL_TEXT_SELECTED")
|
|
|
|
case "$USER_OPT3" in
|
|
"") exit 0 ;;
|
|
"Restart speedwm") speedwm_run -r && exit 0 ;;
|
|
"End task") ENDTASK=$(printf "\n" | $RUNLAUNCHER -l 1 -p "What task to end?" -nb "$COL_NORMAL_BACKGROUND_NORMAL" -sb "$COL_NORMAL_BACKGROUND_SELECTED" -nf "$COL_NORMAL_TEXT_NORMAL" -sf "$COL_NORMAL_TEXT_SELECTED") && pkill $ENDTASK && exit 0 ;;
|
|
"speedwm command") speedwmutils && exit 0 ;;
|
|
"Update speedwm") $TERMINAL -e speedwm-core -update-speedwm ; exit 0 ;;
|
|
"..") $0 && exit 0 ;;
|
|
esac
|
|
}
|
|
|
|
USER_OPT1=$(printf "Shutdown\nReboot\nExit\nLock\nMore" | $RUNLAUNCHER -l 5 -p "What do you want to do?" -nb "$COL_NORMAL_BACKGROUND_NORMAL" -sb "$COL_NORMAL_BACKGROUND_SELECTED" -nf "$COL_NORMAL_TEXT_NORMAL" -sf "$COL_NORMAL_TEXT_SELECTED")
|
|
|
|
case "$USER_OPT1" in
|
|
"Shutdown") CMD="$PERM poweroff" ;;
|
|
"Reboot") CMD="$PERM reboot" ;;
|
|
"Exit") exit 0 ;;
|
|
"Lock") CMD="slock $MESSAGEFLAG '$LOCK_TEXT'" ;;
|
|
"More") MOREOPTS ;;
|
|
"") exit 0 ;;
|
|
esac
|
|
|
|
USER_OPT2=$(printf "Yes\nNo" | $RUNLAUNCHER -l 2 -p "Are you sure?" -nb "$COL_WARNING_BACKGROUND_NORMAL" -sb "$COL_WARNING_BACKGROUND_SELECTED" -nf "$COL_WARNING_TEXT_NORMAL" -sf "$COL_WARNING_TEXT_SELECTED")
|
|
case "$USER_OPT2" in
|
|
"Yes") $CMD ;;
|
|
"No") exit 0 ;;
|
|
"") exit 0 ;;
|
|
esac
|