diff --git a/README.md b/README.md new file mode 100644 index 0000000..f219245 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Sandbox RootFS NG +This is the sandbox's rootfs used by [syzoj-ng-judge](https://github.com/syzoj/syzoj-ng-judge). It's based on Ubuntu 20.04 and contains compilers (and interpreters) below: + +* GCC 10 +* Clang 11 (from [LLVM](https://apt.llvm.org/)) +* OpenJDK 11 +* Kotlin (from [SDKMAN!](https://kotlinlang.org/docs/tutorials/command-line.html)) +* Free Pascal 3 +* Python 2.7 (from [PPA](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa)) +* Python 3.6 +* Python 3.9 (from [PPA](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa)) +* Rust (from [Rustup](https://rustup.rs/)) +* Go (from [PPA](https://launchpad.net/~longsleep/+archive/ubuntu/golang-backports)) +* GHC (from [PPA](https://launchpad.net/~hvr/+archive/ubuntu/ghc)) +* C# (from [Mono](https://www.mono-project.com/download/stable/)) +* F# (from [Mono](https://www.mono-project.com/download/stable/)) + +Each compiler (or interpreter) is available in `$PATH`. It also contains [`testlib.h`](https://github.com/MikeMirzayanov/testlib) in `/usr/include`. + +You can download it from [release](https://github.com/syzoj/sandbox-rootfs-ng/releases) or bootstrap by yourself. + +# Bootstrapping +You'll need: + +* A Linux box with root privilege +* `arch-chroot` (usually in the package `arch-install-scripts`) +* `debootstrap` (some old version of Debian's `debootstrap` couldn't bootstrap Ubuntu 20.04) + +First, clone this repo: + +```bash +git clone git@github.com:syzoj/sandbox-rootfs-ng.git +cd sandbox-rootfs-ng +``` + +Set the path to bootstrap rootfs. If there're anything inside it, it'll be `rm -rf`-ed. If the path doesn't exist, it'll be `mkdir -p`-ed. + +```bash +export ROOTFS_PATH=/rootfs-ng +``` + +If you're root, just run the `bootstrap.sh` script: + +```bash +./bootstrap.sh +``` + +Or if you use `sudo`, remember to preserve the `ROOTFS_PATH` environment variable with `-E` option: + +```bash +sudo -E ./bootstrap.sh +``` diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..47180b8 --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +INSTALL_SCRIPT="install.sh" + +cd "$(dirname "$0")" + +set -e + +if [[ "$UID" != "0" ]]; then + echo This script must be run with root privileges. + exit 1 +fi + +if ! arch-chroot -h >/dev/null 2>&1; then + echo "You need arch-chroot to run this script." + echo "Usually it's in the package "'"'"arch-install-scripts"'".' + exit 1 +fi + +if ! debootstrap --version >/dev/null 2>&1; then + echo "You need debootstrap to run this script." + exit 1 +fi + +if [[ "$ROOTFS_PATH" == "" ]]; then + echo "Please specify the path to put rootfs on with ROOTFS_PATH." + exit 1 +fi + +if [[ "$MIRROR" == "" ]]; then + MIRROR="https://mirrors.tuna.tsinghua.edu.cn/ubuntu" +fi + +rm -rf "$ROOTFS_PATH" +mkdir -p "$ROOTFS_PATH" +debootstrap --components=main,universe focal "$ROOTFS_PATH" "$MIRROR" + +cp "$INSTALL_SCRIPT" "$ROOTFS_PATH/root" +arch-chroot "$ROOTFS_PATH" "/root/$INSTALL_SCRIPT" +rm "$ROOTFS_PATH/root/$INSTALL_SCRIPT" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..3d2f9c9 --- /dev/null +++ b/install.sh @@ -0,0 +1,68 @@ +#!/bin/bash -e + +# Fix PATH environment variable +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + +# Set Locale +sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen +locale-gen +export LC_ALL=en_US.UTF-8 +echo 'LC_ALL=en_US.UTF-8' > /etc/default/locale + +# Create sandbox user and directories +useradd -r sandbox -d /sandbox -m +mkdir -p /sandbox/{binary,source,working} + +# Add focal-updates source +ORIGINAL_SOURCE=$(head -n 1 /etc/apt/sources.list) +sed 's/focal/focal-updates/' <<< "$ORIGINAL_SOURCE" >> /etc/apt/sources.list + +# Install dependencies +apt-get update +apt-get dist-upgrade -y +apt-get install -y gnupg ca-certificates curl wget locales unzip zip git + +# Key: LLVM repo +wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - +# Key: Python repo +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BA6932366A755776 +# Key: Go repo +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys F6BC817356A3D45E +# Key: Haskell repo +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys FF3AEACEF6F88286 +# Key: Mono repo +apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF + +# Add sources +echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main" > /etc/apt/sources.list.d/llvm.list +echo "deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main" > /etc/apt/sources.list.d/python.list +echo "deb http://ppa.launchpad.net/longsleep/golang-backports/ubuntu focal main" > /etc/apt/sources.list.d/go.list +echo "deb http://ppa.launchpad.net/hvr/ghc/ubuntu focal main" > /etc/apt/sources.list.d/haskell.list +echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" > /etc/apt/sources.list.d/mono.list + +# Install some language support via APT +apt-get update +apt-get install -y g++-10-multilib gcc-10-multilib clang-11 libc++-11-dev libc++abi-11-dev openjdk-11-jdk fpc python2.7 python3.6 python3.9 golang-go ghc mono-devel fsharp + +# Install Rust via Rustup +su sandbox -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y" + +# Install Kotlin via SDKMAN! +su sandbox -c "curl -s https://get.sdkman.io | bash" +su sandbox -s /bin/bash -c "source ~/.sdkman/bin/sdkman-init.sh && sdk install kotlin" + +# Create symlinks for compilers and interpreters with non-common names and locations +ln -s /usr/bin/g++-10 /usr/local/bin/g++ +ln -s /usr/bin/gcc-10 /usr/local/bin/gcc +ln -s /usr/bin/clang-11 /usr/local/bin/clang +ln -s /usr/bin/clang++-11 /usr/local/bin/clang++ +ln -s /sandbox/.sdkman/candidates/kotlin/current/bin/kotlin /usr/local/bin/kotlin +ln -s /sandbox/.sdkman/candidates/kotlin/current/bin/kotlinc /usr/local/bin/kotlinc +ln -s /sandbox/.cargo/bin/rustc /usr/local/bin/rustc + +# Clean the APT cache +apt-get clean + +# Install testlib +git clone https://github.com/MikeMirzayanov/testlib /tmp/testlib +cp /tmp/testlib/testlib.h /usr/include/