-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcuc
executable file
·41 lines (33 loc) · 1.07 KB
/
dcuc
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
#!/usr/bin/env bash
# Dasharo Configuration Utility Container
SCRIPT_DIR=$(dirname "$(readlink -f ${BASH_SOURCE[0]})")
DOCKER_IMAGE="ghcr.io/dasharo/dasharo-sdk:v1.5.0"
# Initialize an array to store Docker arguments
DOCKER_ARGS=()
# Initialize an array to store the command to be executed in the container
COMMAND_ARGS=()
# Function to add a bind mount for a file
add_bind_mount() {
local FILE_PATH=$1
local ABS_PATH=""
local DIR_PATH=""
ABS_PATH=$(realpath "$FILE_PATH")
DIR_PATH=$(dirname "$ABS_PATH")
DOCKER_ARGS+=("-v" "$DIR_PATH:$DIR_PATH")
echo "$ABS_PATH"
}
# Iterate over the command line arguments
for ARG in "$@"; do
if [[ -f "$ARG" ]]; then
# Convert the file path to an absolute path and add a bind mount
ABS_PATH=$(add_bind_mount "$ARG")
COMMAND_ARGS+=("$ABS_PATH")
else
COMMAND_ARGS+=("$ARG")
fi
done
if [[ -v CI ]]; then
../dcu "${COMMAND_ARGS[@]}"
else
docker run -t --rm -v "${SCRIPT_DIR}:${SCRIPT_DIR}" "${DOCKER_ARGS[@]}" -w "${SCRIPT_DIR}" $DOCKER_IMAGE ./dcu "${COMMAND_ARGS[@]}"
fi