64 lines
1.9 KiB
Bash
64 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
IFS=$'\n\t'
|
|
|
|
APPS_REPO="${APPS_REPO:-/DATA/AppData/k3d-lab/git/apps-registry}"
|
|
PLATFORM_REPO="${PLATFORM_REPO:-/DATA/AppData/k3d-lab/git/platform-infra}"
|
|
CONFIRM_RETIRE_HEADLAMP="${CONFIRM_RETIRE_HEADLAMP:-false}"
|
|
|
|
find_application_files() {
|
|
local repo="$1"
|
|
local app_name="$2"
|
|
|
|
grep -RIl \
|
|
--exclude-dir=.git \
|
|
--include='*.yaml' \
|
|
--include='*.yml' \
|
|
-E "name:[[:space:]]*${app_name}([[:space:]]|$)" \
|
|
"$repo" 2>/dev/null || true
|
|
}
|
|
|
|
APP_FILES="$(find_application_files "$APPS_REPO" headlamp-app)"
|
|
GOV_FILES="$(find_application_files "$PLATFORM_REPO" headlamp-governance)"
|
|
|
|
printf 'apps-registry:\n'
|
|
printf ' workload: %s\n' "${APPS_REPO}/workloads/headlamp"
|
|
printf '%s\n' "$APP_FILES" | sed '/^$/d;s/^/ application: /'
|
|
|
|
printf 'platform-infra:\n'
|
|
printf '%s\n' "$GOV_FILES" | sed '/^$/d;s/^/ application: /'
|
|
find "$PLATFORM_REPO" \
|
|
-path '*/.git' -prune -o \
|
|
-type d -name headlamp-governance -print 2>/dev/null |
|
|
sed 's/^/ governance: /'
|
|
|
|
if [[ "$CONFIRM_RETIRE_HEADLAMP" != "true" ]]; then
|
|
printf '\nDRY-RUN. Usa CONFIRM_RETIRE_HEADLAMP=true para retirar las rutas detectadas.\n'
|
|
exit 0
|
|
fi
|
|
|
|
if [[ -d "${APPS_REPO}/workloads/headlamp" ]]; then
|
|
git -C "$APPS_REPO" rm -r workloads/headlamp
|
|
fi
|
|
|
|
while IFS= read -r file; do
|
|
[[ -n "$file" ]] || continue
|
|
git -C "$APPS_REPO" rm "${file#${APPS_REPO}/}"
|
|
done <<< "$APP_FILES"
|
|
|
|
while IFS= read -r file; do
|
|
[[ -n "$file" ]] || continue
|
|
git -C "$PLATFORM_REPO" rm "${file#${PLATFORM_REPO}/}"
|
|
done <<< "$GOV_FILES"
|
|
|
|
while IFS= read -r directory; do
|
|
[[ -n "$directory" ]] || continue
|
|
git -C "$PLATFORM_REPO" rm -r "${directory#${PLATFORM_REPO}/}"
|
|
done < <(
|
|
find "$PLATFORM_REPO" \
|
|
-path '*/.git' -prune -o \
|
|
-type d -name headlamp-governance -print 2>/dev/null
|
|
)
|
|
|
|
printf '\nCambios preparados. Revisa git diff, haz commit y push en ambos repositorios.\n'
|