-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit-sandbox.sh
executable file
·44 lines (31 loc) · 1.21 KB
/
init-sandbox.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
set -o errexit
# Params:
# $1: Sandbox directory path
# $2: Mirror
if [ $1 ]; then sandbox_path=${1%*/};
else sandbox_path="/opt/hoj-sandbox"; fi
if [ -d $sandbox_path ]; then rm -r $sandbox_path; fi
mkdir $sandbox_path;
mkdir $sandbox_path/rootfs;
rootfs=$sandbox_path/rootfs
# Mirrors:
# - Alpine: http://dl-cdn.alpinelinux.org
# - Tsinghua: https://mirrors.tuna.tsinghua.edu.cn
if [ $2 ]; then mirror_name="${2}";
else mirror_name="alpine"; fi
if [ $mirror_name == "alpine" ]; then mirror_url="http://dl-cdn.alpinelinux.org";
elif [ $mirror_name == "tuna" ]; then mirror_url="https://mirrors.tuna.tsinghua.edu.cn";
elif [ $mirror_name == "custom" ]; then mirror_url=${3%*/}; fi
download=$mirror_url"/alpine/v3.13/releases/x86_64/alpine-minirootfs-3.13.2-x86_64.tar.gz"
curl -L $download | tar -xzf - -C $rootfs
if [ $mirror_name == "tuna" ]; then
sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' $rootfs/etc/apk/repositories
fi
# Set DNS
echo -e 'nameserver 8.8.8.8\nnameserver 8.8.4.4' > $rootfs/etc/resolv.conf
# Install Packages
cp ./package-install.sh $rootfs/opt/
chroot $rootfs/ /opt/package-install.sh
# Setup Checker Env
cp ./third_party/hoj-testlib/lib/testlib.h $rootfs/usr/include/