-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
executable file
·46 lines (38 loc) · 1.23 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
#!/bin/bash
# Use default user in the Dockerfile
user=$(grep '^ARG username' Dockerfile | awk -F'[ =]' '{print $3}')
# Set the working directory and name of the Docker container
workdir="/home/$user/lab"
image_name="trng"
container_name="test_${image_name}"
# Build the Docker image
docker build -t "$image_name" .
# If the build failed, exit with an error
if [ $? -ne 0 ]; then
echo "Docker build failed" >&2
exit 2
fi
# Get the device file for the RTL-SDR dongle
device=$(lsusb | grep RTL2838 | awk '{print "/dev/bus/usb/" $2 "/" $4}' | tr -d ':')
# Check if the device file exists
if [ ! -e "$device" ]; then
echo "Device not found, running without device" >&2
device="/dev/null"
fi
# Run the Docker in detached mode
docker run \
--detach \
--name "$container_name" \
--hostname "$container_name" \
--device "$device" \
--network host \
--volume "$PWD:$workdir" \
--workdir "$workdir" \
-it \
--rm \
"$image_name"
# If the Docker run failed, exit with an error
if [ $? -ne 0 ]; then
echo "Docker run failed" >&2
exit 3
fi