-
Notifications
You must be signed in to change notification settings - Fork 0
/
exegol
executable file
·111 lines (102 loc) · 2.82 KB
/
exegol
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
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
test -f ~/.exegol && source ~/.exegol
function help () {
echo
echo "# Exegol"
echo
echo "bootstrap [env] : bootstrap an exegol environment."
echo "destroy [env] : destroy an exegol environment."
echo "help [env] : displays this help."
echo "replay [env] [args] : run sudoreplay commands against an exegol environment."
echo "shell [env] : start shell in container of the environment."
echo "status : display running environments."
echo
exit 0
}
function bootstrap () {
test -z $1 && echo "bootstrap: Specify environment and site to bootstrap." && return 1
test -z "$AWS_CREDS" && AWS_CREDS=sudoreplay-global
test -z "$S3_BUCKET_PREFIX" && S3_BUCKET_PREFIX=
test -z "$S3_BUCKET_SUFFIX" && S3_BUCKET_SUFFIX=-sudoreplay-storage
test -z "$S3_BUCKET" && S3_BUCKET="$S3_BUCKET_PREFIX$1$S3_BUCKET_SUFFIX"
echo -n "bootstrap: launching docker container for $1... "
docker run -ti -d --rm \
--name "exegol_$1" \
--privileged \
-v $HOME/.aws:/root/.aws:ro \
-v /etc/localtime:/etc/localtime:ro \
ghcr.io/kronostechnologies/exegol:latest \
/usr/bin/s3fs "$S3_BUCKET" /var/log/sudo-io/ \
-f -d -o use_sse -o use_cache=/tmp -o enable_content_md5 -o stat_cache_expire=30 \
-o profile=$AWS_CREDS 1> /dev/null
sleep 1 && docker inspect "exegol_$1" > /dev/null 2>&1
if (( $? == 0 )); then
echo "done"
return 0
else
echo "failed"
return 1
fi
}
function destroy () {
test -z $1 && echo "destroy: Specify environment and site to destroy." && return 1
CONTAINER_NAME="exegol_$1"
echo -n "destroy: taking down container for $1... "
docker rm -f "$CONTAINER_NAME" 1> /dev/null
echo "done"
shift
(( "$#" != 0 )) && destroy $@
return 0
}
function replay () {
test -z $1 && echo "replay: Specify environment and site to replay." && return 1
CONTAINER_NAME="exegol_$1"
echo "replay: running sudoreplay against $1 environment..."
shift
docker exec -ti "$CONTAINER_NAME" /usr/bin/sudoreplay "$@"
return $?
}
function shell () {
test -z $1 && echo "shell: Specify environment and site to replay." && return 1
CONTAINER_NAME="exegol_$1"
shift
echo "shell: running shell against \"$CONTAINER_NAME\"..."
docker exec -ti "$CONTAINER_NAME" /bin/bash
return $?
}
function status () {
RUNNING=$(docker ps --all --filter "name=exegol_" --format "{{.Names}} - {{.Status }}")
if test -z "$RUNNING"; then
echo "No environment to list."
else
echo "Exegol environments"
echo -e "${RUNNING//exegol_/}"
fi
return 0
}
test -z "$1" && help
case "$1" in
"bootstrap")
shift
bootstrap $@
;;
"destroy")
shift
destroy $@
;;
"replay")
shift
replay $@
;;
"shell")
shift
shell $@
;;
"status")
shift
status
;;
*)
help
;;
esac