summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeine_Ahnung <dirk-vdr@gmx.de>2013-02-06 20:15:43 +0100
committerKeine_Ahnung <dirk-vdr@gmx.de>2013-02-06 20:15:43 +0100
commita99c8f45640a05ca3f529fedab799939211a1cf9 (patch)
tree33a3278d8d1ac6d47f552ca0596498ea3a921bab
parentb2316e705cf742ac9e811d3c3e200a8f21547bab (diff)
downloadvdr-plugin-uactivity-a99c8f45640a05ca3f529fedab799939211a1cf9.tar.gz
vdr-plugin-uactivity-a99c8f45640a05ca3f529fedab799939211a1cf9.tar.bz2
fixed makefile install target; finished #20-switch_tv_light activity script
-rw-r--r--Make.config.template4
-rw-r--r--Makefile.1.7.x7
-rw-r--r--[-rwxr-xr-x]script/uactivity/activity/#20-switch_tv_light65
3 files changed, 51 insertions, 25 deletions
diff --git a/Make.config.template b/Make.config.template
index 04fc5e2..eaa22fa 100644
--- a/Make.config.template
+++ b/Make.config.template
@@ -4,9 +4,7 @@
# Copy this file to 'Make.config' and change the parameters as necessary.
#
-# The shell comman used
-# If you are using upstart you may use
-# PLUGIN_UACTIVITY_COMMAND=initctl emit --system --no-wait vdr-uactivity reason=%1$$s orgin=%2$$s value=%3$$s ConfigDirectory=%4$$s CacheDirectory=%5$$s ResourceDirectory=%6$$s
+# The shell command used
PLUGIN_UACTIVITY_COMMAND?=vdr-uactivity -r %1$$s -o %2$$s -v %3$$s -C %4$$s -c %5$$s -R %6$$s
diff --git a/Makefile.1.7.x b/Makefile.1.7.x
index 047ad15..6c2c777 100644
--- a/Makefile.1.7.x
+++ b/Makefile.1.7.x
@@ -22,6 +22,7 @@ LOCDIR = $(call PKGCFG,locdir)
PLGCFG = $(call PKGCFG,plgcfg)
BINDIR = $(call PKGCFG,bindir)
CFGDIR = $(call PKGCFG,configdir)
+CACHEDIR = $(call PKGCFG,cachedir)
#
TMPDIR ?= /tmp
@@ -123,10 +124,16 @@ ifndef PLUGIN_UACTIVITY_NOINSTALL_BIN
install -D script/vdr-uactivity $(DESTDIR)$(BINDIR)/vdr-uactivity
install -d $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/activity
install script/uactivity/activity/* $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/activity
+ chmod -x $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/activity/README
install -d $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/key
install script/uactivity/key/* $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/key
+ chmod -x $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/key/README
install -d $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/watchdog
install script/uactivity/watchdog/* $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/watchdog
+ chmod -x $(DESTDIR)$(CFGDIR)/plugins/$(PLUGIN)/watchdog/README
+ [ -d "$(DESTDIR)$(CACHEDIR)/plugins/$(PLUGIN)/activity" ] && chmod ugo+w $(DESTDIR)$(CACHEDIR)/plugins/$(PLUGIN)/activity || true
+ [ -d "$(DESTDIR)$(CACHEDIR)/plugins/$(PLUGIN)/key" ] && chmod ugo+w $(DESTDIR)$(CACHEDIR)/plugins/$(PLUGIN)/key || true
+ [ -d "$(DESTDIR)$(CACHEDIR)/plugins/$(PLUGIN)/watchdog" ] && chmod ugo+w $(DESTDIR)$(CACHEDIR)/plugins/$(PLUGIN)/watchdog || true
endif
install: install-lib install-i18n install-bin
diff --git a/script/uactivity/activity/#20-switch_tv_light b/script/uactivity/activity/#20-switch_tv_light
index baae21f..8f1c13c 100755..100644
--- a/script/uactivity/activity/#20-switch_tv_light
+++ b/script/uactivity/activity/#20-switch_tv_light
@@ -5,19 +5,21 @@ set -e
# Your Settings
#
+SWITCH_ON_CMD="touch /tmp/tv_light"
+SWITCH_OFF_CMD="rm -f /tmp/tv_light"
+USE_DAYLIGHT="yes"
LATITUDE="52.000000"
LONGITUDE="11.000000"
# http://search.cpan.org/~rkhill/DateTime-Event-Sunrise-0.0501/lib/DateTime/Event/Sunrise.pm#METHODS
ALTITUDE="-0.833"
-SWITCH_ON_CMD="touch /tmp/tv_light"
-SWITCH_OFF_CMD="rm -f /tmp/tv_light"
#
# End of user config
# apt-get install libdatetime-event-sunrise-perl
-JOB_ID_FILE="${4}/activity/jobid.$(basename ${0})"
+JOB_ID_DIR="${4}/activity/$(basename ${0}).data"
+JOB_ID_FILE="${JOB_ID_DIR}/jobid"
@@ -26,7 +28,7 @@ daylight(){
export LONGITUDE
export ALTITUDE
-sunset="$(perl <<'EOF' 2> /dev/null
+sunsetsunrise="$(perl <<'EOF' 2> /dev/null
use DateTime;
use DateTime::Event::Sunrise;
use DateTime::Format::Strptime;
@@ -39,22 +41,28 @@ sunset="$(perl <<'EOF' 2> /dev/null
my $sunset = DateTime::Event::Sunrise ->sunset (longitude => $longitude, latitude => $latitude, altitude => $altitude, iteration => '1');
my $strp = DateTime::Format::Strptime->new(pattern => '%H:%M %Y-%m-%d');
- print $strp->format_datetime($sunset->next(DateTime->now(time_zone=>'local')));
-
my $day_set = DateTime::SpanSet->from_sets(start_set => $sunrise, end_set => $sunset);
- $day_set->contains(DateTime->now()) ? exit 1 : exit 0;
+ if ($day_set->contains(DateTime->now())) {
+ print $strp->format_datetime($sunset->next(DateTime->now(time_zone=>'local')));
+ exit 1;
+ } else {
+ print $strp->format_datetime($sunrise->next(DateTime->now(time_zone=>'local')));
+ exit 0;
+ }
EOF
)"
err=$?
+
+ [ -z "${sunsetsunrise}" ] && return 2
+
if [ ${err} = 0 ]; then
- echo ""
+ echo "${sunsetsunrise}"
return 0
elif [ ${err} = 1 ]; then
- echo "${sunset}"
+ echo "${sunsetsunrise}"
return 1
else
- echo ""
return 2
fi
}
@@ -71,23 +79,36 @@ delete_job(){
+create_job(){
+ JOB_ID_TMP="$(echo "rm -f "${JOB_ID_FILE}"; ${1}" | at ${2} 2>&1)"
+ JOB_ID="$(echo "${JOB_ID_TMP}" | tr -d '\n' | sed 's/^.*job \([0-9]*\).*$/\1/')"
+ mkdir -p "${JOB_ID_DIR}"
+ echo "${JOB_ID}" > ${JOB_ID_FILE}
+}
+
+
+
switch_tv_light(){
- delete_job
if [ "${1}" = "on" ]; then
- sunset="$(daylight)"
- light=$?
- if [ "${light}" = "1" ]; then
- # daylight now, shedule "light on" for later
- JOB_ID_TMP="$(echo "rm -f "${JOB_ID_FILE}"; ${SWITCH_ON_CMD}" | at ${sunset} 2>&1)"
- JOB_ID="$(echo "${JOB_ID_TMP}" | tr -d '\n' | sed 's/^.*job \([0-9]*\).*$/\1/')"
- echo "${JOB_ID}" > ${JOB_ID_FILE}
- elif [ "${light}" = "0" ]; then
- eval ${SWITCH_ON_CMD}
+ if [ "${USE_DAYLIGHT}" = "yes" ]; then
+ delete_job
+ sunsetsunrise="$(daylight)" && light=0 || light=$?
+ if [ "${light}" = "1" ]; then
+ # daylight now, shedule "light on" for later
+ create_job "${SWITCH_ON_CMD}" "${sunsetsunrise}"
+ elif [ "${light}" = "0" ]; then
+ eval ${SWITCH_ON_CMD}
+ # no daylight now, shedule "light off" for later
+ create_job "${SWITCH_OFF_CMD}" "${sunsetsunrise}"
+ else
+ # Some error
+ eval ${SWITCH_OFF_CMD}
+ fi
else
- # Some error
- eval ${SWITCH_OFF_CMD}
+ eval ${SWITCH_ON_CMD}
fi
else
+ [ "${USE_DAYLIGHT}" = "yes" ] && delete_job
eval ${SWITCH_OFF_CMD}
fi
}