-
Notifications
You must be signed in to change notification settings - Fork 1
/
dev_mount.sh
executable file
·61 lines (51 loc) · 1.79 KB
/
dev_mount.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
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
usb_mount() {
# Ask for sudo password
sudo -v
# List all block devices with more details for debugging
echo "Debug: Listing all block devices with details"
lsblk -a -o NAME,FSTYPE,LABEL,SIZE,TYPE,MOUNTPOINT
echo
# Filter for partitions and display for debugging
echo "Debug: Listing partitions"
PARTITIONS=$(lsblk -dpno NAME,TYPE | grep -E '/dev/sd[b-z][1-9] .*part')
echo "$PARTITIONS"
echo
# If no partitions found, try listing whole disks
if [ -z "$PARTITIONS" ]; then
echo "No partitions found, listing whole disks."
PARTITIONS=$(lsblk -dpno NAME,TYPE | grep -E '/dev/sd[b-z] .*disk')
echo "$PARTITIONS"
echo
fi
# Select partition or whole disk using fzf
DEVICE=$(echo "$PARTITIONS" | awk '{print $1}' | fzf)
echo "Debug: Selected device: $DEVICE"
echo
# Check if a device was selected
if [ -n "$DEVICE" ]; then
# Get the label of the partition
LABEL=$(lsblk -no LABEL "$DEVICE" | sed 's/ /_/g')
echo "Debug: Partition label: $LABEL"
echo
# Correctly identify the user
USER_NAME=$(logname)
echo "Debug: Detected user: $USER_NAME"
echo
# Create the mount point directory based on the label in the /mnt directory
MOUNT_POINT="/mnt/$LABEL"
echo "Debug: Mount point: $MOUNT_POINT"
echo
sudo mkdir -p "$MOUNT_POINT"
# Attempt to mount the device with exFAT filesystem type
if sudo mount -t exfat "$DEVICE" "$MOUNT_POINT"; then
echo "Successfully mounted $DEVICE at $MOUNT_POINT"
else
echo "Failed to mount $DEVICE. Check dmesg for more information."
fi
else
echo "No device selected"
fi
}
# Call the function
usb_mount