Smarthome Functionen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__install__.py 982B

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