#!/bin/sh
########################################################################
# Begin wicd
#
# Description : Wicd bootscript
#
# Authors     : Ragnar Thomsen - rthomsen@linuxfromscratch.org
#
# Version     : BLFS 7.1
#
########################################################################

### BEGIN INIT INFO
# Provides:            
# Required-Start:      $network
# Should-Start:        firewalld iptables nftables
# Required-Stop:       $network
# Should-Stop:         firewalld nftables
# Default-Start:       3 4 5
# Default-Stop:        0 1 2 6
# Short-Description:   Starts the wicd daemon.
# Description:         Starts the wicd daemon
# X-LFS-Provided-By:   BLFS
### END INIT INFO

. /lib/lsb/init-functions
PIDFILE="/run/wicd/wicd.pid"

case "${1}" in
   start)
      if [ -e $PIDFILE ]; then
        echo "Wicd appears to already be running."
        echo "If this is not the case, then remove"
        echo "$PIDFILE and try again..."
      else
        log_info_msg "Starting wicd daemon..."
        start_daemon /usr/sbin/wicd 1>/dev/null
        evaluate_retval
      fi
      ;;

   stop)
      log_info_msg "Stopping wicd daemon..."
      if [ -e $PIDFILE ]; then
	# Shut down wpa_supplicant and any started dhcp 
	# clients before we kill Wicd
	wicd-cli -xyz 1>/dev/null
        kill $(cat $PIDFILE)
        evaluate_retval
      else
        echo "Wicd appears not to be running..."
      fi
      ;;

   restart)
      ${0} stop
      sleep 1
      ${0} start
      ;;

   status)
      if [ -e $PIDFILE ]; then
        echo "Wicd is running with pid $(cat $PIDFILE)"
      else
        echo "Wicd appears not to be running..."
      fi
      ;;

   *)
      echo "Usage: ${0} {start|stop|restart|status}"
      exit 1
      ;;
esac

exit 0

# End wicd
