Write a script to fully install the samba service and share the directory. Input by the user,
The script is automatically determined based on user input. Then write to the samba configuration file and access Samba. The unified user is root.
The password is 123456. The script automatically starts the service. Please tell the user whether the samba service runs successfully.
! /Bin/bash
# Write by Lijun
# Date 2014-07-16
#===================================================== ==================
# The present path
#===================================================== ==================
Pwddir = 'pwd'
#===================================================== ====================
# Function check error
#===================================================== ====================
Function check_err (){
If [$? -EQ 0]
Then
Echo "'basename $ 0' OK !!! "> $ Pwddir/OK. Log
Else
Echo "'basename $ 0' failed..."> $ pwddir/error. Log
Fi
}
#===================================================== ====================
#1. Function check Samba install
#===================================================== ====================
Function check_smb_install (){
Rpm-Q samba
If [$? -EQ 0]
Then
Echo
Echo "you have already installed Samba! "
Echo
Else
Yum install samba-y
Check_err
Fi
}
#===================================================== ==================
# SELinux and iptables
#===================================================== ==================
Function close (){
/Etc/init. d/iptables stop
Setenforce 0
Echo "iptables is stopped! "
Echo "SELinux has set for 0! "
}
#===================================================== ====================
#2. Modify the configration in Service
#===================================================== ====================
Function modify_conf (){
Echo
Read-P "wocould you like to creat a directory? [Yes/No]:"
Echo
If [$ A = "yes"-o $ A = "yes"]
Then
Read-P "Please input the directory name only under the '/' Like/d_name:" Name
Mkdir-p $ name
Chmod 777 $ name-R
Sed-I '101s/share/user/G'/etc/samba/smb. conf
Echo"
[Test 'echo $ name | awk-F/'{print $ NF} '']
Path = $ name
Comment = share 'echo $ name | awk-F/'{print $ NF }''
Valid users = root
Writeable = Yes
Browseable = Yes
Public = yes ">/etc/samba/smb. conf
Check_err
Echo
Echo "Please set password for root"
Smbpasswd-a root
Echo
Read-P "restart the service ?? [Yes/No]: "B
Echo
If [$ B = "yes"-o $ B = "yes"]
Then
Service SMB restart
Else
Exit
Fi
Echo
Echo "OK... Congratulations !!! "
Echo
Echo "Now you can login the system as user of 'root '"
Echo "password is '000000 '"
Echo
Else
Exit
Fi
}
Check_smb_install
Modify_conf
Close