#!/sbin/runscript
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

AEGIS_INSTALL_DIR="/usr/local/aegis"

if [ `id -u` -ne "0" ]; then
	echo "ERROR: Permission denied." 1>&2
	exit 1
fi

start() {
     "${AEGIS_INSTALL_DIR}"/aegis_update/AliYunDunUpdate -f agx_update.cfg
      sleep 1
      status
}

stop() {
	if [ -n "$1" ]; then
		killall -9 AliYunDunUpdate 2>/dev/null
		killall -9 AliYunDun 2>/dev/null
		killall -9 AliHids 2>/dev/null
	else
		echo "Disable Stop Aegis"
	fi
	
	sleep 1
	status
}

restart(){
	stop 1
	start
}

status(){
	if [ -n "$(ps -ef | grep AliYunDunUpdate | grep -v grep)" ]; then
		echo "Aegis is running"
	else
		echo "Aegis stopped"
	fi
}
