Script - OScam [start|stop|restart|check|log|conf|server|...

feissmaik
Entwickler Team
Beiträge: 2576
Registriert: So 17. Apr 2011, 11:39
Been thanked: 1 time
Kontaktdaten:

Script - OScam [start|stop|restart|check|log|conf|server|...

Beitrag von feissmaik »

Startet, stopped, restartet, prüft ob der Prozess läuft und editiert die nötigsten Files von OScam...


Usage: OSCAM [start|stop|restart|check|log|conf|server|user]

Code: Alles auswählen

#!/bin/sh
#
# 08.2010
#
#
## Recommended HowTo:
#
# Add a new shell user and install there your Oscam:
#
#  useradd -m -s/bin/bash CS
#  usermod -G dialout,adm -a CS
#  su - CS
#  mkdir Oscam
#
# Copy your files as followed: (inc. this script as: OSCAM)
#
#  Oscam/
#  oscam  OSCAM  oscam.conf  oscam.server  oscam.services  oscam.srvid  oscam.user
#
# Add some cronjob entry so Oscam gets started on reboot and gets checked every minute:
#
# nano .cron
#
#  @reboot	$HOME/Oscam/OSCAM start  >/dev/null 2>&1
#  * * * * * 	$HOME/Oscam/OSCAM check  >/dev/null 2>&1
#
# crontab .cron
#
# ...Feel free to change the paths...
# ...which depends on your receiver/system/image...
#
### CONFIG - START


# Enable colored output-lines on shell? [yes/no]
ENABLECOLORS="yes"

# Path where the Oscam binary lies, no trailing / [Oscam-default: /var/emu]
OScamPATH="/home/CS/Oscam"

# Name of the Oscam binary [Oscam-default: oscam]
OScamBIN="oscam"

# Options to start Oscam with [Oscam-default: <none>]
# NOTE: you MUST set "-c /path/to/Oscam" if its NOT Oscam-default!
# NOTE: DON'T edit unless you know what you are doing!
OScamOPTIONS="-b -c $OScamPATH"

# Where your Oscam-log is located if enabled?
OScamLOG="/tmp/oscam.log"

# default System's binary paths to locate nano and rar, no trailing /
# NOTE: DON'T edit unless you know what you are doing!
SYSTEMbinPATHS="/bin /usr/bin"

### CONFIG - END


# -------------------------------------------------------------- #
# >>> >> >  DO NOT MESS WiTH ANYTHiNG BELOW THiS LiNE!  < << <<< #
# -------------------------------------------------------------- #


#DEBUG="TRUE"
DEBUG="FALSE"
DATE=$(date)

if [ "$ENABLECOLORS" = "yes" ]; then
	ROT=$(tput setaf 1)
	GRUEN=$(tput setaf 2)
	BOLD=$(tput bold)
	NORM='tput op && tput sgr0'
	else
	ROT="" ; GRUEN="" ; BOLD="" ; NORM=""
fi

if [ "$SYSTEMbinPATHS" = "" ] && [ ! -z "$PATH" ]; then
	SYSTEMbinPATHS=$PATH
fi

# This method starts OScam
start_cam() {
	if ps x |grep -v grep |grep -c $OScamBIN >/dev/null
		then
		echo $ROT "ERROR: $OScamBIN still runs with pids: $(pidof $OScamBIN)..." ; $NORM
	else
		cd $OScamPATH
		./$OScamBIN $OScamOPTIONS
		echo $GRUEN "Successfully started OScam ($OScamOPTIONS) with pids: $(pidof $OScamBIN)" ; $NORM
	fi
}
# This method stops OScam
stop_cam() {
	PiDS=$(pidof $OScamBIN)
	if [ -z "$PiDS" ]; then
		echo $ROT "ERROR: Cant see $OScamBIN to stop..." ; $NORM
	else
		echo $GRUEN "Stopping OScam with pids: $PiDS" ; $NORM
		for pid in $PiDS
			do kill -9 $pid >/dev/null 2>&1
		done
	fi
}
# This method checks for running process and starts if not...
check_run() {
	if ps x |grep -v grep |grep -c $OScamBIN >/dev/null
		then
		echo $GRUEN "Seems OScam still runs with pids: $(pidof $OScamBIN) ..." ; $NORM
	else
		echo $ROT "Cant see OScam... Restarting!" ; $NORM
		start_cam
	fi 
}

# This method watches the $OScamLOG in realtime...
monitor_log() {
	if [ ! -e $OScamLOG ]; then
		echo $ROT "ERROR: Cant find Oscam log $OScamLOG ... Is it enabled?" ; $NORM
	else
		echo " "
		echo $BOLD "Starting monitoring of $OScamLOG in realtime. Hit STRG + C to abort!" ; $NORM
		echo " "
		sleep 1
		tail -f $OScamLOG
	fi
}

proc_Get_Editor() {
	unset UseEDITOR
	for Spath in $SYSTEMbinPATHS ; do
		if [ -x "$Spath/nano" ]; then
			UseEDITOR="$Spath/nano -R"
		fi
	done
	if [ -z "$UseEDITOR" ]; then
		for Spath in $SYSTEMbinPATHS ; do
			if [ -x "$Spath/vi" ]; then
				UseEDITOR="$Spath/vi"
			fi
		done
	fi
	if [ -z "$UseEDITOR" ]; then
		echo $ROT "ERROR: Unable to locate Editor to open file - Be sure SYSTEMbinPATHS is set currectly!" ; $NORM
		proc_exit
	fi
}

# edit files given from $1
edit_file() {
	proc_Get_Editor
	case "$1" in
		conf*)
			EFILE="$OScamPATH/oscam.conf"
		;;
		server*)
			EFILE="$OScamPATH/oscam.server"
		;;
		user*)
			EFILE="$OScamPATH/oscam.user"
			;;
			*)
			EFILE=""
			;;
		esac
		if test -f $EFILE ; then
			echo "$EFILE wird geoeffnet.."
			sleep 1 ; $UseEDITOR $EFILE
		else
			echo -e "\033[1;31mKeine Konfiguration vorhanden $EFILE\033[0m"
		fi
}


