你说的 fetchlinux 脚本,通常是指自动从网络下载 Linux 相关资源(如 ISO、内核、工具、配置等)的 shell 脚本。下面我从「思路 → 基础模板 → 进阶示例」一步步说明,你可以直接套用。
一个 fetchlinux 脚本一般包含:
#!/bin/bash
URL="https://releases.ubuntu.com/22.04/ubuntu-22.04.4-live-server-amd64.iso"
OUT_DIR="$HOME/linux_iso"
OUT_FILE="ubuntu.iso"
mkdir -p "$OUT_DIR"
if command -v wget > /dev/null; then
wget -O "$OUT_DIR/$OUT_FILE" "$URL"
elif command -v curl > /dev/null; then
curl -L -o "$OUT_DIR/$OUT_FILE" "$URL"
else
echo "需要 wget 或 curl"
exit 1
fi
echo "下载完成:$OUT_DIR/$OUT_FILE"
wget -c -O "$OUT_DIR/$OUT_FILE" "$URL"
或 curl:
curl -C - -L -o "$OUT_DIR/$OUT_FILE" "$URL"
#!/bin/bash
URL="https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.10.tar.xz"
SHA_URL="${URL}.sha256"
OUT_DIR="$HOME/linux_src"
OUT_FILE="linux.tar.xz"
mkdir -p "$OUT_DIR"
wget -O "$OUT_DIR/$OUT_FILE" "$URL"
wget -O "$OUT_DIR/$OUT_FILE.sha256" "$SHA_URL"
cd "$OUT_DIR"
sha256sum -c "$OUT_FILE.sha256"
if [ $? -eq 0 ]; then
echo "校验成功"
else
echo "校验失败"
rm -f "$OUT_FILE"
fi
#!/bin/bash
echo "选择 Linux 版本:"
echo "1) Ubuntu 22.04"
echo "2) Debian 12"
read -p "输入数字:" choice
case $choice in
1) URL="https://releases.ubuntu.com/22.04/ubuntu-22.04.4-live-server-amd64.iso" ;;
2) URL="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.4.0-amd64-netinst.iso" ;;
*) echo "无效选择"; exit 1 ;;
esac
wget -c "$URL"
ARCH=$(uname -m)
export https_proxy=http://127.0.0.1:7890
wget -q "$URL"
fetchlinux.sh
├── 参数解析
├── URL 配置
├── 下载工具选择
├── 校验
└── 清理 / 提示
如果你能告诉我:
我可以直接帮你写一个完整可用的 fetchlinux 脚本。