93 lines
No EOL
2.6 KiB
Bash
93 lines
No EOL
2.6 KiB
Bash
#!/bin/bash
|
||
|
||
step_repos() {
|
||
print_section "Repositories"
|
||
log_step "Cloning repositories & configuring .env" 2 $TOTAL_STEPS
|
||
mkdir -p "$HV_BASE"
|
||
chmod 700 "$HV_BASE"
|
||
_clone_repos
|
||
_setup_env
|
||
}
|
||
_clone_repos() {
|
||
for name in core essentials cli gui; do
|
||
local url="${REPO_URLS[$name]}"
|
||
local branch="${REPO_BRANCHES[$name]}"
|
||
local dest="${REPO_DIRS[$name]}"
|
||
[ "$name" = "core" ] && dest="$HV_CORE"
|
||
[ "$name" = "cli" ] && dest="$HV_CLI"
|
||
[ "$name" = "essentials" ] && dest="$HV_ESSENTIALS"
|
||
[ "$name" = "gui" ] && dest="$HV_GUI"
|
||
|
||
if [ -d "$dest/.git" ]; then
|
||
log_warn "Repo already exists: ${dest}"
|
||
if ask_confirm "Delete and re-clone ${name}?"; then
|
||
rm -rf "$dest"
|
||
else
|
||
log_skip "Re-clone skipped — using ${dest}"
|
||
continue
|
||
fi
|
||
fi
|
||
|
||
start_spinner "Cloning ${name} (branch: ${branch})..."
|
||
if git clone --branch "$branch" "$url" "$dest" ; then
|
||
stop_spinner "${name} cloned → ${dest}"
|
||
else
|
||
stop_spinner
|
||
log_error "git clone failed: ${url}"
|
||
exit 1
|
||
fi
|
||
|
||
chmod 700 "$dest"
|
||
done
|
||
}
|
||
|
||
_setup_env() {
|
||
local env_file="$HV_CORE/.env"
|
||
local example_file="$HV_CORE/.env.example"
|
||
|
||
if [ ! -f "$example_file" ]; then
|
||
log_error ".env.example not found: ${example_file}"
|
||
exit 1
|
||
fi
|
||
|
||
if [ -f "$env_file" ]; then
|
||
log_warn ".env already exists — overwriting"
|
||
fi
|
||
|
||
echo ""
|
||
printf " ${DIM}Fill in the variables. ENTER = leave empty.${RESET}\n"
|
||
print_divider
|
||
echo ""
|
||
|
||
select_option \
|
||
"APP_ENV — application environment" \
|
||
"local development / testing" \
|
||
"production production / real domain"
|
||
|
||
case "$SELECT_RESULT" in
|
||
0) _app_env="local" ;;
|
||
1) _app_env="production" ;;
|
||
*) _app_env="production" ;;
|
||
esac
|
||
|
||
echo ""
|
||
printf " ${BCYAN}┌─${RESET} ${BWHITE}SP_API_BASE_URL_PRODUCTION${RESET} ${DIM}e.g. https://fake.simplifiedprivacy.org/api/v1${RESET}\n"
|
||
printf " ${BCYAN}›${RESET} "
|
||
read -r _api_url < /dev/tty
|
||
|
||
cat > "$env_file" << EOF
|
||
APP_ENV=${_app_env}
|
||
SP_API_BASE_URL_LOCAL=http://simplifiedprivacy.test/api/v1
|
||
SP_API_BASE_URL_PRODUCTION=${_api_url}
|
||
HV_CORE_HOME=${HV_CORE}
|
||
INSTALL_DIR=${HOME}
|
||
CORE_DIR=${HV_CORE}
|
||
EOF
|
||
|
||
chmod 600 "$env_file"
|
||
|
||
log_ok "APP_ENV=${_app_env}"
|
||
[ -n "$_api_url" ] && log_ok "SP_API_BASE_URL_PRODUCTION=${_api_url}" || label_skip "SP_API_BASE_URL_PRODUCTION — empty"
|
||
log_ok "INSTALL_DIR=${HOME}"
|
||
log_ok ".env written → ${env_file}"
|
||
} |