Skip to content

Instantly share code, notes, and snippets.

@teancum
Last active April 17, 2019 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teancum/0ce4bb57f014a60475979b3f1c875acc to your computer and use it in GitHub Desktop.
Save teancum/0ce4bb57f014a60475979b3f1c875acc to your computer and use it in GitHub Desktop.
Series of scripts to emulate Suspend/Hibernate on 12" Macbook Retina which at this writing Linux (5.1 and below) does does not support bonifide Suspend/Hibernate
##/etc/sudoers.d/20-mysudos
## for scripting tweaks
ALL ALL=NOPASSWD: /usr/bin/systemd-run
ALL ALL=NOPASSWD: /usr/bin/systemctl
ALL ALL=NOPASSWD: /usr/bin/kill
ALL ALL=NOPASSWD: /usr/bin/kdialog
ALL ALL=NOPASSWD: /usr/bin/su
#ALL ALL=NOPASSWD: /usr/bin/timeshift-gtk
ALL ALL=NOPASSWD: /home/bubba/scripts/fauxhib/init-SD.sh
ALL ALL=NOPASSWD: /home/bubba/scripts/fauxhib/Xsetup.sh
#ALL ALL=NOPASSWD: /usr/sbin/REBOOT.sh
#ALL ALL=NOPASSWD: /usr/sbin/SHUTDOWN.sh
ALL ALL=NOPASSWD: /home/bubba/scripts/fauxhib/save-VMs.sh
ALL ALL=NOPASSWD: /home/bubba/scripts/fauxhib/save-session.sh
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/controlled-RB.sh
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: CRBOOT: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: CRBOOT: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: CRBOOT: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: CRBOOT: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "controlled-RB Timer Tripped"
sleep 1
/usr/bin/sync
logT $(sudo /usr/bin/systemctl reboot 2>&1)
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/controlled-SD.sh
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: CSHUTDN: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: CSHUTDN: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: CSHUTDN: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: CSHUTDN: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "'controlled-SD Timer' Tripped"
sleep 1
/usr/bin/sync
logT $(sudo /usr/bin/systemctl poweroff 2>&1)
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/controlled-SP.sh
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: CSUSPND: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: CSUSPND: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: CSUSPND: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: CSUSPND: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "controlled-SP Timer Tripped"
sleep 1
/usr/bin/sync
logT $(sudo /usr/bin/systemctl poweroff 2>&1)
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/forced-RB.sh
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: FRBOOT: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: FRBOOT: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: FRBOOT: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: FRBOOT: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "forced-RB Timer Tripped"
sleep 1
/usr/bin/sync
logT $(sudo /usr/bin/systemctl --force --force reboot 2>&1)
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/forced-SD.sh
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: FSHUTDN: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: FSHUTDN: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: FSHUTDN: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: FSHUTDN: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "force-SD Timer Tripped"
sleep 1
/usr/bin/sync
logT $(sudo /usr/bin/systemctl --force --force poweroff 2>&1)
#!/bin/bash
##
## /etc/acpi/handler.sh
## Default acpi script that takes an entry for all actions
## Modified To --> Utilize "Custom Logger" function
## --> Logs undefined codes
## --> Handles timed faux(suspend/hibernate) function on LID close
## --> Handles backlight issues on lid close/open
##
## Uncomment next line to DISABLE all functions of this script
#exit
## May or may not be needed to display kdialog statuses
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
#-------------------------------------------------------------------
# Set Static Variables
#
TRUE=1
FALSE=0
RETVAL=""
#LidDelayTime=10
LidDelayTime=180
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: ACPI: $logID$ln"
done
else
echo "$@"
logger "PM: ACPI: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: ACPI: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: ACPI: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
#log '--> "$1" "$2" "$3"'
#log "--> "$@
#logT $1","$2","$3","$4","$5","
#logT "CUSTSD: PowerButton pressed"
#exit
case "$1" in
button/power)
case "$2" in
PBTN|PWRF)
case "$4" in
00000000)
logT "CUSTSD: PowerButton pressed"
;;
*)
logT "ACPI action undefined 01: $1 $2 $3 $4 $5"
;;
esac
;;
*)
logT "ACPI action undefined 02: $1 $2 $3 $4 $5"
;;
esac
;;
button/sleep)
case "$2" in
SLPB|SBTN)
logT "SleepButton pressed"
;;
*)
logT "ACPI action undefined 03: $2"
;;
esac
;;
ac_adapter)
case "$2" in
AC|ACAD|ADP0|ACPI0003:00)
case "$4" in
00000000)
logT "AC un-plugged"
if [[ $(cat /proc/acpi/button/lid/LID0/state | grep -c "closed") -eq TRUE ]]; then
logT "LID currently closed"
logT "CUSTSD: LIDSP: Initiated $LidDelayTime second LID-SP Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=1 --on-active=$LidDelayTime --unit=LID-SP /usr/bin/bash -c '/home/bubba/scripts/fauxhib/LID-SP.sh' 2>&1)
else
logT "LID currently open"
fi
;;
00000001)
logT "AC plugged in"
if [[ $(sudo systemctl status LID-SP.timer | grep -c "Active: active") -eq TRUE ]]; then
logT $(sudo systemctl stop LID-SP.timer 2>&1)
logT $(sudo systemctl status LID-SP.timer 2>&1)
logT "CUSTSD: LIDSP: Cancelled $LidDelayTime second LID-SP Timer"
fi
;;
esac
;;
*)
logT "ACPI action undefined 04: $2"
;;
esac
;;
battery)
case "$2" in
BAT0)
case "$4" in
00000000)
logT "Battery online"
;;
00000001)
logT "Battery offline"
;;
esac
;;
CPU0)
;;
*) logT "ACPI action undefined 05: $2" ;;
esac
;;
button/lid)
case "$3" in
close)
logT "Lid closed"
if [[ $(acpi -a | grep -c "off-line") -eq TRUE ]]; then
if [[ $(sudo systemctl status LID-SP.timer 2>&1 | grep -c "could not be found") -eq TRUE ]]; then
##LID Closed (Faux)Suspend Delay $LidDelayTime seconds timer started"
logT "CUSTSD: LIDSP: Initiated $LidDelayTime second LID-SP Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=1 --on-active=$LidDelayTime --unit=LID-SP /usr/bin/bash -c '/home/bubba/scripts/fauxhib/LID-SP.sh' 2>&1)
fi
else
logT "AC currently plugged in"
fi
logT "Saved keyboard backlight setting and turned off screen"
logT $(cat /sys/class/spi_master/spi2/spi-APP000D:00/leds/spi::kbd_backlight/brightness > /home/bubba/scripts/fauxhib/kbd_backlight-setting 2>&1)
logT $(echo 0 > /sys/class/spi_master/spi2/spi-APP000D:00/leds/spi::kbd_backlight/brightness 2>&1)
## Turn screen off on LID close irrespective of choices in "Energy Saving" applet
logT $(su bubba -c 'xset dpms force off' 2>&1)
;;
open)
logT "Lid opened"
if [[ $(sudo systemctl status LID-SP.timer | grep -c "Active: active") -eq TRUE ]]; then
logT $(sudo systemctl stop LID-SP.timer 2>&1)
logT $(sudo systemctl status LID-SP.timer 2>&1)
logT "CUSTSD: LIDSP: Cancelled $LidDelayTime second LID-SP Timer"
fi
logT "Restored keyboard backlight setting"
logT $(cat /home/bubba/scripts/fauxhib/kbd_backlight-setting > /sys/class/spi_master/spi2/spi-APP000D:00/leds/spi::kbd_backlight/brightness 2>&1)
;;
*)
logT "ACPI action undefined 06: $3"
;;
esac
esac
;;
*)
log "ACPI action undefined 07: "$1","$2","$3","$4","$5","
#log "ACPI group/action undefined: $1 / $2"
;;
esac
# vim:set ts=4 sw=4 ft=sh et:
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/LID-SP.sh
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: LIDSP: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: LIDSP: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: LIDSP: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: LIDSP: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "LID-SP Timer Tripped"
/usr/bin/systemctl suspend
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/REBOOT.sh
# Put a link named "reboot" in "/usr/bin" pointing to this script - rename existing "/usr/bin/reboot" executable to something else
#
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: RBOOTSH: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: RBOOTSH: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: RBOOTSH: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: RBOOTSH: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "In 'REBOOT.sh'"
#-----------------------------------------------------------------------------------------
## *** This section can be used to special handle anything that would otherwise be trashed
## *** because we're doing a SHUTDOWN and not an actual SUSPEND or HIBERNATE
##
## Handle any open Virtual Machines
logT 'Calling "save-VMs.sh"'
#su -p bubba -c '/home/bubba/scripts/fauxhib/save-VMs.sh &> /home/bubba/scripts/fauxhib/SAVVMS.err'
sudo /home/bubba/scripts/fauxhib/save-VMs.sh &> /home/bubba/scripts/fauxhib/SAVVMS.err
#-----------------------------------------------------------------------------------------
## Doing session logout, utilizing KDE 'Desktop Session' applet 'Restore previuos session' feature
logT "Saving current KDE Session"
logT $(qdbus org.kde.ksmserver /KSMServer logout 0 0 0 2>&1)
logT "KDE Session saved"
## Set 10sec faisafe poweroff in case "controlled shutdown" in next command does not work
logT "Started 10s 'forced-RB' Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=100ms --on-active=10 --unit=forced-RB /usr/bin/bash -c '/home/bubba/scripts/fauxhib/forced-RB.sh' 2>&1)
## Set 3sec controlled reboot timer
logT "Initiating 3s 'controlled-RB' Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=100ms --on-active=3 --unit=controlled-RB /usr/bin/bash -c '/home/bubba/scripts/fauxhib/controlled-RB.sh' 2>&1)
logT "Leaving 'REBOOT.sh'"
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/save-VMs.sh
export DISPLAY=:0.0
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SAVVMS: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: SAVVMS: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
}
function logT {
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SAVVMS: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: SAVVMS: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
}
#-------------------------------------------------------------------
#logT "In 'save-VMs.sh'"
runningVMs="/home/bubba/scripts/fauxhib/VMsLastRunning"
#echo $runningVMs
## delete runningVMs file if it exists
if [ -e $runningVMs ];then
rm -f $runningVMs
fi
## determine and write to file all "names" of running VMs
#VBoxManage list runningvms | sed 's/^"\(.*\)".*/\1/' > $runningVMs # <--- works, will not save the quotes
sudo -u bubba VBoxManage list runningvms | grep -o '".*"' | sed 's/"//g' > $runningVMs # <--- last pipe strips quotes
if [ $(wc $runningVMs | grep -c "0 0 0") = $TRUE ];then
logT "No virtual machines running!"
#sudo kdialog --title "No virtual machines running." --passivepopup "...continuing shutdown..." 10
su bubba -c 'kdialog --title "No virtual machines running." --passivepopup "...continuing shutdown" 6'
#logT "Leaving 'save-VMs.sh'"
exit
else
logT "Logged a list of currently running Virtual Machines."
#sudo kdialog --title "Logged a list of currently running Virtual Machines." --passivepopup "...continuing shutdown..." 10
su bubba -c 'kdialog --title "Logged a list of currently running Virtual Machines." --passivepopup "...continuing shutdown" 6'
fi
## send "savestate close" command to each running VM
for VM in `cat $runningVMs`
do
logT "Issued 'Savestate Close' command to Virtual Machine '$VM'."
#sudo kdialog --title "Issued 'Savestate Close' command to Virtual Machine '$VM'." --passivepopup "...continuing shutdown..." 10
su bubba -c 'kdialog --title "Issued 'Savestate Close' command to Virtual Machine '$VM'." --passivepopup "...continuing shutdown" 6'
sudo -u bubba VBoxManage controlvm $VM savestate
sleep 1
done
## Check each formerly running VM and loop until all are in saved state
for VM in `cat $runningVMs`
do
until [ $(sudo -u bubba VBoxManage showvminfo --machinereadable $VM | grep -c ^VMState=.saved.) = $TRUE ]
do
sleep 1
logT "Looping VM Until."
done
logT "Successfully saved state & closed Virtual Machine '$VM'."
#sudo kdialog --title "Issued 'Successfully saved state & closed Virtual Machine '$VM'." --passivepopup "...continuing shutdown..." 10
su bubba -c 'kdialog --title "Issued Successfully saved state & closed Virtual Machine '$VM'." --passivepopup "...continuing shutdown" 6'
done
#logT "Leaving 'save-VMs.sh'"
exit
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/sddm-TO.sh
#
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SDDMTO: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: SDDMTO: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SDDMTO: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: SDDMTO: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "'SDDM Timeout Tripped"
sleep 1
/usr/bin/sync
sleep 1
logT $(sudo /usr/bin/systemctl poweroff 2>&1)
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/SHUTDOWN.sh
# Put a link named "shutdown" in "/usr/bin" pointing to this script - rename existing "/usr/bin/shutdown" executable to something else
#
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SHTDNSH: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: SHTDNSH: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SHTDNSH: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: SHTDNSH: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "In 'SHUTDOWN.sh'"
#-----------------------------------------------------------------------------------------
## *** This section can be used to special handle anything that would otherwise be trashed
## *** because we're doing a SHUTDOWN and not an actual SUSPEND or HIBERNATE
##
## Handle any open Virtual Machines
logT 'Calling "save-VMs.sh"'
#su -p bubba -c '/home/bubba/scripts/fauxhib/save-VMs.sh &> /home/bubba/scripts/fauxhib/SAVVMS.err'
sudo /home/bubba/scripts/fauxhib/save-VMs.sh &> /home/bubba/scripts/fauxhib/SAVVMS.err
#-----------------------------------------------------------------------------------------
## Doing session logout, utilizing KDE 'Desktop Session' applet 'Restore previuos session' feature
logT "Saving current KDE Session"
logT $(qdbus org.kde.ksmserver /KSMServer logout 0 0 0 2>&1)
logT "KDE Session saved"
## Set 10sec failsafe poweroff in case "controlled shutdown" in next command does not work
logT "Started 10s 'forced-SD' Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=100ms --on-active=10 --unit=forced-SD /usr/bin/bash -c '/home/bubba/scripts/fauxhib/forced-SD.sh' 2>&1)
## Set 3sec controlled shutdown timer
logT "Initiating 3s 'controlled-SD' Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=100ms --on-active=3 --unit=controlled-SD /usr/bin/bash -c '/home/bubba/scripts/fauxhib/controlled-SD.sh' 2>&1)
logT "Leaving 'SHUTDOWN.sh'"
#!/bin/bash
#
# /home/bubba/scripts/fauxhib/SUSPEND.sh
#
#export DISPLAY=:0.0
#export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SUSPSH: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: SUSPSH: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SUSPSH: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: SUSPSH: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "In 'SUSPEND.sh'"
#-----------------------------------------------------------------------------------------
## *** This section can be used to special handle anything that would otherwise be trashed
## *** because we're doing a SHUTDOWN and not an actual SUSPEND or HIBERNATE
##
## Handle any open Virtual Machines
logT 'Calling "save-VMs.sh"'
#su -p bubba -c '/home/bubba/scripts/fauxhib/save-VMs.sh &> /home/bubba/scripts/fauxhib/SAVVMS.err'
sudo /home/bubba/scripts/fauxhib/save-VMs.sh &> /home/bubba/scripts/fauxhib/SAVVMS.err
#-----------------------------------------------------------------------------------------
## Doing session logout, utilizing KDE 'Desktop Session' applet 'Restore previuos session' feature
logT "Saving current KDE Session"
logT $(qdbus org.kde.ksmserver /KSMServer logout 0 0 0 2>&1)
logT "KDE Session saved"
## Set 15sec faisafe poweroff in case "controlled shutdown" in next command does not work
logT "Started 15s 'forced-SD' Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=100ms --on-active=15 --unit=forced-SD /usr/bin/bash -c '/home/bubba/scripts/fauxhib/forced-SD.sh' 2>&1)
## Set 10sec controlled Faux-Suspend timer
## Longer times necessary than in "SHUTDOWN.sh"" or "REBOOT.sh"" to accomodate "systemd-suspend.service" functionality
logT "Initiating 10s 'controlled-SP' (Faux-Suspend) Timer"
logT $(sudo systemd-run --timer-property=AccuracySec=100ms --on-active=10 --unit=controlled-SP /usr/bin/bash -c '/home/bubba/scripts/fauxhib/controlled-SP.sh' 2>&1)
logT "Leaving 'SUSPEND.sh'"
##
## systemd-suspend.service
##
## Modified to accomodate MBR12 "FAUX Hibernate/Suspend" requirements (CUSTSD:)
## ie NVME SSD restart problems
## performed service & scripting tweaks utilize KDE "session save" features
## copies of all customized files kept in /home/bubba/scripts/fauxhib and subs
## all scripts run from /home/bubba/scripts/fauxhib with exceptions of....
## ..../usr/share/sddm/scripts/Xsetup
## /etc/sudoers.d/20-mysudos
## /etc/acpi/handler.sh <--- possibly, (<-- depending on special features desired)
##
## and this file...
## /etc/systemd/system/systemd-suspend.service
##
##
[Unit]
Description=Faux Suspend/Hibernate
Documentation=man:systemd-suspend.service(8)
DefaultDependencies=no
#Requires=sleep.target
#After=sleep.target
[Service]
User=bubba
Type=oneshot
#Environment="DISPLAY=:0"
#Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"
ExecStartPre=-/usr/bin/bash -c 'echo -n "PM: CUSTSD: SUSPSV: In Suspend Service. ["; date +%%H":"%%M":"%%S":"%%N"]"'
ExecStart=-/usr/bin/bash -c '/home/bubba/scripts/fauxhib/SUSPEND.sh 2>&1 /home/bubba/scripts/fauxhib/SUSPSV.err'
ExecStop=-/usr/bin/bash -c 'echo -n "PM: CUSTSD: SUSPSV: Leaving Suspend Service. ["; date +%%H":"%%M":"%%S":"%%N"]"'
#!/bin/sh
# /home/bubba/scripts/fauxhib/user-login-housekeeping.sh -
#
# !!!!THIS SCRIPT IS NOT NEEDED TO RESTRT SDDM LOGOUT TIMER, "Xsetup" RESTARTS TIMER ON RENTERING SDDM AT LOGOUT
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
#-------------------------------------------------------------------
# Set Booleans
#
TRUE=1
FALSE=0
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: USERLI: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: USERLI: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: USERLI: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: USERLI: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "In 'User Login Script'"
## Must clear timer that was set in "/usr/share/sddm/scripts/Xsetup"
#logT $(sudo /usr/bin/systemctl status sddm-TO.timer 2>&1)
logT "Cancelling SDDM Idle Limit Timer"
logT $(sudo /usr/bin/systemctl stop sddm-TO.timer 2>&1)
logT "SDDM Idle Limit Timer Cancelled"
logT $(sudo /usr/bin/systemctl status sddm-TO.timer 2>&1)
## Delayed start of TimeShift
#systemd-run \
# --timer-property=AccuracySec=1 \
# --on-active=20 \
# --unit=start-TS \
# /bin/bash -a -c 'sudo /usr/bin/timeshift-gtk &>/home/bubba/scripts/fauxhib/timeshift.err' &>>/home/bubba/scripts/fauxhib/USERLI.err
logT "Leaving 'User Login Script'"
#!/bin/sh
## locate in /usr/share/sddm/scripts/Xsetup - runs as root before the login dialog appears
##
sleep 1
export DISPLAY=:0
export export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u $SUDO_USER)/bus"
#-------------------------------------------------------------------
# Set Statics
#
TRUE=1
FALSE=0
SDDMTO=180
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# Custom LOGGERs
#
## line below essential for Custom LOGGER handling COMMAND output
IFS=$'\n'
logID=""
function log {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SDDM: $logID$ln"
done
else
echo "$@"
logger "PM: CUSTSD: SDDM: $logID$@"
fi
logID="" ## <----- figure out how to pass this param to the 'log(T)' function
fi
}
function logT {
if [ "$#" -gt 0 ]; then
if [ "$#" -gt 1 ]; then
for ln in "$@"; do
echo "$ln"
logger "PM: CUSTSD: SDDM: $logID$ln ["$(date +%H:%M:%S:%N)"]"
done
else
echo "$@"
logger "PM: CUSTSD: SDDM: $logID$@ ["$(date +%H:%M:%S:%N)"]"
fi
logID=""
fi
}
#-------------------------------------------------------------------
logT "In 'SDDM Xsetup Script (/etc/sddm)'"
## For FEDORA 29 --> To overcome 50% failure for bluetooth to proper initialize run /usr/bin/btk script commands
#logT 'Re-Initializing Bluetooth Adapter'
#sudo rmmod hci_uart
#sleep 0.5
#sudo modprobe hci_uart
#sleep 0.5
#logT 'Bluetooth Adapter Initialized'
## Setup SDDM timeout Shutdown if no actvity. For this to work must clear timer on user login (use KDE autologin script feature)
logT "Started $SDDMTO sec SDDM Time-Out Shutdown Timer"
systemd-run \
--timer-property=AccuracySec=1 \
--on-active=$SDDMTO \
--unit=sddm-TO \
/bin/bash -a -c '/home/bubba/scripts/fauxhib/sddm-TO.sh &>>/home/bubba/scripts/fauxhib/SDDM.err' 2>&1 /home/bubba/scripts/fauxhib/SDDM.err
logT "Leaving 'SDDM Xsetup Script (/etc/sddm)'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment