Files
dwarf-fortress-annals/scripts/install-df.sh
T

62 lines
1.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 在 Windows 侧安装 矮人要塞 免费版 + DFHack(经 WSL 的 /mnt/c 操作,免管理员权限)
#
# scripts/install-df.sh 安装/校验
# scripts/install-df.sh --download 重新下载缺的文件
set -euo pipefail
WIN_USER="${WIN_USER:-23518}"
ROOT="/mnt/c/Users/${WIN_USER}/DwarfFortress"
DF_ZIP="df_53_16_win.zip"
DFHACK_ZIP="dfhack-53.16-r2-Windows-64bit.zip"
DF_URL="https://www.bay12games.com/dwarves/${DF_ZIP}"
DFHACK_URL="https://github.com/DFHack/dfhack/releases/download/53.16-r2/${DFHACK_ZIP}"
mkdir -p "$ROOT"
cd "$ROOT"
download() {
local url="$1" out="$2"
echo "== 下载 $out"
for _ in $(seq 1 300); do
wget -c -q --timeout=30 --tries=2 -O "$out" "$url" && return 0
sleep 5
done
echo "下载失败:$url" >&2
return 1
}
if [[ "${1:-}" == "--download" ]]; then
[[ -s "$DF_ZIP" ]] || download "$DF_URL" "$DF_ZIP"
[[ -s "$DFHACK_ZIP" ]] || download "$DFHACK_URL" "$DFHACK_ZIP"
fi
for f in "$DF_ZIP" "$DFHACK_ZIP"; do
[[ -s "$f" ]] || { echo "缺少 $f(先跑 --download)" >&2; exit 1; }
unzip -t "$f" >/dev/null || { echo "$f 已损坏" >&2; exit 1; }
done
echo "== 解压游戏本体"
DF_DIR="$(unzip -Z1 "$DF_ZIP" | head -1 | cut -d/ -f1)"
if [[ ! -d "$DF_DIR" ]]; then
unzip -q -o "$DF_ZIP"
fi
echo " 游戏目录:$ROOT/$DF_DIR"
echo "== 解压 DFHack(覆盖进游戏目录)"
unzip -q -o "$DFHACK_ZIP" -d "$DF_DIR"
echo "== 校验"
ls -1 "$DF_DIR" | head -20
if [[ -f "$DF_DIR/Dwarf Fortress.exe" ]]; then
echo " ✓ 启动器存在:Dwarf Fortress.exe"
else
echo " ✗ 未找到 Dwarf Fortress.exe" >&2
fi
if [[ -d "$DF_DIR/dfhack-config" && -d "$DF_DIR/hack" ]]; then
echo " ✓ DFHack 已就位(hack/ + dfhack-config/)"
else
echo " ✗ DFHack 目录缺失" >&2
fi
echo "$ROOT/$DF_DIR"