Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate

Advertising

mount_file_creator
Sunday, June 10th, 2012 at 8:06:37pm UTC 

  1. #!/bin/bash
  2. # a script to create .mount and .automount unit files
  3. # and install them  :debdj:
  4.  
  5. trap "echo && exit 1" SIGINT SIGTERM
  6.  
  7. tempdir=`mktemp -d`
  8. cd "$tempdir"
  9.  
  10. export ntfsopts='rw,nosuid,exec,uid=1000,gid=1000'
  11. export extopts='defaults'
  12.  
  13. service_enable () {
  14. [[ $UID -ne 0 ]] && beroot='sudo'
  15.  
  16. DEST='/etc/systemd/system/'
  17. echo "Copying files to ${DEST}"
  18. ${beroot} cp * "$DEST"
  19.  
  20. for i in *.automount; do
  21. ${beroot} systemctl enable "${i##*/}" #stript any leading slashes, should not be tho
  22. done
  23.  
  24. echo
  25.  
  26. exit 0
  27. }
  28.  
  29. prepfiles () {
  30. echo -n "Device name: "
  31. read device
  32. echo -n "Mount point: "
  33. read mp
  34. echo -n "fs type: "
  35. read type
  36. echo -n "Mount options: "
  37. read opts
  38.  
  39. if [ -z "$opts" ]; then
  40.   if [ "$type" = "ntfs" ]; then
  41.    opts="$ntfsopts"
  42.    echo "Using Options: ${ntfsopts}"
  43.   else
  44.    opts="$extopts"
  45.    echo "Using Options: ${extopts}"
  46.   fi
  47. fi
  48.  
  49. temp=`echo ${mp#/}` #remove the leading slash
  50. mountfile=${temp////-} #replace intermediate slashes with '-'
  51.  
  52. echo -n "[Unit]
  53. Description=Mount ${mp}
  54. Wants=local-fs.target
  55. After=local-fs.target
  56.  
  57. [Mount]
  58. What=${device}
  59. Where=${mp}
  60. Type=${type}
  61. Options=${opts}
  62.  
  63. [Install]
  64. WantedBy=local-fs.target" > ${mountfile}.mount
  65.  
  66. echo "Wrote  ${mountfile}.mount"
  67.  
  68. echo -n "[Unit]
  69. Description=automount ${mp}
  70. Wants=local-fs.target
  71. After=local-fs.target
  72.  
  73. [Automount]
  74. Where=${mp}
  75.  
  76. [Install]
  77. WantedBy=local-fs.target" > ${mountfile}.automount
  78.  
  79. echo -e "Wrote  ${mountfile}.automount \n"
  80.  
  81. echo -n "More?: (y/n)"
  82. read stud
  83. [ "$stud" = y ] && prepfiles || service_enable
  84.  
  85. }
  86.  
  87. prepfiles

Paste Details

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will not expire by default. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right