diff options
Diffstat (limited to 'abs/core/LinHES-system')
-rw-r--r-- | abs/core/LinHES-system/PKGBUILD | 26 | ||||
-rwxr-xr-x | abs/core/LinHES-system/cacheclean | 134 | ||||
-rw-r--r-- | abs/core/LinHES-system/cacheclean.cron | 2 | ||||
-rwxr-xr-x | abs/core/LinHES-system/diskspace | 2 | ||||
-rwxr-xr-x | abs/core/LinHES-system/diskspace.sh | 81 | ||||
-rwxr-xr-x | abs/core/LinHES-system/firstboot.sh | 21 | ||||
-rw-r--r-- | abs/core/LinHES-system/myth_status.py | 6 |
7 files changed, 260 insertions, 12 deletions
diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD index d04a658..18d67e5 100644 --- a/abs/core/LinHES-system/PKGBUILD +++ b/abs/core/LinHES-system/PKGBUILD @@ -1,6 +1,6 @@ pkgname=LinHES-system pkgver=2 -pkgrel=42 +pkgrel=44 arch=('i686') MVDIR=$startdir/pkg/usr/LH BINDIR=$startdir/pkg/usr/bin @@ -11,7 +11,7 @@ backup=(etc/modprobe.d/alsa-base) binfiles="LinHES-start optimize_mythdb.py myth_mtc.py myth_mtc.sh LinHES-run firstboot.sh load-modules-mythvantage.sh - unclutter-toggle.sh tvterm.sh smolt.cron + unclutter-toggle.sh tvterm.sh mythfrontend-start set_windowmanager.sh myth_status.py myth_status.sh xmsg.py install_supplemental_service.sh @@ -19,10 +19,12 @@ binfiles="LinHES-start optimize_mythdb.py lh_system_restore_job lh_system_host_update lh_system_all_host_update - add_storage.py" - -source=(LinHES-session LinHES-profile.sh $binfiles alsa-base myth_mtc.lr) + add_storage.py + diskspace.sh + cacheclean" +source=(LinHES-session LinHES-profile.sh $binfiles alsa-base myth_mtc.lr + diskspace smolt.cron cacheclean.cron) build() { cd $startdir/src install -m755 -D LinHES-session $startdir/pkg/etc/X11/Sessions/LinHES @@ -45,6 +47,8 @@ build() { install -m644 -D $startdir/src/alsa-base $startdir/pkg/etc/modprobe.d/alsa-base.conf 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 mkdir $startdir/pkg/etc/logrotate.d cp $startdir/myth_mtc.lr $startdir/pkg/etc/logrotate.d } @@ -55,14 +59,13 @@ md5sums=('e8a0e71dabadb5a860b4e113615c3071' 'd1f27cb422010077c841376526fe46ea' '2ef9f945e034119f77d9b6beb17e4fa5' 'c1c5f68835afbb2bad5d5e6cec0fc1dc' - '18a884a73344ff6eb74f63b49745e0f5' + '5e67a8b7ff57ec32d668bce7aab0aa6d' 'dc3eef2a624754e16805d72bbe488b67' 'dc0be354ce77ba2b89868fc29b942c43' '542e670e78d117657f93141e9689f54d' - 'abe887472a170bd1a8e6da6a7b7e93e4' '752488eb8bfb672ce0e4c924f7faf3d1' 'ba351b92e69bcaf26a9bf80417b09c3c' - '657fef69a1da2f6b6cfac97a9d1be043' + '294e54209538018008323d164ce39fb3' '962a3e9eaba2d1466251b7ab0956705d' 'd03aedeeeda0f5e9c1eb437411c88477' '94ce8f1d5085c0db7b267db8c2e9a3ff' @@ -71,5 +74,10 @@ md5sums=('e8a0e71dabadb5a860b4e113615c3071' '859a80ddb4c234506379c605114c1343' '47e093e8cfe4b5b96602358e1f540832' '6faeba0aeb38e772121f751cabda8683' + '68e3e87571f3b0fa4a48a10df50dc220' + '9603b0ca6e090eff31e76482a3c335e7' 'eb879fee9603a05d5420d4ce8ed9e450' - 'f1870a9522c79e6b248fcbf81dec3280') + 'f1870a9522c79e6b248fcbf81dec3280' + '84492954db16740f949d795b74383189' + 'abe887472a170bd1a8e6da6a7b7e93e4' + '02c810c2f47b7c4495fdacaf54189473') diff --git a/abs/core/LinHES-system/cacheclean b/abs/core/LinHES-system/cacheclean new file mode 100755 index 0000000..d32d16b --- /dev/null +++ b/abs/core/LinHES-system/cacheclean @@ -0,0 +1,134 @@ +#!/usr/bin/env python +"""cacheclean - a simple python script to clean up the /data/var/cache/pacman/pkg directory. +More versatile than 'pacman -Sc' in that you can select how many old versions +to keep. +Usage: cacheclean {-p} {-v} <# of copies to keep> + # of copies to keep - (required) how many generations of each package to keep + -p - (optional) preview what would be deleted; forces verbose (-v) mode. + -v - (optional) show deleted packages. + +Adapted from https://github.com/graysky2/cacheclean for LinHES pacman cache directories +and python 2.6.""" + +# Note that the determination of package age is done by simply looking at the date-time +# modified stamp on the file. There is just enough variation in the way package version +# is done that I thought this would be simpler & just as good. +# Also note that you must be root to run this script. + +import getopt +import os +import re +import sys + +# helper function to get tuple of (file dtm, file name, file sz) +def fn_stats(fn): + s = os.stat(fn) + return (s[8], fn, s[6]) + +# cleanup does the actual pkg file deletion +def cleanup(run_list): + # strictly speaking only the first two of these globals need to be listed. + global n_deleted, bytes_deleted, opt_verbose, opt_preview, n_to_keep + # return if the run_list is too short + #print run_list + #return + if len(run_list) <= n_to_keep: return + # Build list of tuples (date-time file modified, file name, file size) + dtm_list = [fn_stats(tfn) for tfn in run_list] + # Sort the list by date-time + dtm_list.sort() + # Build list of the filenames to delete (all but last n_to_keep). + # <showing_off> + #kill_list = [tfn[1] for tfn in dtm_list[:-n_to_keep]] + #bytes_deleted = sum(x[2] for x in dtm_list[:-n_to_keep]) + # </showing_off> + kill_list = [] + for x in dtm_list[:-n_to_keep]: + if os.path.isfile(x[1]): + kill_list.append(x[1]) + bytes_deleted += x[2] + if opt_verbose and kill_list: print (kill_list) + n_deleted += len(kill_list) + # and finally delete (if not in preview mode) + if not opt_preview: + for dfn in kill_list: + os.unlink(dfn) + +###################################################################### +# mainline processing + +# process command line options +try: + opts, pargs = getopt.getopt(sys.argv[1:], 'vp') + opt_dict = dict(opts) + opt_preview = '-p' in opt_dict + opt_verbose = '-v' in opt_dict + if opt_preview: opt_verbose = True + if len(pargs) == 1: + n_to_keep = pargs[0] + else: + raise getopt.GetoptError("missing required argument.") + try: + n_to_keep = int(n_to_keep) + if n_to_keep <= 0: raise ValueError + except ValueError as e: + raise getopt.GetoptError("# of copies to keep must be numeric > 0!") +except getopt.GetoptError as msg: + print ("Error:",msg,"\n",__doc__) + sys.exit(1) + +# change to the pkg directory & get a sorted list of its contents +os.chdir('/data/var/cache/pacman/pkg') +pkg_fns = os.listdir('.') +pkg_fns.sort() + +# Pattern to use to extract the package name from the tar file name: +# for pkg e.g. 'gnome-common-2.8.0-1-i686.pkg.tar.gz' group(1) is 'gnome-common'. + +bpat = re.compile(""" +^([^-/][^/]*?)- # (1) package name +[^-/\s]+- # (2) version +[^-/\s]+ # (3) release +(-i686|-x86_64|-any)? # (4) architecture +\.pkg\.tar # (5) extension +(?:\.(?:gz|bz2|xz|Z))? # (6) compresssion extension +(?:\.aria2|.sig)? # (7) other extension +(?:\.part)?$ # (8) partially-downloaded files' extension +""", re.X) + +n_deleted = 0 +bytes_deleted = 0 +pkg_base_nm = '' +# now look for "runs" of the same package name differing only in version info. +for run_end in range(len(pkg_fns)): + fn = pkg_fns[run_end] + + # make sure we skip directories + if os.path.isfile(fn): + mo = bpat.match(fn) # test for a match of the package name pattern + if mo: + # print ("Processing file '" + fn + "' " + str(mo.lastindex), file=sys.stdout) + tbase = mo.group(1) # gets the 'base' package name + # include the architecture in the name if it's present + if mo.group(2) is not None: + tbase += mo.group(2) + # print ('tbase: ' + tbase + ' ' + str(mo.lastindex), file=sys.stdout) + # is it a new base name, i.e. the start of a new run? + if tbase != pkg_base_nm: # if so then process the prior run + if pkg_base_nm != '': + cleanup(pkg_fns[run_start:run_end]) + pkg_base_nm = tbase # & setup for the new run + run_start = run_end + else: + print >>sys.stderr, "File '"+fn+"' doesn't match package pattern!" + else: + print >>sys.stdout, "skipping directory '"+fn+"'!" + +# catch the final run of the list +run_end += 1 +cleanup(pkg_fns[run_start:run_end]) + +if opt_verbose: + if opt_preview: + print ("Preview mode (no files deleted):"), + print n_deleted,"files deleted,",bytes_deleted/(2**10),"kbytes /",bytes_deleted/(2**20),"MBytes /",bytes_deleted/(2**30), "GBytes." diff --git a/abs/core/LinHES-system/cacheclean.cron b/abs/core/LinHES-system/cacheclean.cron new file mode 100644 index 0000000..b47a3ef --- /dev/null +++ b/abs/core/LinHES-system/cacheclean.cron @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/LH/bin/cacheclean 3 diff --git a/abs/core/LinHES-system/diskspace b/abs/core/LinHES-system/diskspace new file mode 100755 index 0000000..ab3c91b --- /dev/null +++ b/abs/core/LinHES-system/diskspace @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/nice -n19 /usr/LH/bin/diskspace.sh -osd diff --git a/abs/core/LinHES-system/diskspace.sh b/abs/core/LinHES-system/diskspace.sh new file mode 100755 index 0000000..2173c6e --- /dev/null +++ b/abs/core/LinHES-system/diskspace.sh @@ -0,0 +1,81 @@ +#!/bin/sh +### Monitor free disk space +# Display alert if the free percentage of space is >= $ALERT + +# +# Static Config Variables +# +ALERT=90 # free space percentage to trigger an alert + +# +# Static Binary Paths +# +DF='/bin/df' +GREP='/bin/grep' +AWK='/bin/awk' +CUT='/bin/cut' +HOSTNAME='/bin/hostname' +DATE='/bin/date' +OSD_CAT='/usr/bin/osd_cat' +export DISPLAY=:0.0 +# +# Static System Variables +# +THIS_HOST=`${HOSTNAME}` + +# +# Check CLI Options +# +VERBOSE=false +OSD=false +for ARG in "$@" ; do + case $ARG in + "-v") + VERBOSE=true + ;; + "-osd") + OSD=true + ;; + 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 "------------------------------------------------------------------" + +# Dynamic Variables +#DATE_STR=`${DATE} "+%d-%B-%y @ %H%Mhrs"` + +# Call df to find the used percentages. Grep for only local disks (not remote mounts like nfs or smb) +# Pipe the output to awk to get the needed columns, then start a while loop to process each line. +$DF -HPl | $GREP -E "^/dev/" | $AWK '{ print $5 " " $6 " " $1 }' | while read OUTPUT ; do + USED_PCENT=$(echo ${OUTPUT} | $AWK '{ print $1}' | $CUT -d'%' -f1 ) # Used space as a percentage + 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" + 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 & + fi + fi + fi +done + +exit 0 diff --git a/abs/core/LinHES-system/firstboot.sh b/abs/core/LinHES-system/firstboot.sh index 7e2f603..8e3dc57 100755 --- a/abs/core/LinHES-system/firstboot.sh +++ b/abs/core/LinHES-system/firstboot.sh @@ -23,6 +23,26 @@ function try_smolt { } +function fix_lirc_socket { + . /etc/systemconfig + + # Fix LircSocket in mythtv database + SOCKET=`mysql -u mythtv -pmythtv -B --skip-column-names -h "${dbhost}" -D mythconverg -e \ + "SELECT data FROM settings WHERE value = 'LircSocket' AND hostname = '${hostname}';"` + if [ "${SOCKET}" != "/var/run/lirc/lircd" ]; then + mysql -u mythtv -pmythtv -B --skip-column-names -h "${dbhost}" -D mythconverg -e \ + "UPDATE settings SET data = '/var/run/lirc/lircd' WHERE value = 'LircSocket' AND hostname = '${hostname}';" + else + echo ">>>" + echo ">>> ATTENTION! ATTENTION! ATTENTION!" + echo ">>> Unable to connect the the MySQL database to make needed" + echo ">>> changes to the LIRC socket." + echo ">>> LIRC now uses /var/run/lirc/lircd and /dev/lirc is now" + echo ">>> obsolete. Update your MythTV settings to reflect this." + echo ">>>" + fi +} + if [ ! -e /tmp/debug ] then @@ -35,6 +55,7 @@ then fb_status=4 while [ $fb_status != 0 ] do + fix_lirc_socket try_smolt if [ $fb_status != 0 ] then diff --git a/abs/core/LinHES-system/myth_status.py b/abs/core/LinHES-system/myth_status.py index ed5058c..4637b90 100644 --- a/abs/core/LinHES-system/myth_status.py +++ b/abs/core/LinHES-system/myth_status.py @@ -1,6 +1,6 @@ #!/usr/bin/python2 from MythTV import MythBE,MythDB,MythLog -import datetime,time,sys +import datetime,time,sys,subprocess try: be=MythBE() db = MythDB() @@ -110,5 +110,5 @@ else: ur=formatTD(next_start_diff) print "The next recording starts in:\n %s" %(ur) print "" - - +subprocess.call("/usr/LH/bin/diskspace.sh",shell=True) +print "" |