diff options
Diffstat (limited to 'abs/core/LinHES-system')
29 files changed, 1583 insertions, 264 deletions
diff --git a/abs/core/LinHES-system/LinHES-session b/abs/core/LinHES-system/LinHES-session index 61405db..a8c8c09 100755 --- a/abs/core/LinHES-system/LinHES-session +++ b/abs/core/LinHES-system/LinHES-session @@ -26,67 +26,8 @@ MYTH_ARGS="-d --syslog local6" -# # Run any scripting that applies to special hardware. These brand-specific commands that run -# # after Tweaker will, of course, override generic or hardware-specific settings. -# SpecialHardwareCommands() { -# special_hardware_file=/myth/.special_hardware_type -# special_hardware=`cat $special_hardware_file` -# -# case $special_hardware in -# dragon*) -# sudo -E twk_audio.pl --implement digital -# sudo -E twk_dragon.pl --implement all -# ;; -# ausdragon*) -# ;; -# *) -# # there are no brand-specific commands for configuring whatever -# # special hardware the user chose -# ;; -# esac -# } - - -# -# . /etc/osd_cat.cfg || { -# color=yellow -# outline=2 -# outlinecolour=black -# shadow=0 -# shadowcolour=black -# font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" -# } -# -# function delay_osd(){ -# if [ x$STARTUP_STYLE = xenhanced ] -# then -# cmd="ps -ef | grep -v grep | grep -q xmsg.py" -# else -# cmd="ps -ef | grep -v grep | grep -q osd_cat" -# fi -# -# eval $cmd -# -# rc=$? -# while [ $rc = 0 ] -# do -# eval $cmd -# rc=$? -# done -# -# -# } -# -# function msg_osd(){ -# echo -e "$1" | osd_cat --pos=middle --align=center --offset=200 --delay=5 --color=$color --outline=$outline --outlinecolour=$outlinecolour --shadow=$shadow --shadowcolour=$shadowcolour --font=$font -# } -# -# function msg_pyosd(){ -# /usr/LH/bin/xmsg.py -m "$1" -# } function msg(){ - #/usr/LH/bin/lh_message.sh "$1" /usr/LH/bin/msg_client.py --msg "$1" } @@ -99,24 +40,33 @@ function unclutter(){ idle=1 jitter=200 fi - + echo "Starting unclutter" /usr/bin/unclutter -root -idle $idle -jitter $jitter -noevents & } + function keylaunch(){ if [ -f /usr/bin/keylaunch ] then -# MHOME=`cat /etc/passwd | grep "mythtv" | cut -d":" -f6` - if [ ! -e $HOME/.keylaunchrc ] - then - echo "setting symlink for keylaunch" - ln -s /etc/keylaunchrc $HOME/.keylaunchrc - fi - /usr/bin/keylaunch & + if [ ! -z $HOME ] && [ ! -e $HOME/.keylaunchrc ] + then + echo "setting symlink for keylaunch" + ln -s /etc/keylaunchrc $HOME/.keylaunchrc + fi + + echo "Checking if keylaunch is running" + if [ "$(pidof keylaunch)" ] + then + echo "keylaunch is already running" + else + echo "Starting keylaunch" + /usr/bin/keylaunch & + fi fi } + function start_x11vnc(){ if [ x$xvncenable = "x1" ] then @@ -138,11 +88,9 @@ function fluxbox_settings(){ configdir=/usr/share/fluxbox_settings ln -s $configdir $HOME/.fluxbox fi - } - function load_nvidia_settings(){ lsmod |cut -f1 -d" " |grep -q nvidia if [ $? = 0 ] @@ -152,8 +100,6 @@ function load_nvidia_settings(){ } function run_tilda(){ - - if [ -f /usr/bin/tilda ] then if [ ! -e ~/.tilda/config_0 ] @@ -197,7 +143,6 @@ function mouse_move(){ function start_screensaver(){ - if [ x"$Screensavertype" = "xgscreensaver" ] then gnome-screensaver & @@ -207,21 +152,22 @@ function start_screensaver(){ fi } -function show_help_tip(){ +function show_help_tip(){ if [ x$ShowTips = "x1" ] then msg "Alt+h for help" fi } + function notify_scan(){ if [ -e /tmp/scan_report ] then msg "\nNew storage found. \nRun add_storage.py for details" fi +} - } function auto_start(){ asdir="/etc/X11/autostart" @@ -233,18 +179,26 @@ function auto_start(){ $i & fi done - } +} + function update_apple_trailers(){ #update apple trailers if [[ x$RunFrontend = x1 && -f ~/.configure ]] then - /usr/bin/php -q /usr/bin/myth_trailers_grabber > /home/mythtv/appletrailer.xml && /usr/bin/fix_aple_url.sh 2>/dev/null & + /usr/bin/php -q /usr/bin/myth_trailers_grabber > $HOME/appletrailer.xml && /usr/bin/fix_aple_url.sh 2>/dev/null & fi } +function first_mythwelcome_config(){ + echo "First configure: Running mythwelcome-config.py" + /usr/LH/bin/mythwelcome-config.py +} + + function first_configure(){ + first_mythwelcome_config if [ ! x$STARTUP_STYLE = xlegacy ] then first_configure_mv @@ -276,7 +230,7 @@ function first_configure_default(){ sudo sv start mythbackend sudo chown -R mythtv.mythtv /home/mythtv nice -n 19 mythfilldatabase --quiet & - msg "Guide data is being loaded. \n Until this completes\n some shows will appear as unknown \n in the program guide." + msg "Guide data is being loaded.\nUntil this completes\nsome shows will appear as "unknown"\nin the program guide." rm ~/.configure fi else @@ -285,7 +239,6 @@ function first_configure_default(){ rm -f ~/.configure fi fi - } @@ -310,13 +263,13 @@ function first_configure_mv(){ if [ ! $STATUS = 2 ] then /usr/MythVantage/bin/backend_control.sh stop BE 127.0.0.1 - msg "MythTV setup is starting.\nPlease follow the steps for adding tuners and guide data." + msg "MythTV setup is starting.\nPlease follow the steps for adding tuners and guide data." run_wmctrl & /usr/bin/taskset -c 0 /usr/bin/mythtv-setup /usr/MythVantage/bin/backend_control.sh start BE 127.0.0.1 fi nice -n 19 mythfilldatabase --quiet & - msg "Guide data is being loaded. \nUntil this completes \nsome shows will appear as "unknown" \nin the program guide." + msg "Guide data is being loaded.\nUntil this completes\nsome shows will appear as "unknown"\nin the program guide." rm -f ~/.configure fi else @@ -325,9 +278,9 @@ function first_configure_mv(){ rm -f ~/.configure fi fi - } + function start_myth() { if [ x"$UseMythWelcome" = "x1" ] then @@ -364,8 +317,8 @@ function start_myth() { else run_myth fi +} - } function run_wmctrl(){ done="False" @@ -387,9 +340,9 @@ function run_wmctrl(){ fi sleep 5 done - } + function run_myth(){ if [ -f /tmp/nomfe ] then @@ -407,7 +360,6 @@ function run_myth(){ if [ ! x$STARTUP_STYLE = xlegacy ] then - run_wmctrl & $STARTCMD 2>&1 else @@ -431,30 +383,17 @@ function start_myth_mv(){ function set_background() { echo "Setting the background" - } -# if [ x"$WM" = "xdefault" ] -# then -# # fluxbox > /var/log/fluxbox.log 2>&1 -# WM=fluxbox -# fi -# -# -# if [ x"$WM" = "x" ] -# then -# # fluxbox > /var/log/fluxbox.log 2>&1 -# WM=fluxbox -# fi -# - -if [ $WM = "fluxbox" ] + + + +if [ x"$WM" = "fluxbox" ] then fluxbox_settings fi - #if using mythvantage style, start the WM right away # this is done so that starting mythtv can loop. $WM & @@ -462,7 +401,6 @@ pid=$! mouse_move keylaunch start_x11vnc & -#set_background unclutter load_nvidia_settings run_tilda @@ -483,5 +421,3 @@ fi wmctrl -r "MythTV Frontend" -b remove,fullscreen - - diff --git a/abs/core/LinHES-system/LinHES-system.install b/abs/core/LinHES-system/LinHES-system.install deleted file mode 100644 index f2185cd..0000000 --- a/abs/core/LinHES-system/LinHES-system.install +++ /dev/null @@ -1,12 +0,0 @@ -## arg 1: the new package version -post_install() { - /usr/LH/bin/misc_status_config.py -} - -## arg 1: the new package version -## arg 2: the old package version -post_upgrade() { - /usr/LH/bin/misc_status_config.py -} - -# vim:set ts=2 sw=2 et: diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD index a049353..6661028 100755 --- a/abs/core/LinHES-system/PKGBUILD +++ b/abs/core/LinHES-system/PKGBUILD @@ -1,87 +1,78 @@ pkgname=LinHES-system pkgver=8.0 -pkgrel=1 +pkgrel=28 arch=('i686' 'x86_64') -MVDIR=$startdir/pkg/usr/LH -BINDIR=$startdir/pkg/usr/bin install=system.install -pkgdesc="scripts and things related to having an automated system" -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') -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 - mythfrontend-start set_windowmanager.sh - myth_status.py myth_status.sh - install_supplemental_service.sh - lh_system_backup - lh_system_backup_job - lh_system_restore_job - lh_system_host_update - lh_system_all_host_update - add_storage.py - diskspace.sh - cacheclean lh_backend_control.sh switch_web.sh - create_media_dirs.sh - msg_client.py msg_daemon.py +pkgdesc="Everything that makes LinHES an automated system" +license=('GPL2') +depends=('linhes-sounds' 'xdotool' 'tilda' 'keylaunch' + 'python_aosd' 'udisks' 'LinHES-config>=2.3-59' 'sudo' + 'python2-dbus' 'unclutter' 'wmctrl' 'archlinux-xdg-menu' + 'ethtool' 'gnu-netcat' 'normalize' 'ttf-overlock' + 'handbrake-cli' 'mkvtoolnix' 'mplayer') +backup=('etc/modprobe.d/alsa-base.conf') +binfiles="LinHES-start optimize_mythdb.py myth_mtc.py myth_mtc.sh + LinHES-run load-modules-mythvantage.sh unclutter-toggle.sh tvterm.sh + mythfrontend-start set_windowmanager.sh myth_status.py myth_status.sh + install_supplemental_service.sh get_airplay_key importfiles.sh + lh_system_backup lh_system_backup_job lh_system_restore_job + lh_system_host_update lh_system_all_host_update + add_storage.py diskspace.sh cacheclean lh_backend_control.sh + switch_web.sh create_media_dirs.sh msg_client.py msg_daemon.py gen_is_xml.py gen_lib_xml.py gen_light_include.py gen_game_xml.py - 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" + 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 stop_xss.sh + be_check.py checkXFSfrag.sh find_orphans.py idle.sh xwin_find.sh + linhes_update.sh linhes_update2.sh myth2mkv myth2mp3 ripD_eject.sh + mythwelcome-config.py mythwelcome-set-alarm.sh mythwelcome-test-wakeup.sh" -source=(LinHES-session - LinHES-profile.sh $binfiles - alsa-base myth_mtc.lr - diskspace cacheclean.cron +source=(LinHES-session LinHES-profile.sh $binfiles + alsa-base diskspace.cron cacheclean.cron xfs_defrag.cron readme_is_xml readme_light add_storage.readme system-sudo.rules ) -build() { - cd $startdir/src - install -m755 -D LinHES-session $startdir/pkg/etc/X11/Sessions/LinHES - install -m755 -D LinHES-profile.sh $startdir/pkg/etc/profile.d/LinHES-profile.sh - ####### install to /usr/LH/bin - for i in $binfiles - do - item=$i - install -m755 -D $item $MVDIR/bin/$item - echo "installing $item to $MVDIR" - done +package() { + cd $srcdir -# cd $startdir/bin -# for i in * -# do -# item=$i -# install -m755 -D $item $MVDIR/bin/$item -# echo "bin stuff: $item" -# done + MVDIR=$pkgdir/usr/LH + BINDIR=$pkgdir/usr/bin - install -m644 -D $startdir/src/alsa-base $startdir/pkg/etc/modprobe.d/alsa-base.conf - install -m644 -D $startdir/src/readme_is_xml $startdir/pkg/etc/gen_is_xml.d/readme_is_xml - install -m644 -D $startdir/src/readme_is_xml $startdir/pkg/etc/gen_lib_xml.d/readme_gen_xml - install -m644 -D $startdir/src/readme_is_xml $startdir/pkg/etc/gen_game_xml.d/readme_gen_xml - install -m644 -D $startdir/src/readme_light $startdir/pkg/etc/gen_light_conf.d/readme_gen_light - install -m644 -D $startdir/src/add_storage.readme $startdir/pkg/etc/storage.d/readme - # install -m755 -D $startdir/src/smolt.cron $startdir/pkg/etc/cron.weekly/smolt.cron - install -m755 -D $startdir/src/cacheclean.cron $startdir/pkg/etc/cron.weekly/cacheclean.cron - install -m755 -D $startdir/src/diskspace $startdir/pkg/etc/cron.tenminutes/diskspace - install -m644 -D $startdir/src/myth_mtc.lr $startdir/pkg/etc/logrotate.d/myth_mtc + install -m755 -D LinHES-session $pkgdir/etc/X11/Sessions/LinHES + install -m755 -D LinHES-profile.sh $pkgdir/etc/profile.d/LinHES-profile.sh + + #files install to /usr/LH/bin + for i in $binfiles + do + item=$i + install -m755 -D $item $MVDIR/bin/$item + echo "installing $item to $MVDIR" + done + install -m644 -D $srcdir/alsa-base $pkgdir/etc/modprobe.d/alsa-base.conf - #sudo rules - mkdir -p $startdir/pkg/etc/sudoers.d/ - chmod 750 $startdir/pkg/etc/sudoers.d/ - chown -R root:root $startdir/pkg/etc/sudoers.d - install -o root -g root -m 0750 $startdir/src/system-sudo.rules $startdir/pkg/etc/sudoers.d/system_sudo + #readme files + install -m644 -D $srcdir/readme_is_xml $pkgdir/etc/gen_is_xml.d/readme_is_xml + install -m644 -D $srcdir/readme_is_xml $pkgdir/etc/gen_lib_xml.d/readme_gen_xml + install -m644 -D $srcdir/readme_is_xml $pkgdir/etc/gen_game_xml.d/readme_gen_xml + install -m644 -D $srcdir/readme_light $pkgdir/etc/gen_light_conf.d/readme_gen_light + install -m644 -D $srcdir/add_storage.readme $pkgdir/etc/storage.d/readme + #cron files + #install -m755 -D $srcdir/smolt.cron $pkgdir/etc/cron.weekly/smolt.cron + install -m755 -D $srcdir/cacheclean.cron $pkgdir/etc/cron.weekly/cacheclean + install -m755 -D $srcdir/diskspace.cron $pkgdir/etc/cron.tenminutes/diskspace + install -m755 -D $srcdir/xfs_defrag.cron $pkgdir/etc/cron.weekly/xfs_defrag + + #sudo rules + mkdir -p $pkgdir/etc/sudoers.d/ + chmod 750 $pkgdir/etc/sudoers.d/ + chown -R root:root $pkgdir/etc/sudoers.d + install -o root -g root -m 0750 $srcdir/system-sudo.rules $pkgdir/etc/sudoers.d/system_sudo } -md5sums=('08abf577578dd805bab7cd9eba90965a' + +md5sums=('5ee78704cab0e88ec58d1aab821fc1aa' 'de32a1c50101265dd7f6ca5037f7a26a' 'a875ee97f86e46f34a741c2bc455f894' '76b2637cac0452b3acdbeeb4e8a5474b' @@ -89,43 +80,58 @@ md5sums=('08abf577578dd805bab7cd9eba90965a' '6f5b757524d905b5d2420519a88edc93' '4b4585ccba30595cf958d202997c57f7' 'dc3eef2a624754e16805d72bbe488b67' - 'dc0be354ce77ba2b89868fc29b942c43' + '617af86b901538817ebdcaf646248dc5' '542e670e78d117657f93141e9689f54d' '41951459ea9d2b0567be521b67e6285a' 'bb72ab230c7a71706285bd0f31a4fb1f' '692563448cca1d49f45e7d1c8abcaa0c' '962a3e9eaba2d1466251b7ab0956705d' '1758aed160de64abfafb28a3a8f3390e' + '33fbebbd546672cedd3c5e7350ab414e' + 'c773d8caacba8fbd4968e8afe5137bc6' '3edef50a49a47694bf8add39cc160add' '5e17e0786afd891550a660f646076308' 'bc69a520add58ede9b060c73e67ace13' '1be1d3dfc83f828eede93055713882ae' '47e093e8cfe4b5b96602358e1f540832' 'a8e486f5d23913242b6edb862bf44c0e' - 'b9b0a8370f46f0b5e144a66897e8eefb' + '2c005d95312018bef80092136f80f254' '6519d209e151cdc39ae7e1091d189c3e' '8f474e019d5fcb775497aca355d61b0b' '4a3cd8f9b33b2b86fdba47a8f1fa2859' '16f079dab35dde6efd55bf6cf4e2fb2f' - '0e76cd8f320a852a162931450a1fb8b7' - '645297f5905e87eb99999d5a0f3f069a' + '3e60b17892e5b8214d47dcfddf5215a4' + '57ec994cc3964a10c00580e89ebcae35' 'ea315f41dcd6c978e546c95fc05546cf' 'ac61cc460d9e97ba1f5ef69e92cdfbe5' 'f3502bb7c665750da0ecdf6918f7c838' 'b7febd04f64fe21e8cfbb888219b0b31' '06a628469051237943b7c874f2e29b8a' - '54ebcc024db2e0ebe8121305d8926767' + '8fe86aa9109a285aedce3c8658952bbb' '45f46d1f9193c8dde18e56369ec29a1e' - 'a8edbe7bc37e9932e8749d9f5f89c16f' + '145b1da6ce501b3ce38ea415a576bf2d' '116b0f62ed4e8dd6e437930deeb6e49e' '17f678d37187be0f12d67f64e40429c6' 'bacc813b48bafcc6fe906e5969930501' + '8e02efe1ad0df9a179075147eebb05b9' '8b0298f70f97cc1dc2a58b9a73c64bd3' + '911b0fbc8d9178dac1a193346c9decaf' + '34fc1f58ad1eabf4eff4979d420760c0' + 'c3ada01d3a739abe3f920b02d4ea3f6e' + 'a94fe6d980f4b810f2e2ae5352084b39' + 'e1011e0df090372cccc03ecf9d6805c7' + '5727da2f13541b0cde2aea0ab94d4960' + '503df99218373dfc75e7e7f5e449a44e' + '4a1fda884dcd7d65fb2690fbdbd92a83' + '2b7fe3b57592823a4c7e3ec132dcb7f4' + '92950f0ffb1faf1ed64c6be2b8fbc3f6' + '95c092f67036a361ef7a57436f44332e' + '410795ef9039e4c6c0484e706ecfd567' 'eb879fee9603a05d5420d4ce8ed9e450' - '6782771960c495aeb597893f37d1e5ee' '84492954db16740f949d795b74383189' '02c810c2f47b7c4495fdacaf54189473' - '1e2ca4dd872a50df6b70528e06df558a' + '474d5c6883fcfffae4f199aceb3b1356' + '36bdfa8d877cea20ca3870faf08e08d5' '59d0602bac7e06f11abba1894acc8bb0' 'da432d68962e109e09beb2b71c8c8571' '366ccb097d1c221389709485c3b2d159') diff --git a/abs/core/LinHES-system/checkXFSfrag.sh b/abs/core/LinHES-system/checkXFSfrag.sh new file mode 100755 index 0000000..99b833c --- /dev/null +++ b/abs/core/LinHES-system/checkXFSfrag.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# +# Bash script by Gene Alexander (http://www.eracc.com/contact) +# of ERA Computers & Consulting (www.eracc.com, blog.eracc.com, shopping.eracc.com) +# Written using vim, the BEST plain text file editor in all of Creation. +# +# Teach yourself bash scripting: http://tldp.org/LDP/abs/html/index.html +# +# Purpose: To check fragmentation on XFS with xfs_db and run xfs_fsr on XFS mount points that +# are above a specific fragmentation threshold. +# +# What is xfs_db? Use 'man xfs_db' to find out. +# What is xfs_fsr? Use 'man xfs_fsr' to find out. +# +# Any busy files, such as open logs on /var/log, will be skipped. To defragment logs one should +# wrap this script with another script to stop and restart logging. Or, even better, write +# one's own script just for defragmentation of the logs. +# +# Warranty: NONE. Use at your own discretion and be aware that data loss is on your head if +# you choose to use this script. +# +# License: GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html +# +# Suggested Usage: crontab file for root +# 0 0 * * * /root/bin/chkxfsfrag # Run at midnight +# +# Original Release: 2011 December 15 (Merry Christmas!) +# DO NOT ALTER HEADER FROM THIS LINE UP. +# +e='/bin/echo -e' # Use the echo command, not built-in. +xfsfsr=/usr/sbin/xfs_fsr # Set variable with the path to xfs_fsr. +xfsdb=/usr/sbin/xfs_db # Set variable with the path to xfs_db. +pctmax=15 # Set maxiumum frag percent needed for defrag. + # This is zero here for testing purposes only + # a higher number should be used in production. +array=`df -T|grep xfs|cut -f 1 --delim=" "` # Array of all XFS file systems. +for i in ${array[@]}; +do + percentage=`$xfsdb -c frag -r ${i}|cut -f 7 --delim=" "` + percent2=`$e $percentage|cut -f 1 --delim=.` + if [ "$percent2" -gt "$pctmax" ] + then + $e "${i} is $percentage fragmented. Running defragment on ${i}." + # Only uncomment one of the following two lines. + #$xfsfsr -v ${i} # Uncomment for verbose defrag. + $xfsfsr ${i} # Uncomment for quiet defrag. + else + $e "${i}\t$percent2 is not above fragmentation threshold of $pctmax." + fi +done +exit 0 diff --git a/abs/core/LinHES-system/diskspace b/abs/core/LinHES-system/diskspace.cron index ab3c91b..ab3c91b 100755 --- a/abs/core/LinHES-system/diskspace +++ b/abs/core/LinHES-system/diskspace.cron diff --git a/abs/core/LinHES-system/diskspace.sh b/abs/core/LinHES-system/diskspace.sh index 635a972..5b41b73 100755 --- a/abs/core/LinHES-system/diskspace.sh +++ b/abs/core/LinHES-system/diskspace.sh @@ -5,7 +5,8 @@ # # Static Config Variables # -ALERT=90 # free space percentage to trigger an alert +# free space percentage to trigger an alert +ALERT=90 # # Static Binary Paths @@ -16,9 +17,8 @@ AWK='/usr/bin/awk' CUT='/usr/bin/cut' HOSTNAME='/usr/bin/hostname' DATE='/bin/date' -OSD_CAT='/usr/bin/osd_cat' MSG_CLIENT='/usr/LH/bin/msg_client.py --msg' -export DISPLAY=:0.0 + # # Static System Variables # @@ -40,17 +40,6 @@ for ARG in "$@" ; do esac done -#---------------------------------------------------------------------------- -. /etc/osd_cat.cfg || { - color=yellow - outline=2 - outlinecolour=black - shadow=0 - shadowcolour=black - font="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" -} -#---------------------------------------------------------------------------- - [ $VERBOSE = true ] && echo "Checking free disk space on ${THIS_HOST}" [ $VERBOSE = true ] && echo "Threshold for warning is ${ALERT}%" [ $VERBOSE = true ] && echo "------------------------------------------------------------------" @@ -65,17 +54,12 @@ $DF -HPl | $GREP -E "^/dev/" | $AWK '{ print $5 " " $6 " " $1 }' | while read OU PARTITION=$(echo ${OUTPUT} | $AWK '{ print $2 }' ) # Mount Point (eg, /home) DEVICE=$(echo ${OUTPUT} | $AWK '{ print $3 }' ) # Device (eg, /dev/sda1 or LABEL or UUID) if [ $VERBOSE = true ] ; then - echo -e "Checking device ${DEVICE} which is mounted to ${PARTITION} \t${USED_PCENT}% used" + echo -e "${USED_PCENT}% used:\tDevice ${DEVICE} mounted to ${PARTITION}" fi if [ ${USED_PCENT} -ge $ALERT ]; then - if [ $VERBOSE = true ] ; then - echo "WARNING: ${PARTITION} (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}." - else - echo "WARNING: ${PARTITION} (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}." #| - if [ $OSD = true ] && [ ${PARTITION} = / ]; then - #echo "WARNING: The root (${PARTITION}) partition is ${USED_PCENT}% full on ${THIS_HOST}." | $OSD_CAT --pos=top --offset=40 --align=center --delay=10 --color=$color --outline=$outline --outlinecolour=$outlinecolour --shadow=$shadow --shadowcolour=$shadowcolour --font=$font & - $MSG_CLIENT "WARNING: The root (${PARTITION}) partition is ${USED_PCENT}% full on ${THIS_HOST}." - fi + echo "WARNING: Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full on ${THIS_HOST}" + if [ $OSD = true ] && { [ ${PARTITION} = / ] || [ ${PARTITION} = /home ] || [ ${PARTITION} = /data/srv/mysql ]; } then + $MSG_CLIENT "WARNING: Partition (${PARTITION}) on (${DEVICE}) is ${USED_PCENT}% full" fi fi done diff --git a/abs/core/LinHES-system/find_orphans.py b/abs/core/LinHES-system/find_orphans.py new file mode 100644 index 0000000..cdc03d4 --- /dev/null +++ b/abs/core/LinHES-system/find_orphans.py @@ -0,0 +1,238 @@ +#!/usr/bin/env python2 + +from MythTV import MythDB, MythBE, Recorded, MythError +from socket import timeout + +import os +import sys + +def human_size(s): + s = float(s) + o = 0 + while s > 1000: + s /= 1000 + o += 1 + return str(round(s,1))+('B ','KB','MB','GB')[o] + +class File( str ): + def __new__(self, host, group, path, name, size): + return str.__new__(self, name) + def __init__(self, host, group, path, name, size): + self.host = host + self.group = group + self.path = path + self.size = int(size) + def pprint(self): + name = u'%s: %s' % (self.host, os.path.join(self.path, self)) + print u' {0:<90}{1:>8}'.format(name, human_size(self.size)) + def delete(self): + be = MythBE(self.host, db=DB) + be.deleteFile(self, self.group) + +class MyRecorded( Recorded ): + _table = 'recorded' + def pprint(self): + name = u'{0.hostname}: {0.title}'.format(self) + if self.subtitle: + name += u' - '+self.subtitle + print u' {0:<70}{1:>28}'.format(name,self.basename) + +def printrecs(title, recs): + print title + for rec in sorted(recs, key=lambda x: x.title): + rec.pprint() + print u'{0:>88}{1:>12}'.format('Count:',len(recs)) + +def printfiles(title, files): + print title + for f in sorted(files, key=lambda x: x.path): + f.pprint() + size = sum([f.size for f in files]) + print u'{0:>88}{1:>12}'.format('Total:',human_size(size)) + +def populate(host=None): + unfiltered = [] + kwargs = {'livetv':True} + if host: + with DB as c: + c.execute("""SELECT count(1) FROM settings + WHERE hostname=%s AND value=%s""", + (host, 'BackendServerIP')) + if c.fetchone()[0] == 0: + raise Exception('Invalid hostname specified on command line.') + hosts = [host] + kwargs['hostname'] = host + else: + with DB as c: + c.execute("""SELECT hostname FROM settings + WHERE value='BackendServerIP'""") + hosts = [r[0] for r in c.fetchall()] + for host in hosts: + for sg in DB.getStorageGroup(): + if sg.groupname in ('Videos','Banners','Coverart',\ + 'Fanart','Screenshots','Trailers'): + continue + try: + dirs,files,sizes = BE.getSGList(host, sg.groupname, sg.dirname) + for f,s in zip(files,sizes): + newfile = File(host, sg.groupname, sg.dirname, f, s) + if newfile not in unfiltered: + unfiltered.append(newfile) + except: + pass + + recs = list(DB.searchRecorded(**kwargs)) + + zerorecs = [] + orphvids = [] + for rec in list(recs): + if rec.basename in unfiltered: + recs.remove(rec) + i = unfiltered.index(rec.basename) + f = unfiltered.pop(i) + if f.size < 1024: + zerorecs.append(rec) + name = rec.basename.rsplit('.',1)[0] + for f in list(unfiltered): + if name in f: + unfiltered.remove(f) + for f in list(unfiltered): + if not (f.endswith('.mpg') or f.endswith('.nuv')): + continue + orphvids.append(f) + unfiltered.remove(f) + + orphimgs = [] + for f in list(unfiltered): + if not f.endswith('.png'): + continue + orphimgs.append(f) + unfiltered.remove(f) + + dbbackup = [] + for f in list(unfiltered): + if 'sql' not in f: + continue + dbbackup.append(f) + unfiltered.remove(f) + + return (recs, zerorecs, orphvids, orphimgs, dbbackup, unfiltered) + +def delete_recs(recs): + printrecs('The following recordings will be deleted', recs) + print 'Are you sure you want to continue?' + try: + res = raw_input('> ') + while True: + if res == 'yes': + for rec in recs: + rec.delete(True, True) + break + elif res == 'no': + break + else: + res = raw_input("'yes' or 'no' > ") + except MythError: + name = u'{0.hostname}: {0.title}'.format(rec) + if rec.subtitle: + name += ' - '+rec.subtitle + print "Warning: Failed to delete '" + name + "'" + except KeyboardInterrupt: + pass + except EOFError: + sys.exit(0) + +def delete_files(files): + printfiles('The following files will be deleted', files) + print 'Are you sure you want to continue?' + try: + res = raw_input('> ') + while True: + if res == 'yes': + for f in files: + f.delete() + break + elif res == 'no': + break + else: + res = raw_input("'yes' or 'no' > ") + except KeyboardInterrupt: + pass + except EOFError: + sys.exit(0) + +def main(host=None): + while True: + recs, zerorecs, orphvids, orphimgs, dbbackup, unfiltered = populate(host) + + if len(recs): + printrecs("Recordings with missing files", recs) + if len(zerorecs): + printrecs("Zero byte recordings", zerorecs) + if len(orphvids): + printfiles("Orphaned video files", orphvids) + if len(orphimgs): + printfiles("Orphaned snapshots", orphimgs) + if len(dbbackup): + printfiles("Database backups", dbbackup) + if len(unfiltered): + printfiles("Other files", unfiltered) + if not printOnly: + opts = [] + if len(recs): + opts.append(['Delete orphaned recording entries', delete_recs, recs]) + if len(zerorecs): + opts.append(['Delete zero byte recordings', delete_recs, zerorecs]) + if len(orphvids): + opts.append(['Delete orphaned video files', delete_files, orphvids]) + if len(orphimgs): + opts.append(['Delete orphaned snapshots', delete_files, orphimgs]) + if len(unfiltered): + opts.append(['Delete other files', delete_files, unfiltered]) + opts.append(['Refresh list', None, None]) + print 'Please select from the following' + for i, opt in enumerate(opts): + print ' {0}. {1}'.format(i+1, opt[0]) + + try: + inner = True + res = raw_input('> ') + while inner: + try: + res = int(res) + except: + res = raw_input('input number. ctrl-c to exit > ') + continue + if (res <= 0) or (res > len(opts)): + res = raw_input('input number within range > ') + continue + break + opt = opts[res-1] + if opt[1] is None: + continue + else: + opt[1](opt[2]) + + except KeyboardInterrupt: + break + except EOFError: + sys.exit(0) + else: + sys.exit(0) +DB = MythDB() +BE = MythBE(db=DB) +DB.searchRecorded.handler = MyRecorded +DB.searchRecorded.dbclass = MyRecorded + +if __name__ == '__main__': + global printOnly + if "--printonly" in sys.argv : + printOnly=True + else: + printOnly=False + + + if len(sys.argv) == 2 and sys.argv[1] != "--printonly": + main(sys.argv[1]) + else: + main() diff --git a/abs/core/LinHES-system/get_airplay_key b/abs/core/LinHES-system/get_airplay_key new file mode 100755 index 0000000..89a40dd --- /dev/null +++ b/abs/core/LinHES-system/get_airplay_key @@ -0,0 +1,6 @@ +#!/bin/bash + +. /usr/MythVantage/bin/install_functions.sh +curl https://raw.github.com/juhovh/shairplay/master/airport.key > $MYTHHOME/.mythtv/RAOPKey.rsa +chmod 755 $MYTHHOME/.mythtv/RAOPKey.rsa +chown mythtv:mythtv $MYTHHOME/.mythtv/RAOPKey.rsa
\ No newline at end of file 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 <minutes_needed>] [-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/importfiles.sh b/abs/core/LinHES-system/importfiles.sh new file mode 100755 index 0000000..eb0e863 --- /dev/null +++ b/abs/core/LinHES-system/importfiles.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +DVD_or_CD=`cat /proc/mounts |grep iso9660|awk '{print $2}'|tail -1` +if [ "$DVD_or_CD" != "" ]; then + msg_client.py --msg "Copying files from $DVD_or_CD to /myth/video..." --timeout 3600 + /bin/cp -R $DVD_or_CD/* /myth/video/ + msg_client.py --kill + msg_client.py --msg "Finished copying from $DVD_or_CD to /myth/video." +else + msg_client.py --msg "No optical media found. If you just inserted media please wait a moment and try again.|middle" +fi diff --git a/abs/core/LinHES-system/linhes_update.sh b/abs/core/LinHES-system/linhes_update.sh new file mode 100644 index 0000000..87ac8a1 --- /dev/null +++ b/abs/core/LinHES-system/linhes_update.sh @@ -0,0 +1,68 @@ +#!/bin/bash +#Called from LinHES Service Menu Check for Updates Menu + +dsply () { + if grep -q Updates\ Available /usr/share/mythtv/themes/defaultmenu/linhes.xml + then + msg_client.py --clear --tag "checkUpdates" + msg_client.py --kill + msg_client.py --msg "Updates available!\nExit and re-enter Service Menu\nto install the updates.|middle" + exit + else + msg_client.py --msg "Checking for updates...|middle" --timeout 600 --tag "checkUpdates" + fi +} + +chck () { + sudo pacman -Sy + sudo pacman -Qu > /tmp/to_be_upgraded + if [[ ! -s /tmp/to_be_upgraded ]] + then + msg_client.py --clear --tag "checkUpdates" + msg_client.py --kill + msg_client.py --msg "No updates available.|middle" + else + mv /usr/share/mythtv/themes/defaultmenu/linhes.xml /tmp/linhes.xml.tmp + sed -e '/\#Check/,/\#Check/d' < /tmp/linhes.xml.tmp > /usr/share/mythtv/themes/defaultmenu/linhes.xml + mv /usr/share/mythtv/themes/defaultmenu/linhes.xml /tmp + grep -v -e /mythmenu /tmp/linhes.xml > /tmp/linhes.xml.tmp + echo "<!--#UpdatesAvailable-->" >> /tmp/linhes.xml.tmp + echo " <button>" >> /tmp/linhes.xml.tmp + echo " <type>UPGRADE</type>" >> /tmp/linhes.xml.tmp + echo " <text>Updates Available</text>" >> /tmp/linhes.xml.tmp + echo " <action>MENU update2.xml</action>" >> /tmp/linhes.xml.tmp + echo " </button>" >> /tmp/linhes.xml.tmp + echo "<!--#UpdatesAvailable-->" >> /tmp/linhes.xml.tmp + echo "</mythmenu>" >> /tmp/linhes.xml.tmp + mv /tmp/linhes.xml.tmp /usr/share/mythtv/themes/defaultmenu/linhes.xml + + echo "<mythmenu name=\"LinHES\">" > /tmp/update3.xml.tmp + + #check for kernel update and warn reboot is required + if grep linux /tmp/to_be_upgraded || grep nvidia /tmp/to_be_upgraded + then + echo "" >> /tmp/update3.xml.tmp + echo " <button>" >> /tmp/update3.xml.tmp + echo " <type>UPGRADE</type>" >> /tmp/update3.xml.tmp + echo " <text>REBOOT REQUIRED</text>" >> /tmp/update3.xml.tmp + echo " <action>NONE</action>" >> /tmp/update3.xml.tmp + echo " </button>" >> /tmp/update3.xml.tmp + fi + + #create menu items for each pkg to be upgraded + while read line; do + echo "" >> /tmp/update3.xml.tmp + echo " <button>" >> /tmp/update3.xml.tmp + echo " <type>UPGRADE</type>" >> /tmp/update3.xml.tmp + echo " <text>$line</text>" >> /tmp/update3.xml.tmp + echo " <action>NONE</action>" >> /tmp/update3.xml.tmp + echo " </button>" >> /tmp/update3.xml.tmp + done < "/tmp/to_be_upgraded" + echo "</mythmenu>" >> /tmp/update3.xml.tmp + mv /tmp/update3.xml.tmp /usr/share/mythtv/themes/defaultmenu/update3.xml + dsply + fi + } + +dsply +chck diff --git a/abs/core/LinHES-system/linhes_update2.sh b/abs/core/LinHES-system/linhes_update2.sh new file mode 100644 index 0000000..fbdd36b --- /dev/null +++ b/abs/core/LinHES-system/linhes_update2.sh @@ -0,0 +1,37 @@ +#!/bin/bash + + +if [[ "$1" = "install" ]] +then + msg_client.py --msg "Updating...|middle" --timeout 600 --tag "Updating" + sudo pacman -Su --force --noconfirm + msg_client.py --clear --tag "Updating" + msg_client.py --kill + msg_client.py --msg "Updates complete.|middle" + if grep linux /tmp/to_be_upgraded || grep nvidia /tmp/to_be_upgraded + then + msg_client.py --msg "Updates require a reboot.|middle" + fi +else + msg_client.py --msg "Updates canceled.|middle" +fi + +rm -fr /tmp/to_be_upgraded + +if grep -q Updates\ Available /usr/share/mythtv/themes/defaultmenu/linhes.xml +then + mv /usr/share/mythtv/themes/defaultmenu/linhes.xml /tmp/linhes.xml.tmp + sed -e '/\#UpdatesAv/,/\#UpdatesAv/d' < /tmp/linhes.xml.tmp > /usr/share/mythtv/themes/defaultmenu/linhes.xml + mv /usr/share/mythtv/themes/defaultmenu/linhes.xml /tmp + grep -v -e /mythmenu /tmp/linhes.xml > /tmp/linhes.xml.tmp + echo "<!--#Check for updates-->" >> /tmp/linhes.xml.tmp + echo " <button>" >> /tmp/linhes.xml.tmp + echo " <type>UPGRADE</type>" >> /tmp/linhes.xml.tmp + echo " <text>Update LinHES</text>" >> /tmp/linhes.xml.tmp + echo " <action>MENU update.xml</action>" >> /tmp/linhes.xml.tmp + echo " </button>" >> /tmp/linhes.xml.tmp + echo "<!--#Check for updates-->" >> /tmp/linhes.xml.tmp + echo "" >> /tmp/linhes.xml.tmp + echo "</mythmenu>" >> /tmp/linhes.xml.tmp + mv /tmp/linhes.xml.tmp /usr/share/mythtv/themes/defaultmenu/linhes.xml +fi diff --git a/abs/core/LinHES-system/misc_status_config.py b/abs/core/LinHES-system/misc_status_config.py index cc82534..c9b8637 100755 --- a/abs/core/LinHES-system/misc_status_config.py +++ b/abs/core/LinHES-system/misc_status_config.py @@ -6,6 +6,7 @@ from socket import gethostname from MythTV import MythDB mythdb = MythDB() localhostname = gethostname() +import sys # Function to set db setting. This setting is set in mythtv-setup. def dbSettingChange(): @@ -23,7 +24,7 @@ file_name = "/etc/systemconfig" try: config_file = open(file_name) except: - logging.critical("%s could not be opened", file_name) + print file_name + " could not be opened" sys.exit(1) for line in config_file: diff --git a/abs/core/LinHES-system/misc_upcoming_recordings.pl b/abs/core/LinHES-system/misc_upcoming_recordings.pl index 377c2dc..26ec1b4 100755 --- a/abs/core/LinHES-system/misc_upcoming_recordings.pl +++ b/abs/core/LinHES-system/misc_upcoming_recordings.pl @@ -305,7 +305,10 @@ EOF sub status_print { my $count = shift; my $text = $show->format_name($status_text_format, ' ', ' ', 1, 0 ,1); - $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + { + no warnings 'uninitialized'; + $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + } my $value = $show->format_name($status_value_format, ' ', ' ', 1, 0 ,1); $value =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; @@ -320,7 +323,10 @@ EOF sub text_print { my $count = shift; my $text = $show->format_name($text_format, ' ', ' ', 1, 0 ,1); - $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + { + no warnings 'uninitialized'; + $text =~ s/%rs/$MythTV::RecStatus_Types{$show->{'recstatus'}}/g; + } $text =~ s/\\r/\r/g; $text =~ s/\\n/\n/g; print("$heading") if ($count == 0); diff --git a/abs/core/LinHES-system/msg_client.py b/abs/core/LinHES-system/msg_client.py index 54c2e54..8978e86 100755 --- a/abs/core/LinHES-system/msg_client.py +++ b/abs/core/LinHES-system/msg_client.py @@ -23,6 +23,8 @@ def send_message(message): #amount_received = 0 #amount_expected = len(message) print "Waiting for response..." + if cmd == 'list': + time.sleep(1) data = sock.recv(1024) print data @@ -32,9 +34,9 @@ def send_message(message): sock.close() def usage(): line = ''' - Help screen: - msg_client.py is used to add,remove, or list items in the queue of messages that - will be displayed on screen. Optionaly messages can be given an identifier or "tag". + Usage: + msg_client.py is used to add, remove, or list items in the queue of messages that + will be displayed on screen. Optionally messages can be given an identifier or "tag". This identifier does not have to be unique. Items are processed in the order they arrive, based off their slot number. @@ -43,20 +45,27 @@ def usage(): ADD: - To add items to the queue: - msg_client.py --msg "My first message" --tag "tag1" + To add items to the queue (--tag is optional): + msg_client.py --msg "My first message" --tag "tag1" + + To add a message with a line break use \\n: + msg_client.py --msg "My first\\nmessage" + REMOVE: - Removing items are based off the tag. To remove all items from the queue that match the tag "tag1": - msg_client.py --clear --tag tag1 + msg_client.py --clear --tag "tag1" To remove all items from the queue: - msg_client.py --clear + msg_client.py --clear + + To immediately stop displaying the current message: + msg_client.py --kill - Listing items in the queue or to get the total count: - msg_client.py --print_list + LIST: + To list items in the queue or to get the total item count: + msg_client.py --print_list > ------------- > msg : slot 1 > slot : 1 @@ -65,8 +74,12 @@ def usage(): > timeout : None - To immediately stop displaying the current message, use the kill command. - msg_client.py --kill + APPEARANCE: + Display profiles define the font color, display timeout, screen position, + and font. Display profiles are defined in /usr/MythVantage/etc/msg.cfg + + To display the message using a profile: + msg_client.py --msg "Display middle profile.|middle" ''' print line @@ -74,14 +87,14 @@ def usage(): if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument('--tag', action='store', dest='tag',help='message tag') - parser.add_argument('--timeout', action='store', dest='timeout',help='time to display message') + parser.add_argument('--tag', action='store', dest='tag',help='Add a tag to the message') + parser.add_argument('--timeout', action='store', dest='timeout',help='Time to display the message in seconds') action = parser.add_mutually_exclusive_group(required=True) - action.add_argument('--msg', action='store', dest='msg', help='Add message to the queue') - action.add_argument('--clear', action='store_true', help='Remove message from queue that match tag') - action.add_argument('--kill', action='store_true', help='Kill current msg thats displayed') - action.add_argument('--print_list', action='store_true', help='Print current queue') - action.add_argument('--usage', action='store_true', help='Print help screen') + action.add_argument('--msg', action='store', dest='msg', help='Add a message to the queue') + action.add_argument('--clear', action='store_true', help='Remove messages from queue that match tag. No tag will remove all messages in the queue') + action.add_argument('--kill', action='store_true', help='Kill the current message that is displayed') + action.add_argument('--print_list', action='store_true', help='Print the current queue') + action.add_argument('--usage', action='store_true', help='Print usage screen') results = parser.parse_args() resultsdict = vars(results) diff --git a/abs/core/LinHES-system/msg_daemon.py b/abs/core/LinHES-system/msg_daemon.py index cd0465b..f84d0c8 100755 --- a/abs/core/LinHES-system/msg_daemon.py +++ b/abs/core/LinHES-system/msg_daemon.py @@ -20,28 +20,60 @@ class msg_aosd(): def scroll(self,osd, width, height, display_time,position): pos = position step = 1 + ypad = 0 osd.set_position(pos, width, height) (x, y, _, _) = osd.get_geometry() osd.set_position_offset(width, height) + osd.set_geometry(2000, y, width, height) osd.show() x -= 1 - y += height - 1; - for i in range(1, height + 1, step): - osd.loop_for(5) - y -= step - osd.set_geometry(x, y, width, i) - osd.set_position(pos, width, height) - osd.set_position_offset(-1, -1) - (x, y, _, _) = osd.get_geometry() - #time to display - osd.loop_for(display_time) - for i in range(height, 0, -step): - y += step - osd.set_geometry(x, y, width, i); - osd.loop_for(1); + if pos < 3: #top positions 0 to 2 + y -= height; + for i in range(1, height + 1 + ypad, step): + osd.loop_for(5) + y += step + osd.set_geometry(x, y, width, height) + + (x, y, _, _) = osd.get_geometry() + #time to display + osd.loop_for(display_time) + for i in range(height + 1 + ypad, 0, -step): + y -= step + osd.set_geometry(x, y, width, height); + osd.loop_for(1); + + elif pos < 6: #middle positions 3 to 5 + y += height; + for i in range(1, height, step): + osd.loop_for(5) + y -= step + osd.set_geometry(x, y, width, i) + + (x, y, _, _) = osd.get_geometry() + #time to display + osd.loop_for(display_time) + for i in range(height, 0, -step): + y += step + osd.set_geometry(x, y, width, i); + osd.loop_for(1); + + else: #bottom positions 6 to 8 + y += height; + for i in range(1, height + 1 + ypad, step): + osd.loop_for(5) + y -= step + osd.set_geometry(x, y, width, height) + + (x, y, _, _) = osd.get_geometry() + #time to display + osd.loop_for(display_time) + for i in range(height + 1 + ypad, 0, -step): + y += step + osd.set_geometry(x, y, width, height); + osd.loop_for(1); osd.hide(); @@ -55,7 +87,7 @@ class msg_aosd(): osd.geom_y_offset = 0 osd.back_color = "white" - osd.back_opacity = 50 + osd.back_opacity = 25 osd.shadow_color = "black" osd.shadow_opacity = 127 @@ -351,7 +383,7 @@ if __name__ == "__main__": for k,v in i.iteritems(): line=" %s : %s\n" %(k,v) connection.send(line) - line = "Number of messages in queue: %s \n" %(len(q)) + line = "\nNumber of messages in queue: %s \n" %(len(q)) connection.send(line) #connection.send(pickle.dumps(q)) diff --git a/abs/core/LinHES-system/myth2mkv b/abs/core/LinHES-system/myth2mkv new file mode 100644 index 0000000..aedccff --- /dev/null +++ b/abs/core/LinHES-system/myth2mkv @@ -0,0 +1,433 @@ +#!/bin/bash +# +# Convert video to AVC-1 / h264 +# +# version 0.25-004 +# +# Prerequisites: +# - mythtv >= 0.25 +# - handbrake-cli +# - mplayer +# - mkvtoolnix +# +# Arguments +# $1 must be the directory/file of the recording +# $2 must be chanid +# $3 must be starttime +# $4 must be title +# $5 must be subtitle +# $6 must be jobid +# $7 must be quality of encode +# +# As a MythTV user job: +# myth2mkv "%DIR%/%FILE%" "%CHANID%" "%STARTTIME%" "%TITLE%" "%SUBTITLE%" "%JOBID%" HQ|MQ|LQ + +######################## +# # +# Adjustable variables # +# # +######################## + +OUTDIR=/myth/video +LOGPATH=/var/log/mythtv +LOGFILE=${LOGPATH}/myth2mkv-$$.log + +# TMPDIR is for large transient files +TMPDIR=/myth/tmp + +# x264 tuning: +# Tune x264 based on content. Valid options for TUNING are: +# film, animation, grain, stillimage, psnr, ssim, fastdecode, zerolatency +# Separate multiple options with a comma. DEFAULT: none +TUNING="" + +# Custom cropping. Useful if you have a 4:3 image in a HD frame or if +# HandBrake's autocrop smarts fail you. +# Crop 240 pixels off the left and right for 4:3 image in 1920x1080 frame +# Crop 160 pixels off the left and right for 4:3 image in 1280x720 frame +# <T:B:L:R> +# i.e. 0:0:240:240 +# Default: In HQ: CROP="0:0:0:0" (no cropping). +# IN MQ and LQ: autocrop. +CROP="" + +# Force custom output resolution. +# Default: Keep same resolution as input file (less any cropping). +WIDTH="" +HEIGHT="" + +# Force use/non-use of deinterlacing filter. Y|N|G (Yes, No, Guess) +# Default: G - Guess based on source resolution. +# If the source video width is 1920, 1440, 852, 704, 640 or 528 pixels +# "G" will deinterlace the video. Change to "Y" to force use of deinterlacing +# filter or to "N" to NOT use deinterlace filter no matter the resolution. +DEINT="G" + +############################ +# # +# End adjustable variables # +# # +############################ + +if [[ -e $HOME/.mythtv/mysql.txt ]] ; then + . $HOME/.mythtv/mysql.txt +else + DBHostName=${DBHostName:-"localhost"} + DBUserName=${DBUserName:-"mythtv"} + DBPassword=${DBPassword:-"mythtv"} + DBName=${DBName:-"mythconverg"} +fi + +if [[ ! -d ${TMPDIR} ]] ; then + mkdir -p ${TMPDIR} +fi + +if [[ ! -d ${OUTDIR} ]] ; then + mkdir -p ${OUTDIR} +fi + +#------FUNCTIONS--------------- +update_comment() +# Arg_1 = COMMENT +{ +if [ ${NO_JOBID} -eq 0 ]; then + SQL_CMD="update jobqueue set comment=\"${1}\" where id=\"${JOBID}\";" + `${MYSQLCMD} "${SQL_CMD}"` +fi +} + +check_background_progress() +# check handbrake progress in background +{ +while [ `tail -2 ${STATUSFILE} | grep -c "^HandBrake has exited"` = 0 ] +do + sleep 10 + check_myth_jobcmds + pass=`tail -1 ${STATUSFILE} | egrep -o -e 'task [0-9]' | tail -1 | sed 's/task\ //g'` + prog_percent=`tail -1 ${STATUSFILE} | egrep -o -e '[0-9]*\.[0-9]. %' | tail -1 | sed 's/\ %//g'` + current_FPS=`tail -1 ${STATUSFILE} | egrep -o -e 'avg [0-9.]*\.[0-9]* fps' | tail -1 | sed -e 's/avg\ //g' -e 's/\ fps//g'` + current_ETA=`tail -1 ${STATUSFILE} | egrep -o -e 'ETA [0-9.][0-9.]h[0-9.][0-9.]m[0-9.][0-9.]s' | tail -1` + if [ -n "$prog_percent" ]; then + echo "Pass ${pass}, ${prog_percent}% @ ${current_FPS} fps. ${current_ETA}" + update_comment "Pass ${pass} of 2, ${prog_percent}% @ ${current_FPS} fps. ${current_ETA}" + fi + sleep 10 +done +} + +check_myth_jobcmds() +# check the myth database for stop pause or resume commands +{ +if [[ ${NO_JOBID} -eq 0 ]] ; then + CURRENT_CMD=`${MYSQLCMD} "select cmds from jobqueue where id = \"${JOBID}\";"` + case "${CURRENT_CMD}" in + # JOB_RUN + 0) ;; + # JOB_PAUSE + 1) `${MYSQLCMD} "update jobqueue set status=\"6\" where id=\"${JOBID}\";"` + kill -s STOP ${handbrake_pid} ;; + # JOB_RESUME + 2) `${MYSQLCMD} "update jobqueue set status=\"4\" where id=\"${JOBID}\";"` + `${MYSQLCMD} "update jobqueue set cmds=\"0\" where id=\"${JOBID}\";"` + kill -s CONT ${handbrake_pid} ;; + # JOB_STOP + 4) `${MYSQLCMD} "update jobqueue set status=\"5\" where id=\"${JOBID}\";"` + `${MYSQLCMD} "update jobqueue set cmds=\"0\" where id=\"${JOBID}\";"` + kill -9 ${handbrake_pid} ${command_pid} + clean_up_files + echo "Encode Cancelled" >> ${LOGFILE} + `${MYSQLCMD} "update jobqueue set status=\"320\" where id=\"${JOBID}\";"` + exit ;; + esac +fi +} + +get_info_for_hb() { +# Collect some info about source file + +/usr/bin/mplayer -nolirc -identify -frames 0 "${HBINPUTFILE}" \ + 2>/dev/null 1>"${IDFILE}" + +VIDEOW=$( grep ID_VIDEO_WIDTH= "${IDFILE}" | awk -F= '{ print $NF }' ) +FPS=$( grep ID_VIDEO_FPS= "${IDFILE}" | awk -F= '{ print $NF }' ) + +# HandBrake does not like a framerate of 29.970, so let's drop the 0 +if [[ ${FPS} = "29.970" ]] ; then + FPS="29.97" +fi + +# HandBrake does not like a framerate of 59.940, so let's drop the 0 +if [[ ${FPS} = "59.940" ]] ; then + FPS="59.94" +fi + +# A rough guestimation that if the video width is 1920, 1440, 852, 704, 640 or +# 528 pixels it is probably interlaced. +if [[ ${DEINT} = Y ]] ; then + DEINT="-d slow" +else + if [[ ${DEINT} = N ]] ; then + DEINT="" + else + if [[ ${VIDEOW} = 1920 || ${VIDEOW} = 1440 || ${VIDEOW} = 852 || \ + ${VIDEOW} = 704 || ${VIDEOW} = 640 || ${VIDEOW} = 528 ]] ; then + DEINT="-d slow" + else + DEINT="" + fi + fi +fi + +if [[ -n ${DEINT} ]] ; then + if [[ ${QUALITY} = LQ ]] ; then + DEINT="-d fast" + fi +fi + +if [[ -n ${TUNING} ]] ; then + TUNING="--x264-tune ${TUNING}" +fi + +if [[ -n ${CROP} ]] ; then + CROP="--crop ${CROP}" +fi + +if [[ -n ${WIDTH} ]] ; then + WIDTH="-w ${WIDTH} -X ${WIDTH}" +fi + +if [[ -n ${HEIGHT} ]] ; then + HEIGHT="-l ${HEIGHT} -Y ${HEIGHT}" +fi + +if [[ ${QUALITY} = HQ ]] ; then + if [[ -n ${CROP} ]] ; then + CROP="--crop ${CROP}" + else + CROP="--crop 0:0:0:0 --strict-anamorphic" + fi + HB_OPTS="-o ${TMPFILE} -f mkv -m -e x264 ${TUNING} -x b-adapt=2:rc-lookahead=50 -b 5000 -2 -T ${WIDTH} ${HEIGHT} -r ${FPS} --cfr ${CROP} ${DEINT} -a 1 -E copy -s 1" +else + if [[ ${CROP} = "--crop 0:0:0:0" ]] ; then + CROP="${CROP} --strict-anamorphic" + fi + if [[ ${QUALITY} = LQ ]] ; then + HB_OPTS="-o ${TMPFILE} -f mkv -m -e x264 ${TUNING} -b 1250 ${WIDTH} ${HEIGHT} -r ${FPS} --pfr ${CROP} ${DEINT} -a 1 -E lame -B 128 -Q 8 -6 stereo -s 1" + else + # Fallback to "MQ" + HB_OPTS="-o ${TMPFILE} -f mkv -m -e x264 ${TUNING} -b 2500 -2 -T ${WIDTH} ${HEIGHT} -r ${FPS} --pfr ${CROP} ${DEINT} -a 1 -E lame -B 256 -Q 3 -6 stereo -s 1" + fi +fi +} + +get_handbrake_pid() +{ +process_name="" +i1=1 +while [ "${process_name}" != "found" ]; do + handbrake_pid=`expr ${handbrake_pid} + 1` + i1=`expr ${i1} + 1` + if [ "`ps ${handbrake_pid} | grep HandBrakeCLI | sed 's_.*\(HandBrakeCLI\).*_\1_'`" = "HandBrakeCLI" ]; then + process_name="found" + fi + if [ ${i1} -gt 20 ]; then + break + fi +done +} + +tag_file() { +DATE=`date` + +# Create a tag file here +echo "<?xml version='1.0' encoding='ISO-8859-1'?>" > "${TAG_FILE}" +echo "" >> "${TAG_FILE}" +echo "<!DOCTYPE Tags SYSTEM 'matroskatags.dtd'>" >> "${TAG_FILE}" +echo "" >> "${TAG_FILE}" +echo "<Tags>" >> "${TAG_FILE}" +echo " <Tag>" >> "${TAG_FILE}" +echo " <Simple>" >> "${TAG_FILE}" +echo " <Name>TITLE</Name>" >> "${TAG_FILE}" +echo " <String>${TITLE}</String>" >> "${TAG_FILE}" +echo " <Simple>" >> "${TAG_FILE}" +echo " <Name>SUBTITLE</Name>" >> "${TAG_FILE}" +echo " <String>${SUBTITLE}</String>" >> "${TAG_FILE}" +echo " <Simple>" >> "${TAG_FILE}" +echo " <Name>SUMMARY</Name>" >> "${TAG_FILE}" +echo " <String>${DESCR}</String>" >> "${TAG_FILE}" +echo " </Simple>" >> "${TAG_FILE}" +echo " <Simple>" >> "${TAG_FILE}" +echo " <Name>DATE_RELEASED</Name>" >> "${TAG_FILE}" +echo " <String>${OAD}</String>" >> "${TAG_FILE}" +echo " </Simple>" >> "${TAG_FILE}" +echo " </Simple>" >> "${TAG_FILE}" +echo " </Simple>" >> "${TAG_FILE}" +echo " <Simple>" >> "${TAG_FILE}" +echo " <Name>ENCODER</Name>" >> "${TAG_FILE}" +echo " <String>HandBrakeCLI ${HBCLIVER}</String>" >> "${TAG_FILE}" +echo " </Simple>" >> "${TAG_FILE}" +echo " <Simple>" >> "${TAG_FILE}" +echo " <Name>DATE_TAGGED</Name>" >> "${TAG_FILE}" +echo " <String>${DATE}</String>" >> "${TAG_FILE}" +echo " </Simple>" >> "${TAG_FILE}" +echo " </Tag>" >> "${TAG_FILE}" +echo "</Tags>" >> "${TAG_FILE}" + +# Add tag info into MKV file +echo "Adding tag info to ${TITLE} - ${SUBTITLE} ..." >> ${LOGFILE} + +/usr/bin/mkvpropedit -r ${LOGFILE} -t all:"${TAG_FILE}" "${TMPFILE}" +} + +clean_up_files() +# clean up left over files +{ +unlink ${TMPFILE} 2> /dev/null +unlink ${TMPCUTFILE} 2> /dev/null +unlink ${TMPCUTFILE}.map 2> /dev/null +unlink ${STATUSFILE} 2> /dev/null +unlink ${IDFILE} 2> /dev/null +unlink ${HB_RETURN_CODE} 2> /dev/null +unlink ${TAG_FILE} 2> /dev/null +} + +#-------MAIN SCRIPT------------ + +# create temp filename so multiple instances won't conflict +TMPNAME=toX264-$$ +TMPFILE=${TMPDIR}/${TMPNAME}.mkv +TMPCUTFILE=${TMPDIR}/${TMPNAME}.mpg +HBINPUTFILE="${1}" +TITLE="${4}" +SUBTITLE="${5}" +JOBID="${6}" +QUALITY="${7}" +BASE=`basename ${HBINPUTFILE}` +HBCLIVER=`pacman -Q | grep handbrake-cli | awk '{ print $NF }' | awk -F"-" '{ print $1 }'` +STATUSFILE=/tmp/${TMPNAME}-status.log +HB_RETURN_CODE=/tmp/${TMPNAME}-hb_return_code +IDFILE=/tmp/${TMPNAME}-id.txt +TAG_FILE=/tmp/${TMPNAME}.xml +MYSQLCMD="mysql -B --skip-column-names -u ${DBUserName} -p${DBPassword} -h ${DBHostName} -D ${DBName} -e" +OAD=`${MYSQLCMD} "select originalairdate from recorded where basename LIKE '${BASE}';"` +DESCR=`${MYSQLCMD} "select description from recorded where basename LIKE '${BASE}';" | sed 's/\&/and/g'` +USER=`whoami` + +# check if %JOBID% is passed from command line +if [ -z ${JOBID} ]; then + NO_JOBID=1 +else + NO_JOBID=0 +fi + +# log file location +CDate="`date`" +echo "" >> ${LOGFILE} +echo $CDate >> ${LOGFILE} +echo "File to encode: ${HBINPUTFILE}" >> ${LOGFILE} +echo " --> Name: ${TITLE} - ${SUBTITLE}" >> ${LOGFILE} +echo " --> Temporary Files: ${TMPNAME}.*" >> ${LOGFILE} +echo "" >> ${LOGFILE} + +get_info_for_hb +ERROR=$? + +if [[ ${ERROR} != 0 ]] ; then + echo "Error parsing source file information!" >> ${LOGFILE} + cat ${IDFILE} >> ${LOGFILE} + clean_up_files + exit 1 +fi + +# start timer +beforetime="$(date +%s)" + +check_myth_jobcmds + +# If there is a cutlist, use it: +if [[ -n `mythutil --getcutlist --chanid "${2}" --starttime "${3}" | grep \ + Cutlist: | awk -F": " '{ print $NF }'` ]] ; then + echo "Applying cutlist for ${TITLE} - ${SUBTITLE} ..." >> ${LOGFILE} + mythtranscode --chanid "${2}" --starttime "${3}" -m --honorcutlist \ + -q --loglevel info --logpath "${LOGPATH}" -o "${TMPCUTFILE}" + mythtrans_pid=$! + ERROR=$? + HBINPUTFILE=${TMPCUTFILE} +fi + +if [[ ${ERROR} != 0 ]] ; then + echo "MythTranscode error!" >> ${LOGFILE} + echo "Check ${LOGPATH}/mythtranscode.date.${mythtrans_pid}.log for mythtranscode error" >> ${LOGFILE} + clean_up_files + exit 1 +fi + +# run handbrake in background to do conversion +echo "Encoding ${TITLE} - ${SUBTITLE} ..." >> ${LOGFILE} + +( /usr/bin/nice -n19 nohup /usr/bin/HandBrakeCLI -i ${HBINPUTFILE} ${HB_OPTS} \ + > ${STATUSFILE} 2>&1 ; echo $? > ${HB_RETURN_CODE} ) & +handbrake_pid=$! +command_pid=${handbrake_pid} +get_handbrake_pid + +check_background_progress + +if [[ `cat ${HB_RETURN_CODE}` != 0 ]] ; then + echo "HandBrakeCLI error!" >> ${LOGFILE} + cat ${STATUSFILE} >> ${LOGFILE} + clean_up_files + exit 1 +fi + +tag_file +ERROR=$? + +if [[ ${ERROR} != 0 ]] ; then + echo "Error creating tag file!" >> ${LOGFILE} + cat ${TAG_FILE} >> ${LOGFILE} + clean_up_files + exit 1 +fi + +# make output filename unique and do not clobber an existing file +# Build a final file name +FILE=$( echo "${TITLE,,} ${OAD} ${SUBTITLE,,}" | tr -d [:punct:] | tr [:blank:] "_" | tr -s "_" ) +OUTPUTFILE="${OUTDIR}/${FILE}.mkv" +i=1 +while [ -e "${OUTPUTFILE}" ] +do + OUTPUTFILE="${OUTDIR}/${FILE}-${i}.mkv" + i=`expr $i + 1` +done + +# move temp file to output location +chown -v "${USER}" "${TMPFILE}" >> ${LOGFILE} +mv -v "${TMPFILE}" "$OUTPUTFILE" >> ${LOGFILE} +ERROR=$? + +if [[ ${ERROR} != 0 ]] ; then + echo "Error moving ${TMPFILE} to ${OUTPUTFILE} !" >> ${LOGFILE} + clean_up_files + exit 1 +fi + +# stop timer +aftertime="$(date +%s)" +seconds="$(expr ${aftertime} - ${beforetime})" + +if [ ${ERROR} -eq 0 ]; then + echo "File Encoded Successfully: ${OUTPUTFILE}" >> ${LOGFILE} + hours=$((seconds / 3600)) + seconds=$((seconds % 3600)) + minutes=$((seconds / 60)) + seconds=$((seconds % 60)) + echo "Encoding took ${hours} hour\(s\) ${minutes} minute\(s\) ${seconds} second\(s\) @ ${current_FPS} fps." >> ${LOGFILE} + `${MYSQLCMD} "update jobqueue set status = \"272\" where id = \"${JOBID}\";"` + update_comment "Encode Successful. Encoding Time: ${hours} hour\(s\) ${minutes} minute\(s\) ${seconds} second\(s\)" +else + echo "ERROR: ${ERROR}" >> ${LOGFILE} +fi + +# Clean up +clean_up_files diff --git a/abs/core/LinHES-system/myth2mp3 b/abs/core/LinHES-system/myth2mp3 new file mode 100755 index 0000000..69d5d3f --- /dev/null +++ b/abs/core/LinHES-system/myth2mp3 @@ -0,0 +1,96 @@ +#!/bin/sh +# convert recordings to as mp3 audio only +# version 1.1.3 + +# usage: +# first parameter must be %DIR%/%FILE% of the recording +# second parameter must be the desired base name of the output +# third parameter must be %CHANID% if you set USECUTLIST=Y +# fourth parameter must be %STARTTIME% if you set USECUTLIST=Y +# In the mythtv setup screen invoke this script like this: +# MYTHTV User Job Command: +# /usr/LH/bin/myth2mp3 "%DIR%/%FILE%" "%TITLE% - %SUBTITLE%" "%CHANID%" "%STARTTIME%" + +# options: +BITRATE=256k #ie. 128k, 160k, 192k, 224k, 256k +USECUTLIST=Y #Y or N + +# where the converted audio is stored +OUT_DIR=/myth/music + +# create temp filename so multiple instances won't conflict +TMPNAME=toMP3-$$ +TMPFILE=/myth/tmp/$TMPNAME +TMPCUTFILE=/myth/tmp/$TMPNAME.mpg +FFINPUTFILE=$1 +TITLE=`echo $2 | sed 's/\//_/g'` + +# log file location +LOGFILE=/var/log/mythtv/myth2mp3.log +CDate="`date`" +echo "" >> $LOGFILE +echo $CDate >> $LOGFILE +echo "File to encode: $1 Name: $TITLE" >> $LOGFILE + +# start timer +beforetime="$(date +%s)" + +# check if using cutlist +if [ $USECUTLIST = Y ];then + MYTHCOMMFRAMES=`mythutil --getcutlist --chanid "$3" --starttime "$4" | grep 'Cutlist:' | cut -d \ -f 2` + if [ -n "$MYTHCOMMFRAMES" ]; then + echo "Extracting Cutlist..." >> $LOGFILE + /usr/bin/nice -n19 /usr/bin/mythtranscode --chanid "$3" --starttime "$4" --outfile "$TMPCUTFILE" --mpeg2 --honorcutlist + FFINPUTFILE=$TMPCUTFILE + fi +fi + +# run ffmpeg to do conversion to wav +echo "Encoding to intermediate wav..." >> $LOGFILE +/usr/bin/nice -n19 /usr/bin/ffmpeg -i "$FFINPUTFILE" -vn -acodec pcm_s16le -ar 44100 -ac 2 "$TMPFILE.wav" +ERROR=$? + +# Normalize the intermediate wav +echo "Normalizing intermediate wav..." >> $LOGFILE +/usr/bin/nice -n19 /usr/bin/normalize -q "$TMPFILE.wav" +ERROR=$? + +FFINPUTFILE=$TMPFILE.wav + +# Final encode of normalized wav to mp3 +echo "Encoding normalized wav to mp3..." >> $LOGFILE +/usr/bin/nice -n19 /usr/bin/ffmpeg -i "$FFINPUTFILE" -vn -acodec libmp3lame -ab $BITRATE -ar 44100 -ac 2 "$TMPFILE.mp3" +ERROR=$? + +# make output filename unique +OUTPUTFILE=$OUT_DIR/$TITLE.mp3 +i=1 +while [ -e "$OUTPUTFILE" ] +do + OUTPUTFILE=$OUT_DIR/$TITLE-$i.mp3 + i=`expr $i + 1` +done + +# move temp file to output location +chown mythtv "$TMPFILE.mp3" && mv "$TMPFILE.mp3" "$OUTPUTFILE" + +# stop timer +aftertime="$(date +%s)" +seconds="$(expr $aftertime - $beforetime)" + +if [ $ERROR -eq 0 ]; then + echo "File Encoded Sucessfully: $OUTPUTFILE" >> $LOGFILE + hours=$((seconds / 3600)) + seconds=$((seconds % 3600)) + minutes=$((seconds / 60)) + seconds=$((seconds % 60)) + echo "Encoding Time: $hours hour(s) $minutes minute(s) $seconds second(s)" >> $LOGFILE +else + echo "ERROR: $ERROR" >> $LOGFILE +fi + +# clean up left over files +unlink $TMPFILE.mp3 2> /dev/null +unlink $TMPFILE.wav 2> /dev/null +unlink $TMPCUTFILE 2> /dev/null +unlink $TMPCUTFILE.map 2> /dev/null diff --git a/abs/core/LinHES-system/myth_mtc.lr b/abs/core/LinHES-system/myth_mtc.lr deleted file mode 100644 index 2b2fbba..0000000 --- a/abs/core/LinHES-system/myth_mtc.lr +++ /dev/null @@ -1,9 +0,0 @@ -/var/log/mythtv/myth_mtc.log { - copytruncate - daily - #size 1M - missingok - rotate 7 - compress - notifempty -} diff --git a/abs/core/LinHES-system/mythwelcome-config.py b/abs/core/LinHES-system/mythwelcome-config.py new file mode 100755 index 0000000..5ab24b0 --- /dev/null +++ b/abs/core/LinHES-system/mythwelcome-config.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python2 + +# This script will configure the myth db to allow MythWelcome to wake and shutdown the system. + +from socket import gethostname +from MythTV import MythDB +mythdb = MythDB() +localhostname = gethostname() + +# mythwelcome --setup +mythdb.settings[localhostname].MythShutdownNvramCmd = u'sudo sh -c \"/usr/LH/bin/mythwelcome-set-alarm.sh $time\"' +mythdb.settings[localhostname].MythShutdownWakeupTimeFmt = u'time_t' +mythdb.settings[localhostname].MythShutdownNvramRestartCmd = u'' +mythdb.settings[localhostname].MythShutdownReboot = u'sudo /sbin/reboot' +mythdb.settings[localhostname].MythShutdownPowerOff = u'sudo /sbin/poweroff' +mythdb.settings[localhostname].MythShutdownXTermCmd = u'xterm' +mythdb.settings[localhostname].MythWelcomeStartFECmd = u'/usr/LH/bin/mythfrontend-start' + + +# mythtv-setup Shutdown/Wakeup options +if mythdb.settings[localhostname].idleTimeoutSecs == u'0': + mythdb.settings[localhostname].idleTimeoutSecs = u'40' + +mythdb.settings.NULL.WakeupTimeFormat = u'yyyy-MM-ddThh:mm:ss' +mythdb.settings.NULL.SetWakeuptimeCommand = u'/usr/bin/mythshutdown --setwakeup $time' +mythdb.settings.NULL.ServerHaltCommand = u'/usr/bin/mythshutdown --shutdown' +mythdb.settings.NULL.preSDWUCheckCommand = u'/usr/LH/bin/idle.sh -s -m -r' diff --git a/abs/core/LinHES-system/mythwelcome-set-alarm.sh b/abs/core/LinHES-system/mythwelcome-set-alarm.sh new file mode 100755 index 0000000..990adf7 --- /dev/null +++ b/abs/core/LinHES-system/mythwelcome-set-alarm.sh @@ -0,0 +1,23 @@ +#!/bin/sh +#$1 is the first argument to the script. It is the time in seconds since 1970 +#This is defined in mythwelcome with the time_t argument + +# Configure mythwelcome --setup page: +# Command to Set Wakeup Time: sudo sh -c "/usr/LH/bin/mythwelcome-set-alarm.sh $time" +# Wakeup Time Format: time_t +# nvram-wakeup Restart Command: Leave this blank +# Command to reboot: sudo /sbin/reboot +# Command to shutdown: sudo /sbin/poweroff +# Command to run Xterm: xterm +# Command to start the Frontend: /usr/bin/mythfrontend -l /var/log/mythtv/mythfrontend.log + +# Configure mythtv-setup Shutdown/Wakeup Options page: +# Idletimeout (secs): any value greater that 0 +# Wakeup time format: yyyy-MM-ddThh:mm:ss +# Set wakeup time command: /usr/bin/mythshutdown --setwakeup $time +# Server Halt command: /usr/bin/mythshutdown --shutdown +# Pre shutdown check command: /usr/bin/mythshutdown --check + +echo 0 > /sys/class/rtc/rtc0/wakealarm #this clears your alarm +echo $1 > /sys/class/rtc/rtc0/wakealarm #this writes your alarm +cat /proc/driver/rtc > /var/log/wake_alarm diff --git a/abs/core/LinHES-system/mythwelcome-test-wakeup.sh b/abs/core/LinHES-system/mythwelcome-test-wakeup.sh new file mode 100755 index 0000000..4aadf6d --- /dev/null +++ b/abs/core/LinHES-system/mythwelcome-test-wakeup.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm" #this clears your alarm +sudo sh -c "echo `date '+%s' -d '+ 4 minutes'` > /sys/class/rtc/rtc0/wakealarm" #this writes your alarm +cat /proc/driver/rtc +cat /proc/driver/rtc > /var/log/wake_alarm +echo "Your computer is set to start up in 4 minutes using ACPI." +echo -n "Do you want to shutdown the computer now? (y/n): " +read -n 1 shutdown +if [ "$shutdown" == "y" ]; then + echo -e "\nShutting down now..." + sudo shutdown -t 5 -h now +else + echo -e "\nTo shutdown execute the following:" + echo " sudo shutdown -t 5 -h now" +fi diff --git a/abs/core/LinHES-system/readme_is_xml b/abs/core/LinHES-system/readme_is_xml index d2af0f6..f0a13cb 100644 --- a/abs/core/LinHES-system/readme_is_xml +++ b/abs/core/LinHES-system/readme_is_xml @@ -1 +1 @@ -Files ending in .conf will be read by gen_is_xml.py or gen_lib_xml.py and output xml as appropriate +Files ending in .conf will be read by gen_is_xml.py or gen_lib_xml.py or gen_game_xml.py and output xml as appropriate diff --git a/abs/core/LinHES-system/ripD_eject.sh b/abs/core/LinHES-system/ripD_eject.sh new file mode 100755 index 0000000..715d0dd --- /dev/null +++ b/abs/core/LinHES-system/ripD_eject.sh @@ -0,0 +1,118 @@ +#!/bin/bash +# /usr/LH/bin/ripD_eject.sh +# A DVD rip and eject script. +######################################################################## +DEV='/dev/sr0' # DVD device +MPNT='media/cdrom' # Mount Point +Ddir='/myth/video' # DVD output dir List +Bsnd='/usr/share/sounds/init.wav' # Begin sound file +Esnd='/usr/share/sounds/complete.wav' # End sound file +DATE=$(date +%Y%m%d_%H%M) # current date/time +LOG='/var/log/mythtv/ripD.log' # name of Log file. +TRACK=$(lsdvd | grep -i longest | awk '{print $3}') #Finds longest track +FILE=$TITLE +#----------------------------------------------------------------------- +[ -r /etc/rip.cfg ] && . /etc/rip.cfg +#----------------------------------------------------------------------- +LOCK=/tmp/.ripLock.$$ +[ "$DISPLAY" == "" ] && export DISPLAY=:0 +######################################################################## +function osd { # $1=text, $2=delay + msg_client.py --kill + msg_client.py --msg "$1" --timeout $2 +} >& /dev/null +function osd_loop() { + FN=$1 ; shift + TXT="to $dir/$FILE" + N=0 + while [ -f "$LOCK" ]; do + osd "Backing up '$TITLE' $TXT" 70 + N=$(($N+1)) +# [ -d "$FN" ] && SIZE=$(du -sh $FN | awk '{print $1}') +# TXT="$SIZE of $MAX @ $N min. elapsed" + TXT="($N min. elapsed)" + sleep 60 + done +} +######################################################################## +osd "Detecting DVD..." 60 & +echo "`date` detected DVD" >> $LOG +rm -f /tmp/.ripLock.* +#======================================================================= +for dir in $Ddir ; do + if [ -d $dir -a -w $dir ]; then + break + fi +done +#----------------------------------------------------------------------- +if [ ! -d "$dir" ]; then + echo "no $dir" >> $LOG + osd "$dir Not Found!" 10 & + eject ; eject + exit 0 +fi +if [ ! -w "$dir" ]; then + echo "$dir not writable" >> $LOG + osd "$dir Not Writable!" 10 & + eject ; eject + exit 0 +fi +#----------------------------------------------------------------------- +mount $DEV >& /dev/null +dev=$(readlink $DEV) +df=$(df -h /dev/$dev | grep /dev/$dev) +MAX=$(echo $df | while read d v r ; do echo $v ; done) +echo " backup $MAX to $dir" >> $LOG +#======================================================================= +# first make sure DMA is on: +sudo hdparm -d1 -u1 $DEV >& /dev/null +# attempt to get the DVD information: +TITLE=$(dvdbackup -i /dev/sr0 -I | grep information | awk '{ s = ""; for (i = 8; i <= NF; i++) s = s $i " "; print s }' | tr -d '"' | sed 's/ /_/g' | sed 's/_$//g') +if [ "$TITLE" == "DVD_VIDEO" -o "$TITLE" == "" \ + -o "$TITLE" == " " -o "$TITLE" == "[ ].*" ]; then + # if not a good title, + TITLE="dvdbackup_$DATE" +fi +echo " $TITLE" >> $LOG +if [ $1 = m ] +then + COMMAND="dvdbackup -M -i $DEV -o $dir -n $TITLE" + elif [ $1 = h ] + then +# COMMAND="mencoder dvd://$TRACK -alang en -oac mp3lame -lameopts br=320:cbr -ovc lavc -lavcopts vcodec=mpeg4:vhq -vf scale -zoom -xy 720 -o $dir/$TITLE.avi" + COMMAND="HandBrakeCLI -i $DEV -o $dir/$TITLE.mp4 --preset "High\ Profile" --main-feature" + FILE=$TITLE.mp4 + elif [ $1 = n ] + then +# COMMAND="mencoder dvd://$TRACK -alang en -oac mp3lame -lameopts br=160:cbr -ovc lavc -lavcopts vcodec=mpeg4:vhq -vf scale -zoom -xy 512 -o $dir/$TITLE.avi" + COMMAND="HandBrakeCLI -i $DEV -o $dir/$TITLE.mp4 --preset "Normal" --main-feature" + FILE=$TITLE.mp4 + elif [ $1 = l ] + then +# COMMAND="mencoder dvd://$TRACK -alang en -oac mp3lame -lameopts br=96:cbr -ovc lavc -lavcopts vcodec=mpeg4:vhq -vf scale -zoom -xy 320 -o $dir/$TITLE.avi" + COMMAND="HandBrakeCLI -i $DEV -o $dir/$TITLE.mp4 --preset "Classic" --main-feature" + FILE=$TITLE.mp4 + elif [ $1 = i ] + then + COMMAND="dd if=$DEV of=$dir/$TITLE.iso bs=2048" + FILE=$TITLE.iso +fi +{ # for the redir below: + # Begin: + touch $LOCK + osd_loop "$dir/$TITLE" "$TITLE" & + dvdbackup -i $DEV -I + sleep 1 ; aplay $Bsnd + $COMMAND + # Finish: + rm -f $LOCK + osd "Done Backing up '$TITLE' to $dir/$FILE" 5 & + sleep 1 ; aplay $Esnd + # Eject the media: + sudo eject ; sudo eject +} > $dir/.$TITLE.log 2>&1 +echo " `du -sh $dir/$FILE`" >> $LOG +echo " `date` finished DVD" >> $LOG +exit 0 +######################################################################## +# End diff --git a/abs/core/LinHES-system/stop_xss.sh b/abs/core/LinHES-system/stop_xss.sh new file mode 100755 index 0000000..b03169b --- /dev/null +++ b/abs/core/LinHES-system/stop_xss.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +while [ 1=1 ]; +do + + if [ "$(pidof google-chrome)" -o "$(pidof huludesktop)" -o "$(pidof xbmc.bin)" ] + then + xscreensaver-command -deactivate + fi + sleep 60 + +done diff --git a/abs/core/LinHES-system/system.install b/abs/core/LinHES-system/system.install index 662e271..ddad9e3 100644 --- a/abs/core/LinHES-system/system.install +++ b/abs/core/LinHES-system/system.install @@ -18,6 +18,8 @@ post_install() { # Add db entry for misc status in MythWeb # not needed in R8 because it's in the DB, may be removed #/usr/LH/bin/misc_status_config.py + + sv restart msg_daemon } # arg 1: the new package version diff --git a/abs/core/LinHES-system/unclutter-toggle.sh b/abs/core/LinHES-system/unclutter-toggle.sh index aadce50..9b08a14 100644 --- a/abs/core/LinHES-system/unclutter-toggle.sh +++ b/abs/core/LinHES-system/unclutter-toggle.sh @@ -5,7 +5,9 @@ idle=1 . /etc/unclutter.cfg if [ -n "${PIDUNC}" ]; then + msg_client.py --msg "Showing mouse pointer..." killall -9 unclutter else - /usr/X11R6/bin/unclutter -root -idle $idle -jitter $jitter -noevents & + msg_client.py --msg "Hiding mouse pointer..." + /usr/bin/unclutter -root -idle $idle -jitter $jitter -noevents & fi diff --git a/abs/core/LinHES-system/xfs_defrag.cron b/abs/core/LinHES-system/xfs_defrag.cron new file mode 100755 index 0000000..4d35507 --- /dev/null +++ b/abs/core/LinHES-system/xfs_defrag.cron @@ -0,0 +1,3 @@ +#!/bin/bash +#. /etc/profile +/usr/LH/bin/checkXFSfrag.sh > /var/log/xfs_defrag.log 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 + |