deploy: dynamic remote staging dir resolution for exegesis RPM SSH deploy
This commit is contained in:
1 parent
70a69ef647
commit
0d4b2a5d27
2 files changed
+76
-7
No files matched your search
@@ -227,16 +227,85 @@ if [[ "${SKIP_EXEGESIS_DEPLOY}" -eq 0 ]] && [[ -n "${EXEGESIS_HOST}" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
RPM_NAME="$(basename "${RPM_FILE}")"
|
||||
echo "[deploy] Found built RPM: ${RPM_FILE}"
|
||||
RPM_SIZE_BYTES="$(wc -c < "${RPM_FILE}" | tr -d '[:space:]')"
|
||||
MIN_STAGE_KB="$(( (RPM_SIZE_BYTES + 1023) / 1024 + 1024 ))"
|
||||
echo "[deploy] Found built RPM: ${RPM_FILE} (${RPM_SIZE_BYTES} bytes)"
|
||||
|
||||
echo "[deploy] Transferring ${RPM_NAME} to ${EXEGESIS_HOST}:/tmp/${RPM_NAME}..."
|
||||
scp "${RPM_FILE}" "${EXEGESIS_HOST}:/tmp/${RPM_NAME}"
|
||||
echo "[deploy] Resolving writable remote staging directory on ${EXEGESIS_HOST} (need >= ${MIN_STAGE_KB} KiB)..."
|
||||
REMOTE_STAGE_DIR="$(
|
||||
ssh -o BatchMode=yes -o ConnectTimeout=5 "${EXEGESIS_HOST}" bash -s -- "${MIN_STAGE_KB}" <<'EOF_STAGE'
|
||||
set -euo pipefail
|
||||
min_kb="${1:-2048}"
|
||||
home_dir="${HOME:-$(pwd)}"
|
||||
for cand in "/tmp" "${home_dir}/.cache/rpm-stage" "${home_dir}/rpm-stage"; do
|
||||
created_parent=0
|
||||
if [[ "${cand}" != "/tmp" ]]; then
|
||||
if [[ ! -d "${cand}" ]]; then
|
||||
mkdir -p "${cand}" || continue
|
||||
created_parent=1
|
||||
fi
|
||||
fi
|
||||
if [[ ! -d "${cand}" ]] || [[ ! -w "${cand}" ]]; then
|
||||
continue
|
||||
fi
|
||||
if mount_opts="$(findmnt -n -o OPTIONS -T "${cand}" 2>&1)"; then
|
||||
mount_opts="${mount_opts//[[:space:]]/}"
|
||||
case ",${mount_opts}," in
|
||||
*,noexec,*)
|
||||
if [[ "${created_parent}" -eq 1 ]]; then
|
||||
rmdir "${cand}" || true
|
||||
fi
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
avail_kb="$(df -Pk "${cand}" 2>&1 | awk 'NR==2 {print $4}')"
|
||||
case "${avail_kb}" in
|
||||
''|*[!0-9]*) avail_kb=0 ;;
|
||||
esac
|
||||
if [[ "${avail_kb}" -lt "${min_kb}" ]]; then
|
||||
if [[ "${created_parent}" -eq 1 ]]; then
|
||||
rmdir "${cand}" || true
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
if stage_dir="$(mktemp -d "${cand}/ingglish-exegesis-stage.XXXXXX" 2>&1)"; then
|
||||
if [[ -d "${stage_dir}" ]] && [[ -w "${stage_dir}" ]]; then
|
||||
printf '%s\n' "${stage_dir}"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [[ "${created_parent}" -eq 1 ]]; then
|
||||
rmdir "${cand}" || true
|
||||
fi
|
||||
done
|
||||
echo "[ERROR] Failed to resolve a writable remote staging directory with >= ${min_kb} KiB free and without noexec." >&2
|
||||
exit 1
|
||||
EOF_STAGE
|
||||
)"
|
||||
if [[ -z "${REMOTE_STAGE_DIR}" ]]; then
|
||||
echo "[ERROR] Remote staging directory resolution returned an empty path on ${EXEGESIS_HOST}." >&2
|
||||
exit 1
|
||||
fi
|
||||
REMOTE_RPM_PATH="${REMOTE_STAGE_DIR}/${RPM_NAME}"
|
||||
echo "[deploy] Using remote staging directory: ${REMOTE_STAGE_DIR}"
|
||||
|
||||
cleanup_remote_stage() {
|
||||
ssh -o BatchMode=yes -o ConnectTimeout=5 "${EXEGESIS_HOST}" "rm -rf '${REMOTE_STAGE_DIR}'; if [ -d \"\${HOME}/.cache/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/.cache/rpm-stage\" || true; fi; if [ -d \"\${HOME}/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/rpm-stage\" || true; fi" || true
|
||||
}
|
||||
|
||||
echo "[deploy] Transferring ${RPM_NAME} to ${EXEGESIS_HOST}:${REMOTE_RPM_PATH}..."
|
||||
if ! scp "${RPM_FILE}" "${EXEGESIS_HOST}:${REMOTE_RPM_PATH}"; then
|
||||
cleanup_remote_stage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[deploy] Installing/upgrading ${RPM_NAME} on ${EXEGESIS_HOST}..."
|
||||
INSTALL_CMD="rc=0; sudo rpm -Uvh --replacepkgs '${REMOTE_RPM_PATH}' || rc=\$?; rm -rf '${REMOTE_STAGE_DIR}'; if [ -d \"\${HOME}/.cache/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/.cache/rpm-stage\" || true; fi; if [ -d \"\${HOME}/rpm-stage\" ]; then rmdir --ignore-fail-on-non-empty \"\${HOME}/rpm-stage\" || true; fi; exit \${rc}"
|
||||
if [[ -t 0 ]]; then
|
||||
ssh -t "${EXEGESIS_HOST}" "sudo rpm -Uvh --replacepkgs /tmp/${RPM_NAME} && rm -f /tmp/${RPM_NAME}"
|
||||
ssh -t "${EXEGESIS_HOST}" "${INSTALL_CMD}"
|
||||
else
|
||||
ssh "${EXEGESIS_HOST}" "sudo rpm -Uvh --replacepkgs /tmp/${RPM_NAME} && rm -f /tmp/${RPM_NAME}"
|
||||
ssh "${EXEGESIS_HOST}" "${INSTALL_CMD}"
|
||||
fi
|
||||
|
||||
echo "[deploy] Running in-situ dry-run verification on ${EXEGESIS_HOST}..."
|
||||
|
||||
Reference in new issue
Block a user