Advertisement
Guest User

automount

a guest
Mar 16th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.78 KB | None | 0 0
  1. $ cat /etc/udev/rules.d/20-automount.rules
  2. ACTION!="add", GOTO="usb_add_end"
  3. KERNEL=="sd[b-z][0-9]", RUN+="/bin/systemctl start mount@%k"
  4. KERNEL=="mmcblk[0-9]", RUN+="/bin/systemctl start mount@%k"
  5. KERNEL=="mmcblk[0-9]p[0-9]", RUN+="/bin/systemctl start mount@%k"
  6. SUBSYSTEMS=="usb", ATTR{interface}=="MTP", RUN+="/bin/systemctl start mount@mtp"
  7. LABEL="usb_add_end"
  8.  
  9. ACTION!="remove", GOTO="usb_rem_end"
  10. KERNEL=="sd[b-z][0-9]", RUN+="script/mount/automount.sh umnt %k"
  11. KERNEL=="mmcblk[0-9]", RUN+="script/mount/automount.sh umnt %k"
  12. KERNEL=="mmcblk[0-9]p[0-9]", RUN+="script/mount/automount.sh umnt %k"
  13. #нефурычит(((
  14. KERNEL=="2-1.3", ENV{ID_MTP_DEVICE}="1", RUN+="script/mount/automount.sh umnt mnt"
  15. LABEL="usb_rem_end"
  16.  
  17. $ cat /etc/systemd/system/mount@.service
  18. [Unit]
  19. Description=mount_%I
  20. [Service]
  21. Type=forking
  22. ExecStart=/home/admin/script/mount/automount.sh mnt %I
  23. [Install]
  24. WantedBy=multi-user.target
  25.  
  26.  
  27. $ cat script/mount/automount.sh
  28. #!/bin/bash
  29. export DISPLAY=:0.0
  30. format_dev=`lsblk -dnro FSTYPE "/dev/$2"`
  31. user_dev=`ps -C dwm -o user=`
  32.  
  33. fmnt()
  34. {
  35. mkdir /media/usb-$1
  36. chown $user_dev:$user_dev /media/usb-$1
  37. notify-send-root  "#Udev:" "mount /media/usb-$1 $format_dev"
  38.  
  39. if [ "$1" == "mtp" ]; then
  40.         su $user_dev -c "simple-mtpfs /media/usb-$1"
  41. else
  42. case "$format_dev" in
  43.         "" ) systemctl stop mount@$1 ;;
  44.         ntfs ) mount /dev/$1 /media/usb-$1 -o uid=1000,fmask=113,dmask=002,utf8 ;;
  45.         vfat ) mount /dev/$1 /media/usb-$1 -o uid=1000,utf8 ;;
  46.         exfat ) mount  /dev/$1 /media/usb-$1 -o uid=1000,utf8 ;;
  47.         *)  mount  /dev/$1 /media/usb-$1
  48. esac
  49. fi
  50. }
  51.  
  52. fumnt()
  53. {
  54. umount /media/usb-$1
  55. rmdir /media/usb-$1
  56. systemctl stop mount@$1
  57. }
  58.  
  59. case "$1" in
  60.         mnt ) fmnt $2;;
  61.         umnt ) fumnt $2;;
  62.         * ) ;;
  63. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement