#!/bin/sh DAEMON=external CONF_NAME=mod . /etc/init.d/modlibrc local LOG_FILE=/var/log/$DAEMON.log local EXTERNAL_LINK=/mod/external local EXTERNAL_DIRECTORY=`echo $MOD_EXTERNAL_DIRECTORY|sed 's/\/*$//'` local EXTERNAL_CUSTOM_FILE=/tmp/flash/mod/rc.external #parameter -n: no new-line at line end #parameter -x: add trailing new-line, if logfile exists log() { local addl="" local newl="" while [ "$1" == "-n" -o "$1" == "-x" ]; do [ "$1" == "-n" ] && newl="-n" [ "$1" == "-x" ] && [ -f $LOG_FILE ] && addl="\n" shift done [ -z "$*" ] && return echo $newl -e "$addl$*" | tee -a $LOG_FILE [ "$*" == "." -o "$*" == " ." ] && return echo "EXTERNAL: $*" > /dev/console logger -t EXTERNAL "$*" } check_date() { log -n "Waiting for time-synchronisation:" counter=225 spaceit=" " while [ `date +%Y` -lt 2010 -a $counter -ne 0 ]; do log -n "$spaceit." spaceit= [ "$MOD_EXTERNAL_WAIT_INFINITE" == "yes" ] || let counter=$counter-1 sleep 4 done if [ `date +%Y` -lt 2010 ]; then log " timeout, failed." exit 1 fi if [ `date +%Y` -gt $MOD_EXTERNAL_YEAR_MAX ]; then log " error, failed." [ -f /tmp/flash/mod/external.year ] && . /tmp/flash/mod/external.year exit 1 fi log " done." } exec_rcs() { eventadd 1 "Running external: $1" 2>/dev/null if [ "$MOD_EXTERNAL_FREETZ_SERVICES" != "yes" ]; then if [ -z "$MOD_EXTERNAL_OWN_SERVICES" ]; then log "No services selected, failed." exit 1 fi EXTERNAL_SERVICES="$MOD_EXTERNAL_OWN_SERVICES" else EXTERNAL_SERVICES="$(cat /etc/external.pkg 2>/dev/null) $MOD_EXTERNAL_OWN_SERVICES" fi if [ ! -d "$EXTERNAL_DIRECTORY" ]; then rm -rf "$EXTERNAL_LINK" 2>/dev/null log "Directory could not be found, failed." exit 1 fi for pkg in $(cat /etc/static.pkg 2>/dev/null); do if echo " $EXTERNAL_SERVICES " | grep -q " $pkg "; then [ -x /etc/init.d/rc.$pkg ] && log "$(/etc/init.d/rc.$pkg $1 2>&1)" fi done [ -f $EXTERNAL_CUSTOM_FILE ] && log "$(. $EXTERNAL_CUSTOM_FILE $1 2>&1)" } start() { log -x "Starting external ($EXTERNAL_DIRECTORY):" if [ ! -e /tmp/.modstarted -o -e /var/run/onlinechanged ]; then log -n "Waiting for mod-startup:" spaceit=" " while [ true ]; do [ -e /tmp/.modstarted -a ! -e /var/run/onlinechanged ] && break log -n "$spaceit." spaceit= sleep 1 done log " done." fi [ "$MOD_EXTERNAL_YEAR_MIN" == "yes" ] && check_date rm -rf "$EXTERNAL_LINK" 2>/dev/null ln -s "$EXTERNAL_DIRECTORY" "$EXTERNAL_LINK" exec_rcs load log "Starting external finished." } stop() { log -x "Stopping external ($EXTERNAL_DIRECTORY):" if [ -e /var/run/shutdown ]; then log -x "Stopping external is skipped because of system shutdown." else exec_rcs unload fi rm -rf "$EXTERNAL_LINK" 2>/dev/null log "Stopping external finished." } if [ $# -ge 2 ]; then # no output, every mounted partition runs this with its path echo "$EXTERNAL_DIRECTORY" | grep -q "$2" || exit 1 fi create_custom_file() { cat << 'EOF' > $EXTERNAL_CUSTOM_FILE #!/bin/sh case "$1" in load) ;; unload) ;; esac EOF } case $1 in ""|load) modreg file mod rc_external rc.external 0 rc_external [ ! -e $EXTERNAL_CUSTOM_FILE ] && create_custom_file ;; start) start ;; stop) stop ;; status) [ -d "$EXTERNAL_DIRECTORY" ] && echo running || echo stopped ;; *) echo "Usage: $0 [start|stop|status] [mountpoint]" 1>&2 echo "Logfile is stored here: $LOG_FILE" exit 1 ;; esac exit 0