#!/bin/sh

#*********************************************************************************************************
#*   __     __               __     ______                __   __                      _______ _______   *
#*  |  |--.|  |.---.-..----.|  |--.|   __ \.---.-..-----.|  |_|  |--..-----..----.    |       |     __|  *
#*  |  _  ||  ||  _  ||  __||    < |    __/|  _  ||     ||   _|     ||  -__||   _|    |   -   |__     |  *
#*  |_____||__||___._||____||__|__||___|   |___._||__|__||____|__|__||_____||__|      |_______|_______|  *
#* http://www.blackpantheros.eu | http://www.blackpanther.hu - kbarcza[]blackpanther.hu * Charles Barcza *
#*************************************************************************************(c)2002-2011********
export PATH=$PATH:/usr/sbin:/sbin

SERVICE=$1
OPTION=$2
ENGINE="/sbin/service "
if [ ! -x /sbin/service ];then
      ENGINE="/etc/rc.d/init.d/"
fi
. /etc/blackPanther-default-apps.conf

case $LANG in 
	hu*) 
	notroot=$notroot_hu
	maybeservice=$maybeservice_hu
	serviceshelp="
	
 $GRN SZOLGÁLTATÁSKEZELÉS ${BLU}blackPanther OS$GRN -hez - www.blackpantheros.eu$DEF
   
  Bekapcsol/kikapcsol egy szolgáltatást az indítási időben: szolgaltatasok szolgaltatasnev [be|ki]
    
    Például:$MAG szolgaltatasok proftpd be$DEF
    
  Elindít/Allapot/Újraindít egy szolgaltatást bármikor: szolgaltatasok szolgaltatásnev [indit|allapot|ujraindit|allj]
  
    Például:$MAG szolgaltatasok proftpd urjaindit$DEF

   
   $GRN-h|--help|--segits   megjeleníti ezt az üzenetet$DEF
"
	;;
	*) 
	notroot=$notroot_en
	maybeservice=$maybeservice_en
	serviceshelp="

 ${GRN}SERVICE MANAGEMENT FOR ${BLU}blackPanther OS$GRN - www.blackpantheros.eu$DEF
	
 Enable service in boot-time: services servicename [on|off]
  
   Example:$MAG services proftpd on$DEF
  
 Start/Status/Restart service anytime: services servicename [start|status|restart|stop]
 
   Example:$MAG services proftpd restart$DEF


  -h|--help|--segits   for this text
"
	;;
esac

fail() {
	#echo ""
    echo -e "${YEL} ** $maybeservice **"
	echo ""
    exit 1
}

if [ "$1" = '-h' -o "$1" = "--help" -o "$1" = "--segits" ]; then
	echo -e "$serviceshelp"
	exit
fi

if [ $UID != 0 ];then 
    echo -e "${RED} $notroot ${DEF}"
    echo -en "${YEL}  * "
     su -c "$0 $*" root
    exit
fi

echo -n "  
"
if [ "$OPTION" = "start" -o "$OPTION" = "indit" -o "$OPTION" = "inditas" ];then
    echo -n " * Start query: "
    RET=`$ENGINE${SERVICE} start`
    if [ "$RET" = "" ];then
    	fail
    fi
    echo "$RET"
    echo ""
    exit

elif [ "$OPTION" = "restart" -o "$OPTION" = "ujraindit" -o "$OPTION" = "ujrainditas" ];then
    echo -n " * Restart query: "
    $ENGINE${SERVICE} restart
    echo ""
    exit

elif [ "$OPTION" = "stop" -o "$OPTION" = "allj" ];then
    echo -n " * Stop query: "
    $ENGINE${SERVICE} stop
    echo ""
    exit

elif [ "$OPTION" = "status" -o "$OPTION" = "allapot" ];then
    echo -n " * Status query: "
    $ENGINE${SERVICE} status
    echo ""
    exit

fi    


if [ "$OPTION" = "be" -o "$OPTION" = "Be" -o "$OPTION" = "BE" -o "$OPTION" = "on" -o "$OPTION" = "ON" -o "$OPTION" = "On"  ];then
    echo -n " * Enable query: "    
    chkconfig "${SERVICE}" on
    echo -n " enabled "    
    echo ""
     exit
#fi
#echo 1

elif [ "$OPTION" = "ki" -o "$OPTION" = "Ki" -o "$OPTION" = "KI" -o "$OPTION" = "OFF" -o "$OPTION" = "Off" -o "$OPTION" = "off" ];then
    echo -n " * Disable query: "    
    chkconfig "${SERVICE}" off
    echo -n " disabled "    
    echo ""
    exit
# else
#    echo "Error in entered command!"
fi

echo -e "$RED ** Invalid command or parameter! Try with -h. Example $0 --help
     $DEF"
