attach 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/local/bin/guile3.0 \
  2. -e main -s
  3. !#
  4. ;;; This is a simple script that automounts your usb stick to /mnt/usb
  5. ;; see man hotplugd for more info
  6. ;;;
  7. ;;; To easily test this script execute
  8. ;;; doas ./attach 2 "sd2"
  9. ;;;
  10. ;;; TODO make it more robust:
  11. ;;; https://github.com/a12n/openbsd-hotplug/blob/master/hotplug.pl
  12. ;;; Should I check to make sure the label is "USB Flash Drive"?
  13. ;;; or is "USB Flash Drive" not guarenteed to be there all the time
  14. ;;; for all USB Flash Drives?
  15. (use-modules (rnrs io ports))
  16. (use-modules (ice-9 popen))
  17. (define (fs-type-and-partition name)
  18. (let* ((port (open-input-pipe
  19. (string-append "/sbin/disklabel -t " name " 2>&1 | \
  20. grep -e ':t[ab]=' -e ':t[d-p]'| cut -f 4 -d ':'")))
  21. (str (string-drop-right (get-line port) 1)))
  22. (close-pipe port)
  23. str))
  24. (define (main args)
  25. (define class (car (cdr args)))
  26. (define name (car (cddr args)))
  27. ;; when this is a disk drive with a filesystem of msdos, mount it
  28. (when (and (string=? "2" class)
  29. (fs-type-msdos? name))
  30. (display "mounting")
  31. (system* "mount" "-o" "rw,nodev,noexec,nodev" (string-append "/dev/" name "i") "/mnt/usb")))