eibgrad

ddwrt-mount-usb-drives.sh

Jun 4th, 2019 (edited)
1,702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.63 KB | None | 0 0
  1. #!/bin/sh
  2. #DEBUG=; set -x # comment/uncomment to disable/enable debug mode
  3.  
  4. #           name: ddwrt-mount-usb-drives.sh
  5. #        version: 1.2.3, 29-jun-2019, by eibgrad
  6. #        purpose: mount usb drive(s)/partition(s)
  7. #    script type: startup (autostart)
  8. #  compatibility: ext2, ext3, ext4, fat, fat32
  9. #   installation:
  10. #     1. enable jffs2 (administration->jffs2)
  11. #     2. enable syslogd (services->services->system log)
  12. #     3. set services->usb->usb support options as follows:
  13. #          core usb support = enable
  14. #          usb storage support = enable
  15. #          automatic drive mount = disable
  16. #     4. install usb drive(s) and reboot
  17. #     5. use shell (telnet/ssh) and blkid utility to determine uuid(s)
  18. #     6. use shell (telnet/ssh) to execute one of the following commands:
  19. #          curl -kLs bit.ly/ddwrt-installer|tr -d '\r'|sh -s VDZ32r2D startup
  20. #        or
  21. #          wget -qO - bit.ly/ddwrt-installer|tr -d '\r'|sh -s VDZ32r2D startup
  22. #     7. use vi editor to modify script w/ your preferred options and
  23. #              mounting points:
  24. #          vi /jffs/etc/config/ddwrt-mount-usb-drives.startup
  25. #     8. reboot
  26. #    limitations:
  27. #      - ntfs is NOT supported at this time
  28. {
  29. # ------------------------------ BEGIN OPTIONS ------------------------------- #
  30.  
  31. # read/write access, no special devices, don't update access time
  32. OPT="-o rw,nodev,noatime" # uncomment/comment to enable/disable
  33.  
  34. # check (and repair as necessary) all usb partitions
  35. CLEAN_PARTITIONS= # uncomment/comment to enable/disable
  36.  
  37. # allow other startup scripts (if any) to run concurrently
  38. #DAEMONIZE= # uncomment/comment to enable/disable
  39.  
  40. # ------------------------------- END OPTIONS -------------------------------- #
  41. add_mounts() {
  42. # ------------------------------- BEGIN MOUNTS ------------------------------- #
  43.  
  44. # create mounting point(s) (/opt is pre-defined by the system)
  45. mkdir -p /mnt/dropbox
  46.  
  47. # mount each partition to its preferred mounting point based on UUID
  48. mount $(findfs UUID=576f3b60-5cb7-4f5d-9800-c309778c2af8) $OPT /opt
  49. mount $(findfs UUID=427cb076-6681-4a15-9e27-4b90aaf8de3e) $OPT /mnt/dropbox
  50.  
  51. # alternate method:
  52. #   mount each partition to its preferred mounting point based on its LABEL;
  53. #   this requires partitions to be uniquely labeled across all devices
  54. #
  55. #   for linux filesystems only (ext*): if available in your build, use the
  56. #   e2label utility to relabel partitions as necessary (beware, this will
  57. #   likely change its UUID too), otherwise use the gparted utility found on
  58. #   most linux distros
  59.  
  60. #mount $(findfs LABEL=optware) $OPT /opt
  61. #mount $(findfs LABEL=dropbox) $OPT /mnt/dropbox
  62.  
  63. # -------------------------------- END MOUNTS -------------------------------- #
  64. :;}
  65. # ---------------------- DO NOT CHANGE BELOW THIS LINE ----------------------- #
  66.  
  67. # function is_mounted( partition )
  68. is_mounted() { df | grep -Eq "^$1[[:space:]]+"; }
  69.  
  70. # function findfs( LABEL=<label>|UUID=<uuid> )
  71. findfs() { blkid | sed 's/"//g' | grep -wm1 "$1" | cut -d ':' -f 1; }
  72.  
  73. if [ "$(which modprobe)" ]; then
  74.     modprobe ext4
  75.     modprobe msdos
  76. else
  77.     insmod crc16 && insmod mbcache && insmod jbd2 && insmod ext4
  78.     insmod fat && insmod vfat
  79. fi
  80.  
  81. # check (and repair as necessary) usb partitions (ext* only)
  82. if [ ${CLEAN_PARTITIONS+x} ]; then
  83.     for part in /dev/sd*; do
  84.         if $(echo $part | grep -Eq '[0-9]+$'); then
  85.             is_mounted $part || e2fsck -p $part 2>/dev/null
  86.         fi
  87.     done
  88. fi
  89.  
  90. # add mounts
  91. add_mounts
  92.  
  93. exit 0
  94.  
  95. } 2>&1 | logger $([ ${DEBUG+x} ] && echo "-p user.debug") \
  96.     -t $(echo $(basename $0) | grep -Eo '^.{0,23}')[$$] \
  97.     $([ ${DAEMONIZE+x} ] && echo &)
Add Comment
Please, Sign In to add comment