Browse Source

Add sleep scripts

master
Ali Hatami Tajik 2 years ago
parent
commit
c6959ac725
  1. 10
      setup.sh
  2. 13
      src/scripts/sleeputil.sh
  3. 25
      src/scripts/utils/socknix.py

10
setup.sh

@ -40,6 +40,16 @@ sudo chmod +x /usr/local/bin/setupmonitor.sh
draw_progress_bar 30
sudo chmod +x /usr/local/bin/changemouse.py
log 'Installing Sleep scripts ...'
sudo cp src/scripts/utils/socknix.py /usr/local/bin
draw_progress_bar 33
sudo chmod +x /usr/local/bin/socknix.py
draw_progress_bar 35
sudo cp src/scripts/sleeputil.sh /lib/systemd/system-sleep/
draw_progress_bar 36
sudo chmod +x /lib/systemd/system-sleep/sleeputil.sh
draw_progress_bar 45
log 'Installing config files ...'
# TODO

13
src/scripts/sleeputil.sh

@ -3,14 +3,19 @@
# should be moved to the /lib/systemd/system-sleep/
PATH=/sbin:/usr/sbin:/bin:/usr/bin
case "$1" in
pre)
#code execution BEFORE sleeping/hibernating/suspending
STATUS=$(/usr/local/bin/socknix.py --socket /tmp/sleep.socket -m SUSPEND)
if [ "$STATUS" != "OK" ]; then
exit 1
fi
;;
post)
#code execution AFTER resuming
STATUS=$(/usr/local/bin/socknix.py --socket /tmp/sleep.socket -m AWAIKEN)
if [ "$STATUS" != "OK" ]; then
exit 1
fi
;;
esac
exit 0
exit 0

25
src/scripts/utils/socknix.py

@ -0,0 +1,25 @@
#!/usr/bin/python3
# Author: Ali Hatami Tajik (info@alihatamitajik.ir)
# Date: 08 May 2023
import socket
import argparse
parser = argparse.ArgumentParser(prog='socknix.py',
description='Sends specified massage to unix socket specified prints out the answer of the server in the stdout.')
parser.add_argument('--socket', '-s', required=True,
help='address of the UNIX socket in the filesystem')
parser.add_argument('--message', '-m')
parser.add_argument('--buffer', '-b', type=int, default=1024)
args = parser.parse_args()
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(args.socket)
if args.message:
s.send(args.message.encode())
else:
s.send(input().encode())
print(s.recv(args.buffer).decode(), end='')
Loading…
Cancel
Save