forked from fuzztruction/fuzztruction
-
Notifications
You must be signed in to change notification settings - Fork 5
/
start.sh
executable file
·99 lines (83 loc) · 2.53 KB
/
start.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
set -eu
set -o pipefail
cd $(dirname $0)
source config.sh
cd ..
function yes_no() {
if [[ "$1" == "yes" || "$1" == "y" ]]; then
return 0
else
return 1
fi
}
if use_prebuilt; then
container_name=$PREBUILT_CONTAINER_NAME
else
container_name=$CONTAINER_NAME
fi
container="$(docker ps --filter="name=^/$container_name$" --latest --quiet)"
if [[ -n "$container" ]]; then
# Connect to already running container
log_success "[+] Found running instance: $container, connecting..."
cmd="docker start $container"
log_success "[+] $cmd"
$cmd > /dev/null
if [[ -v NO_TTY ]]; then
HAS_TTY=""
else
HAS_TTY="-t"
fi
cmd="docker exec -i $HAS_TTY --workdir /home/user/fuzztruction $container zsh"
log_success "[+] $cmd"
$cmd
exit 0
fi
touch "$PWD/data/bash_history"
touch "$PWD/data/zsh_history"
mkdir -p "$PWD/data/ccache"
mkdir -p "$PWD/data/vscode-data"
mkdir -p "$PWD/eval-result"
log_success "[+] Creating new container..."
mounts=""
if use_prebuilt; then
log_success "[+] Using prebuilt image"
else
log_success "[+] Using locally build image"
mounts+=" -v $PWD:/home/user/fuzztruction "
fi
mounts+=" -v $PWD:/shared "
cmd="docker run -ti -d --privileged
$mounts
-v $PWD/data/zshrc:/home/user/.zshrc
-v $PWD/data/zsh_history:/home/user/.zsh_history
-v $PWD/data/bash_history:/home/user/.bash_history
-v $PWD/data/init.vim:/home/user/.config/nvim/init.vim
-v $PWD/data/ccache:/ccache
-v $PWD/data/vscode-data:/home/user/.config/Code
-v $PWD/eval-result:/home/user/fuzztruction/eval-result
--mount type=tmpfs,destination=/tmp,tmpfs-mode=777
--ulimit msgqueue=2097152000
--shm-size=64G
--net=host
--name $container_name
--env "PREBUILT_ENV_VAR_NAME=$PREBUILT_ENV_VAR_NAME"
--env "$PREBUILT_ENV_VAR_NAME=${!PREBUILT_ENV_VAR_NAME:-}" "
if [[ ! -z "${SSH_AUTH_SOCK:-}" ]]; then
log_success "[+] Forwarding ssh agent ($SSH_AUTH_SOCK -> /ssh-agent)"
cmd+="-v $(readlink -f "$SSH_AUTH_SOCK"):/ssh-agent --env SSH_AUTH_SOCK=/ssh-agent"
fi
# Use local gitconfig if any
if [[ -f "/home/$USER/.gitconfig" ]]; then
cmd+=" -v /home/$USER/.gitconfig:/home/user/.gitconfig"
fi
if use_prebuilt; then
log_success "[+] Using $PREBUILT_IMAGE_NAME as docker image"
cmd+=" ${PREBUILT_IMAGE_NAME}"
else
log_success "[+] Using $IMAGE_NAME as docker image"
cmd+=" ${IMAGE_NAME}"
fi
log_success "[+] $(echo $cmd | xargs)"
$cmd > /dev/null
log_success "[+] Rerun $0 to connect to the new container."