|
@@ -0,0 +1,40 @@
|
|
1
|
+#!/bin/python
|
|
2
|
+#
|
|
3
|
+import os
|
|
4
|
+import sys
|
|
5
|
+
|
|
6
|
+SERVICE_FILE = """
|
|
7
|
+[Unit]
|
|
8
|
+Description=Spotify Service
|
|
9
|
+After=mosquitto.target
|
|
10
|
+[Service]
|
|
11
|
+User=%(UID)d
|
|
12
|
+Group=%(GID)d
|
|
13
|
+ExecStart=%(MY_PATH)s/spotify.sh
|
|
14
|
+Type=simple
|
|
15
|
+[Install]
|
|
16
|
+WantedBy=default.target
|
|
17
|
+"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+def help():
|
|
21
|
+ print("Usage: prog <UID> <GID> <TARGET_PATH>")
|
|
22
|
+
|
|
23
|
+if __name__ == "__main__":
|
|
24
|
+ if len(sys.argv) == 4:
|
|
25
|
+ try:
|
|
26
|
+ uid = int(sys.argv[1])
|
|
27
|
+ gid = int(sys.argv[2])
|
|
28
|
+ except ValueError:
|
|
29
|
+ help()
|
|
30
|
+ else:
|
|
31
|
+ if os.path.isdir(sys.argv[3]):
|
|
32
|
+ with open(os.path.join(sys.argv[3], 'spotify.service'), "w") as fh:
|
|
33
|
+ fh.write(SERVICE_FILE % {
|
|
34
|
+ "MY_PATH": os.path.dirname(os.path.abspath(__file__)),
|
|
35
|
+ "UID": uid,
|
|
36
|
+ "GID": gid})
|
|
37
|
+ else:
|
|
38
|
+ help()
|
|
39
|
+ else:
|
|
40
|
+ help()
|