-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvdat.sh
More file actions
executable file
·101 lines (83 loc) · 3.79 KB
/
vdat.sh
File metadata and controls
executable file
·101 lines (83 loc) · 3.79 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
# !/bin/bash
if [[ -e $1 && $1 =~ .*\.msi$ ]]; then
echo "Extracting $1"
# create a temporary directory and delete on exit
VDAT_TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$VDAT_TEMP_DIR"' EXIT
# copy the Fathom Connect installer to the temp directory
cp $1 $VDAT_TEMP_DIR/fathom_connect.msi
# Pull out vdat.exe from the Fathom Connect installer
## --rm -> remove container after run
## -v -> mount temporary directory to /VDAT in container
## ghcr.io/trackyverse/vdat sh -c -> run the following commands in a shell
## within the container
## msiextract fathom_connect.msi > /dev/null -> extract the .msi file and
## suppress output
## mv Innovasea/Fathom\ Connect/vdat.exe /VDAT/vdat.exe -> move the extracted
## vdat.exe file to the mounted directory
docker run --rm \
-v $VDAT_TEMP_DIR:/VDAT \
ghcr.io/trackyverse/vdat sh -c \
"msiextract fathom_connect.msi > /dev/null; \
mv Innovasea/Fathom\ Connect/vdat.exe /VDAT/vdat.exe;
rm -rf Innovasea"
# copy vdat.exe to current directory
cp $VDAT_TEMP_DIR/vdat.exe .
# clean up temporary directory
rm -rf $VDAT_TEMP_DIR
echo "vdat.exe extracted to $PWD"
# If the first argument is not an MSI, run vdat.exe with Wine
else
# Check that vdat.exe exists in the current directory
if [[ ! -e "vdat.exe" ]]; then
echo -e "vdat.exe not found in current directory."
exit 1
fi
# Expand the full path of the vdat.exe file
VDAT_FULL_PATH=$(readlink -f "vdat.exe")
# This is the base command to run vdat.exe with wine in the container
# ${*:1} is grabbing all of the arguments
# So, it assumes: ./vdat.sh <vdat args>
VDAT_CMD="wine vdat.exe ${*:1};"
# This is overly strict and needs to be updated to allow for more options
# Right now it doesnt allow for multiple convert options
# If vdat convert is being run and the 3rd argument is a .vdat or .vrl file, then
# build the docker command to mount the input file and output directory
# So, it assumes something like:
# ./vdat.sh convert --format=<format> <input.vdat>
if [[ $1 == "convert" && $3 =~ .*\.v(dat|rl)$ ]]; then
# If converting, we need to mount the input file to send it to the container
# AND mount an output directory to get the output files from the container
THINGS_TO_MOUNT="-v ${PWD}/vdat_out:/VDAT/vdat_out -v $(readlink -f $3):/VDAT/$(basename $3)"
if [[ $2 == "--format=csv.fathom" ]]; then
# Move the output CSV file to the mounted output directory and set permissions
VDAT_CMD+="mv ${3%.*}.csv /VDAT/vdat_out; chmod -R 666 /VDAT/vdat_out"
else
# Move the output folder to the mounted output directory and set permissions
VDAT_CMD+="mv ${3%.*}.csv-fathom-split /VDAT/vdat_out; chmod -R 666 /VDAT/vdat_out"
fi
elif [[ $1 == "inspect" ]]; then
# If inspecting, we need to mount the input file to send it to the container
THINGS_TO_MOUNT="-v $(readlink -f $2):/VDAT/$(basename $2)"
fi
# we need to ID host arch to get the correct build
HOST_ARCH=$(uname -m)
# Default docker platform option empty
DOCKER_PLATFORM=""
# If host is arm64 (M1, ect MACs), force amd64 for vdat since vdat is 86-64
if [ "$HOST_ARCH" = "aarch64" ] || [ "$HOST_ARCH" = "arm64" ]; then
DOCKER_PLATFORM="--platform linux/amd64"
fi
# Run the vdat.exe command in the container with wine
# --rm -> remove container after run
# -v ${VDAT_FULL_PATH}:/VDAT/vdat.exe -> mount vdat.exe to the container
# $THINGS_TO_MOUNT -> mount any input/output files or directories if needed
# ghcr.io/trackyverse/vdat sh -c "$VDAT_CMD" -> run the vdat command in a shell
# within the container
# add in docker platform
docker run --rm \
$DOCKER_PLATFORM \
-v ${VDAT_FULL_PATH}:/VDAT/vdat.exe \
$THINGS_TO_MOUNT \
ghcr.io/trackyverse/vdat sh -c "$VDAT_CMD"
fi