forked from rene-d/mini-kali
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·74 lines (61 loc) · 1.91 KB
/
run.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
#!/usr/bin/env bash
progname=$(basename "$0")
# run the native container (amd64/i386)
function run()
{
exec docker run --rm -ti --label ${IMAGE_NAME} --hostname ${IMAGE_NAME} -v "$PWD":/${IMAGE_NAME} --cap-add=SYS_PTRACE ${IMAGE_NAME} $*
}
# run the arm/v7 container
function arm()
{
exec docker run --rm -ti --label ${IMAGE_NAME} --hostname ${IMAGE_NAME} -v "$PWD":/${IMAGE_NAME} --cap-add=SYS_PTRACE -e flavor=arm ${IMAGE_NAME}:arm $*
}
# run the arm64 container
function arm64()
{
exec docker run --rm -ti --label ${IMAGE_NAME} --hostname ${IMAGE_NAME} -v "$PWD":/${IMAGE_NAME} --cap-add=SYS_PTRACE -e flavor=arm64 ${IMAGE_NAME}:arm64 $*
}
# run the crypto/SageMath container
function crypto()
{
exec docker run --rm -ti --label ${IMAGE_NAME} --hostname ${IMAGE_NAME} -v "$PWD":/${IMAGE_NAME} -e flavor=crypto ${IMAGE_NAME}:crypto $*
}
# attach to a running container
function attach()
{
if [[ "$1" == "-h" ]]; then
echo "Usage: $progname [-h | list | <n>]"
exit
fi
if [[ "$1" == "list" ]]; then
docker container ls --filter 'label=${IMAGE_NAME}' --format '{{.ID}}\t{{.Status}}\t{{.Image}}\t{{.Command}}'
exit
fi
declare -a ids
ids=($(docker container ls --format '{{.ID}}' --filter 'label=${IMAGE_NAME}'))
nb=${#ids[@]}
if [ "${nb}" -eq 1 ]; then
n=0
elif [[ "$1" == "" ]]; then
echo "${nb} containers are running, please choose one"
exit
else
n=$(($1))
if [ $n -lt 0 -o $n -ge $nb ]; then
echo "Invalid container number ($n), should be 0 ≤ n < ${nb}"
exit
fi
fi
exec docker exec -ti -e instance=$n ${ids[$n]} bash
}
if [[ "$progname" =~ ^.*\-attach$ ]]; then
attach $*
elif [[ "$progname" =~ ^.*\-arm$ ]]; then
arm $*
elif [[ "$progname" =~ ^.*\-arm64$ ]]; then
arm64 $*
elif [[ "$progname" =~ ^.*\-crypto$ ]]; then
crypto $*
else
run $*
fi