#!/bin/bash
# ipcop addon binary installer Ver 0.9a for IPCop 1.4.x
#
# created 01 January 2005 by Frank 'Darkmann' Koch <darkmann@black-empire.de>
# modified 02 January 2005 by Tom 'wintermute' Eichstaedt <wintermute@tom-e.de>
#
# extended 2006-02-24 by weizen_42
#


CMD="$1"

#clear screen if available
if [ -e /bin/clear ]; then
	/bin/clear
fi
if [ -e /usr/bin/clear ]; then
	/usr/bin/clear
fi

#error handling
err()
{
	echo " "
	echo "Error : $1 "
	echo " "
	echo "Choose your option:"
	echo " "
	echo "./install -i   ---> to install"
	echo "./install -u   ---> to uninstall"
	echo " "
	exit
}

# installation
ai()
{
  ## verify already installed and uninstall
  if [ -e /etc/log.d/scripts/services/dialup ]; then
    echo "Upgrading"
    au
  fi

  echo "Copying files"
  cp -p dialup /etc/log.d/scripts/services/dialup
  cp -p dialup.conf /etc/log.d/conf/services/dialup.conf

  # supported languages
  # english, german
  echo "Adding language texts"
  cd langs/
  addto_lang en.dialupmon,de.dialupmon dialupmon
  cd ..
}

# deinstallation
au()
{
  if [ ! -e /etc/log.d/scripts/services/dialup ]; then
    echo "Dialup monitor addon is not installed !"
    exit
  fi

  rm /etc/log.d/scripts/services/dialup
  rm /etc/log.d/conf/services/dialup.conf

  # remove languages
  echo "Removing language texts"
  removefrom_lang en,de dialupmon
}


# get usefull subroutines
# taken from:
# MOD Addons Server Ver 2.3 for IPCop 1.3.0/1.4.0
. ./library.addons

case $CMD in
    -i|i|install)
        echo " "
        echo "Installing now ..."
        ai
        echo "Successfully done!"
        echo " ";;

    -u|u|uninstall)
        echo " "
        echo "Deinstalling addon now ..."
        au
	echo "Successfully done!"
        echo " ";;
 
    *)
        err "Invalid Option";;
esac
sync
#end of file
