mauvehed's dotfiles for personal and work environments
at main 167 lines 4.8 kB view raw
1#!/usr/bin/env bash 2set -euo pipefail 3 4BASE_DIR="/Users/nate/gitwork/github/mauvehed" 5FORGEJO_BASE="git@git:mauvehed" 6 7# Format: "local_dir|forgejo_repo_name" 8# Standard repos (local dir name = forgejo repo name) 9REPOS=( 10 "aha-art|aha-art" 11 "bm_monitor|bm_monitor" 12 "discord_bot|discord_bot" 13 "dotfiles|dotfiles" 14 "fly-tailscale-exit|fly-tailscale-exit" 15 "fork_auto_update|fork_auto_update" 16 "fuckery|fuckery" 17 "github-gitea-mirror|github-gitea-mirror" 18 "homelab|homelab" 19 "infra|infra" 20 "k0mvh.io|k0mvh.io" 21 "kevvy|kevvy" 22 "kevvy-web|kevvy-web" 23 "komodo|komodo" 24 "mauve.haus|mauve.haus" 25 "matrix-takeonme|matrix-takeonme" 26 "mauvecraft|mauvecraft" 27 "mauveRANT|mauveRANT" 28 "mkdocs|mkdocs" 29 "mvh.dev|mvh.dev" 30 "nate.fail|nate.fail" 31 "pixelfed-import|pixelfed-import" 32 "samcrow|samcrow" 33 "slidev|slidev" 34 "starred|starred" 35 "tailscale|tailscale" 36 "terraform|terraform" 37 "tf-matrix-synapse|tf-matrix-synapse" 38 "trackerstatus|trackerstatus" 39 "trackerstatus_discord|trackerstatus_discord" 40 "ubuntu-server|ubuntu-server" 41 "yourip|yourip" 42 # Name mismatches (local dir name differs from forgejo repo name) 43 "github-runner|GitHub-runner" 44 "HackerNewsDiscordFeed|hackernewsdiscordfeed" 45 "mauvehed-README|mauvehed" 46 "mauvehed.github.io-ARCHIVED|mauvehed.github.io" 47 "reaper-bot|discord-activity" 48 "ombi-redirect|omni-redirect" 49) 50 51MODE="dry-run" 52if [[ "${1:-}" == "--execute" ]]; then 53 MODE="execute" 54fi 55 56migrate_repo() { 57 local local_dir="$1" 58 local forgejo_repo="$2" 59 local repo_path="${BASE_DIR}/${local_dir}" 60 local forgejo_url="${FORGEJO_BASE}/${forgejo_repo}.git" 61 62 if [[ ! -d "${repo_path}/.git" ]]; then 63 echo "[SKIP] ${local_dir} -- not a git repo" 64 return 65 fi 66 67 local current_origin 68 current_origin=$(git -C "$repo_path" remote get-url origin 2>/dev/null || echo "") 69 70 if [[ -z "$current_origin" ]]; then 71 echo "[SKIP] ${local_dir} -- no origin remote" 72 return 73 fi 74 75 if [[ "$current_origin" == *"git@git:"* ]]; then 76 echo "[SKIP] ${local_dir} -- origin already points to Forgejo (${current_origin})" 77 return 78 fi 79 80 local has_github 81 has_github=$(git -C "$repo_path" remote get-url github 2>/dev/null || echo "") 82 83 if [[ -n "$has_github" ]]; then 84 echo "[SKIP] ${local_dir} -- github remote already exists (${has_github})" 85 return 86 fi 87 88 if [[ "$MODE" == "dry-run" ]]; then 89 echo "[WOULD] ${local_dir}" 90 echo " rename origin -> github (${current_origin})" 91 echo " add origin (${forgejo_url})" 92 else 93 git -C "$repo_path" remote rename origin github 94 git -C "$repo_path" remote add origin "$forgejo_url" 95 echo "[DONE] ${local_dir}" 96 echo " github = ${current_origin}" 97 echo " origin = ${forgejo_url}" 98 fi 99} 100 101echo "=== Migrate GitHub Remotes to Forgejo ===" 102echo "Mode: ${MODE}" 103echo "" 104 105for entry in "${REPOS[@]}"; do 106 IFS='|' read -r local_dir forgejo_repo <<< "$entry" 107 migrate_repo "$local_dir" "$forgejo_repo" 108done 109 110# --- Homelab submodule migration --- 111echo "" 112echo "=== Homelab Submodules ===" 113echo "" 114 115HOMELAB_PATH="${BASE_DIR}/homelab" 116 117# Format: "submodule_section_name|new_url" 118# Section names from .gitmodules (may differ from path) 119SUBMODULES=( 120 "websites/mauve.haus|git@git:mauvehed/mauve.haus.git" 121 "websites/mauvehed.github.io|git@git:mauvehed/mauvehed.github.io.git" 122 "websites/mauveRANT|git@git:mauvehed/mauveRANT.git" 123 "websites/chezmoi|git@git:mauvehed/chezmoi.git" 124 "websites/watchkeepers.org|git@git:mauvehed/watchkeepers.org.git" 125 "websites/ombi-redirect|git@git:mauvehed/omni-redirect.git" 126 "scripts/ansible|git@git:mauvehed/ansible.git" 127 "shell-config/dotfiles|git@git:mauvehed/dotfiles.git" 128) 129 130for entry in "${SUBMODULES[@]}"; do 131 IFS='|' read -r sub_name new_url <<< "$entry" 132 133 current_url=$(git -C "$HOMELAB_PATH" config --file .gitmodules --get "submodule.${sub_name}.url" 2>/dev/null || echo "") 134 135 if [[ -z "$current_url" ]]; then 136 echo "[SKIP] ${sub_name} -- not found in .gitmodules" 137 continue 138 fi 139 140 if [[ "$current_url" == *"git@git:"* ]]; then 141 echo "[SKIP] ${sub_name} -- already points to Forgejo (${current_url})" 142 continue 143 fi 144 145 if [[ "$MODE" == "dry-run" ]]; then 146 echo "[WOULD] ${sub_name}" 147 echo " ${current_url}" 148 echo " -> ${new_url}" 149 else 150 git -C "$HOMELAB_PATH" config --file .gitmodules "submodule.${sub_name}.url" "$new_url" 151 echo "[DONE] ${sub_name}" 152 echo " ${current_url} -> ${new_url}" 153 fi 154done 155 156if [[ "$MODE" == "execute" ]]; then 157 git -C "$HOMELAB_PATH" submodule sync 158 echo "" 159 echo "Ran 'git submodule sync' in homelab." 160 echo "NOTE: .gitmodules has been modified but NOT committed." 161 echo " Review and commit when ready." 162fi 163 164echo "" 165if [[ "$MODE" == "dry-run" ]]; then 166 echo "Dry-run complete. Run with --execute to apply changes." 167fi