99 lines
4.3 KiB
Bash
99 lines
4.3 KiB
Bash
|
|
# Legacy Hecate migration helpers for the Ananke installer.
|
||
|
|
|
||
|
|
legacy_path_rewrite() {
|
||
|
|
local src="$1"
|
||
|
|
local dst="$2"
|
||
|
|
sed \
|
||
|
|
-e 's#/etc/hecate/hecate.yaml#/etc/ananke/ananke.yaml#g' \
|
||
|
|
-e 's#/etc/hecate/kubeconfig#/etc/ananke/kubeconfig#g' \
|
||
|
|
-e 's#/var/lib/hecate/vault-unseal.key#/var/lib/ananke/vault-unseal.key#g' \
|
||
|
|
-e 's#/var/lib/hecate/hecate.lock#/var/lib/ananke/ananke.lock#g' \
|
||
|
|
-e 's#/opt/hecate#/opt/ananke#g' \
|
||
|
|
-e 's#/etc/hecate#/etc/ananke#g' \
|
||
|
|
-e 's#/var/lib/hecate#/var/lib/ananke#g' \
|
||
|
|
-e 's#/usr/local/bin/hecate#/usr/local/bin/ananke#g' \
|
||
|
|
-e 's#/usr/local/lib/hecate#/usr/local/lib/ananke#g' \
|
||
|
|
-e 's/hecate.yaml/ananke.yaml/g' \
|
||
|
|
-e 's/hecate.lock/ananke.lock/g' \
|
||
|
|
-e 's/hecate/ananke/g' \
|
||
|
|
-e 's/Hecate/Ananke/g' \
|
||
|
|
-e 's#hecate\.lock#ananke.lock#g' \
|
||
|
|
"${src}" > "${dst}"
|
||
|
|
}
|
||
|
|
|
||
|
|
migrate_legacy_hecate_install() {
|
||
|
|
local legacy_conf_dir="/etc/hecate"
|
||
|
|
local legacy_state_dir="/var/lib/hecate"
|
||
|
|
local legacy_systemd_dir="/etc/systemd/system"
|
||
|
|
|
||
|
|
install -d -m 0750 "${CONF_DIR}"
|
||
|
|
install -d -m 0750 "${STATE_DIR}"
|
||
|
|
|
||
|
|
if [[ ! -f "${CONF_DIR}/ananke.yaml" && -f "${legacy_conf_dir}/hecate.yaml" ]]; then
|
||
|
|
echo "[install] migrating legacy config ${legacy_conf_dir}/hecate.yaml -> ${CONF_DIR}/ananke.yaml"
|
||
|
|
legacy_path_rewrite "${legacy_conf_dir}/hecate.yaml" "${CONF_DIR}/ananke.yaml"
|
||
|
|
chmod 0640 "${CONF_DIR}/ananke.yaml"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ ! -f "${CONF_DIR}/kubeconfig" && -f "${legacy_conf_dir}/kubeconfig" ]]; then
|
||
|
|
echo "[install] migrating legacy kubeconfig ${legacy_conf_dir}/kubeconfig -> ${CONF_DIR}/kubeconfig"
|
||
|
|
install -m 0600 "${legacy_conf_dir}/kubeconfig" "${CONF_DIR}/kubeconfig"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ ! -f "${STATE_DIR}/vault-unseal.key" && -f "${legacy_state_dir}/vault-unseal.key" ]]; then
|
||
|
|
echo "[install] migrating legacy vault key ${legacy_state_dir}/vault-unseal.key -> ${STATE_DIR}/vault-unseal.key"
|
||
|
|
install -m 0600 "${legacy_state_dir}/vault-unseal.key" "${STATE_DIR}/vault-unseal.key"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ ! -f "${STATE_DIR}/runs.json" && -f "${legacy_state_dir}/runs.json" ]]; then
|
||
|
|
echo "[install] migrating legacy run history ${legacy_state_dir}/runs.json -> ${STATE_DIR}/runs.json"
|
||
|
|
install -m 0640 "${legacy_state_dir}/runs.json" "${STATE_DIR}/runs.json"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ ! -f "${STATE_DIR}/intent.json" && -f "${legacy_state_dir}/intent.json" ]]; then
|
||
|
|
echo "[install] migrating legacy intent state ${legacy_state_dir}/intent.json -> ${STATE_DIR}/intent.json"
|
||
|
|
install -m 0640 "${legacy_state_dir}/intent.json" "${STATE_DIR}/intent.json"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ ! -f "${STATE_DIR}/ananke.lock" && -f "${legacy_state_dir}/hecate.lock" ]]; then
|
||
|
|
echo "[install] migrating legacy lock ${legacy_state_dir}/hecate.lock -> ${STATE_DIR}/ananke.lock"
|
||
|
|
install -m 0640 "${legacy_state_dir}/hecate.lock" "${STATE_DIR}/ananke.lock"
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ -d "${legacy_systemd_dir}" ]]; then
|
||
|
|
if ls "${legacy_systemd_dir}"/hecate*.service >/dev/null 2>&1 || ls "${legacy_systemd_dir}"/hecate*.timer >/dev/null 2>&1; then
|
||
|
|
echo "[install] detected legacy hecate systemd unit files; will retire after ananke install"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
retire_legacy_hecate_install() {
|
||
|
|
local ts backup_dir
|
||
|
|
ts="$(date +%Y%m%d%H%M%S)"
|
||
|
|
backup_dir="/var/backups/ananke-legacy-hecate-${ts}"
|
||
|
|
|
||
|
|
systemctl disable --now hecate.service hecate-bootstrap.service hecate-update.timer >/dev/null 2>&1 || true
|
||
|
|
systemctl stop hecate-update.service >/dev/null 2>&1 || true
|
||
|
|
|
||
|
|
if [[ -d /etc/hecate || -d /var/lib/hecate || -d /usr/local/lib/hecate || -d /opt/hecate ]]; then
|
||
|
|
install -d -m 0750 "${backup_dir}"
|
||
|
|
[[ -d /etc/hecate ]] && cp -a /etc/hecate "${backup_dir}/" || true
|
||
|
|
[[ -d /var/lib/hecate ]] && cp -a /var/lib/hecate "${backup_dir}/" || true
|
||
|
|
[[ -d /usr/local/lib/hecate ]] && cp -a /usr/local/lib/hecate "${backup_dir}/" || true
|
||
|
|
[[ -d /opt/hecate ]] && cp -a /opt/hecate "${backup_dir}/" || true
|
||
|
|
[[ -f /usr/local/bin/hecate ]] && install -m 0755 /usr/local/bin/hecate "${backup_dir}/hecate.bin" || true
|
||
|
|
echo "[install] backed up legacy hecate assets to ${backup_dir}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
rm -f \
|
||
|
|
/etc/systemd/system/hecate.service \
|
||
|
|
/etc/systemd/system/hecate-bootstrap.service \
|
||
|
|
/etc/systemd/system/hecate-update.service \
|
||
|
|
/etc/systemd/system/hecate-update.timer
|
||
|
|
rm -f /usr/local/bin/hecate
|
||
|
|
rm -rf /usr/local/lib/hecate
|
||
|
|
rm -rf /opt/hecate
|
||
|
|
rm -rf /etc/hecate
|
||
|
|
rm -rf /var/lib/hecate
|
||
|
|
}
|