env-wrapper 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "Set options with: $ snap set ${SNAP_NAME} param=key"
  48. echo "For example: $ snap set ${SNAP_NAME} server.host=0.0.0.0"
  49. echo ""
  50. echo "Other settings can be set in the UI after start."
  51. echo ""
  52. echo "Follow the log with"
  53. echo "$ snap logs ${SNAP_NAME} -f"
  54. echo ""
  55. echo "Other commands"
  56. echo "Disable the daemon: $ ${SNAP_NAME}.disable"
  57. echo "Restart the daemon: $ ${SNAP_NAME}.restart"
  58. exit 0
  59. fi
  60. require_root
  61. plugs_connected
  62. if [ $? -ne 0 ]; then
  63. exit 1
  64. fi
  65. ensure_zwavejs_config
  66. export SERVER_SSL=$(snapctl get server.ssl)
  67. export SERVER_HOST=$(snapctl get server.host)
  68. export SERVER_PORT=$(snapctl get server.port)
  69. export GIT_DIR="${SNAP}/usr/lib/zwavejs2mqtt/.git"
  70. export HTTPS="${SERVER_SSL}"
  71. export SESSION_SECRET=$(snapctl get session.secret)
  72. export USE_SECURE_COOKIE=$(snapctl get session.cookie-secure)
  73. if [ "${HTTPS}" != true ]; then
  74. unset HTTPS
  75. unset SERVER_SSL
  76. fi
  77. if [ "${USE_SECURE_COOKIE}" != true ]; then
  78. unset USE_SECURE_COOKIE
  79. fi
  80. export HOST="${SERVER_HOST}"
  81. export PORT="${SERVER_PORT}"
  82. exec "$@"