-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoom.sh
More file actions
executable file
·138 lines (117 loc) · 4.74 KB
/
Copy pathdoom.sh
File metadata and controls
executable file
·138 lines (117 loc) · 4.74 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
# Copyright (c) 2024, The ATARI-DOOM Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#==
# Configurations
#==
# Exits if error occurs
set -e
# Set tab-spaces
tabs 4
#==
# Helper functions
#==
# print the usage description
print_help () {
echo -e "\nusage: $(basename "$0") [-h] [-i] -- Utility to manage ATARI DOOM."
echo -e "\noptional arguments:"
echo -e "\t-h, --help Display the help content."
echo -e "\t-i, --install Install ATARI DOOM, build docker container and setup network interface with Go2."
echo -e "\t-b, --build Build the docker image."
echo -e "\t-e, --enter Enter the DOOM docker container."
echo -e "\t-d, --delete Delete all existing DOOM docker containers and images."
echo -e "\t-a, --attach Attach shell to existing DOOM docker container."
echo -e "\n" >&2
}
# check argument provided
if [ -z "$*" ]; then
echo "[Error] No arguments provided." >&2;
print_help
exit 1
fi
# Pass the arguments
while [[ $# -gt 0 ]]; do
# Read the key
case "$1" in
-i|--install)
# Get submodules
git submodule update --init --recursive
# Build Docker Image if it doesn't exist
if ! docker image inspect mujuni-image >/dev/null 2>&1; then
echo "Building Docker image 'mujuni-image'..."
docker build --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) -t mujuni-image unitree_mujoco_container/.devcontainer/.
else
echo "Docker image 'mujuni-image' already exists. Skipping build."
fi
# Check if the network interface already exists, and add it only if it doesn't
if ! nmcli con show | grep -q "$NETWORK_INTERFACE"; then
echo "Adding network interface for $NETWORK_INTERFACE..."
sudo nmcli con add type ethernet ifname $NETWORK_INTERFACE ipv4.addresses 192.168.123.1/24 ipv4.method manual
else
echo "Network interface '$NETWORK_INTERFACE' already exists. Skipping network setup."
fi
shift
;;
-b|--build)
# Build Docker Image if it doesn't exist
if ! docker image inspect mujuni-image >/dev/null 2>&1; then
echo "Building Docker image 'mujuni-image'..."
docker build --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) -t mujuni-image unitree_mujoco_container/.devcontainer/.
else
echo "Docker image 'mujuni-image' already exists. Skipping build."
fi
shift
;;
-e|--enter)
# Check if a container with the same name exists
CONTAINER_NAME="DOOM" # Replace with your container's desired name
if ! docker ps -a --format '{{.Names}}' | grep -q "$CONTAINER_NAME"; then
# If container doesn't exist, create and start a new container
xhost +local:root & \
docker run --shm-size=2g -it --privileged \
--env-file .env.docker \
--network host \
--device /dev/input \
--group-add 107 \
--user $(id -u):$(id -g) \
--gpus all \
-e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix \
-v /dev/shm:/dev/shm \
-v $PWD/src:/home/atari/workspace/DOOM/src \
-v $HOME/.Xauthority:/root/.Xauthority \
-v $PWD/.vscode:/home/atari/workspace/.vscode \
-v $PWD/pyproject.toml:/home/atari/workspace/pyproject.toml \
--env XAUTHORITY=/root/.Xauthority \
--name $CONTAINER_NAME mujuni-image
else
# If container exists, just start it
echo "Container $CONTAINER_NAME already exists. Starting the container..."
docker start -i $CONTAINER_NAME
fi
shift
;;
-d|--delete)
# Enter the docker container
docker container prune -f
docker image prune -f
docker rmi mujuni-image
shift
;;
-a|--attach)
# Attach shell to existing docker container
docker exec -it $(docker ps --filter "ancestor=mujuni-image" -q | head -n 1) /bin/bash
shift
;;
-h|--help)
print_help
exit 1
;;
*) # Unknown option
echo "[Error] Invalid argument provided: $1"
print_help
exit 1
;;
esac
done