std.h: Don't use `extern` in function prototypes
[sunny256-utils.git] / mountusb
blob00c56e7c5cd109ed99cf8985eb28ac6e2f0ecbfd
1 #!/usr/bin/env bash
3 # File ID: 43e64d72-d26d-11de-a010-90e6ba3022ac
5 dev=sdb1
6 mountp=/media/usb
8 if [ "$1" = "-l" ]; then
9 unset tzval
10 shift
11 else
12 tzval="tz=UTC,"
14 [ -z "$1" ] || dev=$1
15 [ -z "$2" ] || mountp=$2
16 [ -d "$mountp/." ] || { mkdir $mountp || { echo mountusb: $mountp: Cannot create directory; exit 1; }; }
17 opts="-o fmask=0111,uid=sunny,gid=sunny,${tzval}shortname=mixed"
19 mount | grep /dev/$dev && {
20 echo mountusb: Unmounting /dev/$dev
21 sudo umount /dev/$dev || { echo mountusb: /dev/$dev: Cannot unmount >&2; exit 1; }
22 sleep 2
25 echo "mountusb: Mounting /dev/$dev on $mountp using \"$opts\""
26 sudo mount /dev/$dev $mountp $opts
28 # Check for existing /mntopts file in disk root. That file contains mount
29 # options used on the command line when mounting.
30 if [ -e $mountp/mntopts -o -e $mountp/MNTOPTS ]; then
31 [ -e $mountp/MNTOPTS ] && mntopts=MNTOPTS
32 [ -e $mountp/mntopts ] && mntopts=mntopts
33 opts2="`cat $mountp/$mntopts`"
34 [ "$opts" = "$opts2" ] && { echo "mountusb: /mntopts contains standard options, remount not necessary"; exit 0; }
35 sync
36 sleep 3
37 sudo umount $mountp
38 sync
39 echo "mountusb: Remount /dev/$dev on $mountp using \"$opts2\""
40 sudo mount /dev/$dev $mountp $opts2