Advertisement
Guest User

Untitled

a guest
Aug 31st, 2021
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.00 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ♥©♥ hana, mod annelin
  4.  
  5. # disabled
  6. # exit 0
  7.  
  8. user=ann
  9. display=":0.0"
  10. usbdevices=""
  11. brightness="/sys/class/backlight/intel_backlight/brightness"
  12. cpus="2 3 4 5 6 7"
  13. wlan="wlp0s20f3"
  14. ps_blacklist="systemd zsh ssh audacious pulseaudio gajim polkit- dbus- xfce4-power-manager xfce4-notifyd i3lock"
  15.  
  16.  
  17. function whichusb(){
  18.  for X in /sys/bus/usb/devices/*; do
  19.     if [ "${1:0:4}" == "$(cat "$X/idVendor" 2>/dev/null)" -a "${1:5}" == "$(cat "$X/idProduct" 2>/dev/null)" ]
  20.     then
  21.         echo "$X"
  22.     fi
  23.  done
  24. }
  25.  
  26. case $1 in
  27.    
  28.     sleep)
  29.  
  30.             # disable xfce sleep md #
  31.             #sudo -u ${user} DISPLAY=${display} xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/inactivity-on-battery -s 14
  32.  
  33.             # usb #
  34.             for usbd in $usbdevices; do
  35.               # echo "unbind $usbd `whichusb $usbd` "
  36.               echo $(whichusb $usbd | sed 's/\/.*\///g') > /sys/bus/usb/drivers/usb/unbind
  37.             done
  38.  
  39.             # wifi #
  40.             iwconfig $wlan txpower 10
  41.  
  42.             # backlight #
  43.             cat $brightness > /tmp/fakesleep.brightness
  44.             echo 0 > $brightness
  45.             sudo -u ${user} DISPLAY=${display} xset dpms force off
  46.  
  47.             # sleep user procs #
  48.             for pid in $(ps -u ${user} -o pid,cmd | grep -vE "`echo $ps_blacklist|sed 's/ /|/g'`" | awk '{ print $1 }') ; do
  49.                 echo $pid >> /tmp/fakesleep.pid
  50.                 kill -STOP $pid
  51.             done
  52.  
  53.  
  54.             # sleep Xorg #
  55.             # kill -STOP $(pidof X)
  56.  
  57.             # sleep cores #
  58.             for i in $cpus ; do echo 0 > /sys/devices/system/cpu/cpu${i}/online; done
  59.  
  60.             # completed #
  61.             # echo -n 7 on >> /proc/acpi/ibm/led
  62.             echo "`date` stopping completed for `hostname`"  >> /tmp/fakesleep.log ;;
  63.  
  64.     resume)
  65.  
  66.             if [ ! -f /tmp/fakesleep.pid ] ; then exit ; fi
  67.  
  68.             # cpu #
  69.             for i in $cpus ; do echo 1 > /sys/devices/system/cpu/cpu${i}/online; done
  70.  
  71.             # ps resume #
  72.             # kill -CONT $(pidof X)
  73.             for i in $(cat /tmp/fakesleep.pid) ; do
  74.                  kill -CONT $i
  75.             done
  76.  
  77.             # disable xfce sleep md #
  78.             # sudo -u ${user} DISPLAY=${display} xfconf-query -c xfce4-power-manager -p /xfce4-power-manager/inactivity-on-battery -s 60
  79.  
  80.             for usbd in $usbdevices; do
  81.                 echo $(whichusb $usbd | sed 's/\/.*\///g') > /sys/bus/usb/drivers/usb/bind
  82.             done
  83.  
  84.             # wifi #
  85.             iwconfig $wlan txpower 24  
  86.  
  87.             # disp #
  88.             sleep 1s
  89.             sudo -u ${user} DISPLAY=${display} xset dpms force on
  90.             cat /tmp/fakesleep.brightness > $brightness
  91.  
  92.  
  93.             # remove tmp data #
  94.             rm /tmp/fakesleep.pid
  95.             rm /tmp/fakesleep.brightness
  96.  
  97.  
  98.             # completed #
  99.             # echo -n 7 off >> /proc/acpi/ibm/led
  100.             echo "`date` resume completed for `hostname`"  >> /tmp/fakesleep.log ;;
  101. esac
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement