-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomount.sh
More file actions
executable file
·53 lines (41 loc) · 1.24 KB
/
automount.sh
File metadata and controls
executable file
·53 lines (41 loc) · 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
52
53
#!/bin/bash
set -e
action=$1
devname=$2
device="/dev/${devname}"
# Change this to the user running the photobooth application
user="photobooth"
mount_point=$(/bin/mount | /bin/grep -e "^${device}" | awk '{ print $3 }')
case "${action}" in
"mount")
if [[ -n "${mount_point}" ]]; then
echo "[I] ${device} already mounted on ${mount_point}"
exit 0
fi
uid=$(id -u "${user}")
gid=$(id -g "${user}")
label=$(/sbin/blkid -o value -s LABEL "${device}")
if [[ -z "${label}" ]]; then
mount_point="/mnt/${devname}"
else
mount_point="/mnt/${label}"
fi
echo "[I] Mounting ${device} to ${mount_point}"
/bin/mkdir -p "${mount_point}"
fstype=$(/sbin/blkid -o value -s TYPE "${device}")
if [[ "${fstype}" == "vfat" || "${fstype}" == "exfat" || "${fstype}" == "ntfs" ]]; then
/bin/mount -o nosuid,nodev,nofail,uid=${uid},gid=${gid},umask=0022 "${device}" "${mount_point}"
else
/bin/mount -o nosuid,nodev,nofail "${device}" "${mount_point}"
/bin/chown "${uid}:${gid}" "${mount_point}"
fi
;;
"umount")
if [[ -z "${mount_point}" ]]; then
echo "[I] ${device} is not mounted"
exit 0
fi
/bin/umount -l "${device}"
/bin/rm -r "${mount_point}"
;;
esac