-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_runner.sh
More file actions
executable file
·72 lines (55 loc) · 1.64 KB
/
docker_runner.sh
File metadata and controls
executable file
·72 lines (55 loc) · 1.64 KB
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
#!/bin/bash
scriptdir=$(cd $(dirname $0) && pwd)
workdir="/home/cracker"
image=hashcracker:latest
run() {
echo "$*"
"$@" || exit $?
}
usage() {
echo "usage: $(basename "$0") [OPTIONS]"
echo " options:"
echo " -h|--help - Show this help menu"
echo " -t|--terminal - Open the terminal on the container"
echo " -r|--run - Run the program"
echo ""
}
main() {
if ! OPTS=$(getopt -o 'htr' --long help,terminal,run -n 'parse-options' -- "$@"); then
err "Failed parsing options." >&2
usage
exit 1
fi
eval set -- "$OPTS"
while true; do
case "$1" in
-h | --help) usage; exit 0; shift ;;
-t | --terminal) TERMINAL="-it"; shift ;;
-r | --run) RUN="--entrypoint ./build/bin/hashCracker"; shift ;;
-- ) shift; break ;;
* ) err "unsupported argument $1"; usage; exit 1 ;;
esac
done
image="hashcracker:latest"
# Default docker arguments
docker_args=(
# Automatically remove the container when it exits
--rm
# Working directory inside the container
--workdir "${workdir}"
# Bind mount a volume. Binds the host directory to the docker.
# It is possible to replace "${scriptdir}" with "/" and get access to all files on
# the machine.
-v "${scriptdir}:${workdir}"
)
if [ -n "$TERMINAL" ]; then
docker_args+=("${TERMINAL}")
fi
if [ -n "$RUN" ]; then
docker_args+=(${RUN})
fi
run docker run "${docker_args[@]}" hashcracker:latest
}
TERMINAL=""
RUN=""
main "$@"