I've adapted my SBS svn setup script from Fedora to Ubuntu.  I've tested
this on Ubuntu server 10.04 and it works well.  For this script to work
you must first install SBS via apt-get or dpkg.  Enjoy.


Code:
--------------------
    
  #!/bin/bash
  
  
#------------------------------------------------------------------------------
  # Script to download and prepare squeezeboxserver svn code to run as a 
service on ubuntu...
  #
  # Prerequsite: squeezeboxserver must first be installed via apt-get or dpkg 
from the nightly deb file.
  #
  # After running this script, you can (if you want or need to) safely 
uninstall squeezeboxserver: 'apt-get remove squeezeboxserver'
  #
  
  
  user=`whoami`
  if [ "$user" != "root" ] 
  then
  echo 'Error: This script needs to be run with root cridentials,'
  echo "either via # sudo $0"
  echo 'or under su.'
  exit
  fi
  
  
#------------------------------------------------------------------------------
  # Uncomment the desired svn codebase to install:
  
  # Testing (a.k.a 7.5.x, source of nightly releases after official 7.5 
release?)
  #SOURCEREPO='http://svn.slimdevices.com/repos/slim/7.5/trunk/server'
  
  # Embedded (a.k.a 7.5.x embedded )
  
#SOURCEREPO='http://svn.slimdevices.com/repos/slim/7.5/branches/embedded/server'
  
  # Unstable (a.k.a. 7.6)
  SOURCEREPO='http://svn.slimdevices.com/repos/slim/7.6/trunk/server'
  
  
#------------------------------------------------------------------------------
  # Installation name: This will be the name of the installed service and 
determines the names of many folders.
  # You can change this to anything that strikes you as more descriptive.  
E.g.: 'sbs75_trunk' or whathaveyou.
  INSTNAME='squeezeboxserver_trunk'
  
  
#------------------------------------------------------------------------------
  # Destination.  This is where the code gets installed to..
  DESTREPO="/usr/share/$INSTNAME/server/"
  
  function pause(){
  read -p "$*"
  }
  
  
#------------------------------------------------------------------------------
  # Check to see if the svn code is already installed...if it is, update it..
  
  if [ -e "/usr/share/$INSTNAME/server" ]
  then
  echo "$INSTNAME is already installed!"
  echo "Updating $INSTNAME code.."
  if [ ! -e "/var/log/$INSTNAME" ]
  then
  mkdir "/var/log/$INSTNAME"
  fi
  svn up "$DESTREPO" >> "/var/log/$INSTNAME/svn.log"
  #exit 1
  fi
  
  
#------------------------------------------------------------------------------
  # Script banner and warnings..
  
  echo ' '
  echo "This script installs the Squeezebox Server svn code as the $INSTNAME 
service."
  echo ' '
  echo "The source for the svn checkout will be $SOURCEREPO"
  echo ' '
  echo "The destination for the svn code will be $DESTREPO"
  echo ' '
  echo ' '
  echo 'For this script to work, this machine MUST already have a working copy 
of'
  echo 'squeezeboxserver that was previously installed via apt-get or dpkg.'
  echo ' '
  pause 'Press Enter to continue, or ctrl-c to abort..'
  
  
#------------------------------------------------------------------------------
  # Stop the squeezeboxserver service if it's running...
  
  SERVICE=`/bin/ps ax | grep " /usr/sbin/squeezeboxserver "`
  if (( $(echo $SERVICE | egrep -c "/usr/bin/perl") >= 1 ))
  then
  /usr/sbin/service squeezeboxserver stop
  fi
  
  
#------------------------------------------------------------------------------
  # Create the squeezeboxserver user if not present..
  SBSUSER=`id squeezeboxserver`
  if (( $(echo $SBSUSER | egrep -c "No such user") >= 1 ))
  then
  useradd --gid nogroup --no-create-home --no-user-group  --comment 
SqueezeBox,,, --shell /bin/false  squeezeboxserver
  fi
  
  
#------------------------------------------------------------------------------
  # Prepare initial directories..
  
  echo "Creating directory for $INSTNAME.."
  mkdir "/usr/share/$INSTNAME"
  
  echo 'Preparing the log dir..'
  mkdir "/var/log/$INSTNAME"
  
  
#------------------------------------------------------------------------------
  # Download the svn code via svn checkout..
  
  echo 'Downloading SqueezeboxServer svn code..'
  echo 'This can take a LONG time...30 minutes or more.'
  echo 'Please be patient.  The script will continue when the svn checkout is 
complete.'
  echo ' '
  echo "You can the monitor progress of the checkout by viewing the 
