#!/bin/sh DAEMON=sispmctl DAEMON_LONG_NAME="SIS-PM" MODSHAREDIR="/var/mod/usr/share" SISPMCTL_DEFAULT_WEBDIR="/usr/share/$DAEMON" SISPMCTL_WEBDIR="$MODSHAREDIR/$DAEMON" . /etc/init.d/modlibrc [ -n "$SISPMCTL_PORT" ] && DEFAULTPORT="$SISPMCTL_PORT" || DEFAULTPORT="2638" sis_error_reporter() { # printing error messages finalising it with 'done' or 'failed' # $1: Error code # $2: Error message (optional) retval=$1 case $retval in 0) echo "done." && return $retval;; 1) echo "failed." && return $retval;; 11) echo -n "none SIS-PM device connected on USB port ... ";; 12) echo -n "web directory with actual skin not found ... ";; 13) echo -n "can not create working directory for web interface ... ";; 21) echo -n "PID verification fault ... ";; *) [ -z "$2" ] && echo -n "unknown error #$1 ... " || echo -n "$2 ... " ;; esac echo "failed." return $retval } sis_pid() { # detecting sispmctl pid for defined port number # $1: Port number for integrated web interface [ -n "$1" ] && sis_webport="$1" || sis_webport="$DEFAULTPORT" sis_pid="$(ps | sed -n -e "/[[:space:]]sispmctl.* -p $1/s/^ *\([0-9]*\) .*/\1/p")" if [ -z "$sis_pid" ] then echo "" retval=1 else echo "$sis_pid" retval=0 fi return $retval } sispmctl_daemon() { # daemon start for integrated web interface # $1: device number (1...9) in freetz configuration (required for name conversion) # $1=0: special case for binding device #0 on default port [ -n "$1" ] && out_number=$1 || out_number=0 eval sis_id="\$SISPMCTL_D${out_number}_ID" eval sis_name="\$SISPMCTL_D${out_number}_NAME" eval sis_webport="\$SISPMCTL_D${out_number}_PORT" [ -z "$sis_name" ] && sis_name="SIS-PM-$out_number" [ -z "$sis_webport" ] && sis_webport="$DEFAULTPORT" [ $out_number -eq 0 ] && sis_id=$(echo "$IDs" | head -n 1) # special case: use first ID WEBDIR_PORT="$SISPMCTL_WEBDIR-$sis_webport" # separate web directory for current port PID_FILE_PORT="${PID_FILE%.pid}-$sis_webport.pid" # separate PID file for current port config par_D="" [ -n "$sis_id" ] && par_D="-D $sis_id" # option -D for ID definition echo -n " Binding web interface for $sis_name [$sis_id] on port $sis_webport ... " sispmctl -q $par_D -p $sis_webport -u "$WEBDIR_PORT" -l 1>/dev/null 2>/tmp/sispmerror siserrcode=$? if [ $siserrcode -ne 0 ] then sis_error="$(cat /tmp/sispmerror)" # cat error messages retval=20 # error during starting of sispmctl sis_error_reporter $retval "$sis_error" return $retval fi sis_pid $sis_webport > ${PID_FILE_PORT} # find PID for actual process an save it in separate PID file if [ $? -ne 0 ] then retval=21 # error: PID verification fault rm -f ${PID_FILE_PORT} >/dev/null 2>&1 sis_error_reporter $retval return $retval fi if [ -e ${PID_FILE} ] then old_pids="$(cat ${PID_FILE})" new_pid="$(cat ${PID_FILE_PORT})" echo "$old_pids $new_pid" > ${PID_FILE} 2>/dev/null # global PID file consists all the PIDs separated by spaces (like pidof) else cp ${PID_FILE_PORT} ${PID_FILE} >/dev/null 2>&1 fi retval=0 sis_error_reporter $retval return $retval } prepare_webdir() { # preparation of web directories for internal integrated web interface # standard names for outlets are replaced with user defined values # $1: device number (0...9) in freetz configuration (required for name conversion) retval=0 [ -n "$1" ] && out_number=$1 || out_number=1 eval sis_name="\$SISPMCTL_D${out_number}_NAME" eval sis_webport="\$SISPMCTL_D${out_number}_PORT" [ -z "$sis_name" ] && sis_name="SIS-PM-$out_number" [ -z "$sis_webport" ] && sis_webport="$DEFAULTPORT" kk=1 while [ $kk -le 4 ] do # reading names for outlets 1...4 from FREETZ configuration eval NAME_O_curr="\$SISPMCTL_D${out_number}_O${kk}" [ -z "$NAME_O_curr" ] && NAME_O_curr="Socket ${kk}" eval NAME_O${kk}="\$NAME_O_curr" kk=$(($kk + 1)) done # Internal web interface will be run from /var/mod/usr/share/sispmctl-PORT WEBDIR_PORT="$SISPMCTL_WEBDIR-$sis_webport" [ -d "$WEBDIR_PORT" ] || mkdir "$WEBDIR_PORT" >/dev/null 2>&1 retval=$? [ $retval -eq 0 ] || return 13 # can't create web directory [ -n "$WEBDIR_PORT" -a -d "$WEBDIR_PORT" ] && rm -R -f ${WEBDIR_PORT}/* >/dev/null 2>&1 if [ -n "$SISPMCTL_SKIN" -a -d "/usr/share/sispmctl-${SISPMCTL_SKIN}" ] then WEB_SOURCE_DIR="/usr/share/sispmctl-${SISPMCTL_SKIN}" else echo -n "skin ${SISPMCTL_SKIN} not found. Use default skin ... " [ -d "$SISPMCTL_DEFAULT_WEBDIR" ] && WEB_SOURCE_DIR="$SISPMCTL_DEFAULT_WEBDIR" || WEB_SOURCE_DIR="" fi [ -z "$WEB_SOURCE_DIR" ] && return 12 # can't find source directory with actual skin for web interface ls -1 "$WEB_SOURCE_DIR" | while read file_name do # linking and copying of actual skin if [ "$file_name" = "index.html" ] then # index.html is parsed for user defined name conversion cat /usr/share/sispmctl-${SISPMCTL_SKIN}/index.html \ | sed -e "s/