WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Example script to manage install/start and stop/uninstall of samba  (Read 4502 times)

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Here's an example script that manages the dynamic use of samba. It manages the installation and startup, stopping and uninstall and restart of samba. It seems to work for me but that doesn't mean it's flawless.
Code: [Select]
#!/bin/sh
# bigpcman May 25, 2009
# Samba Prep
# Download samba3.tczl to tce/optional
# My usb persistent storage = /mnt/sdc1
# Make directories - sudo mkdir -p /var/lib/samba /etc/samba/private
# Edit conf file - /etc/samba/smb.conf
# Create samba password - /usr/local/bin/smbpasswd
# Save the conf file  - sudo cp -a /etc/samba/smb.conf /mnt/sdc1/samba
# Save the pass word file - sudo cp -a /etc/samba/private/smbpasswd /mnt/sdc1/samba
# Run this script - sambaserver start,  sambaserver stop, sambaserver restart

 stop()
    {
    echo "Stopping Samba..."
    sudo killall smbd 2>&1 > /dev/null &
    sudo killall nmbd 2>&1 > /dev/null &
    sleep 1
    tcz-uninstall samba3 --force --purge 2>&1 > /dev/null &
    sleep 2
    tcz-uninstall cups --force --purge 2>&1 > /dev/null &
    sleep 2
    sudo rm -R /etc/cups 2>&1 > /dev/null &
    sudo rm -R /etc/samba 2>&1 > /dev/null &
    sudo rm -R /usr/local/share/doc/cups 2>&1 > /dev/null &
    sudo rm -R /usr/local/include/cups 2>&1 > /dev/null &
    sudo rm -R /usr/local/share/cups 2>&1 > /dev/null &
    sudo rm -R /usr/local/tce.flwm/cups 2>&1 > /dev/null &
    sudo rm -R /usr/local/lib/cups 2>&1 > /dev/null &
    sudo rm -R /var/lib/samba 2>&1 > /dev/null &
    sudo rm -R /var/run/smbd.pid 2>&1 > /dev/null &
    sudo rm -R /var/run/nmbd.pid 2>&1 > /dev/null &
    }

 start()
   {
   echo "Starting Samba..."
   tce-load /mnt/sdc1/tce/optional/samba3.tczl 2>&1 > /dev/null &
   sleep 3
   sudo mkdir -p /etc/samba/private /var/lib/samba 2>&1 > /dev/null &
   sudo cp -a /mnt/sdc1/samba/smb.conf /etc/samba 2>&1 > /dev/null &
   sudo cp -a /mnt/sdc1/samba/smbpasswd /etc/samba/private 2>&1 > /dev/null &
   sudo /usr/local/sbin/smbd 2>&1 > /dev/null &
   sudo /usr/local/sbin/nmbd 2>&1 > /dev/null &
   }


 restart()
  {
  echo  "Restarting Samba.."
  stop
  sleep 3
  start
  }

case "$1" in
  stop) stop;;
  restart) restart;;
  start)  PID=$(pidof smbd)
          [ -n "$PID" ] && echo "Samba already started" || start;;

  *)
   echo "Usage: $0 {start|stop|restart}"
   esac
big pc man

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: Example script to manage install/start and stop/uninstall of samba
« Reply #1 on: May 27, 2009, 09:01:49 AM »
I haven't used samba in a while, but I'm surprised you didn't include the option to start/stop/restart without installing/uninstalling.  (ie, having separate commands). 

Offline bigpcman

  • Hero Member
  • *****
  • Posts: 719
Re: Example script to manage install/start and stop/uninstall of samba
« Reply #2 on: May 27, 2009, 09:36:18 AM »
I haven't used samba in a while, but I'm surprised you didn't include the option to start/stop/restart without installing/uninstalling.  (ie, having separate commands). 
Good suggestion to make it more general. I just don't use it that way now. But while I was trying to get the conf settings to work I did do a lot of start and stops so it is a good idea.
big pc man