Automount/unmount USB drives.
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 20 Sep 2018 05:14:06 +0000 (22:14 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 20 Sep 2018 05:14:06 +0000 (22:14 -0700)
CHANGELOG.md
scripts/install.sh

index feb00720f5cb335882c87e111aa81930d376f114..c0aece3ffabbc0f0f508bbba7721b9cbe2df13e5 100644 (file)
@@ -10,6 +10,7 @@ Buildbotics CNC Controller Firmware Changelog
  - Camera hotpluging.
  - Move camera video to header.
  - Click to switch through three video sizes.
+ - Automount/unmount USB drives.
 
 ## v0.3.28
  - Show step rate on motor configuration page.
index 54b0f7fbfd17a1ebf3a491f2f2a376d6771d623a..ba7a3449bcb38e34758bd1f71b664c84d1acd624 100755 (executable)
@@ -65,6 +65,30 @@ sed -i 's/^TimeoutStartSec=.*$/TimeoutStartSec=1/' \
 sed -i 's/^XKBLAYOUT="gb"$/XKBLAYOUT="us" # Comment stops change on upgrade/' \
     /etc/default/keyboard
 
+# Setup USB stick automount
+if [ ! -e /etc/udev/rules.d/11-automount.rules ]; then
+    (
+        echo 'KERNEL!="sd[a-z]*", GOTO="automount_end"'
+        echo 'IMPORT{program}="/sbin/blkid -o udev -p %N"'
+        echo 'ENV{ID_FS_TYPE}=="", GOTO="automount_end"'
+        echo 'ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"'
+        echo 'ENV{ID_FS_LABEL}=="", ENV{dir_name}="usb-%k"'
+        echo 'ACTION=="add", ENV{mount_options}="relatime"'
+        echo 'ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002,sync"'
+        echo 'ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"'
+        echo 'ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"'
+        echo 'LABEL="automount_end"'
+    ) > /etc/udev/rules.d/11-automount.rules
+
+    grep "/etc/init.d/udev restart" /etc/rc.local >/dev/null
+    if [ $? -ne 0 ]; then
+        echo "/etc/init.d/udev restart" >> /etc/rc.local
+    fi
+
+    sed -i 's/^\(MountFlags=slave\)/#\1/' /lib/systemd/system/systemd-udevd.service
+    REBOOT=true
+fi
+
 if $UPDATE_PY; then
     rm -rf /usr/local/lib/python*/dist-packages/bbctrl-*
     ./setup.py install --force