start-dev.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env bash
  2. set -o errexit
  3. set -o nounset
  4. set -o pipefail
  5. if [[ "${TRACE-0}" == "1" ]]; then
  6. set -o xtrace
  7. fi
  8. source "${BASH_SOURCE%/*}/common.sh"
  9. ### --------------------------------
  10. ### General variables
  11. ### --------------------------------
  12. ROOT_FOLDER="${PWD}"
  13. STATE_FOLDER="${ROOT_FOLDER}/state"
  14. SED_ROOT_FOLDER="$(echo "$ROOT_FOLDER" | sed 's/\//\\\//g')"
  15. NGINX_PORT=80
  16. NGINX_PORT_SSL=443
  17. DOMAIN=tipi.localhost
  18. DNS_IP="9.9.9.9" # Default to Quad9 DNS
  19. ARCHITECTURE="$(uname -m)"
  20. TZ="UTC"
  21. JWT_SECRET=secret
  22. POSTGRES_PASSWORD=postgres
  23. TIPI_VERSION=$(get_json_field "${ROOT_FOLDER}/package.json" version)
  24. INTERNAL_IP=localhost
  25. storage_path="${ROOT_FOLDER}"
  26. STORAGE_PATH_ESCAPED="$(echo "${storage_path}" | sed 's/\//\\\//g')"
  27. if [[ "$ARCHITECTURE" == "aarch64" ]]; then
  28. ARCHITECTURE="arm64"
  29. elif [[ "$ARCHITECTURE" == "armv7l" ]]; then
  30. ARCHITECTURE="arm"
  31. elif [[ "$ARCHITECTURE" == "x86_64" ]]; then
  32. ARCHITECTURE="amd64"
  33. fi
  34. # If none of the above conditions are met, the architecture is not supported
  35. if [[ "$ARCHITECTURE" != "arm64" ]] && [[ "$ARCHITECTURE" != "arm" ]] && [[ "$ARCHITECTURE" != "amd64" ]]; then
  36. echo "Architecture not supported!"
  37. exit 1
  38. fi
  39. ### --------------------------------
  40. ### Apps repository configuration
  41. ### --------------------------------
  42. apps_repository="https://github.com/meienberger/runtipi-appstore"
  43. APPS_REPOSITORY_ESCAPED="$(echo ${apps_repository} | sed 's/\//\\\//g')"
  44. REPO_ID="$("${ROOT_FOLDER}"/scripts/git.sh get_hash ${apps_repository})"
  45. # Override configs with settings.json
  46. if [[ -f "${STATE_FOLDER}/settings.json" ]]; then
  47. if [[ "$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoUrl)" != "null" ]]; then
  48. apps_repository=$(get_json_field "${STATE_FOLDER}/settings.json" appsRepoUrl)
  49. APPS_REPOSITORY_ESCAPED="$(echo "${apps_repository}" | sed 's/\//\\\//g')"
  50. REPO_ID="$("${ROOT_FOLDER}"/scripts/git.sh get_hash "${apps_repository}")"
  51. fi
  52. fi
  53. ### --------------------------------
  54. ### Watcher and system-info
  55. ### --------------------------------
  56. if [[ ! -f "${ROOT_FOLDER}/state/events" ]]; then
  57. touch "${ROOT_FOLDER}/state/events"
  58. fi
  59. if [[ ! -f "${ROOT_FOLDER}/state/system-info.json" ]]; then
  60. echo "{}" >"${ROOT_FOLDER}/state/system-info.json"
  61. fi
  62. chmod -R a+rwx "${ROOT_FOLDER}/state/events"
  63. chmod -R a+rwx "${ROOT_FOLDER}/state/system-info.json"
  64. kill_watcher
  65. "${ROOT_FOLDER}/scripts/watcher.sh" &
  66. ### --------------------------------
  67. ### env file generation
  68. ### --------------------------------
  69. ENV_FILE=$(mktemp)
  70. [[ -f "${ROOT_FOLDER}/.env" ]] && rm -f "${ROOT_FOLDER}/.env"
  71. [[ -f "$ROOT_FOLDER/templates/env-sample" ]] && cp "$ROOT_FOLDER/templates/env-sample" "$ENV_FILE"
  72. OS=$(uname)
  73. sed_args=(-i)
  74. # If os is macos, use gnu sed
  75. if [[ "$OS" == "Darwin" ]]; then
  76. echo "Using gnu sed"
  77. sed_args=(-i '')
  78. fi
  79. for template in ${ENV_FILE}; do
  80. sed "${sed_args[@]}" "s/<dns_ip>/${DNS_IP}/g" "${template}"
  81. sed "${sed_args[@]}" "s/<internal_ip>/${INTERNAL_IP}/g" "${template}"
  82. sed "${sed_args[@]}" "s/<tz>/${TZ}/g" "${template}"
  83. sed "${sed_args[@]}" "s/<jwt_secret>/${JWT_SECRET}/g" "${template}"
  84. sed "${sed_args[@]}" "s/<root_folder>/${SED_ROOT_FOLDER}/g" "${template}"
  85. sed "${sed_args[@]}" "s/<tipi_version>/${TIPI_VERSION}/g" "${template}"
  86. sed "${sed_args[@]}" "s/<architecture>/${ARCHITECTURE}/g" "${template}"
  87. sed "${sed_args[@]}" "s/<nginx_port>/${NGINX_PORT}/g" "${template}"
  88. sed "${sed_args[@]}" "s/<nginx_port_ssl>/${NGINX_PORT_SSL}/g" "${template}"
  89. sed "${sed_args[@]}" "s/<postgres_password>/${POSTGRES_PASSWORD}/g" "${template}"
  90. sed "${sed_args[@]}" "s/<apps_repo_id>/${REPO_ID}/g" "${template}"
  91. sed "${sed_args[@]}" "s/<apps_repo_url>/${APPS_REPOSITORY_ESCAPED}/g" "${template}"
  92. sed "${sed_args[@]}" "s/<domain>/${DOMAIN}/g" "${template}"
  93. sed "${sed_args[@]}" "s/<storage_path>/${STORAGE_PATH_ESCAPED}/g" "${template}"
  94. done
  95. mv -f "$ENV_FILE" "$ROOT_FOLDER/.env.dev"
  96. cp "$ROOT_FOLDER/.env.dev" "$ROOT_FOLDER/.env"
  97. chmod a+rwx "$ROOT_FOLDER/.env"
  98. chmod a+rwx "${ROOT_FOLDER}/.env.dev"
  99. ### --------------------------------
  100. ### Start the project
  101. ### --------------------------------
  102. docker compose -f docker-compose.dev.yml --env-file "${ROOT_FOLDER}/.env.dev" up --build