start-dev.sh 4.1 KB

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