svarbox/scripts/prepare-svardos.sh

40 lines
1.2 KiB
Bash
Raw Normal View History

2025-10-18 11:47:07 +03:00
#!/bin/bash
set -euo pipefail
2025-10-18 20:34:07 +03:00
SVARDOS_ROOT="${SVARDOS_ROOT:-/opt/svardos}"
SVARDOS_BASE_DIR="${SVARDOS_BASE_DIR:-${SVARDOS_ROOT}/base}"
DEFAULT_URL="http://svardos.org/download/20250427/svardos-20250427-dosemu.zip"
ARCHIVE_URL="${SVARDOS_IMG_URL:-$DEFAULT_URL}"
2025-10-18 11:47:07 +03:00
2025-10-18 20:34:07 +03:00
# Skip work if the base tree already exists (unless SVARDOS_REFRESH is set)
if [ -z "${SVARDOS_REFRESH:-}" ] && [ -e "${SVARDOS_BASE_DIR}/COMMAND.COM" ]; then
2025-10-18 11:47:07 +03:00
exit 0
fi
2025-10-18 20:34:07 +03:00
mkdir -p "${SVARDOS_BASE_DIR}"
tmpdir="$(mktemp -d)"
cleanup() {
rm -rf "${tmpdir}"
}
trap cleanup EXIT
2025-10-18 11:47:07 +03:00
2025-10-18 20:34:07 +03:00
archive_path="${tmpdir}/svardos.zip"
unpack_dir="${tmpdir}/unpacked"
2025-10-18 11:47:07 +03:00
2025-10-18 20:34:07 +03:00
echo "Fetching SvarDOS base from ${ARCHIVE_URL}"
curl -fsSL "${ARCHIVE_URL}" -o "${archive_path}"
2025-10-18 11:47:07 +03:00
2025-10-18 20:34:07 +03:00
unzip -q "${archive_path}" -d "${unpack_dir}"
2025-10-18 11:47:07 +03:00
2025-10-18 20:34:07 +03:00
# Some archives might unpack into a single top-level directory; flatten it if so.
if [ "$(find "${unpack_dir}" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 1 ] && \
[ "$(find "${unpack_dir}" -mindepth 1 -maxdepth 1 | wc -l)" -eq 1 ]; then
unpack_dir="$(find "${unpack_dir}" -mindepth 1 -maxdepth 1 -type d)"
2025-10-18 11:47:07 +03:00
fi
2025-10-18 20:34:07 +03:00
rm -rf "${SVARDOS_BASE_DIR:?}/"*
cp -a "${unpack_dir}/." "${SVARDOS_BASE_DIR}/"
2025-10-18 11:47:07 +03:00
echo "SvarDOS base copied to ${SVARDOS_BASE_DIR}"