forked from compiler-explorer/infra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmount-all-img.sh
More file actions
executable file
·30 lines (25 loc) · 793 Bytes
/
Copy pathmount-all-img.sh
File metadata and controls
executable file
·30 lines (25 loc) · 793 Bytes
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
#!/bin/bash
set -euo pipefail
IMG_DIR=/efs/squash-images
MOUNT_DIR=/opt/compiler-explorer
shopt -s globstar
declare -A mounts
for img_file in "${IMG_DIR}"/**/*.img; do
dst_path=${img_file/${IMG_DIR}/${MOUNT_DIR}}
dst_path=${dst_path%.img}
if mountpoint -q "$dst_path"; then
echo "$dst_path is mounted already, skipping"
else
mounts["$img_file"]="$dst_path"
fi
done
if [ -z "${!mounts[*]}" ]; then
echo "Nothing to do, stopping"
exit
fi
# If we try and do this in the loop, the mountpoint and mount commands effectively
# serialise and we end up blocking until the whole thing's done.
for img_file in "${!mounts[@]}"; do
dst_path="${mounts[$img_file]}"
echo mount -v -t squashfs "${img_file}" "${dst_path}" -o ro,nodev,relatime
done | xargs -d'\n' -n1 -P16 sh -c