env-wrapper 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. set -e
  3. if [ -z ${DAEMONIZED} ]; then
  4. DAEMONIZED=0
  5. fi
  6. function lprint {
  7. if [ ${DAEMONIZED} -eq 0 ]; then
  8. echo ${1}
  9. else
  10. logger "${SNAP_NAME}: ${1}"
  11. fi
  12. }
  13. if ! snapctl is-connected raw-usb; then
  14. lprint "Please connect raw-usb interface!"
  15. lprint "Run: snap connect ${SNAP_NAME}:raw-usb"
  16. exit 1
  17. fi
  18. export NETWORK_KEY=$(snapctl get network.key)
  19. if [ -f "${SNAP_DATA}/settings.json" ]; then
  20. SETTINGS_KEY=$(jq '.zwave.networkKey' -r ${SNAP_DATA}/settings.json)
  21. if [ "${SETTINGS_KEY}" != "" ] && [ "${NETWORK_KEY}" != "${SETTINGS_KEY}" ]; then
  22. snapctl set network.key="${SETTINGS_KEY}"
  23. export NETWORK_KEY="${SETTINGS_KEY}"
  24. fi
  25. fi
  26. export SERVER_SSL=$(snapctl get server.ssl)
  27. export SERVER_HOST=$(snapctl get server.host)
  28. export SERVER_PORT=$(snapctl get server.port)
  29. export SERVER_URL=$(snapctl get server.url)
  30. export SERVER_WS_URL=$(snapctl get server.ws-url)
  31. OPT_HELP=false
  32. if [ "${1}" = "--help" ]; then
  33. OPT_HELP=true
  34. fi
  35. if [ ${OPT_HELP} = true ]; then
  36. echo "Zwavejs2mqtt ($ ($ 1 --version))"
  37. echo ""
  38. echo "IMPORTANT! The DAEMON/SERVICE is disabled by default after installation."
  39. echo "You have to manually 'daemonize' OpenZWave Daemon with executing the command"
  40. echo ""
  41. echo "$ ${SNAP_NAME}.enable"
  42. echo ""
  43. echo "But first set your configuration as descrived below"
  44. echo ""
  45. echo "Base configuration values:"
  46. echo "- network.key: $(snapctl get network.key)"
  47. echo "Server configuration values: $(snapctl get server -d)"
  48. echo ""
  49. echo "- server.ssl: Use secure communication"
  50. echo "- server.host: IP address to bind to, e.g 127.0.0.1"
  51. echo "- server.port: Port to reach the web interface"
  52. echo "- server.url: Hostname for http/https"
  53. echo "- server.ws-url: Hostname for websocket"
  54. echo ""
  55. echo "Set options with: $ snap set ${SNAP_NAME} param=key"
  56. echo "For example: $ snap set ${SNAP_NAME} server.host=0.0.0.0"
  57. echo ""
  58. echo "Also see 'snap info ${SNAP_NAME}'."
  59. echo ""
  60. echo "Follow the log with"
  61. echo "$ snap logs ${SNAP_NAME} -f"
  62. echo ""
  63. echo "Other commands"
  64. echo "Disable the daemon: $ ${SNAP_NAME}.disable"
  65. echo "Restart the daemon: $ ${SNAP_NAME}.restart"
  66. exit 0
  67. fi
  68. exec "$@"