-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.sh
More file actions
47 lines (39 loc) · 1003 Bytes
/
device.sh
File metadata and controls
47 lines (39 loc) · 1003 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
VERSION="20260416"
# Library for managing devices
mount_device_at_path() {
local device=$1 mount=$2 dir=$3
# Ensure mount point exists
if [ ! -d "$mount" ]; then
sudo mkdir -p "$mount" > /dev/null
if [ $? -ne 0 ]; then
showx "Unable to locate or create '$mount'." >&2
exit 2
fi
fi
# Attempt to mount the device
sudo mount "$device" "$mount" > /dev/null
if [ $? -ne 0 ]; then
showx "Unable to mount the device '$device'." >&2
exit 2
fi
if [ -n "$dir" ] && [ ! -d "$mount/$dir" ]; then
# Ensure the directory structure exists
sudo mkdir "$mount/$dir" > /dev/null
if [ $? -ne 0 ]; then
showx "Unable to locate or create '$mount/$dir'." >&2
exit 2
fi
fi
}
unmount_device_at_path() {
local path=$1
# Unmount if mounted
if mountpoint -q "$path"; then
sudo umount "$path" > /dev/null
if [ $? -ne 0 ]; then
showx "Unable to locate or unmount '$path'." >&2
exit 2
fi
fi
}