## Procedure for logging
proc_log() {
  if [ "$OScamLOG" ]; then
    if [ -w "$OScamLOG" ]; then
      echo `$DATE "+%a %b %e %T %Y"` "$@" >> $OScamLOG
    else
      if [ "$USER" = "root" ]; then
        touch $OScamLOG
        if [ -x "chmod" ]; then
          chmod 666 $OScamLOG
        fi
      else
        logname=`basename $OScamLOG`
        echo "Error: Can not write to $logname. Create and set chmod 666."
      fi
    fi
  fi
}

proc_debug() {
  if [ "$DEBUG" = "TRUE" ]; then
    echo "$*"
  fi
}

proc_exit() {
  rm -f "/tmp/OscamCheck.lock"
  exit 0
}

if [ -e "/tmp/OscamCheck.lock" ]; then
	if [ "`find \"/tmp/OscamCheck.lock\" -type f -mmin -5`" ]; then
		echo "Lockfile /tmp/OscamCheck.lock exists and is not 5 minutes old yet. Quitting!"
		exit 0
	else
		echo "Lockfile exists, but its older then 5 minutes. Removing lockfile."
		touch "/tmp/OscamCheck.lock"
	fi
else
	touch "/tmp/OscamCheck.lock"
fi

case "$1" in
	[sS][tT][aA][rR][tT])
		echo "[SCRIPT] $1:"
		start_cam
	;;
	[sS][tT][oO][pP])
		echo "[SCRIPT] $1:"
		stop_cam
	;;
	[rR][eE][sS][tT][aA][rR][tT])
		echo "[SCRIPT] $1:"
		stop_cam
		sleep 5
		start_cam
	;;
	[cC][hH][eE][cC][kK])
		echo "[SCRIPT] $1:"
		check_run
	;;	
	[lL][oO][gG]|[sS][hH][oO][wW][lL][oO][gG])
		echo "[SCRIPT] $1:"
		monitor_log
	;;
	[cC][oO][nN][fF])
		echo "[SCRIPT] $1:"
		edit_file "conf"
	;;
	[sS][eE][rR][vV][eE][rR])
		echo "[SCRIPT] $1:"
		edit_file "server"
	;;
	[uU][sS][eE][rR])
		echo "[SCRIPT] $1:"
		edit_file "user"
	;;
	*)
		echo "Usage: $0 [start|stop|restart|check|log|conf|server|user]"
	;;
	esac
proc_exit

Du musst nicht kämpfen um zu siegen

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 0 Gäste