[mythtv-users] ACPI

Daryl McDonald darylangela at gmail.com
Sun Sep 13 17:39:36 UTC 2020

I hope this result will confirm that I have followed your instruction:

daryl at trieli:~$ ls -al /etc/sudoers.d/acpi
-r--r----- 1 root root 162 Sep 13 09:45 /etc/sudoers.d/acpi
daryl at trieli:~$ sudo cat /etc/sudoers.d/acpi
#instead of adding directly to sudoers file, this file was created

#mythtv,%mythtv ALL = NOPASSWD: /sbin/shutdown, /usr/bin/setwakeup.sh,

daryl at trieli:~$ ls -al /sbin/shutdown
lrwxrwxrwx 1 root root 14 Jul  6 17:38 /sbin/shutdown -> /bin/systemctl
daryl at trieli:~$ ls -al /usr/bin/setwakeup.sh
-r-xr-xr-x 1 root mythtv 1221 Sep 10 16:37 /usr/bin/setwakeup.sh
daryl at trieli:~$ ls -al /usr/bin/checklogin.sh
-r-xr-xr-x 1 root mythtv 1222 Sep 10 16:47 /usr/bin/checklogin.sh
daryl at trieli:~$ cat /usr/bin/setwakeup.sh
#$1 is the first argument to the script. It is the time in seconds since
#this is defined in mythtv-setup with the time_t argument

echo 0 > /sys/class/rtc/rtc0/wakealarm      #this clears your alarm.
echo $1 > /sys/class/rtc/rtc0/wakealarm     #this writes your alarm

LOG_FILE='/var/log/mythtv/hwclock-rebootTime.log' #log file

# Now write the time the system is expected to come out of power save mode
# so there is at least a small record of when if it was supposed to recover

# Note:- Log file will just keep growing

# date in Epoch format
a="`date  +%s`"

# Subtract Current time from Future time
let "b=$1-$a"

# echo $b
# echo "result of time subtraction `date -d @$b`"

# Get Date and Subtract 1,.. as date starts from 1st Jan 1970
dte=`date -d @$b +%d`
let "dte -= 1"

echo "Current Time      ->`date`" >> $LOG_FILE

# Simple check to determine if to include days in output string
if (dte=0)
    echo "Shutting down for ->`date -d @$b +%Hhrs:%MMins`" >> $LOG_FILE
    echo "Shutting down for ->$[dte]Days `date -d @$b +%Hhrs:%MMins`" >>

echo "Wake up at approx.->`date -d @$1`"  >> $LOG_FILE
echo "------------------------------------------------------" >> $LOG_FILE

daryl at trieli:~$ cat /usr/bin/checklogin.sh
# Check to see if anyone is currently logged in or if the machine was
recently switched on.
# Echoed text appears in log file. It can be removed and --quiet added to
# grep command once you are satisfied that mythTV is working properly.
# Exit codes:-
# 2 - Machine recently switched on, don't shut down.
# 1 - A user is logged in, don't shut down.
# 0 - No user logged in, OK to shut down.

# Customizable variables
MIN_UPTIME=10   # Minimum up time in minutes
# End of customizable variables

# Get a date/time stamp to add to log output
DATE=`date +%F\ %T\.%N`

UPTIME=`cat /proc/uptime | awk '{print int($1/60)}'`

if [ "$UPTIME" -lt "$MIN_UPTIME" ]; then
    echo $DATE Machine uptime less than $MIN_UPTIME minutes, don\'t shut
    exit 2

# Some configurations ( at least lxdm + xfce4) do not report GUI-logged-on
# with "who" or "users".
# pgrep tests if processes named xfce* exist

XFCE_PROCS=`pgrep xfce`

USERS=`who -q | tail -n 1 | sed 's/[a-z #]*=//'`

if [ "$USERS" == "0" ] && [ "$XFCE_PROCS" == "" ]; then
    echo $DATE No users are logged in, ok to shut down.
    exit 0
    echo $DATE Someone is still logged in, don\'t shut down.
    exit 1

daryl at trieli:~$

On Sun, Sep 13, 2020 at 1:42 AM Stephen Worthington <
stephen_agent at jsw.gen.nz> wrote:

> On Sat, 12 Sep 2020 16:38:11 -0400, you wrote:
> >Still no joy. When I ran "sudo visudo" the comments said "consider
> creating
> >a sudoers.d file" (or something similar) which I didn't because the wiki
> >saed add this to the end of the file. Should I try the former?
> visudo will only edit the /etc/sudoers file.  It is usually better
> just to create a new file under /etc/sudoers.d, as the /etc/sudoers
> file can be updated by package updates.  However, visudo does do basic
> sanity checks on your edits, which does not happen if you create a new
> /etc/sudoers.d file.  For a /etc/sudoers.d file to work, it needs to
> be owned by root and you need to remove all write privileges.  It is
> also important that any executable file or script you are listing in
> the sudoers.d file is also not writeable at all (or only writeable by
> root).  So when I created my /usr/local/bin/mythtv-systemctl-helper.sh
> script, I did this:
> sudo chown root:mythtv /usr/local/bin/mythtv-systemctl-helper.sh
> sudo chmod u=rx,g=rx /usr/local/bin/mythtv-systemctl-helper.sh
> Then I created a /etc/sudoers.d/mythtv-systemctl-helper file
> containing this:
> mythtv,%mythtv ALL=NOPASSWD:/usr/local/bin/mythtv-systemctl-helper.sh
> which says that the mythtv user or any user in the mythtv group
> (%mythtv) can run the mythtv-systemctl-helper.sh file with sudo
> without needing a password.  I did this:
> sudo chown root:root /etc/sudoers.d/mythtv-systemctl-helper
> sudo chmod u=r,g=r /etc/sudoers.d/mythtv-systemctl-helper
> to secure that file and make sudo accept it as valid.
> _______________________________________________
> mythtv-users mailing list
> mythtv-users at mythtv.org
> http://lists.mythtv.org/mailman/listinfo/mythtv-users
> http://wiki.mythtv.org/Mailing_List_etiquette
> MythTV Forums: https://forum.mythtv.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20200913/27ce553c/attachment.htm>

More information about the mythtv-users mailing list