-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart_gnome_remote_desktop.py
executable file
·73 lines (55 loc) · 1.89 KB
/
restart_gnome_remote_desktop.py
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
73
#!/usr/bin/python3 -u
import sys
import os
import re
import pathlib
import subprocess
import argparse
import shutil
def run_shell(cmd, check=True, env=None, log_file=None, shell=False):
print(f'{cmd}\n')
if log_file:
print(f'Write log: {log_file}\n')
result = subprocess.run(cmd.split(),
check=check,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=shell,
text=True)
with open(log_file, 'w', encoding="utf-8") as f:
f.write(result.stdout)
else:
result = subprocess.run(cmd.split(), check=check, env=env)
result.stdout = None
print(f'{result}\n')
return result
def main() -> int:
parser = argparse.ArgumentParser(allow_abbrev=False)
parser.add_argument('-p',
'--password',
dest='password',
action='store',
default=None,
help="Specify password")
args = parser.parse_args()
if not args.password:
raise RuntimeError(f'{password} it not set')
cmd = f'killall gnome-keyring-daemon'
run_shell(cmd, check=True, shell=True)
cmd = f"echo -n '{args.password}' | gnome-keyring-daemon -l -d"
run_shell(cmd, check=True, shell=True)
cmd = f'gnome-keyring-daemon -s'
run_shell(cmd, check=True, shell=True)
'''
cmd = f'systemctl --user daemon-reload'
run_shell(cmd, check=True, shell=True)
'''
cmd = f'systemctl --user restart gnome-remote-desktop'
run_shell(cmd, check=True, shell=True)
cmd = f'systemctl --user status gnome-remote-desktop'
run_shell(cmd, check=True, shell=True)
print('Done')
return 0
if __name__ == '__main__':
sys.exit(main())