summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/udev/mount-usb
blob: 2d3b3f564f03663e9dc866ceb438316d8166ce5e (plain)
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


DIR=/media
DEVICE=$2
LABEL=`/lib/udev/vol_id -L /dev/$DEVICE`
FS=`/lib/udev/vol_id -t /dev/$DEVICE`


mount_device () {
    if [ "$LABEL" == "" ];
      then
      mkdir -p $DIR/usb-$DEVICE
      case $FS in 
        vfat)    /bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/$DEVICE $DIR/usb-$DEVICE
        ;; 
        *)    /bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/$DEVICE $DIR/usb-$DEVICE
        ;;
      esac
    else
	mkdir -p $DIR/$LABEL
      echo $LABEL >$DIR/.$DEVICE
      case $FS in 
        vfat)    /bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/$DEVICE $DIR/$LABEL
        ;; 
        *)    /bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/$DEVICE $DIR/$LABEL
        ;;
      esac
    fi
}

umount_device () {
    if [ -e $DIR/usb-$DEVICE ];
      then
      umount -l $DIR/usb-$DEVICE
      rmdir $DIR/usb-$DEVICE;
    else
      ULABEL=`cat $DIR/.$DEVICE`
      umount -l $DIR/$ULABEL
      rmdir $DIR/$ULABEL
      rm $DIR/.$DEVICE;
	fi
}

case $1 in 
  mount) mount_device
  ;;
  umount) umount_device
  ;;
  *) echo "Usage: mount-usb mount/umount sdxY"
esac