#! /bin/sh
. /etc/term.sh
PATH=/bin:/usr/bin:/sbin:/usr/sbin
term_usb()
{
#################################
## USB-HOST: das USB-Subsystem vor dem Runterfahren der Box (z.B. im Kontext eines Firmware-Updates) anhalten.
#################################
## Es wird nach dem Aufruf von /etc/hotplug/usb.pandu stop sofort zum Aufrufer zur.ckgekehrt,
## w.hrend im Hintergrund alle USB-Klienten ein "remove" gesendet bekommen, was dort dann das
## gro.e Aufr.umen ausl.st. Dieser Hintergrundproze. wartet bis zu 5 Sekunden auf
## das Beenden aller USB-Klienten und schie.t dann den OHCI-Treiber ab: Kein USB
## mehr vorhanden.
if [ -e /etc/hotplug/usb.pandu ] ; then
/etc/hotplug/usb.pandu stop
sleep 2
date > /dev/console
fi
}
## the parameter 'downgrade' is used just before /var/install is called with downgrade allowed
if [ "$1" = "downgrade" ]
then
## terminate multid to not write /var/flash/multid.leases after a downgrade with factorydefaults
## is done in /var/install
termavmforcedwait 5 multid
exit 0
fi
## Terminate any scheduled delayed reboot from firmwarecfg-CGI
local REBOOT_PID=`cat /var/run/delayed_reboot.pid`
rm /var/run/delayed_reboot.pid
if [ "$REBOOT_PID" != "" ] ; then
kill -9 $REBOOT_PID
fi
ps > /dev/console
date > /dev/console
if [ "$1" = "start" ] || [ "$1" = "start_from_internet" ] || [ "$1" = "start_tr069" ]
then
## kill everything except websrv,multid and firmwarecfg and sh
## to make room in RAM to store the firmware images before
## flashing them. if we download from the internet dsld is kept running also.
## NOTE that we have to keep the user modules for WLAN running!
## NOTE that voipd, upnpd, dsld and ctlmgr are terminated by
## firmwarecfg before the script is run, to have more free RAM (SL)
#################################
## Media-Subsystem vor dem Runterfahren der Box (z.B. im Kontext eines Firmware-Updates) anhalten.
#################################
if [ -e /etc/init.d/rc.media ] ; then
/etc/init.d/rc.media stop
sleep 2
date > /dev/console
fi
#################################
## Home Automation
#################################
if [ -x /usr/bin/aha ] ; then
/usr/bin/aha -s
fi
#################################
## EWETEL
#################################
if [ -x /bin/smartmeter ] ; then
/bin/smartmeter stop
fi
#################################
#################################
## Chrony stoppen
#################################
if [ -e /etc/init.d/rc.chrony ] ; then
/etc/init.d/rc.chrony stop
date > /dev/console
fi
if [ "$CONFIG_LLTD" = y ] ; then
lltdd -s
killall lltdd
fi
KEEP_USB=no
## due to use of term...forcedwait (may use kill -9) we have to disable the watchdog early
if [ -c /dev/watchdog ] ; then
echo disable watchdog >/dev/console
echo disable > /dev/watchdog
fi
if [ "`pidof touchdisplay`" != "" ] ; then
## Beim NLR wird der ctlmgr noch gebraucht
KEEP_CTLMGR=yes
else
KEEP_CTLMGR=no
if [ "$1" = "start" ] ; then
if [ "`pidof websrv`" = "" ] ; then
if netstat -l -n | grep -q "tcp.*\(0\.0\.0\.0\|::\):80 .*LISTEN" ; then
## active tcp listen on port 80 without websrv running
## --> keep ctlmgr running
KEEP_CTLMGR=yes
fi
fi
else
if [ "$1" = "start_from_internet" ] ; then
## one click update
KEEP_CTLMGR=yes
fi
fi
fi
if [ "$1" != "start" ] ; then
## UMTS-Stick wird beim Update via Internet u.U. noch gebraucht
KEEP_USB=yes
fi
## shutdown-list
## stage 1
## inetd restarts ftpd and smbd on demand, stop it first
PROCESSES="inetd capiotcp_server pbd faxd telefon dtrace printserv smbd nmbd"
## stage 2/3 - telefon & dect_manager have to stop before (at stage 1), configd at least.
## NOTICE: Once, if maild uses configd, it also must stop before configd.
PROCESSES_2="audiod pictured feedd playerd"
PROCESSES_3="configd"
## stage 4
## do not stop UPnP Deamon if running a UPnP-CGI
if [ "$2" != "UPNP" ] ; then
AVMDAEMONS="lltdd maild voipd usermand upnpd mediasrv avmlogd tr069discover contfiltd fritznasdb cableinfo"
else
AVMDAEMONS="lltdd maild voipd usermand mediasrv avmlogd tr069discover contfiltd fritznasdb cableinfo"
fi
if [ "$KEEP_CTLMGR" = "no" ] ; then
AVMDAEMONS="$AVMDAEMONS ctlmgr"
fi
if [ "$1" != "start" ] ; then
## we will download the update image from the internet so keep dsld running
echo "" >/dev/null
else
PROCESSES="$PROCESSES mailer"
AVMDAEMONS="$AVMDAEMONS dsld avmike"
fi
if [ "$KEEP_USB" = "no" ] ; then
term_usb
fi
ps > /dev/console
date > /dev/console
echo TERMINATING $PROCESSES > /dev/console
termforcedwait 5 $PROCESSES
date > /dev/console
echo TERMINATING $PROCESSES_2 > /dev/console
termforcedwait 5 $PROCESSES_2
date > /dev/console
echo TERMINATING $PROCESSES_3 > /dev/console
termforcedwait 5 $PROCESSES_3
date > /dev/console
echo TERMINATING $AVMDAEMONS > /dev/console
termavmforcedwait 5 $AVMDAEMONS
date > /dev/console
rm -rf /var/dtrace.txt
rm -rf /var/dtrace.tx2
termforcedwait 4 udhcpd dproxy ftpd
rmmod userman_mod
## Make room for update over internet on 7113
rmmod isdn_fbox_fon3
if [ "$1" = "start_tr069" ] ; then
echo "stopping wlan ..." >/dev/console
/etc/init.d/rc.net wlanstop
fi
killall -9 checkservices
date > /dev/console
rm -f /var/install
rm -f /var/tmp/*.image
exit 0
fi
if [ "$1" = "end" ]
then
## now kill everything else to avoid access to flash while flashing
/etc/init.d/rc.net wlanstop
if [ -c /dev/watchdog ] ; then
echo disable watchdog >/dev/console
echo disable > /dev/watchdog
fi
termforcedwait 5 mailer wpa_authenticator wstart
## do not stop UPnP Deamon if running a UPnP-CGI
if [ "$2" != "UPNP" ] ; then
termavmforcedwait 5 websrv upnpd usermand contfiltd dsld avmike multid ddnsd upnpdevd ctlmgr tr069discover
else
termavmforcedwait 5 websrv usermand contfiltd dsld avmike multid ddnsd upnpdevd ctlmgr tr069discover
fi
term_usb
exit 0
fi
echo "use: $0 [start|start_from_internet|start_tr069|end] [UPNP]"
exit 1