Guest User

Untitled

a guest
Jun 17th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. ### BEGIN INIT INFO
  4. # Provides: mount_shares_locally
  5. # Required-Start: $network $local_fs $remote_fs samba
  6. # Required-Stop: $network $local_fs $remote_fs samba
  7. # Default-Start: 2 3 4 5
  8. # Default-Stop: 0 1 6
  9. # Short-Description: mount Samba shares locally
  10. ### END INIT INFO
  11.  
  12. username="bot"
  13.  
  14. if [ -f /lib/lsb/init-functions ]; then
  15. . /lib/lsb/init-functions
  16. fi
  17.  
  18. LOCKFILE=/var/lock/mount_shares_locally
  19.  
  20. lock_mount_shares_locally() {
  21. if [ -x /usr/bin/lockfile-create ]; then
  22. lockfile-create $LOCKFILE
  23. lockfile-touch $LOCKFILE &
  24. fi
  25. }
  26.  
  27. unlock_mount_shares_locally() { if [ -x /usr/bin/lockfile-create ] ; then
  28. lockfile-remove $LOCKFILE
  29. fi
  30. }
  31.  
  32. start () {
  33. uid=`id -u $username`
  34. gid=`id -g $username`
  35.  
  36. log_daemon_msg "Mounting Samba shares locally..."
  37. if [ ! -x /mnt/samba/ ]; then
  38. mkdir -p /mnt/samba/
  39. fi
  40. cd /mnt/samba/
  41. lock_mount_shares_locally
  42. grep "^\[" /etc/samba/smb.conf | grep -v "\[global\]" | grep -v "\[homes\]" | awk -F'[' '{print $2}' | awk -F']' '{print $1}' | xargs -d "\n" mkdir -p
  43. sleep 5
  44. ls -1 | while read d; do
  45. if [ "`mount | grep "//127.0.0.1/$d/* on " | wc -l`" = "0" ]; then
  46. /sbin/mount.cifs "//127.0.0.1/$d" "$d" -o credentials=/home/${username}/.smb_credentials,uid=${uid},gid=${gid},file_mode=0660,dir_mode=0770,nobrl,hard,_netdev,iocharset=utf8,noserverino,mfsymlinks
  47. else
  48. echo " Share [$d] is already mounted."
  49. fi
  50. done
  51. unlock_mount_shares_locally
  52. log_end_msg
  53. return 0
  54. }
  55.  
  56. stop () {
  57. log_daemon_msg "Unmounting locally mounted Samba shares..."
  58. /bin/umount -l /mnt/samba/*
  59. log_end_msg
  60. return 0
  61. }
  62.  
  63. case "$1" in
  64. start)
  65. start
  66. ;;
  67. stop)
  68. stop
  69. ;;
  70. restart)
  71. $0 stop && sleep 2 && $0 start
  72. ;;
  73. *)
  74. echo "Usage: $0 {start|stop|restart}"
  75. exit 2
  76. ;;
  77. esac
Add Comment
Please, Sign In to add comment