gharris999;415761 Wrote:
> So..I can't agree with your assessment that this approach is "over
> engineered." To me, it makes perfect sense to keep the platform
> specific stuff external to the plugin.
:-) Sorry if I came across critical of your good work, but it wasn't so
much an "assessment", more a gut feeling without any knowledge of the
internals. Thanks for the explanation anyway, although I still don't
get the bit about gharris999;415761 Wrote:
> On windows, that utility is SCPowerTool.exe and it uses that UTC based
> time to schedule the wakeup without having to reference any local time
> offset from UTC since we've established that Windows keeps the RTC in local
> time, so
something must be referencing a local time offset (or is it the Windows
API or something like that?).
Anyway, I think I've fixed the script:
Code:
--------------------
#!/bin/bash
#
# SrvrPowerCtrl plugin helper script for linux.
#
# This script will set the system's RTC to wake the system up in advance of a
programmed SqueezeCenter alarm.
#
# It attempts to accommodate hardware clocks set either to UTC or local time.
(Thnx to rickwookie.)
#
#
# Copy this script to /usr/bin/scwakeup.sh: cp ./scwakeup.sh
/usr/bin/scwakeup.sh
#
# Give root only permissions: chown root:root /usr/bin/scwakeup.sh
#
# Make it executable: chmod a+x /usr/bin/scwakeup.sh
#
# Test it: sudo /usr/bin/scwakeup.sh 1234567890
#
# View the log: cat /var/log/squeezecenter/srvrpowerctrl.log
#
# See http://www.mythtv.org/wiki/index.php/ACPI_Wakeup
# for apci wakeup troubleshooting...
#
debug=1
log_file=/var/log/squeezecenter/srvrpowerctrl.log
clear
rm $log_file
#Try to figure out if RTC is set to UTC or local time..
rtcStatus=`/sbin/hwclock --debug --directisa`
if [[ "$rtcStatus" =~ "Hardware clock is on UTC time" ]]
then
RTCisUTC=1
else
RTCisUTC=0
fi
#Get the wakeup time from the cmd line arg..
waketimeUTC=$1
waketimeUTCp=`/bin/date -u -d "1970-01-01 $waketimeUTC seconds" +"%Y-%m-%d
%H:%M:%S"`
#Compute the local time offset in seconds from UTC..
localOffsetStr=`/bin/date +%z`
#Is our offset from UTC positive (east) or negative (west)?
if [[ "$localOffsetStr" =~ "+" ]]
then
IsWest=0
else
IsWest=1
fi
localOffsetHours="${localOffsetStr:1:2}"
localOffsetMinutes="${localOffsetStr:3:2}"
localOffsetSeconds=$(($localOffsetHours*3600+$localOffsetMinutes*60))
if [[ $IsWest>0 ]]
then
localOffsetSeconds=-$localOffsetSeconds
fi
#Compute the local wakeup time..
waketimeLocal=$(($waketimeUTC+$localOffsetSeconds))
waketimeLocalp=`/bin/date -u -d "1970-01-01 $waketimeLocal seconds"
+"%Y-%m-%d %H:%M:%S"`
if [[ $debug>0 ]]
then
if [[ $RTCisUTC>0 ]]
then
echo " RTC is set to == UTC" >>$log_file
else
echo " RTC is set to == localtime"
>>$log_file
fi
/bin/echo " Localtime offset from UTC == $localOffsetStr"
>>$log_file
/bin/echo "Localtime offset seconds form UTC == $localOffsetSeconds"
>>$log_file
/bin/echo " waketimeUTC == $waketimeUTC"
>>$log_file
/bin/echo " waketimeUTCp == $waketimeUTCp"
>>$log_file
/bin/echo " waketime local == $waketimeLocal"
>>$log_file
/bin/echo " waketime localp == $waketimeLocalp"
>>$log_file
fi
#Which type of RTC interface is present?
if [[ -f /sys/class/rtc/rtc0/wakealarm ]]
then
if [[ $RTCisUTC>0 ]]
then
#Kernels > 2.6.22 and higher use /sys/class/rtc/rtc0/wakealarm
/bin/echo "Setting /sys/class/rtc/rtc0/wakealarm to
$waketimeUTC ($waketimeUTCp)" >>$log_file
/bin/echo 0 >/sys/class/rtc/rtc0/wakealarm
/bin/echo $waketimeUTC >/sys/class/rtc/rtc0/wakealarm
else
/bin/echo "Setting /sys/class/rtc/rtc0/wakealarm to
$waketimeLocal ($waketimeLocalp)" >>$log_file
/bin/echo 0 >/sys/class/rtc/rtc0/wakealarm
/bin/echo $waketimeLocal >/sys/class/rtc/rtc0/wakealarm
fi
elif [[ -f /proc/acpi/alarm ]]
then
if [[ $RTCisUTC>0 ]]
then
#Kernels < 2.6.21 and lower use /proc/acpi/alarm
/bin/echo "Setting /proc/acpi/alarm to $waketimeUTCp"
>>$log_file
/bin/echo $waketimeUTCp >/proc/acpi/alarm
else
/bin/echo "Setting /proc/acpi/alarm to $waketimeLocalp"
>>$log_file
/bin/echo $waketimeLocalp >/proc/acpi/alarm
fi
else
/bin/echo "SrvrPowerCtrl does not support RTC wakeup on this system!"
>>$log_file
fi
if [[ $debug>0 ]]
then
/bin/cat $log_file
fi
--------------------
Changing #!/bin/sh to #!/bin/bash makes stuff between [[ ]] work, and
since bc (and dc and concalc] doesn't seem to be installed by default
on Ubuntu (though they're in the repository) and since this is only
integer calculations, $(($VarA+$VarB)) will do.
Since I knew nothing about Linux shell scripting before today, that
took quite a bit of guess work and googling.
--
rickwookie
------------------------------------------------------------------------
rickwookie's Profile: http://forums.slimdevices.com/member.php?userid=6397
View this thread: http://forums.slimdevices.com/showthread.php?t=62339
_______________________________________________
plugins mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/plugins