From 6c193eb4b591326d8febd3dbebe0f9318c5c3c85 Mon Sep 17 00:00:00 2001 From: S Date: Sun, 1 Mar 2026 10:08:28 -0500 Subject: [PATCH] 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 --- setup/configure_env.sh | 60 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/setup/configure_env.sh b/setup/configure_env.sh index 82a55d5..e4616d6 100755 --- a/setup/configure_env.sh +++ b/setup/configure_env.sh @@ -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"