PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/trkinitrd/bin/fileserver

https://bitbucket.org/harakiri/trk
#! | 104 lines | 89 code | 15 blank | 0 comment | 0 complexity | 78c597dac7c2d102015c7e61096dacb3 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. #!/bin/bash
  2. # Script to generate Samba server shares and start/restart Samba
  3. RO=No
  4. if [ "r$1" = "rstop" ]; then /etc/init.d/smb stop && umountallfs; exit 0; fi;
  5. function SecuredServer {
  6. echow "Starting a username/password secured Samba fileserver and sharing all local filesystems"
  7. until [ r"$NEWUSR" != "r" ]; do
  8. printf "Enter a username which will be created to have access to your local files: "
  9. read NEWUSR;
  10. done
  11. grep -q $NEWUSR /etc/passwd
  12. if [ $? != 0 ]; then echo "$NEWUSR:x:0:0::/root:/bin/bash" >> /etc/passwd; fi
  13. smbpasswd -a $NEWUSR
  14. echo "[global]
  15. workgroup = WORKGROUP
  16. server string = "Trinity Rescue Kit 3.4 fileserver"
  17. netbios name = TRKSRV
  18. encrypt passwords = Yes
  19. update encrypted = Yes
  20. security = user
  21. map to guest = Bad Password
  22. socket options = TCP_NODELAY SO_RCVBUF=131072 SO_SNDBUF=131072
  23. max protocol = SMB2
  24. load printers = no
  25. " > /etc/samba/smb.conf
  26. if ! [ -s /etc/mountallfstab ]; then mountallfs -g; fi
  27. echow "Mounting all your local filesystems using mountallfs -g"
  28. for i in `cat /etc/mountallfstab`; do
  29. SHARENAME=`echo $i | tr "/" "-"`
  30. echo "[$SHARENAME]
  31. path = /$i
  32. read only = $RO
  33. guest ok = No
  34. " >> /etc/samba/smb.conf
  35. done
  36. } # end function SecuredServer
  37. function Guestserver {
  38. echow "Starting an unsecured Samba fileserver and sharing all local filesystems"
  39. echo "[global]
  40. workgroup = WORKGROUP
  41. server string = "Trinity Rescue Kit 3.4 fileserver \(guest\)"
  42. netbios name = TRKSRV
  43. encrypt passwords = Yes
  44. update encrypted = Yes
  45. security = user
  46. map to guest = Bad Password
  47. socket options = TCP_NODELAY SO_RCVBUF=131072 SO_SNDBUF=131072
  48. max protocol = SMB2
  49. load printers = no
  50. " > /etc/samba/smb.conf
  51. if ! [ -s /etc/mountallfstab ]; then
  52. echow "Mounting all your local filesystems using mountallfs -g"
  53. mountallfs -g; fi
  54. for i in `cat /etc/mountallfstab`; do
  55. SHARENAME=`echo $i | tr "/" "-"`
  56. echo "[$SHARENAME]
  57. path = /$i
  58. read only = $RO
  59. guest ok = Yes
  60. " >> /etc/samba/smb.conf
  61. done
  62. } # end function Guestserver
  63. function Help {
  64. echo "Usage: fileserver -s OR fileserver -g
  65. -s: sets up a username/password protected Windows fileservice and shares all your local partitions.
  66. -g: sets up a completely open, unsecured Windows fileservice and shares all your local partitions. Use with caution!
  67. -r: all shares are read-only"
  68. } # end function Help
  69. while getopts sghr name
  70. do
  71. case $name in
  72. s) ;;
  73. g) ;;
  74. h) Help && exit 2;;
  75. r) RO=Yes;;
  76. [?]) Help && exit 2;;
  77. esac
  78. done
  79. # Make sure if we omit guest server to run a secured server
  80. echo $@ | grep -q -e "-g" || SecuredServer
  81. echo $@ | grep -q -e "-g" && Guestserver
  82. if [ -s /var/run/smbd.pid ]; then /etc/init.d/smb restart;
  83. else
  84. echo "This is the IP-address of your fileserver:"
  85. color ltgreen
  86. ifconfig | grep "inet addr" | grep -v "127.0.0.1" | cut -d : -f 2 | cut -d " " -f 1
  87. color off
  88. /etc/init.d/smb start;
  89. fi;