From 3c36d806034f2c63d48bf0d7c577969be4155fb7 Mon Sep 17 00:00:00 2001 From: Britney Fransen Date: Sat, 14 Sep 2013 16:41:47 -0500 Subject: LinHES-system, linhes-scripts: move idle.sh and xwin_find.sh to LinHES-system. LinHES-system: add gnu-netcat as dep for idle.sh. --- abs/core/LinHES-system/PKGBUILD | 8 +- abs/core/LinHES-system/idle.sh | 147 +++++++++++++++++++++++++++++++++++ abs/core/LinHES-system/xwin_find.sh | 72 +++++++++++++++++ abs/core/linhes-scripts/PKGBUILD | 8 +- abs/core/linhes-scripts/idle.sh | 147 ----------------------------------- abs/core/linhes-scripts/xwin_find.sh | 72 ----------------- 6 files changed, 226 insertions(+), 228 deletions(-) create mode 100755 abs/core/LinHES-system/idle.sh create mode 100644 abs/core/LinHES-system/xwin_find.sh delete mode 100755 abs/core/linhes-scripts/idle.sh delete mode 100644 abs/core/linhes-scripts/xwin_find.sh diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD index b97034e..a00751b 100755 --- a/abs/core/LinHES-system/PKGBUILD +++ b/abs/core/LinHES-system/PKGBUILD @@ -1,6 +1,6 @@ pkgname=LinHES-system pkgver=8.0 -pkgrel=5 +pkgrel=6 arch=('i686' 'x86_64') install=system.install pkgdesc="Everything that makes LinHES an automated system" @@ -8,7 +8,7 @@ license=('GPL2') depends=('linhes-sounds' 'xdotool' 'tilda' 'keylaunch' 'python_aosd' 'linhes-scripts>=7-24' 'udisks' 'LinHES-config>=2.3-59' 'sudo' 'python2-dbus' 'unclutter' - 'wmctrl' 'archlinux-xdg-menu' 'ethtool') + 'wmctrl' 'archlinux-xdg-menu' 'ethtool' 'gnu-netcat') backup=('etc/modprobe.d/alsa-base') binfiles="LinHES-start optimize_mythdb.py myth_mtc.py myth_mtc.sh LinHES-run load-modules-mythvantage.sh unclutter-toggle.sh tvterm.sh @@ -22,7 +22,7 @@ binfiles="LinHES-start optimize_mythdb.py myth_mtc.py myth_mtc.sh misc_recent_recordings.pl misc_status_config.py misc_status_info.sh misc_upcoming_recordings.pl misc_which_recorder.pl change_channel.sh change_channel_wrapper.sh - be_check.py checkXFSfrag.sh find_orphans.py" + be_check.py checkXFSfrag.sh find_orphans.py idle.sh xwin_find.sh" source=(LinHES-session LinHES-profile.sh $binfiles @@ -116,6 +116,8 @@ md5sums=('8fc4b7c1ddf8f3c4d2266ce55086b4d4' '8b0298f70f97cc1dc2a58b9a73c64bd3' '911b0fbc8d9178dac1a193346c9decaf' '34fc1f58ad1eabf4eff4979d420760c0' + 'c3ada01d3a739abe3f920b02d4ea3f6e' + 'a94fe6d980f4b810f2e2ae5352084b39' 'eb879fee9603a05d5420d4ce8ed9e450' '6782771960c495aeb597893f37d1e5ee' '84492954db16740f949d795b74383189' diff --git a/abs/core/LinHES-system/idle.sh b/abs/core/LinHES-system/idle.sh new file mode 100755 index 0000000..4f6174c --- /dev/null +++ b/abs/core/LinHES-system/idle.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +usage () { + echo "Usage: $0 [-h] [-s] [-t ] [-l] [-w] [-m] [-r] [-v]" + echo + echo "-h - Print this help/usage message and quit" + echo "-s - Run silently (default is verbose)" + echo "-t - Minutes of idle time needed (default is 20)" + echo "-l - Check for user logins (default: false - do not check)" + echo "-w - Check for open windows (default: false - do not check)" + echo "-m - Include mythshutdown daily wake, locked, & about to start wake in system busy" + echo " (default: daily wake, locked & about to start wake is system idle)" + echo "-r - Check if mythfrontends are running (default: false - do not check)" + echo "-v - Be more verbose for debugging" + echo + echo "Silent mode is recommended for use in cron jobs or scripts." + exit $1 +} + +msg () { # A status reporting function + [ "$VERBOSE" -ne 0 ] && echo "$*" +} + +mysql_cmd () { + /usr/bin/mysql -u root mythconverg -sBe "$*" +} + +# Command line argument handling +VERBOSE=1 +LOGINS=0 +WINDOWS=0 +DAILY=0 +RUNNING=0 +TIME_BEFORE=20 +TIME_AFTER=5 # Only adjustable by editing here + +while getopts "hslwmrt:v" OPT ; do + case $OPT in + h) usage 0 ;; + s) VERBOSE=0 ;; + t) TIME_BEFORE=$OPTARG ;; + l) LOGINS=1 ;; + w) WINDOWS=1 ;; + m) DAILY=1 ;; + r) RUNNING=1 ;; + v) VERBOSE=2 ;; + *) usage 1 ;; + esac +done +# Check for extra cruft on the command line... +shift $(($OPTIND - 1)) +[ -n "$*" ] && usage 1 + +msg "Checking what MythTV is doing now or plans to within $TIME_BEFORE minutes..." +msg + +/usr/bin/mythshutdown --status +BUSY="$?" +msg "mythshutdown returned $BUSY" +if [ "$DAILY" -eq 0 ] ; then + msg " including daily wake, locked, and about to start wake as system idle" + # Ignore daily wake, locked and about to start wake flag values + BUSY=$(($BUSY & 0x2F)) + msg " mythshutdown returned $BUSY" +fi + +SCHEMALOCK=$(mysql_cmd "select count(*) from schemalock") +msg "schemalock $SCHEMALOCK" + +JOBS=$(mysql_cmd "select count(*) from jobqueue where status = 4") +msg "running jobs $JOBS" + +INUSE=$(mysql_cmd "select count(*) from inuseprograms") +msg "inuse programs $INUSE" + +UPCOMING=$(timeout 3 misc_upcoming_recordings.pl --plain_text --text_format "%rs " --heading "" --minutes $TIME_BEFORE --recordings -1 | wc -w) +msg "planned recordings $UPCOMING" +if [ "$VERBOSE" -ge 2 ] ; then + msg + timeout 3 /usr/LH/bin/misc_upcoming_recordings.pl --plain_text --minutes $TIME_BEFORE --recordings -1 +fi + +# Check all host's mythfrontends if they are running and playing +HOSTNAMES=$(mysql_cmd "select hostname from settings where value = 'FrontendIdleTimeout'") +FERUNNING=0 +PLAYING=0 +for HOST in $HOSTNAMES +do + if [ "$VERBOSE" -ge 2 ]; then + msg "Checking $HOST's mythfrontend status..." + fi +ncOUTPUT=$(timeout 2 nc $HOST 6546 << EOF +query location +quit +EOF +) + if [ "$RUNNING" -ge 1 ] ; then + if [[ "$ncOUTPUT" == *"# "* ]]; then + FERUNNING=$(( $FERUNNING + 1 )) + msg "$HOST's mythfrontend is running $FERUNNING" + else + msg "$HOST's mythfrontend is NOT running $FERUNNING" + fi + fi + if [[ "$ncOUTPUT" == *"# Playback "* ]]; then + PLAYING=$(( $PLAYING + 1 )) + msg "$HOST is playing a recording or video $PLAYING" + else + msg "$HOST is NOT playing a recording or video $PLAYING" + fi +done + +# Check for users logged in +if [ "$LOGINS" -ge 1 ] ; then + USERS=`/usr/bin/last | /bin/grep "still logged in" | awk '{ print $1 }'` + if [ -n "$USERS" ] ; then + LOGINS=1 + msg "The following user(s) are still logged in:" + msg "${USERS}" + else + LOGINS=0 + msg "No users are logged in $LOGINS" + fi +fi + +# Check for open windows +FOUNDWINDOWS=0 +if [ "$WINDOWS" -ge 1 ] ; then + /usr/LH/bin/xwin_find.sh -q '.*(mythtv@|xterm|Firefox|Namoroka|Opera|Chromium).*' + FOUNDWINDOWS="$?" + FOUNDWINDOWS=$(($FOUNDWINDOWS == 0)) + if [ "$FOUNDWINDOWS" -eq 0 ] ; then + msg "no application windows open $FOUNDWINDOWS" + else + msg "one or more application windows open $FOUNDWINDOWS" + fi +fi + +activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING + $FERUNNING + $PLAYING + $LOGINS + $FOUNDWINDOWS)) +msg +if [ "$activities" -eq 0 ] ; then + msg "System is idle" + exit 0 +else + msg "System is busy" + exit 1 +fi diff --git a/abs/core/LinHES-system/xwin_find.sh b/abs/core/LinHES-system/xwin_find.sh new file mode 100644 index 0000000..35309dd --- /dev/null +++ b/abs/core/LinHES-system/xwin_find.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# +# xwin_find [-v|-q] [timeout] window_name_regex +# +# Look for a window of the windows full name given by a awk regular +# expression, and print the windows xwindow ID. +# +# If a timeout is given (in seconds)continue to look for the windows ID +# for this amount of time before returning. (EG default a single search) +# +# If no such window is found output nothing, just exit +# +# OPTIONS +# -v verbose, print the full matching xwininfo line on stderr +# -q do not print windows ID on stdout +# +#### +# Anthony Thyssen September 2005 +# +PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path +PROGDIR=`dirname $PROGNAME` # extract directory of program +PROGNAME=`basename $PROGNAME` # base name of program +Usage() { + echo >&2 "$PROGNAME:" "$@" + sed >&2 -n '/^###/q; s/^#$/# /; 3s/^#/# Usage:/; 3,$s/^# //p;' \ + "$PROGDIR/$PROGNAME" + exit 10; +} + +timeout=0 + +while [ $# -gt 0 ]; do + case "$1" in + [0-9]*) timeout=`date +%s` + timeout=`expr $timeout + $1 + 1` || Usage + ;; + -q) QUIET=true ;; # don't print the final window ID, just status + -v) VERBOSE=true ;; # output the full xwininfo line on stderr + + --) shift; break ;; # end of user options + -*) Usage "Unknown option \"$1\"" ;; + *) break ;; # end of user options + esac + shift # next option +done + +[ $# -lt 1 ] && Usage "Missing window search regex" +[ $# -gt 1 ] && Usage "Too many arguments." + + +find_win() { + # nice added to let it give way to starting processes + if [ "$VERBOSE" ]; then + line=`nice xwininfo -root -tree | awk '/"'"$1"'":/ {print; exit}'` + echo >&2 $line # VERBOSE - xwininfo output + echo "$line" | sed 's/ .*//' + else + nice xwininfo -root -tree | awk '/"'"$1"'":/ {print $1; exit}' + fi +} + +while :; do + id=`find_win "$1"` + if [ "$id" ]; then + [ -z "$QUIET" ] && echo $id # the window ID found + exit 0; + fi + [ `date +%s` -ge $timeout ] && break +done + +exit 1 # window was not found + diff --git a/abs/core/linhes-scripts/PKGBUILD b/abs/core/linhes-scripts/PKGBUILD index d376bbb..5ccc91a 100644 --- a/abs/core/linhes-scripts/PKGBUILD +++ b/abs/core/linhes-scripts/PKGBUILD @@ -3,12 +3,12 @@ pkgname=linhes-scripts pkgver=7 -pkgrel=52 +pkgrel=53 pkgdesc="Various scripts that help to make LinHES, LinHES." arch=('i686' 'x86_64') license=('GPL2') depends=('xosd' 'cpulimit' 'screen' 'mencoder' 'tablet-encode' 'mplayer' - 'normalize' 'handbrake-cli' 'mkvtoolnix' 'perl' 'perl-shell' 'gnu-netcat') + 'normalize' 'handbrake-cli' 'mkvtoolnix' 'perl' 'perl-shell') url="http://linhes.org/" install="linhes-scripts.install" source=( @@ -29,7 +29,6 @@ mythwelcome-config.py pause_mythcommflag limit-mythcommflag.sh vdpau-detector -idle.sh screenshooter.sh run-limit-mythcommflag linhes_update.sh @@ -44,7 +43,6 @@ myth2fuze dct700-cc.sh qip7100-cc.sh dtheme.sh -xwin_find.sh upgrade_screen_rc upgrade_linhes_script.sh acl_fix_fstab.py @@ -87,7 +85,6 @@ md5sums=('47a66238d95259d75c9c5cbcbb6da19f' '3b776bbff68906ddc2f62b7e0dde3fe4' 'a57641fb63d7bb6d92a438f1ea779a57' '3d0adf26280cde55a0c47188fff34826' - 'c3ada01d3a739abe3f920b02d4ea3f6e' 'b2c3dd48a4abb976eda2d5fbf22a173a' 'b527b01d119d3bc33b8fa69bdf1082bb' '9d077c24d102fa02e4f417d639d8b00a' @@ -102,7 +99,6 @@ md5sums=('47a66238d95259d75c9c5cbcbb6da19f' 'df727c98350a64e2171c950bbefc9c5d' '7b890e7044db38e8d439f67e398af206' '35693f50939d5827aeabfce8c5dce589' - 'a94fe6d980f4b810f2e2ae5352084b39' '974c137d3fcb85942ba8945a1bc815fe' 'f454faeabfa153b10389a9a3bfd51c4a' 'cc9cdabcdfc969c2829b58c0e513488c' diff --git a/abs/core/linhes-scripts/idle.sh b/abs/core/linhes-scripts/idle.sh deleted file mode 100755 index 4f6174c..0000000 --- a/abs/core/linhes-scripts/idle.sh +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash - -usage () { - echo "Usage: $0 [-h] [-s] [-t ] [-l] [-w] [-m] [-r] [-v]" - echo - echo "-h - Print this help/usage message and quit" - echo "-s - Run silently (default is verbose)" - echo "-t - Minutes of idle time needed (default is 20)" - echo "-l - Check for user logins (default: false - do not check)" - echo "-w - Check for open windows (default: false - do not check)" - echo "-m - Include mythshutdown daily wake, locked, & about to start wake in system busy" - echo " (default: daily wake, locked & about to start wake is system idle)" - echo "-r - Check if mythfrontends are running (default: false - do not check)" - echo "-v - Be more verbose for debugging" - echo - echo "Silent mode is recommended for use in cron jobs or scripts." - exit $1 -} - -msg () { # A status reporting function - [ "$VERBOSE" -ne 0 ] && echo "$*" -} - -mysql_cmd () { - /usr/bin/mysql -u root mythconverg -sBe "$*" -} - -# Command line argument handling -VERBOSE=1 -LOGINS=0 -WINDOWS=0 -DAILY=0 -RUNNING=0 -TIME_BEFORE=20 -TIME_AFTER=5 # Only adjustable by editing here - -while getopts "hslwmrt:v" OPT ; do - case $OPT in - h) usage 0 ;; - s) VERBOSE=0 ;; - t) TIME_BEFORE=$OPTARG ;; - l) LOGINS=1 ;; - w) WINDOWS=1 ;; - m) DAILY=1 ;; - r) RUNNING=1 ;; - v) VERBOSE=2 ;; - *) usage 1 ;; - esac -done -# Check for extra cruft on the command line... -shift $(($OPTIND - 1)) -[ -n "$*" ] && usage 1 - -msg "Checking what MythTV is doing now or plans to within $TIME_BEFORE minutes..." -msg - -/usr/bin/mythshutdown --status -BUSY="$?" -msg "mythshutdown returned $BUSY" -if [ "$DAILY" -eq 0 ] ; then - msg " including daily wake, locked, and about to start wake as system idle" - # Ignore daily wake, locked and about to start wake flag values - BUSY=$(($BUSY & 0x2F)) - msg " mythshutdown returned $BUSY" -fi - -SCHEMALOCK=$(mysql_cmd "select count(*) from schemalock") -msg "schemalock $SCHEMALOCK" - -JOBS=$(mysql_cmd "select count(*) from jobqueue where status = 4") -msg "running jobs $JOBS" - -INUSE=$(mysql_cmd "select count(*) from inuseprograms") -msg "inuse programs $INUSE" - -UPCOMING=$(timeout 3 misc_upcoming_recordings.pl --plain_text --text_format "%rs " --heading "" --minutes $TIME_BEFORE --recordings -1 | wc -w) -msg "planned recordings $UPCOMING" -if [ "$VERBOSE" -ge 2 ] ; then - msg - timeout 3 /usr/LH/bin/misc_upcoming_recordings.pl --plain_text --minutes $TIME_BEFORE --recordings -1 -fi - -# Check all host's mythfrontends if they are running and playing -HOSTNAMES=$(mysql_cmd "select hostname from settings where value = 'FrontendIdleTimeout'") -FERUNNING=0 -PLAYING=0 -for HOST in $HOSTNAMES -do - if [ "$VERBOSE" -ge 2 ]; then - msg "Checking $HOST's mythfrontend status..." - fi -ncOUTPUT=$(timeout 2 nc $HOST 6546 << EOF -query location -quit -EOF -) - if [ "$RUNNING" -ge 1 ] ; then - if [[ "$ncOUTPUT" == *"# "* ]]; then - FERUNNING=$(( $FERUNNING + 1 )) - msg "$HOST's mythfrontend is running $FERUNNING" - else - msg "$HOST's mythfrontend is NOT running $FERUNNING" - fi - fi - if [[ "$ncOUTPUT" == *"# Playback "* ]]; then - PLAYING=$(( $PLAYING + 1 )) - msg "$HOST is playing a recording or video $PLAYING" - else - msg "$HOST is NOT playing a recording or video $PLAYING" - fi -done - -# Check for users logged in -if [ "$LOGINS" -ge 1 ] ; then - USERS=`/usr/bin/last | /bin/grep "still logged in" | awk '{ print $1 }'` - if [ -n "$USERS" ] ; then - LOGINS=1 - msg "The following user(s) are still logged in:" - msg "${USERS}" - else - LOGINS=0 - msg "No users are logged in $LOGINS" - fi -fi - -# Check for open windows -FOUNDWINDOWS=0 -if [ "$WINDOWS" -ge 1 ] ; then - /usr/LH/bin/xwin_find.sh -q '.*(mythtv@|xterm|Firefox|Namoroka|Opera|Chromium).*' - FOUNDWINDOWS="$?" - FOUNDWINDOWS=$(($FOUNDWINDOWS == 0)) - if [ "$FOUNDWINDOWS" -eq 0 ] ; then - msg "no application windows open $FOUNDWINDOWS" - else - msg "one or more application windows open $FOUNDWINDOWS" - fi -fi - -activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING + $FERUNNING + $PLAYING + $LOGINS + $FOUNDWINDOWS)) -msg -if [ "$activities" -eq 0 ] ; then - msg "System is idle" - exit 0 -else - msg "System is busy" - exit 1 -fi diff --git a/abs/core/linhes-scripts/xwin_find.sh b/abs/core/linhes-scripts/xwin_find.sh deleted file mode 100644 index 35309dd..0000000 --- a/abs/core/linhes-scripts/xwin_find.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# -# xwin_find [-v|-q] [timeout] window_name_regex -# -# Look for a window of the windows full name given by a awk regular -# expression, and print the windows xwindow ID. -# -# If a timeout is given (in seconds)continue to look for the windows ID -# for this amount of time before returning. (EG default a single search) -# -# If no such window is found output nothing, just exit -# -# OPTIONS -# -v verbose, print the full matching xwininfo line on stderr -# -q do not print windows ID on stdout -# -#### -# Anthony Thyssen September 2005 -# -PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path -PROGDIR=`dirname $PROGNAME` # extract directory of program -PROGNAME=`basename $PROGNAME` # base name of program -Usage() { - echo >&2 "$PROGNAME:" "$@" - sed >&2 -n '/^###/q; s/^#$/# /; 3s/^#/# Usage:/; 3,$s/^# //p;' \ - "$PROGDIR/$PROGNAME" - exit 10; -} - -timeout=0 - -while [ $# -gt 0 ]; do - case "$1" in - [0-9]*) timeout=`date +%s` - timeout=`expr $timeout + $1 + 1` || Usage - ;; - -q) QUIET=true ;; # don't print the final window ID, just status - -v) VERBOSE=true ;; # output the full xwininfo line on stderr - - --) shift; break ;; # end of user options - -*) Usage "Unknown option \"$1\"" ;; - *) break ;; # end of user options - esac - shift # next option -done - -[ $# -lt 1 ] && Usage "Missing window search regex" -[ $# -gt 1 ] && Usage "Too many arguments." - - -find_win() { - # nice added to let it give way to starting processes - if [ "$VERBOSE" ]; then - line=`nice xwininfo -root -tree | awk '/"'"$1"'":/ {print; exit}'` - echo >&2 $line # VERBOSE - xwininfo output - echo "$line" | sed 's/ .*//' - else - nice xwininfo -root -tree | awk '/"'"$1"'":/ {print $1; exit}' - fi -} - -while :; do - id=`find_win "$1"` - if [ "$id" ]; then - [ -z "$QUIET" ] && echo $id # the window ID found - exit 0; - fi - [ `date +%s` -ge $timeout ] && break -done - -exit 1 # window was not found - -- cgit v0.12