Added setup-build-host.sh

This commit is contained in:
2026-04-28 00:15:32 +08:00
parent ee890a5494
commit 1d45b07e1a
2 changed files with 75 additions and 0 deletions

73
devtools/setup-bulid-host.sh Executable file
View File

@@ -0,0 +1,73 @@
#!/usr/bin/env bash
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root, e.g. sudo $0" >&2
exit 1
fi
. /etc/os-release
if [ "${ID:-}" != "debian" ]; then
echo "This script is intended for Debian. Detected ID=${ID:-unknown}" >&2
exit 1
fi
echo "==> Removing conflicting Docker packages, if present"
apt-get remove -y \
docker.io \
docker-compose \
docker-doc \
podman-docker \
containerd \
runc || true
echo "==> Installing minimal repo setup tools"
apt-get update
apt-get install -y --no-install-recommends \
ca-certificates \
curl
echo "==> Adding Docker official APT repo"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg \
-o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
cat > /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/debian
Suites: ${VERSION_CODENAME}
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
echo "==> Installing build/test packages"
apt-get update
apt-get install -y --no-install-recommends \
docker-ce \
docker-buildx-plugin \
qemu-user-static \
binfmt-support \
make
echo "==> Enabling Docker"
systemctl enable --now docker
echo "==> Registering binfmt handlers"
systemctl restart binfmt-support || true
echo "==> Docker version"
docker --version
echo "==> Buildx version"
docker buildx version || true
echo "==> Done"
echo
echo "Optional: allow your normal user to run docker without sudo:"
echo " sudo usermod -aG docker \$USER"
echo "Then log out and back in."