public
Description: personal scripts
Homepage:
Clone URL: git://github.com/mackstann/bin.git
bin / Mount
100755 51 lines (43 sloc) 1.24 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
#!/bin/sh
 
# Written by Nick Welch <nick@incise.org>. Author disclaims copyright.
 
# Mount: mounts a disk based on the name of the hardware instead of numbered
# /dev files. also waits for them to appear (i.e. if you just plugged it in
# and the kernel hasn't finished recognizing it, it won't just reject you with
# an error)
 
glob="$1"
mountpoint="$2"
theumask="$3"
optionarg=""
 
if [ -z "$glob" -o -z "$mountpoint" ]
then
echo "Usage: $0 <device id glob> <mount point> [optional umask]"
    echo "Example: $0 'usb-Seagate*part1' /mnt/music 0000"
    exit 1
fi
 
if [ -n "$theumask" ]
then
theumask="umask=$theumask"
    optionarg="-o"
fi
 
while true
do
num_matching_disks=`find /dev/disk/by-id -iname "$glob" | wc -l`
    case $num_matching_disks in
        0)
            printf "."
            sleep 0.3
            continue
            ;;
        1)
            dev=`find /dev/disk/by-id -iname "$glob"`
            echo "mounting $dev at $mountpoint"
            sudo mount $optionarg $theumask "$dev" "$mountpoint"
            exit 0
            ;;
        *)
            echo there are multiple disks that match "$glob":
            find /dev/disk/by-id -iname "$glob"
            exit 1
            ;;
    esac
done