feat: dynamic repo count in configure_env.sh wizard

Replace 3 hardcoded REPO_N_NAME prompts with:
- "How many repos?" prompt
- Loop for each repo name
- Saves as space-delimited REPO_NAMES in .env
TOTAL_PROMPTS computed dynamically after repo count is known.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
S
2026-03-01 10:08:28 -05:00
parent e564a99937
commit 6c193eb4b5

View File

@@ -64,7 +64,8 @@ get_env_val() {
# ---------------------------------------------------------------------------
# Prompt function
# ---------------------------------------------------------------------------
TOTAL_PROMPTS=56
# Base prompt count (fixed prompts only — repo prompts added dynamically)
TOTAL_PROMPTS=53
CURRENT_PROMPT=0
LAST_SECTION=""
@@ -262,9 +263,58 @@ prompt_var "BACKUP_RETENTION_COUNT" "Number of backup archives to keep"
# --- REPOSITORIES ---
prompt_var "GITHUB_USERNAME" "GitHub username or org name" nonempty "" "REPOSITORIES"
prompt_var "GITHUB_TOKEN" "GitHub PAT with repo scope (read+write)" nonempty "" "REPOSITORIES"
prompt_var "REPO_1_NAME" "First repo name (exact match)" nonempty "" "REPOSITORIES"
prompt_var "REPO_2_NAME" "Second repo name (exact match)" nonempty "" "REPOSITORIES"
prompt_var "REPO_3_NAME" "Third repo name (exact match)" nonempty "" "REPOSITORIES"
# Dynamic repo collection — ask how many, then prompt for each
printf '\n%b── REPOSITORIES ─────────────────────────────────────────%b\n' "$C_BOLD" "$C_RESET"
LAST_SECTION="REPOSITORIES"
# Determine existing repo count from .env
EXISTING_REPOS=$(get_env_val "REPO_NAMES" "")
EXISTING_COUNT=0
if [[ -n "$EXISTING_REPOS" ]]; then
# shellcheck disable=SC2086
set -- $EXISTING_REPOS
EXISTING_COUNT=$#
fi
CURRENT_PROMPT=$((CURRENT_PROMPT + 1))
printf '%b[%d/~%d]%b How many repos to migrate? %b[%s]%b: ' "$C_DIM" "$CURRENT_PROMPT" "$TOTAL_PROMPTS" "$C_RESET" "$C_YELLOW" "${EXISTING_COUNT:-3}" "$C_RESET"
read -r REPO_COUNT
if [[ -z "$REPO_COUNT" ]]; then REPO_COUNT="${EXISTING_COUNT:-3}"; fi
while ! [[ "$REPO_COUNT" =~ ^[1-9][0-9]*$ ]]; do
printf '%b Invalid: must be a positive integer%b\n' "$C_RED" "$C_RESET"
printf 'How many repos to migrate? '
read -r REPO_COUNT
done
# Update total now that we know how many repos
TOTAL_PROMPTS=$((TOTAL_PROMPTS + 1 + REPO_COUNT))
# Collect repo names
COLLECTED_REPOS=""
# shellcheck disable=SC2086
set -- $EXISTING_REPOS
for ((i = 1; i <= REPO_COUNT; i++)); do
CURRENT_PROMPT=$((CURRENT_PROMPT + 1))
local_default="${1:-}"
shift 2>/dev/null || true
if [[ -n "$local_default" ]]; then
printf '%b[%d/~%d]%b Repo %d name %b[%s]%b: ' "$C_DIM" "$CURRENT_PROMPT" "$TOTAL_PROMPTS" "$C_RESET" "$i" "$C_YELLOW" "$local_default" "$C_RESET"
else
printf '%b[%d/~%d]%b Repo %d name: ' "$C_DIM" "$CURRENT_PROMPT" "$TOTAL_PROMPTS" "$C_RESET" "$i"
fi
read -r repo_name
if [[ -z "$repo_name" ]]; then repo_name="$local_default"; fi
while [[ -z "$repo_name" ]]; do
printf '%b Invalid: repo name cannot be empty%b\n' "$C_RED" "$C_RESET"
printf 'Repo %d name: ' "$i"
read -r repo_name
done
if [[ -n "$COLLECTED_REPOS" ]]; then
COLLECTED_REPOS="${COLLECTED_REPOS} ${repo_name}"
else
COLLECTED_REPOS="${repo_name}"
fi
done
write_env_var "REPO_NAMES" "$COLLECTED_REPOS"
prompt_var "MIGRATE_ISSUES" "Migrate GitHub issues" bool "false" "REPOSITORIES"
prompt_var "MIGRATE_LABELS" "Migrate GitHub labels" bool "true" "REPOSITORIES"
prompt_var "MIGRATE_MILESTONES" "Migrate GitHub milestones" bool "false" "REPOSITORIES"
@@ -319,7 +369,7 @@ printf ' Unraid: %s@%s:%s\n' "$(get_env_val UNRAID_SSH_USER)" "$(get_env_va
printf ' Fedora: %s@%s:%s\n' "$(get_env_val FEDORA_SSH_USER)" "$(get_env_val FEDORA_IP)" "$(get_env_val FEDORA_SSH_PORT 22)"
printf ' Gitea: %s (admin: %s, password: ****)\n' "$(get_env_val GITEA_DOMAIN)" "$(get_env_val GITEA_ADMIN_USER)"
printf ' Org: %s\n' "$(get_env_val GITEA_ORG_NAME)"
printf ' Repos: %s, %s, %s\n' "$(get_env_val REPO_1_NAME)" "$(get_env_val REPO_2_NAME)" "$(get_env_val REPO_3_NAME)"
printf ' Repos: %s\n' "$(get_env_val REPO_NAMES)"
printf ' TLS/SSL: %s\n' "${COLLECTED_SSL_MODE}"
printf ' .env saved: %s\n\n' "$ENV_FILE"