env-wrapper 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. # WITH S0+n NETWORK KEY IS NOT USED ANYMORE
  14. #export NETWORK_KEY=$(snapctl get network.key)
  15. # SETTINGS_KEY=$(same_network_key "${NETWORK_KEY}")
  16. # if [ $? -ne 0 ]; then
  17. # snapctl set network.key="${SETTINGS_KEY}"
  18. # export NETWORK_KEY="${SETTINGS_KEY}"
  19. # fi
  20. OPT_HELP=false
  21. if [ "${1}" = "--help" ]; then
  22. OPT_HELP=true
  23. fi
  24. if [ ${OPT_HELP} = true ]; then
  25. plugs_connected
  26. if [ $? -ne 0 ]; then
  27. echo ""
  28. echo "NOTE! NOTE! NOTE!"
  29. echo ""
  30. fi
  31. echo "${SNAP_NAME} - $(yq eval '.version' "${SNAP}/meta/snap.yaml")"
  32. echo ""
  33. echo "IMPORTANT! The DAEMON/SERVICE is disabled by default after installation."
  34. echo "You have to manually 'daemonize' it with executing the command"
  35. echo ""
  36. echo "$ ${SNAP_NAME}.enable"
  37. echo ""
  38. echo "Set your configuration as descrived below"
  39. echo ""
  40. # echo "Base configuration values:"
  41. # echo "- network.key: $(snapctl get network.key)"
  42. echo "Server configuration values: $(snapctl get server -d)"
  43. echo ""
  44. echo "- server.ssl: Use secure communication"
  45. echo "- server.host: IP address to bind to, e.g 127.0.0.1"
  46. echo "- server.port: Port to reach the web interface"
  47. echo ""
  48. echo "Session configuration values: $(snapctl get session -d)"
  49. echo ""
  50. echo "- session.secret: Used as secret for session. If not provided a default one is used."
  51. echo "- session.cookie-secure: Set the cookie secure option. See: https://github.com/expressjs/session#cookiesecure"
  52. echo ""
  53. echo "Session configuration values: $(snapctl get mqtt -d)"
  54. echo ""
  55. echo "- mqtt.name: The name used as client name when connecting to the mqtt server."
  56. echo ""
  57. echo "Set options with: $ snap set ${SNAP_NAME} param=key"
  58. echo "For example: $ snap set ${SNAP_NAME} server.host=0.0.0.0"
  59. echo ""
  60. echo "Other settings can be set in the UI after start."
  61. echo ""
  62. echo "If you have turned OFF «log to file», follow the log(s) with"
  63. echo " $ sudo snap logs ${SNAP_NAME} -f"
  64. echo ""
  65. echo "OR if you have turned ON «log to file», tail the logs with"
  66. echo " $ tail -f ${SNAP_DATA}/*.log"
  67. echo ""
  68. echo "Other commands"
  69. echo "Disable the daemon: $ ${SNAP_NAME}.disable"
  70. echo "Restart the daemon: $ ${SNAP_NAME}.restart"
  71. echo ""
  72. echo "Info on the serial-port plug:"
  73. echo " This plug requires the experimental hotplug feature in snapd."
  74. echo " Enable it with"
  75. echo " $ sudo snap set system experimental.hotplug=true"
  76. echo ""
  77. echo " And restart snapd with:"
  78. echo " $ sudo systemctl restart snapd"
  79. echo ""
  80. echo " Now list available serial slots with:"
  81. echo " $ sudo snap iterface serial-port"
  82. echo ""
  83. echo " And connect it to ${SNAP_NAME} with:"
  84. echo " $ sudo snap connect ${SNAP_NAME}:serial-port <slot name>"
  85. exit 0
  86. fi
  87. require_root
  88. plugs_connected
  89. if [ $? -ne 0 ]; then
  90. exit 1
  91. fi
  92. # Not needed anymore as of ZWAVEJS_EXTERNAL_CONFIG?
  93. # ensure_zwavejs_config
  94. export SERVER_HOST=$(snapctl get server.host)
  95. export SERVER_PORT=$(snapctl get server.port)
  96. export HOST="${SERVER_HOST}"
  97. export PORT="${SERVER_PORT}"
  98. export SERVER_SSL=$(snapctl get server.ssl)
  99. export HTTPS="${SERVER_SSL}"
  100. export FORCE_DISABLE_SSL=$(snapctl get server.force-disable-ssl)
  101. if [ "${FORCE_DISABLE_SSL}" != true ]; then
  102. unset FORCE_DISABLE_SSL
  103. fi
  104. export USE_SECURE_COOKIE=$(snapctl get session.cookie-secure)
  105. if [ "${HTTPS}" != true ] || [ "${FORCE_DISABLE_SSL}" == true ]; then
  106. unset HTTPS
  107. unset SERVER_SSL
  108. unset USE_SECURE_COOKIE
  109. elif [ "${USE_SECURE_COOKIE}" != true ]; then
  110. unset USE_SECURE_COOKIE
  111. fi
  112. export SESSION_SECRET=$(snapctl get session.secret)
  113. export MQTT_NAME=$(snapctl get mqtt.name)
  114. if [ -z "${MQTT_NAME}" ]; then
  115. unset MQTT_NAME
  116. fi
  117. export GIT_DIR="${SNAP}/lib/zwavejs2mqtt/.git"
  118. [ "$(basename "${1}")" == "yarn" ] && cd "${SNAP}/lib/zwavejs2mqtt" && exec "${@}" || exec "${@}"