Docker configuration templates
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

start.sh 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. #
  3. APP_TARGET_PATH=/opt/zigbee2mqtt
  4. my_print()
  5. {
  6. echo `date` $HOST [$$]: $1
  7. }
  8. fail_loop()
  9. {
  10. my_print "Start script failed..."
  11. for (( ; ; ))
  12. do
  13. sleep 60
  14. done
  15. }
  16. check_environment()
  17. {
  18. fail=0
  19. # returns 0 if environment is not okay
  20. if [[ -z $APP_GIT_VERSION ]]; then
  21. my_print "Environment variable APP_GIT_VERSION does not exist!"
  22. fail=1
  23. fi
  24. if [[ -z $APP_MQTT_SERVER ]]; then
  25. my_print "Environment variable APP_MQTT_SERVER does not exist!"
  26. fail=1
  27. fi
  28. #
  29. if [[ $fail -ne 0 ]]; then
  30. fail_loop
  31. fi
  32. }
  33. if [[ ! -d $APP_TARGET_PATH ]]; then
  34. my_print "Directory \"$APP_TARGET_PATH\" does not exist."
  35. fi
  36. if [[ ! -d $APP_TARGET_PATH/.git ]]; then
  37. check_environment
  38. my_print "Cloning zigbee2mqtt repository..."
  39. git clone https://github.com/Koenkk/zigbee2mqtt.git $APP_TARGET_PATH
  40. my_print "Changing to directory $APP_TARGET_PAT"
  41. cd $APP_TARGET_PATH
  42. my_print "Changing to git version $APP_GIT_VERSION"
  43. git checkout $APP_GIT_VERSION
  44. my_print "Replacing MQTT servername in $APP_TARGET_PATH/data/configuration.yaml"
  45. sed -i "s|mqtt://localhost|mqtt://$APP_MQTT_SERVER|g" $APP_TARGET_PATH/data/configuration.yaml
  46. if [[ ! -z $APP_MQTT_USER ]]; then
  47. my_print "Adding MQTT username in $APP_TARGET_PATH/data/configuration.yaml"
  48. sed -i "s|# user: my_user|user: $APP_MQTT_USER|g" $APP_TARGET_PATH/data/configuration.yaml
  49. fi
  50. if [[ ! -z $APP_MQTT_PASSWORD ]]; then
  51. my_print "Adding MQTT password in $APP_TARGET_PATH/data/configuration.yaml"
  52. sed -i "s|# password: my_password|password: $APP_MQTT_PASSWORD|g" $APP_TARGET_PATH/data/configuration.yaml
  53. fi
  54. my_print "Preparing application (npm ci)"
  55. npm ci
  56. fi
  57. cd $APP_TARGET_PATH
  58. my_print "Starting zigbee2mqtt..."
  59. npm start
  60. my_print "**********************************************************"
  61. my_print "* Start of zigbee2mqtt failed. *"
  62. my_print "* Check running npm ci and npm start in /opt/zigbee2mqtt *"
  63. my_print "**********************************************************"
  64. fail_loop