Skip to content

Instantly share code, notes, and snippets.

@shankerwangmiao
Last active March 30, 2023 15:06
Show Gist options
  • Save shankerwangmiao/042bc81b7d9571d937932de2e561c6e8 to your computer and use it in GitHub Desktop.
Save shankerwangmiao/042bc81b7d9571d937932de2e561c6e8 to your computer and use it in GitHub Desktop.
#!/bin/bash
DOCKER=docker
if [ "$(id --user)" != "0" ]; then
DOCKER="sudo $DOCKER"
fi
MIRROR=http://mirrors.tuna.tsinghua.edu.cn/debian
: ${NAME="$(basename "$(readlink -f .)")-dev"}
: ${RELEASE="stable"}
IMAGE="debian:$RELEASE"
$DOCKER pull "$IMAGE"
$DOCKER run --name "$NAME" --volume "$PWD:$PWD" --user "$(id --user):$(id --group)" --detach --workdir "$PWD" "$IMAGE" bash -c "exec sleep infinity"
$DOCKER exec --interactive --user 0:0 --env "RELEASE=$RELEASE" --env "MIRROR=$MIRROR" "$NAME" bash -s "$@" << 'EOF'
for i in "" "-updates" "-backports"; do
for j in "deb" "deb-src"; do
echo "$j $MIRROR ${RELEASE}$i main contrib non-free"
done
done > /etc/apt/sources.list
apt-get update
apt-get -y install vim devscripts
apt-get -y build-dep "$@"
EOF
echo $DOCKER exec -it "\"$NAME\"" bash
exec $DOCKER exec -it "$NAME" bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment