/trkinitrd/bin/fileserver
#! | 104 lines | 89 code | 15 blank | 0 comment | 0 complexity | 78c597dac7c2d102015c7e61096dacb3 MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
- #!/bin/bash
- # Script to generate Samba server shares and start/restart Samba
- RO=No
- if [ "r$1" = "rstop" ]; then /etc/init.d/smb stop && umountallfs; exit 0; fi;
- function SecuredServer {
- echow "Starting a username/password secured Samba fileserver and sharing all local filesystems"
- until [ r"$NEWUSR" != "r" ]; do
- printf "Enter a username which will be created to have access to your local files: "
- read NEWUSR;
- done
- grep -q $NEWUSR /etc/passwd
- if [ $? != 0 ]; then echo "$NEWUSR:x:0:0::/root:/bin/bash" >> /etc/passwd; fi
- smbpasswd -a $NEWUSR
- echo "[global]
- workgroup = WORKGROUP
- server string = "Trinity Rescue Kit 3.4 fileserver"
- netbios name = TRKSRV
- encrypt passwords = Yes
- update encrypted = Yes
- security = user
- map to guest = Bad Password
- socket options = TCP_NODELAY SO_RCVBUF=131072 SO_SNDBUF=131072
- max protocol = SMB2
- load printers = no
- " > /etc/samba/smb.conf
- if ! [ -s /etc/mountallfstab ]; then mountallfs -g; fi
- echow "Mounting all your local filesystems using mountallfs -g"
- for i in `cat /etc/mountallfstab`; do
- SHARENAME=`echo $i | tr "/" "-"`
- echo "[$SHARENAME]
- path = /$i
- read only = $RO
- guest ok = No
- " >> /etc/samba/smb.conf
- done
- } # end function SecuredServer
- function Guestserver {
-
- echow "Starting an unsecured Samba fileserver and sharing all local filesystems"
- echo "[global]
- workgroup = WORKGROUP
- server string = "Trinity Rescue Kit 3.4 fileserver \(guest\)"
- netbios name = TRKSRV
- encrypt passwords = Yes
- update encrypted = Yes
- security = user
- map to guest = Bad Password
- socket options = TCP_NODELAY SO_RCVBUF=131072 SO_SNDBUF=131072
- max protocol = SMB2
- load printers = no
- " > /etc/samba/smb.conf
- if ! [ -s /etc/mountallfstab ]; then
- echow "Mounting all your local filesystems using mountallfs -g"
- mountallfs -g; fi
- for i in `cat /etc/mountallfstab`; do
- SHARENAME=`echo $i | tr "/" "-"`
- echo "[$SHARENAME]
- path = /$i
- read only = $RO
- guest ok = Yes
- " >> /etc/samba/smb.conf
- done
- } # end function Guestserver
- function Help {
- echo "Usage: fileserver -s OR fileserver -g
- -s: sets up a username/password protected Windows fileservice and shares all your local partitions.
- -g: sets up a completely open, unsecured Windows fileservice and shares all your local partitions. Use with caution!
- -r: all shares are read-only"
- } # end function Help
- while getopts sghr name
- do
- case $name in
- s) ;;
- g) ;;
- h) Help && exit 2;;
- r) RO=Yes;;
- [?]) Help && exit 2;;
- esac
- done
- # Make sure if we omit guest server to run a secured server
- echo $@ | grep -q -e "-g" || SecuredServer
- echo $@ | grep -q -e "-g" && Guestserver
- if [ -s /var/run/smbd.pid ]; then /etc/init.d/smb restart;
- else
- echo "This is the IP-address of your fileserver:"
- color ltgreen
- ifconfig | grep "inet addr" | grep -v "127.0.0.1" | cut -d : -f 2 | cut -d " " -f 1
- color off
- /etc/init.d/smb start;
- fi;