#!/usr/bin/env bash set -euo pipefail branch="${1:-main}" target_dir="${2:-~/egbim}" env_file="${3:-}" db_dump_path="${4:-egbim_DB.sql}" db_import_marker=".db_import_done" case "$target_dir" in '~') target_dir="$HOME" ;; '~/'*) target_dir="$HOME/${target_dir#\~/}" ;; esac mkdir -p "$target_dir" cd "$target_dir" if [[ ! -d .git ]]; then git clone --branch "$branch" https://gitea.hmac.kr/b24014/egbim_homepage.git . else git fetch origin git checkout "$branch" git reset --hard "origin/$branch" fi if [[ -n "$env_file" ]]; then cp "$env_file" .env fi if [[ -f .env ]]; then set -a # shellcheck disable=SC1091 source .env set +a fi mkdir -p \ egbim/data/cache \ egbim/data/session \ egbim/data/log \ eng/data/cache \ eng/data/session \ eng/data/log mkdir -p docker/mysql/init docker compose up -d --build if [[ -f "$db_dump_path" && ! -f "$db_import_marker" ]]; then for _ in $(seq 1 30); do if docker compose exec -T db mariadb-admin ping -h localhost -uroot "-p${MARIADB_ROOT_PASSWORD}" >/dev/null 2>&1; then break fi sleep 2 done docker compose exec -T db mariadb-admin ping -h localhost -uroot "-p${MARIADB_ROOT_PASSWORD}" >/dev/null 2>&1 docker compose exec -T db mariadb -u"${G5_MYSQL_USER}" "-p${G5_MYSQL_PASSWORD}" "${G5_MYSQL_DB}" < "$db_dump_path" touch "$db_import_marker" fi