Extending uShare with RC Scripts

Posted on November 19, 2007
Author: Sean Potter
Pages: 1 2 3
Tags: HTPC, Gentoo, uPnP

To begin, we need to make sure that the user doesn't have an empty or missing variable. We'll add the checkconfig function to our rc-script to make sure all four variables are present. We can access our variables from the config file the same way we access HOSTNAME, via $variables.
# Copyright 2007 Sean Potter
# Distributed under the terms of the GNU General Public License, v2 or later

  need net
  use logger

checkconfig() {
        if [ -z "$uNAME" ] || [ -z "$uINT" ] || [ -z "$uOPTS" ] || [ -z "$uPORT" ] ; then
          eerror "You must set config options in /etc/conf.d/ushare first"
          return 1

start() {
        ebegin "Starting uShare with XBox 360 Support"
        checkconfig || return 1
        start-stop-daemon --start --background --pidfile /var/run/ushare.pid --make-pidfile --exec /usr/bin/ushare -- -i $uINT -p $uPORT $uOPTS -n $uNAME
        eend $?

stop () {
        ebegin "Stopping uShare with XBox 360 Support"
        start-stop-daemon --stop --quiet --pidfile=/var/run/ushare.pid
        eend $?
The end result looks good to me. We're checking for required configuration options, then starting the service with the options that we configured. If you're into more advanced scripting, you could probably extend this further so you would be able to declare all your shared directories in a single variable, then let the script take care of passing each one to uShare. If you've got the knowledge to write that kind of script, please reply join the discussion in our forums. For this post's purposes, this simple configuration is all that is needed. In my next article on uShare, we'll look at creating an ebuild of the file to insert into portage. I hope you enjoyed this short how-to. In a future article, I'll show you how to package up uShare's sourcecode and our custom RC scripts into an eBuild for Gentoo's portage. Stay tuned!

Jump to page:

blog comments powered by Disqus