-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshmount.sh
executable file
·51 lines (45 loc) · 1.18 KB
/
shmount.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
47
48
49
50
51
#!/bin/bash
#
### Shell script dir mount
#
# Requires: shlog.sh
#
### To be sourced from other scripts
mount_mounts (){
MOUNTS=("$@")
for MOUNT in "${MOUNTS[@]}"; do
IFS="," read -r -a MOUNT_ARRAY <<< "${MOUNT}"
local MOUNT_UUID=${MOUNT_ARRAY[0]}
local MOUNT_DIR=${MOUNT_ARRAY[1]}
local MOUNT_FSTYPE=${MOUNT_ARRAY[2]:=auto}
local MOUNT_OPTS=${MOUNT_ARRAY[3]:=defaults}
if mountpoint -q "$MOUNT_DIR"; then
shlog -s datestamp "Skipping already mounted '$MOUNT_DIR'"
else
sudo mount -t "$MOUNT_FSTYPE" -o "$MOUNT_OPTS" -U "$MOUNT_UUID" "$MOUNT_DIR"
if [[ $? -ne 0 ]]; then
shlog -s datestamp "Failed to mount '$MOUNT_DIR'"
return 1
fi
fi
done
}
umount_mounts (){
MOUNTS=("$@")
# Mountpoints should be unmounted in reverse order, so reverse array
for i in "${MOUNTS[@]}"; do
MOUNTS_REV=("$i" "${MOUNTS_REV[@]}")
done
for MOUNT in "${MOUNTS_REV[@]}"; do
IFS="," read -r -a MOUNT_ARRAY <<< "${MOUNT}"
local MOUNT_UUID=${MOUNT_ARRAY[0]}
local MOUNT_DIR=${MOUNT_ARRAY[1]}
if mountpoint -q "$MOUNT_DIR"; then
sudo umount -q "$MOUNT_DIR"
if [[ $? -ne 0 ]]; then
shlog -s datestamp "Failed to umount '$MOUNT_DIR'"
return 1
fi
fi
done
}