summaryrefslogtreecommitdiffstats
path: root/scripts/S88hdsync
blob: 8e4b7929f28f96f3b846a333f5e09587eb2c9653 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
#
# Copyright (C) 2010-2011 Denis Roio <jaromil@nimk.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or 
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# wait the boot to complete

APPROOT=/apps/hdsync

if [ "$1" = "stop" ]; then
    UPNPPORT="`lsof -a -i4 -sTCP:LISTEN -c DMARender -F n | awk -v FS=':' '/^n/ {print $2}'`"
    $APPROOT/bin/avremote -p $UPNPPORT stop
    rm -f /tmp/hdsync.reply
    umount /apps/hdsync
    exit 0
fi

sleep 15


touch /tmp/hdsync.log
# USBROOT=`mount | awk '/.tmp.mnt/ { print $3}'`
USBROOT=`cat /tmp/appsRoot | grep hdsync | sed 's/hdsync//`
echo "HDSync app running on USB $USBROOT" >> /tmp/hdsync.log
date >> /tmp/hdsync.log
echo "args: $@" >> /tmp/hdsync.log

# if there is a custom osd, we have to wait longer
ls $USBROOT/ | grep 'osd.bin$'
if [ $? = 0 ]; then
    sleep 15
fi

if ! [ -r $USBROOT/hdsync.conf ]; then
    echo "config file not found" >> /tmp/hdsync.log
    echo "place hdsync.conf in your usb key" >> /tmp/hdsync.log
    exit 0
else
# source settings
    . $USBROOT/hdsync.conf
    echo "config file found in ${USBROOT}hdsync.conf" >> /tmp/hdsync.log
fi

export USBROOT
export APPROOT
export HDSYNC_NETWORK
export HDSYNC_CHANNEL
export HDSYNC_SLEEP
export TOTAL_CHANNELS

# load up utils
. $APPROOT/bin/utils-sync.sh

# retrieve network details
get_ip

# retrieve application details
get_bins $APPROOT

if [ $HDSYNC_SLEEP ]; then
    echo "SLEEP adjust set to $HDSYNC_SLEEP useconds" >> /tmp/hdsync.log
fi

UPNPPORT="`lsof -a -i4 -sTCP:LISTEN -c DMARender -F n | awk -v FS=':' '/^n/ {print $2}'`"
export UPNPPORT
echo "UPNP port detected listening on $UPNPPORT" >> /tmp/hdsync.log
# this exports UPNPPORT if a UPNP daemon is found listening

# wait that the usb is mounted
sleep 10

# turn off screensaver
config_tool -c DMA_ENABLE_SCREENSAVER='0'
config_tool -c DMA_SCREENSAVER='0'

# kill all services hogging our resources
killall dmaosd
killall pandora_ep
killall apache2
killall smbtree

if test $WATCHDOGTIMER -gt 0; then
    #start watchdog timer
    echo "starting watchdog, movielenght is $WATCHDOGTIMER" 
    ps | grep watchdog | grep -v grep
    if [ $? -ne 0 ]; then
        rm -f /tmp/hdsync.error
        touch /tmp/hdsync.error
        $APPROOT/bin/watchdog.sh >> /tmp/hdsync.error &
    fi
fi

if [ "$HDSYNC_CHANNEL" = "1" ]; then
    echo "Offering sync" >> /tmp/hdsync.log
    $APPROOT/bin/offer-sync.sh >> /tmp/hdsync.log
else
    echo "Listening for sync offers" >> /tmp/hdsync.log
    $APPROOT/bin/listen-sync.sh >> /tmp/hdsync.log
fi