/var/log/$INSTNAME/svn.log file.."
  echo ' '
  echo 'Downloading svn code now..'
  /bin/date > "/var/log/$INSTNAME/svn.log"
  svn co "$SOURCEREPO" "$DESTREPO" >> "/var/log/$INSTNAME/svn.log"
  #svn up "$DESTREPO" >> "/var/log/$INSTNAME/svn.log"
  
  
  
#------------------------------------------------------------------------------
  # Prepare the config files..get them from a current squeezeboxserver install 
if present?
  # mkdir "/etc/$INSTNAME"
  # /etc/$INSTNAME/convert.conf
  # /etc/$INSTNAME/modules.conf
  # /etc/$INSTNAME/slimservice-convert.conf
  # /etc/$INSTNAME/types.conf
  
  echo 'Preparing the config dir..'
  cp -R /etc/squeezeboxserver /etc/$INSTNAME
  
  
  
#------------------------------------------------------------------------------
  # Prepare the lib dir..
  echo 'Preparing the lib dir..'
  mkdir "/var/lib/$INSTNAME"
  # Start with an empty lib
  
  # Important for proper svn updating..
  #cp -R /usr/share/$INSTNAME/server/Plugins/ /var/lib/$INSTNAME/
  mkdir /var/lib/$INSTNAME/Plugins
  rm -rf /usr/share/$INSTNAME/server/Plugins
  ln -s /var/lib/$INSTNAME/Plugins /usr/share/$INSTNAME/server/Plugins
  chown -h squeezeboxserver:nogroup /usr/share/$INSTNAME/server/Plugins
  
  
  
  
  
#------------------------------------------------------------------------------
  # Prepare the service start script..
  # /etc/default/$INSTNAME 
  cp -R /etc/default/squeezeboxserver /etc/default/$INSTNAME
  
  cp -f /etc/init.d/squeezeboxserver /etc/init.d/$INSTNAME
  
  TMPFILE=$( /bin/mktemp -t )
  
  cat >$TMPFILE <<DIFF1;
  5c5
  < # squeezeboxserver  initscript for squeezebox.pl
  ---
  > # squeezeboxserver_trunk    initscript for squeezebox.pl
  14c14
  < # Provides:                 squeezeboxserver
  ---
  > # Provides:                 squeezeboxserver_trunk
  21c21
  < # Short-Description:        Startup script for the SqueezeBox Music Server
  ---
  > # Short-Description:        Startup script for the SqueezeBox Music Server 
svn code
  31,34c31,34
  < DESC="Squeezebox Server"
  < NAME=squeezeboxserver
  < DAEMON=/usr/sbin/\$NAME
  < DAEMON_SAFE=/usr/sbin/\${NAME}_safe
  ---
  > DESC="Squeezebox Server svn code"
  > NAME=squeezeboxserver_trunk
  > DAEMON=/usr/share/\$NAME/server/slimserver.pl
  > DAEMON_SAFE=/usr/sbin/squeezeboxserver_safe
  37c37
  < SLIMUSER=\$NAME
  ---
  > SLIMUSER=squeezeboxserver
  DIFF1
  
  patch /etc/init.d/$INSTNAME $TMPFILE
  rm $TMPFILE
  
  
  
  
#------------------------------------------------------------------------------
  # Create the service control links..
  /usr/sbin/update-rc.d -f $INSTNAME defaults
  
  
  
#------------------------------------------------------------------------------
  # Fix file permissions..
  echo 'Fixing file permissions...'
  chown -R squeezeboxserver:nogroup "/etc/$INSTNAME"
  chown -R squeezeboxserver:nogroup "/usr/share/$INSTNAME"
  chown -R squeezeboxserver:nogroup "/var/lib/$INSTNAME"
  chown -R squeezeboxserver:nogroup "/var/log/$INSTNAME"
  
  
  
#------------------------------------------------------------------------------
  # Start the service..
  #service $INSTNAME start
  
  echo "Done! The Squeezebox Server svn code is ready to run as a service 
(daemon)."
  echo "Run the command \"service $INSTNAME start\" to start the service."
  echo ' '
  echo "Run the command \"svn up $DESTREPO\" to update $INSTNAME."
  echo ' '
  echo 'Enjoy!'
  
  exit 0
  
  
--------------------


-- 
gharris999
------------------------------------------------------------------------
gharris999's Profile: http://forums.slimdevices.com/member.php?userid=115
View this thread: http://forums.slimdevices.com/showthread.php?t=79400

_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix

Reply via email to