start.sh 3.4 KB

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