env-wrapper 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env bash
  2. source $SNAP/helper/functions
  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. export NETWORK_KEY=$(snapctl get network.key)
  14. SETTINGS_KEY=$(same_network_key "${NETWORK_KEY}")
  15. if [ $? -ne 0 ]; then
  16. snapctl set network.key="${SETTINGS_KEY}"
  17. export NETWORK_KEY="${SETTINGS_KEY}"
  18. fi
  19. OPT_HELP=false
  20. if [ "${1}" = "--help" ]; then
  21. OPT_HELP=true
  22. fi
  23. if [ ${OPT_HELP} = true ]; then
  24. plugs_connected
  25. if [ $? -ne 0 ]; then
  26. echo ""
  27. echo "NOTE! NOTE! NOTE!"
  28. echo ""
  29. fi
  30. echo "${SNAP_NAME} ($ ($ 1 --version))"
  31. echo ""
  32. echo "IMPORTANT! The DAEMON/SERVICE is disabled by default after installation."
  33. echo "You have to manually 'daemonize' it with executing the command"
  34. echo ""
  35. echo "$ ${SNAP_NAME}.enable"
  36. echo ""
  37. echo "Set your configuration as descrived below"
  38. echo ""
  39. echo "Base configuration values:"
  40. echo "- network.key: $(snapctl get network.key)"
  41. echo "Server configuration values: $(snapctl get server -d)"
  42. echo ""
  43. echo "- server.ssl: Use secure communication"
  44. echo "- server.host: IP address to bind to, e.g 127.0.0.1"
  45. echo "- server.port: Port to reach the web interface"
  46. echo ""
  47. echo "Session configuration values: $(snapctl get session -d)"
  48. echo ""
  49. echo "Set options with: $ snap set ${SNAP_NAME} param=key"
  50. echo "For example: $ snap set ${SNAP_NAME} server.host=0.0.0.0"
  51. echo ""
  52. echo "Other settings can be set in the UI after start."
  53. echo ""
  54. echo "Follow the log with"
  55. echo "$ snap logs ${SNAP_NAME} -f"
  56. echo ""
  57. echo "Other commands"
  58. echo "Disable the daemon: $ ${SNAP_NAME}.disable"
  59. echo "Restart the daemon: $ ${SNAP_NAME}.restart"
  60. exit 0
  61. fi
  62. require_root
  63. plugs_connected
  64. if [ $? -ne 0 ]; then
  65. exit 1
  66. fi
  67. ensure_zwavejs_config
  68. export SERVER_SSL=$(snapctl get server.ssl)
  69. export SERVER_HOST=$(snapctl get server.host)
  70. export SERVER_PORT=$(snapctl get server.port)
  71. export GIT_DIR="${SNAP}/usr/lib/zwavejs2mqtt/.git"
  72. export HTTPS="${SERVER_SSL}"
  73. export SESSION_SECRET=$(snapctl get session.secret)
  74. export USE_SECURE_COOKIE=$(snapctl get session.cookie-secure)
  75. if [ "${HTTPS}" != true ]; then
  76. unset HTTPS
  77. unset SERVER_SSL
  78. fi
  79. if [ "${USE_SECURE_COOKIE}" != true ]; then
  80. unset USE_SECURE_COOKIE
  81. fi
  82. export HOST="${SERVER_HOST}"
  83. export PORT="${SERVER_PORT}"
  84. exec "$@"