start.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/env bash
  2. set -e # Exit immediately if a command exits with a non-zero status.
  3. # use greadlink instead of readlink on osx
  4. if [[ "$(uname)" == "Darwin" ]]; then
  5. readlink=greadlink
  6. else
  7. readlink=readlink
  8. fi
  9. ROOT_FOLDER="$($readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
  10. STATE_FOLDER="${ROOT_FOLDER}/state"
  11. INTERNAL_IP="$(hostname -I | awk '{print $1}')"
  12. PUID="$(id -u)"
  13. PGID="$(id -g)"
  14. TZ="$(cat /etc/timezone | sed 's/\//\\\//g' || echo "Europe/Berlin")"
  15. if [[ $UID != 0 ]]; then
  16. echo "Tipi must be started as root"
  17. echo "Please re-run this script as"
  18. echo " sudo ./scripts/start"
  19. exit 1
  20. fi
  21. # Configure Umbrel if it isn't already configured
  22. if [[ ! -f "${STATE_FOLDER}/configured" ]]; then
  23. "${ROOT_FOLDER}/scripts/configure.sh"
  24. fi
  25. # Copy the app state if it isn't here
  26. if [[ ! -f "${STATE_FOLDER}/apps.json" ]]; then
  27. cp "${ROOT_FOLDER}/templates/apps-sample.json" "${STATE_FOLDER}/apps.json"
  28. fi
  29. export DOCKER_CLIENT_TIMEOUT=240
  30. export COMPOSE_HTTP_TIMEOUT=240
  31. echo "Generating config files..."
  32. # Remove current .env file
  33. [[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
  34. # Store paths to intermediary config files
  35. ENV_FILE="$ROOT_FOLDER/templates/.env"
  36. # Remove intermediary config files
  37. [[ -f "$ENV_FILE" ]] && rm -f "$ENV_FILE"
  38. # Copy template configs to intermediary configs
  39. [[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
  40. for template in "${ENV_FILE}"; do
  41. sed -i "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
  42. sed -i "s/<puid>/${PUID}/g" "${template}"
  43. sed -i "s/<pgid>/${PGID}/g" "${template}"
  44. sed -i "s/<tz>/${TZ}/g" "${template}"
  45. done
  46. mv -f "$ENV_FILE" "$ROOT_FOLDER/.env"
  47. ansible-playbook ansible/start.yml -i ansible/hosts -K
  48. # Run docker-compose
  49. docker-compose --env-file "${ROOT_FOLDER}/.env" up --detach --remove-orphans --build || {
  50. echo "Failed to start containers"
  51. exit 1
  52. }
  53. # Get field from json file
  54. function get_json_field() {
  55. local json_file="$1"
  56. local field="$2"
  57. echo $(jq -r ".${field}" "${json_file}")
  58. }
  59. str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
  60. apps_to_start=($str)
  61. # for app in "${apps_to_start[@]}"; do
  62. # "${ROOT_FOLDER}/scripts/app.sh" start $app
  63. # done
  64. echo "Tipi is now running"
  65. echo ""
  66. cat << "EOF"
  67. _,.
  68. ,` -.)
  69. '( _/'-\\-.
  70. /,|`--._,-^| ,
  71. \_| |`-._/|| ,'|
  72. | `-, / | / /
  73. | || | / /
  74. `r-._||/ __ / /
  75. __,-<_ )`-/ `./ /
  76. ' \ `---' \ / /
  77. | |./ /
  78. / // /
  79. \_/' \ |/ /
  80. | | _,^-'/ /
  81. | , `` (\/ /_
  82. \,.->._ \X-=/^
  83. ( / `-._//^`
  84. `Y-.____(__}
  85. | {__)
  86. ()`
  87. EOF
  88. echo ""
  89. echo "Visit http://${INTERNAL_IP}/ to view the dashboard"
  90. echo ""