1. #!/bin/bash
    2. if [ "$#" -ne 1 ]
    3. then
    4. echo "运行脚本的格式为:$0 /dir/"
    5. exit 1
    6. else
    7. if ! echo $1 | grep -q '^/.*'
    8. then
    9. echo "请提供一个绝对路径"
    10. exit 1
    11. fi
    12. fi
    13. if ! rpm -q samba > /dev/null
    14. then
    15. echo "将要安装samba"
    16. sleep 1
    17. yum install -y samba
    18. if [ $? -ne 0 ]
    19. then
    20. echo "samba安装失败"
    21. exit 1
    22. fi
    23. fi
    24. cnfdir="/etc/samba/smb.conf"
    25. cat >> $cnfdir << EOF
    26. [share]
    27. comment = share all
    28. path = $1
    29. browseable = yes
    30. public = yes
    31. writable = no
    32. EOF
    33. if [ ! -d $1 ]
    34. then
    35. mkdir -p $1
    36. fi
    37. chmod 777 $1
    38. echo "test" > $1/test.txt
    39. systemctl start smb
    40. if [ $? -ne 0 ]
    41. then
    42. echo "samba服务启动失败,请检查配置文件是否正确"
    43. else
    44. echo "samba配置完毕,请验证"
    45. fi