-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathset-startup.py
More file actions
72 lines (60 loc) · 2.62 KB
/
set-startup.py
File metadata and controls
72 lines (60 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/python
# (c) 2023 Asa Durkee. MIT License.
import os
import platform
import subprocess
"""
Configure system to autostart snakewm at login
Reference for ardangelo keyboard firmware:
https://github.com/ardangelo/beepberry-keyboard-driver/blob/main/README.md#module-parameters
"""
HOMEUSER = os.getlogin()
HOME_DIR = os.path.join('/home',HOMEUSER)
WORK_DIR = os.path.join(HOME_DIR,'glowfire')
PYTHONPATH = os.path.join(HOME_DIR,'glowfire/snakewm/data/lib')
print('INFO : PYTHONPATH = ' + PYTHONPATH)
WMPATH = os.path.join(HOME_DIR,'glowfire/snakewm/wm.py')
def systemctl(*args):
""" Shell command for systemctl, followed by a list of arguments. """
return subprocess.check_call(['systemctl'] + list(args))
def create_snakewm_service():
print('INFO : Creating snakewm service in systemd as a unit file.')
lines_to_write = \
['[Unit]',
'Description=snakewm',
'Documentation=https://github.com/hack-shack/glowfire',
'After=multi-user.target',
'\n[Service]',
'Type=simple',
'Environment="PYTHONPATH=' + PYTHONPATH + '" "HOMEUSER=' + HOMEUSER + '"',
'ExecStart=/usr/bin/python ' + WMPATH + ' --dfb:vt-num=1 --dfb:graphics-vt',
'ExecStartPost=/usr/bin/sh -c \'echo always | sudo tee /sys/module/beepy_kbd/parameters/touch_act\'',
'ExecStartPost=/usr/bin/sh -c \'echo mouse | sudo tee /sys/module/beepy_kbd/parameters/touch_as\'',
'ExecStartPost=/usr/bin/sh -c \'echo 0 | sudo tee /sys/firmware/beepy/keyboard_backlight\'',
'ExecStartPost=/usr/bin/sh -c \'echo 0 | sudo tee /sys/class/leds/ACT/brightness\'',
'WorkingDirectory=' + WORK_DIR + '',
'StandardOutput=journal+console',
'Restart=always\nRestartSec=5s\n\n[Install]\nWantedBy=multi-user.target']
systemd_service_file = os.path.join('/etc/systemd/system/snakewm.service')
print('INFO : snakewm service file = ' + systemd_service_file)
print('INFO : The system will appear to hang while the service is created.')
if not os.path.exists(systemd_service_file):
os.mknod(systemd_service_file)
with open(systemd_service_file,'r+') as f:
f.seek(0)
f.truncate()
for line in lines_to_write:
f.write(line + '\n')
def enable_snakewm_service():
systemctl('daemon-reload')
systemctl('enable','snakewm.service')
def main():
if os.getuid() != 0:
print('ERROR : This script is not running as root. Re-run as root.')
exit()
print('INFO : Configuring system to autostart snakewm at login.\n'+56*'-')
create_snakewm_service()
enable_snakewm_service()
print('INFO : snakewm automatically restarts. Use "sudo systemctl disable snakewm.service" to turn it off.')
if __name__ == "__main__":
main()