This commit is contained in:
randogoth 2025-10-18 11:47:07 +03:00
parent 48372efb6d
commit daae8bd74e
9 changed files with 184 additions and 34 deletions

115
scripts/dos-shell Executable file
View file

@ -0,0 +1,115 @@
#!/bin/bash
# /usr/local/bin/dos-shell
# 1) reset C: drive contents to only the allowed files
# 2) launch dosemu with /cdrive mounted as C:
set -euo pipefail
ALLOWED_LIST="/etc/dos_allowed"
ALLOWED_REPO="/opt/allowed_repo" # repository of allowed DOS files stored in container
C_DRIVE="/cdrive"
ENV_DIR="/etc/dos_env"
AUTOEXEC_TEMPLATE="${ENV_DIR}/AUTOEXEC.BAT"
CONFIG_TEMPLATE="${ENV_DIR}/CONFIG.SYS"
SVARDOS_BASE="/opt/svardos/base"
ALLOW_MODE="${DOS_ALLOW_MODE:-all}" # default to exposing everything from the repo
if [ "$(id -u)" -eq 0 ] && [ ! -d "${ENV_DIR}" ]; then
mkdir -p "${ENV_DIR}"
fi
# clear C: drive to ensure only allowed programs are present
rm -rf "${C_DRIVE:?}/"*
mkdir -p "${C_DRIVE}"
# Seed the C: drive with the SvarDOS base image
if [ -e "${SVARDOS_BASE}/COMMAND.COM" ] || [ -e "${SVARDOS_BASE}/command.com" ]; then
cp -a "${SVARDOS_BASE}/." "${C_DRIVE}/"
else
echo "SvarDOS base not found in ${SVARDOS_BASE}. Aborting." >&2
exit 1
fi
# Sync additional DOS files into the C: drive
allowed_entries=()
case "${ALLOW_MODE}" in
all)
if [ -d "${ALLOWED_REPO}" ] && [ "$(ls -A "${ALLOWED_REPO}")" ]; then
cp -a "${ALLOWED_REPO}/." "${C_DRIVE}/"
fi
;;
list|allowlist)
;;
*)
echo "Unknown DOS_ALLOW_MODE '${ALLOW_MODE}', falling back to allowlist mode." >&2
ALLOW_MODE="list"
;;
esac
if [ "${ALLOW_MODE}" != "all" ]; then
if [ -f "${ALLOWED_LIST}" ]; then
while IFS= read -r line || [ -n "$line" ]; do
# trim whitespace
line="$(printf '%s' "$line" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
# skip blank/comment lines
case "$line" in
''|\#*) continue ;;
esac
allowed_entries+=("$line")
done < "${ALLOWED_LIST}"
fi
for entry in "${allowed_entries[@]}"; do
src="${ALLOWED_REPO}/${entry}"
if [ -e "$src" ]; then
dst_dir="$(dirname "${entry}")"
mkdir -p "${C_DRIVE}/${dst_dir}"
cp -a "$src" "${C_DRIVE}/${dst_dir}/"
else
echo "Warning: allowed file not found: $src" >&2
fi
done
fi
# Optional: create an AUTOEXEC.BAT and CONFIG.SYS or other DOS boot files
autoexec_path="${C_DRIVE}/AUTOEXEC.BAT"
config_path="${C_DRIVE}/CONFIG.SYS"
if [ -f "${AUTOEXEC_TEMPLATE}" ]; then
cp "${AUTOEXEC_TEMPLATE}" "${autoexec_path}"
else
cat > "${autoexec_path}" <<'EOF'
@echo off
prompt [DOS]$P$G
echo Welcome to the containerized DOS environment.
EOF
fi
if [ "${ALLOW_MODE}" = "all" ]; then
printf 'echo All repository programs are currently enabled.\r\n' >> "${autoexec_path}"
elif [ ${#allowed_entries[@]} -gt 0 ]; then
{
printf 'echo Allowed programs:\r\n'
for entry in "${allowed_entries[@]}"; do
dos_entry="${entry//\//\\}"
printf 'echo %s\r\n' "${dos_entry}"
done
} >> "${autoexec_path}"
else
{
printf 'echo No extra programs are currently enabled.\r\n'
} >> "${autoexec_path}"
fi
if [ -f "${CONFIG_TEMPLATE}" ]; then
cp "${CONFIG_TEMPLATE}" "${config_path}"
fi
# Drop privileges to dosuser if we were run as root (ssh will run as the user)
# but in case sshd runs ForceCommand as root, we switch.
if [ "$(id -u)" -eq 0 ]; then
exec runuser -u dosuser -- dosemu -quiet -K "${C_DRIVE}"
else
# running as the user already
exec dosemu -quiet -K "${C_DRIVE}"
fi

View file

@ -0,0 +1,79 @@
#!/bin/bash
set -euo pipefail
SVARDOS_BASE_DIR="/opt/svardos/base"
SVARDOS_CACHE="/opt/svardos/cache"
SVARDOS_IMG="${SVARDOS_CACHE}/svardos.img"
DEFAULT_REL="download/20250427/svardos-20250427-floppy-1.44M.zip"
DEFAULT_BASE="http://svardos.org"
if [ -z "${SVARDOS_IMG_URL:-}" ]; then
homepage="$(
curl -fsSL "${DEFAULT_BASE}/" 2>/dev/null || true
)"
discovered_rel=""
if [ -n "$homepage" ]; then
for pattern in 'download/[0-9]+/svardos-[0-9]+-floppy-1\.44M\.zip' 'download/[0-9]+/svardos-[0-9]+-usb\.zip'; do
candidate="$(printf '%s' "$homepage" | grep -Eo "$pattern" | head -n1)"
if [ -n "$candidate" ]; then
discovered_rel="$candidate"
break
fi
done
fi
if [ -n "$discovered_rel" ]; then
SVARDOS_IMG_URL="${DEFAULT_BASE}/${discovered_rel}"
else
SVARDOS_IMG_URL="${DEFAULT_BASE}/${DEFAULT_REL}"
fi
fi
if [ -e "${SVARDOS_BASE_DIR}/COMMAND.COM" ] || [ -e "${SVARDOS_BASE_DIR}/command.com" ]; then
exit 0
fi
mkdir -p "${SVARDOS_BASE_DIR}" "${SVARDOS_CACHE}"
tmp_archive="${SVARDOS_CACHE}/svardos_download"
rm -f "${tmp_archive}" "${SVARDOS_IMG}"
echo "Fetching SvarDOS base from ${SVARDOS_IMG_URL}"
curl -fsSL "${SVARDOS_IMG_URL}" -o "${tmp_archive}"
mime_type="$(file -b --mime-type "${tmp_archive}")"
case "${mime_type}" in
application/zip)
unzip -o "${tmp_archive}" -d "${SVARDOS_CACHE}" >/dev/null
;;
application/x-bzip2|application/x-gzip|application/x-xz)
tar -xf "${tmp_archive}" -C "${SVARDOS_CACHE}"
;;
application/octet-stream)
# assume this is already a raw image
cp "${tmp_archive}" "${SVARDOS_IMG}"
;;
*)
echo "Unsupported SvarDOS payload type: ${mime_type}" >&2
exit 1
;;
esac
if [ ! -f "${SVARDOS_IMG}" ]; then
# try to locate the image file
candidate="$(find "${SVARDOS_CACHE}" -maxdepth 1 -type f \( -iname '*svardos*.img' -o -iname '*.ima' -o -iname '*.img' \) | head -n1)"
if [ -z "${candidate}" ]; then
echo "Could not locate a SvarDOS disk image after extraction." >&2
exit 1
fi
mv "${candidate}" "${SVARDOS_IMG}"
fi
rm -rf "${SVARDOS_BASE_DIR}"/*
mkdir -p "${SVARDOS_BASE_DIR}"
# Copy contents of FAT image into the base directory
mcopy -s -i "${SVARDOS_IMG}" ::* "${SVARDOS_BASE_DIR}/"
rm -f "${SVARDOS_IMG}" "${tmp_archive}"
rm -rf "${SVARDOS_CACHE}"
echo "SvarDOS base copied to ${SVARDOS_BASE_DIR}"

20
scripts/start-services.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/bash
set -euo pipefail
TELNET_PORT="${TELNET_PORT:-23}"
TELNET_LOGIN="${TELNET_LOGIN:-/bin/login}"
TELNETD_BIN="${TELNETD_BIN:-/bin/busybox}"
ENABLE_TELNET="${ENABLE_TELNET:-1}"
if [ "$ENABLE_TELNET" = "1" ]; then
if [ ! -x "$TELNETD_BIN" ]; then
echo "Telnet disabled: telnetd binary not found at $TELNETD_BIN" >&2
else
echo "Starting telnetd on port $TELNET_PORT"
if ! "$TELNETD_BIN" telnetd -p "$TELNET_PORT" -l "$TELNET_LOGIN"; then
echo "Warning: failed to launch telnetd; SSH remains available." >&2
fi
fi
fi
exec /usr/sbin/sshd -D -e