diff options
| author | James Meyer <james.meyer@operamail.com> | 2013-02-19 21:10:18 (GMT) |
|---|---|---|
| committer | James Meyer <james.meyer@operamail.com> | 2013-02-19 21:10:18 (GMT) |
| commit | 2648e999d277eac5c3d331a3609bcc73fafbea71 (patch) | |
| tree | 40951fb8e7fdbe28a0baa324ae615055203f1e2e /abs/core/LinHES-config | |
| parent | c759b5e0c4aa6fc37412b4dee2cf9ad993fd376d (diff) | |
| parent | 7e6f7ca174e1af67178dc5293a312a4a733eb095 (diff) | |
| download | linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.zip linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.tar.gz linhes_pkgbuild-2648e999d277eac5c3d331a3609bcc73fafbea71.tar.bz2 | |
Merge branch 'testing'
# By James Meyer (1091) and others
# Via James Meyer (5) and others
* testing: (1148 commits)
LinHES-config: during install don't kill off lirc. This keeps the remote active all the way to the finish
Change version numbers to 8.0 to match the release number. LinHES-conifg LinHES-system mythdb-initial runit-scripts supplemental-web
LinHES-conifig: mv_install.py for the last partition don't go all the way to the end. Gotta leave room for gpt tables.
xf86-video-ati: xorg ati driver.
LinHES-config: timezip.py add syncing up of parental lvl passwords and starting level with MBE.
LinHES-system: correct the logic for breaking out of the wmctrl loop. As written it would break out of the inner loop..but not the 60 iteration loop.
e16_theme_settings: remove slide-in prop for new windows. For whatever reason this was preventing mplayer from being positioned correctly for appletrailers.
LinHES-config, mythinstall: change case of hd_pvr and serial to all lower refs #902
zilog-firmware: firmware for TX support of the hdpvr and pvr-150 In general I can't recommend anybody using these transmitters but including the firmware just in case someone really wants to
linhes-udev-rules: added hdprv_lirc rule. All of these lirc rules are limited to exactly one device. If more then one device is present then only the last device in init will get the symlink
runit-scripts: fix logging for igdeamon, add support to remote init script so that the blaster is always the first device in the chain. added support specificly for hd_pvr
LinHES-system: add lh_system_restore and lh_system_backup. These scripts are called from the mythmenu. refs #900
iguanair: rebuild with python 2.7
LinHES-system: msg_daemon.py fix init and nasty bug related to timeout. In a nutshell timeout wouldn't work unless a msg without a timeout was called first.
linhes-udev-rules: add rules for mce,streamzap,serial lirc devices.
mythinstall: recompile for matching libs
mythtv: latest .25-fixes and change mythbackup/restore call lh_system_$op to replace mythbackup/mythrestore. mythbackup no longer works correctly with the new windowmanager
linhes-scripts: myth2mp3, myth2x264, myth2xvid: use mythutil to get cutlist
LinHES-config, supplimental-web: Fix proxy numbering for Ceton infiniTV
linhes-system: add additional stuff to the system backup and also introduced an exclude file. The exclude/include files are locate in /home/mythtv/backup_config/
...
Diffstat (limited to 'abs/core/LinHES-config')
44 files changed, 4669 insertions, 1722 deletions
diff --git a/abs/core/LinHES-config/09_mythvantge_runit_grub b/abs/core/LinHES-config/09_mythvantge_runit_grub new file mode 100644 index 0000000..17fff2e --- /dev/null +++ b/abs/core/LinHES-config/09_mythvantge_runit_grub @@ -0,0 +1,54 @@ +#!/bin/sh +prefix="/usr" +exec_prefix="${prefix}" +datarootdir="/usr/share" +. "${datarootdir}/grub/grub-mkconfig_lib" +if [ -z "$boot_device_id" ]; then +boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")" +fi + +if [ -f "/etc/grub.d/install_modules" ] +then + . /etc/grub.d/install_modules +else + install_modules='' +fi + +gettext_printf "Found LinHES runit: \n" >&2 +echo " +menuentry 'LinHES' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-$boot_device_id' { + #load_video + #set gfxpayload=keep + + insmod gzio + insmod part_msdos + insmod ext2 + set root='hd0,msdos1' + if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 $boot_device_id + else + search --no-floppy --fs-uuid --set=root $boot_device_id + fi + echo 'Loading Linux core repo kernel ...' + linux /boot/vmlinuz-linux root=UUID=$boot_device_id ro quiet splash init=/sbin/runit $install_modules + echo 'Loading initial ramdisk ...' + initrd /boot/initramfs-linux.img + } +menuentry 'LinHES --no-splash' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-core repo kernel-true-$boot_device_id' { + #load_video + #set gfxpayload=keep + insmod gzio + insmod part_msdos + insmod ext2 + set root='hd0,msdos1' + if [ x$feature_platform_search_hint = xy ]; then + search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 $boot_device_id + else + search --no-floppy --fs-uuid --set=root $boot_device_id + fi + echo 'Loading Linux core repo kernel ...' + linux /boot/vmlinuz-linux root=UUID=$boot_device_id ro init=/sbin/runit $install_modules + echo 'Loading initial ramdisk ...' + initrd /boot/initramfs-linux.img +} +" diff --git a/abs/core/LinHES-config/LinHES-release b/abs/core/LinHES-config/LinHES-release index 3939edc..747db47 100644 --- a/abs/core/LinHES-config/LinHES-release +++ b/abs/core/LinHES-config/LinHES-release @@ -1 +1 @@ -LinHES R7.3 (Crave) +LinHES 8.0 (Trip the bits) diff --git a/abs/core/LinHES-config/MythVantage.sh b/abs/core/LinHES-config/MythVantage.sh index 286c908..ffa8d34 100755 --- a/abs/core/LinHES-config/MythVantage.sh +++ b/abs/core/LinHES-config/MythVantage.sh @@ -1,3 +1,5 @@ export MV_ROOT=/usr/MythVantage export PATH=$PATH:$MV_ROOT/bin export TEMPLATES=$MV_ROOT/templates +results=`grep MYTHHOME $MV_ROOT/bin/mv_config.py` +eval export $results diff --git a/abs/core/LinHES-config/PKGBUILD b/abs/core/LinHES-config/PKGBUILD index e872bcf..449f456 100644..100755 --- a/abs/core/LinHES-config/PKGBUILD +++ b/abs/core/LinHES-config/PKGBUILD @@ -1,15 +1,16 @@ pkgname=LinHES-config -pkgver=2.3 -pkgrel=78 +pkgver=8.0 +pkgrel=2 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev LinHes-config ) pkgdesc="Install and configure your system" depends=('bc' 'libstatgrab' 'mysql-python' 'expect' 'curl' 'dnsutils' 'parted' 'sg3_utils' 'nmbscan' 'system-templates' 'rsync' 'python-parted' - 'ddcxinfo' 'python-pexpect' 'python-netifaces' 'LinHES-timezone' - 'python-iplib' 'mythinstall>=2-10') -arch=('i686') + 'python-pexpect' 'python-netifaces' + 'python-iplib' 'mythinstall>=2-10' 'sudo' 'setserial' 'udevil') +#LinHES-timezone +arch=('i686' 'x86_64') -source=(mv_install.py +source=(mv_install.py 09_mythvantge_runit_grub mv_config.py myth_user_call file_time_offset.py @@ -19,16 +20,16 @@ source=(mv_install.py install_db_chroot.sh restore_default_settings.sh myth_settings_wrapper.sh - xconfig.sh + xconfig.sh timezip.py soundconfig.sh LinHES-release - issue MythVantage.sh create_master.sh build_diskless.sh networkconfig.sh autocard.py + udev_link.sh restore_km_db_chroot.sh README mv_advanced.py @@ -43,16 +44,26 @@ source=(mv_install.py mv_webuser.py mv_hostype.py mv_supplemental.py + mv_vnc.py + mv_fileshare.py + mv_locale.py systemconfig.py myth_user_call.py - mythvantage.cfg) + mythvantage.cfg + config-sudo.rules + hdhr.conf blacklist_nouveau.conf blacklist_pcspkr.conf + print_xorg_res.py backend_control.sh + plymouth_config.py + discover_infinitv.py) backup=(etc/mythvantage.cfg) -install=LinHES.install +install=config.install build() { mkdir -p $startdir/pkg/etc mkdir -p $startdir/pkg/usr/share/mythtv/themes/default + install -D -m0755 09_mythvantge_runit_grub $startdir/pkg/etc/grub.d/09_mythvantge_runit_grub + MVDIR=$startdir/pkg/usr/MythVantage mkdir $startdir/pkg/etc/profile.d @@ -61,15 +72,14 @@ build() { mkdir -p $MVDIR/etc #copy in all the installer specific stuff -# install -m0700 myth_user_call $MVDIR/bin/myth_user_call - install -m0700 myth_user_call.py $MVDIR/bin/myth_user_call + install -m 0700 myth_user_call.py $MVDIR/bin/myth_user_call install -m 0755 install_proxy.sh $MVDIR/bin/install_proxy.sh install -m 0755 install_functions.sh $MVDIR/bin/install_functions.sh install -m 0755 systemconfig.sh $MVDIR/bin/systemconfig.sh install -m 0755 xconfig.sh $MVDIR/bin/xconfig.sh install -m 0755 install_db_chroot.sh $MVDIR/bin/install_db_chroot.sh install -m 0755 restore_km_db_chroot.sh $MVDIR/bin/restore_km_db_chroot.sh - install -m 0755 restore_default_settings.sh $MVDIR/bin/restore_default_settings.sh +# install -m 0755 restore_default_settings.sh $MVDIR/bin/restore_default_settings.sh install -m 0755 myth_settings_wrapper.sh $MVDIR/bin/myth_settings_wrapper.sh install -m 0755 soundconfig.sh $MVDIR/bin/soundconfig.sh install -m 0755 networkconfig.sh $MVDIR/bin/networkconfig.sh @@ -77,6 +87,7 @@ build() { install -m 0755 build_diskless.sh $MVDIR/bin/build_diskless.sh install -m 0755 timezip.py $MVDIR/bin/timezip.py install -m 0755 autocard.py $MVDIR/bin/autocard.py + install -m 0755 udev_link.sh $MVDIR/bin/udev_link.sh install -m 0755 mv_config.py $MVDIR/bin/mv_config.py install -m 0755 mv_install.py $MVDIR/bin/mv_install.py install -m 0755 mv_advanced.py $MVDIR/bin/ @@ -91,7 +102,14 @@ build() { install -m 0755 mv_webuser.py $MVDIR/bin/ install -m 0755 mv_hostype.py $MVDIR/bin/ install -m 0755 mv_supplemental.py $MVDIR/bin/ + install -m 0755 mv_vnc.py $MVDIR/bin/ + install -m 0755 mv_fileshare.py $MVDIR/bin/ + install -m 0755 mv_locale.py $MVDIR/bin/ install -m 0755 systemconfig.py $MVDIR/bin/ + install -m 0755 print_xorg_res.py $MVDIR/bin/ + install -m 0755 plymouth_config.py $MVDIR/bin/ + install -m 0755 discover_infinitv.py $MVDIR/bin/ + install -m 0755 backend_control.sh $MVDIR/bin/ install -m 0755 mythvantage.cfg $startdir/pkg/etc/ #README file displayed on install @@ -99,46 +117,68 @@ build() { mkdir -p $startdir/pkg/usr/bin install -m 0755 file_time_offset.py $startdir/pkg/usr/bin/file_time_offset.py - #Copy in the branding stuff install -m 0755 LinHES-release $startdir/pkg/etc/LinHES-release - install -m 0755 issue $startdir/pkg/etc/issue + #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 config-sudo.rules $startdir/pkg/etc/sudoers.d/config_sudo + + #sysctrl conf + install -o root -g root -D -m 0755 hdhr.conf $startdir/pkg/etc/sysctl.d/hdhr.conf + + #modules blacklist files + install -o root -g root -D -m 0755 blacklist_pcspkr.conf $startdir/pkg/etc/modprobe.d/blacklist_pcspkr.conf + install -o root -g root -D -m 0755 blacklist_nouveau.conf $startdir/pkg/etc/modprobe.d/blacklist_nouveau.conf } -md5sums=('18af4fe481e1fc2ae02050026eb5cd27' - '16b98fcb3753ef6cfc35075c326d30e4' - 'e36da536dd651ef182e7642337889e77' +md5sums=('7cdc9bc678ab02a2d30444e20a3c71eb' + '3f6855b7bb860a44f96a972c2e80f497' + 'aaeb581275433649ff74e05da5e61a78' + '2596460462cf6c889cf8f95485537b20' '985891a43f7c4c983eb2a362162f1a0f' - '13172731c8b08d669336da31cece5775' - '5a31addfbdc1154b05997f972a32fa33' - 'c20f73d4da5d7e15e1f3eb85c7dcb49a' - '68199e861c2933ccbb84735b9b440157' - '9ae8d79f620c6d19973c55c32a921874' - '79579277e0545aeeb50fba403434194c' - '960017a34d9cc78af6298f45aad6eb8e' - 'ecf9e5df20683a769c4a8a8f2d65de85' - '6d32a88e76b0a97b0ce67d37ef6394aa' - '40d28d5f5009971c507e94c9639be4a1' - '6aff504ed5e860adc1b7317cd0780900' - '55fccb1da0417a896b724f7cfc32dd5a' + 'fda01259a4bc74d83c9092d338bd247a' + '768504ef10ecd11a22875ccea9fcf62b' + 'f73d6d6f98839e900cb6685bf5dc4eae' + '408688e3bcb2cefe512f9a89863137c8' + '2a7f3b34e522acfd08283b86c8926aba' + 'b596d2e3779a434435bc0f0277b1ba3e' + '5012fbd31d205a6d6b0a1d8caf3eba8f' + '157e73d0f90d7b306aba8f5921aeedd3' + 'a6faa20d905e2fd92ce79acab044b759' + '8ba06c2ce6129371548cc360ccca27f8' + '5f890ea9bda6aef652d2560ca19dac07' 'ab2aa42c2947148c2b1cac0ade6d1d55' 'd429b59d3cfb37b0624c6a4a71a7c2c0' - 'a225143e3df6f56d451c2875e54ddbae' - '9151c74fcaf18ec4cf5e757cfdbc7017' + 'f6a935c35123fdc7c259c01cbc794a64' + '5e865cc04fe5de8a39d9c1e377fc4ebe' + 'd3490e93f313bbbcbc6c3693c56b9c17' '3d1e4a119f38cff0498bf8a67e94e4b3' '71fd2d0d448fc2fcd15415a1beed7109' - '61ccbf573ee196e3edf53a512820b431' - 'e1715bbbabd42e7419755b09f60734aa' + 'c0549457750c4f8e8038d904a0f3012a' + '3d1e3c7315881a109fb089a540d2262c' 'b845de3e05c1734cce4b9ac5e8f1baaf' - '6801f87992b44118a12b6dfe6ea68127' - '5e69839659d65ddda35b8a9982dc29e9' - '3afd18517bb765d1680f4fcc8d08c9cc' - 'ec6a9961e4d1b53ec1240c5979efff11' + 'f9b38f3d8e6d25b7c67b4c33cdee58db' + '8b7dce4a3a0a281fa6656aa8781a648e' + 'f7f2dc11d1ba454cd25eeaa133104b62' + '824e49d9b01fed295c704ab68908b464' 'fe5e31b833cc6707209e9d656b6eb53c' - 'ecb52b9b7a9ac0c8988093c1dfdda635' - '23d0e12b7ca1cc6ea6b993c1d7ff20b9' - '0b5b9e5385c7ae77e561812e96ce8161' - '755c05b833aca6c5be130972af052e8b' - 'd8f80e5686d02555f044363f1ac17d97' + '3eec99951c01d1a1abf7ecfeb33f922b' + '087a0ef743bc8af915503f8773536ce4' + '183a11aa06d60065106472ed9f72cc4a' + 'b4900090d841d3e390cb840cf16afd85' + '299c24c0820fc9c483c820db2595e3cb' + 'cf51cb22e23218ae7e9b55cac1ba3a7f' + 'e4b61402858058f7575b776d62d5ee89' + '1a17256202d851f37c54f2836c244b5d' '2596460462cf6c889cf8f95485537b20' - 'a63ff9ef5250965aeabc74bfa8e43981') + 'dc3c5270691a62600475705f4cb78b56' + '4804aa93aaad3dfcfff08cd9ffd68836' + '0fa6fffd87f350380d45f1f8a5b7babe' + '6ec39b010c0ed8901ea896c7e153d330' + '3866086e6af5e3528a66eff492f2f4dd' + 'c9279fa095af624ee3d9bc75d3328360' + '02cf69074d2bbacef05fa3e451af9af3' + '85d15efc55074a94c58d44542ea1dd13' + 'e410d108ed4778dd898dc68fad4e8828') diff --git a/abs/core/LinHES-config/autocard.py b/abs/core/LinHES-config/autocard.py index f8bb173..c461714 100755..100644 --- a/abs/core/LinHES-config/autocard.py +++ b/abs/core/LinHES-config/autocard.py @@ -1,307 +1,1099 @@ #!/usr/bin/python2 -# import MySQL module -#jm -import MySQLdb import sys import getopt import socket -import os +import os , re import time import string import glob from string import letters from string import digits -def INSERTNULL_SOURCE(name,xmltvgrabber,userid,freqtable,lineupid,password,useeit): - cursor = db.cursor() - cursor.execute("INSERT INTO videosource(name,xmltvgrabber,userid,freqtable,lineupid,password,useeit) VALUES(%s,%s,%s,%s,%s,%s,%s);",(name,xmltvgrabber,userid,freqtable,lineupid,password,useeit)) - -def INSERTCARD_INTOMYTH(Device,Driver,Cardvendor): - global currenthostname - print Device - print Driver, - print Cardvendor - cursor = db.cursor() - insert = "false" - if Driver == "ivtv" : - cardtype="MPEG" - defaultinput="Tuner 1" - insert="true" - if Cardvendor == "pcHDTV HD3000 HDTV": - insert="false" - cardtype ="whocares" - - #print insert - if insert == "true" : - cursor.execute("INSERT INTO capturecard (videodevice,cardtype,defaultinput,hostname) VALUES(%s,%s,%s,%s);",(Device,cardtype,defaultinput,currenthostname)) - -def INSERTHDR_INTOMYTH(deviceid,tuner_number): - cardtype='HDHOMERUN' - defaultinput='MPEG2TS' - global currenthostname - print deviceid - print cardtype - print defaultinput - print tuner_number - cursor = db.cursor() - #print insert - cursor.execute("INSERT INTO capturecard (videodevice,cardtype,defaultinput,dbox2_port ,hostname) VALUES(%s,%s,%s,%s,%s);",(deviceid,cardtype,defaultinput,tuner_number,currenthostname)) - -def INSERTAUTOCARD(): - global cardlist - global currenthostname - # create a cursor - cursor = db.cursor() - - - for i in range( 1 , len(cardlist)): - insert = "false" -# print cardlist[i] - Device=cardlist[i][0] - Driver=cardlist[i][1] - Cardvendor=cardlist[i][2] - Businfo=cardlist[i][3] - if Driver == "ivtv" : - insert="true" - devicestatus="unused" - if Cardvendor == "pcHDTV HD3000 HDTV": - insert="false" - cardtype ="whocares" - if Driver == "hdr": - insert="true" - devicestatus="unused" - - if insert == "true" : - cursor.execute("delete from autocard where uniqid=%s;",(Businfo)) - if Driver=="hdr": - Cardvendor="HDHOMERUN Tuner 1" - cursor.execute("INSERT INTO autocard (dev,driver,description,uniqid,devicestatus,hostname) VALUES(%s,%s,%s,%s,%s,%s);",(Device,Driver,Cardvendor,Businfo,devicestatus,currenthostname)) - Cardvendor="HDHOMERUN Tuner 2" - cursor.execute("INSERT INTO autocard (dev,driver,description,uniqid,devicestatus,hostname) VALUES(%s,%s,%s,%s,%s,%s);",(Device,Driver,Cardvendor,Businfo,devicestatus,currenthostname)) +from xml.dom.minidom import parseString +import errno, fcntl +import urllib2,urllib,json +#http://code.activestate.com/recipes/576891/ + +class ApplicationLock: + ''' + Ensures application is running only once, by using a lock file. + + Ensure call to lock works. Then call unlock at program exit. + + You cannot read or write to the lock file, but for some reason you can + remove it. Once removed, it is still in a locked state somehow. Another + application attempting to lock against the file will fail, even though + the directory listing does not show the file. Mysterious, but we are glad + the lock integrity is upheld in such a case. + + Instance variables: + lockfile -- Full path to lock file + lockfd -- File descriptor of lock file exclusively locked + ''' + def __init__ (self, lockfile): + self.lockfile = lockfile + self.lockfd = None + + def lock (self): + ''' + Creates and holds on to the lock file with exclusive access. + Returns True if lock successful, False if it is not, and raises + an exception upon operating system errors encountered creating the + lock file. + ''' + try: + # + # Create or else open and trucate lock file, in read-write mode. + # + # A crashed app might not delete the lock file, so the + # os.O_CREAT | os.O_EXCL combination that guarantees + # atomic create isn't useful here. That is, we don't want to + # fail locking just because the file exists. + # + # Could use os.O_EXLOCK, but that doesn't exist yet in my Python + # + self.lockfd = os.open (self.lockfile, + os.O_TRUNC | os.O_CREAT | os.O_RDWR) + + # Acquire exclusive lock on the file, but don't block waiting for it + fcntl.flock (self.lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB) + + # Writing to file is pointless, nobody can see it + os.write (self.lockfd, "My Lockfile") + + return True + except (OSError, IOError), e: + # Lock cannot be acquired is okay, everything else reraise exception + if e.errno in (errno.EACCES, errno.EAGAIN): + return False else: - cursor.execute("INSERT INTO autocard (dev,driver,description,uniqid,devicestatus,hostname) VALUES(%s,%s,%s,%s,%s,%s);",(Device,Driver,Cardvendor,Businfo,devicestatus,currenthostname)) + raise + + def unlock (self): + try: + # FIRST unlink file, then close it. This way, we avoid file + # existence in an unlocked state + os.unlink (self.lockfile) + # Just in case, let's not leak file descriptors + os.close (self.lockfd) + except (OSError, IOError), e: + # Ignore error destroying lock file. See class doc about how + # lockfile can be erased and everything still works normally. + pass +#------- START OF TUNER CLASSES----------- +class v4l_tuners(): + def __init__(self, device): + self.device = device + self.full_attribs = self.find_full_attribs() + self.full_udev_attribs = self.find_full_udev_attribs() + self.description,self.driver = self.find_description() + self.udev_props = self.parse_full_udev() + self.tuner_hash = self.find_tuner_hash() + self.udev_rule = self.create_udev_rule() + #self.staticdevice is set in create_udev_rule + + def find_full_attribs(self): + cmd = 'v4l2-ctl -D -d' + self.device + return os.popen(cmd).readlines() + + def find_full_udev_attribs(self): + cmd = 'udevadm info -a -p $(udevadm info -q path -n %s)' %self.device + return os.popen(cmd).readlines() + + def find_description(self): + for line in self.full_attribs: + #print line + pos = string.find(line,"Driver name") + if pos >=0: + splitline= line.split(':') + Driver=splitline[1].strip() + pos = string.find(line,"Card type") + if pos >=0: + splitline= line.split(':') + Cardtype=splitline[1].strip() + + pos = string.find(line,"Bus info") + if pos >=0: + splitline= line.split(':',1) + Businfo=splitline[1].strip() + return Cardtype,Driver + + def parse_full_udev(self): + udev_props = [] + #ATTRS{serial}=="00A2023E"\n', + #SUBSYSTEMS=="usb"\n', + #SUBSYSTEM=="video4linux"\n', + #KERNELS=="0000:08:08.0"\n', + #DRIVERS=="hdpvr"\n' + #DRIVERS=="ivtv"\n', + #ATTR{index}=="0" + match = ['SUBSYSTEM', + 'SUBSYSTEMS', + 'DRIVERS', + 'KERNELS', + 'ATTRS{serial}', + 'ATTR{name}', + 'ATTR{index}' + ] + + for item in match: + regex = re.compile('%s.*$' %item) + for line in self.full_udev_attribs: + m = regex.search(line.strip()) + if m: + #print line + udev_props.append(line.strip()) + break + + #throw out kernels for usb subsystems. + if 'SUBSYSTEMS=="usb"' in udev_props: + #print "found usb" + new_udev_props=[] + for index, item in enumerate(udev_props): + #print item,index + if item.startswith("DRIVERS=="): + continue + elif item.startswith("KERNELS=="): + continue + else: + new_udev_props.append(item) + udev_props = new_udev_props + + + return udev_props + + def is_hdpvr(self): + if self.description == "Hauppauge HD PVR": + return True + return False + + def is_mpeg(self): + if self.driver in ["ivtv","saa7164[0]","saa7164"]: + return True + return False + + def find_tuner_hash(self): + #tuner hash will be driven by card_type pci id and index + i='' + k='' + tuner_hash='' + card_type = self.get_card_type() + if card_type == "v4l_hdpvr": + for index, item in enumerate(self.udev_props): + if item.startswith("ATTRS{serial}=="): + hex_serial=item.split("==")[1].strip('''"''') + serial = int(hex_serial, 16) + tuner_hash="hdpvr_%s" %serial + + else: + for index, item in enumerate(self.udev_props): + if item.startswith("KERNELS=="): + k=item.split("==")[1].strip('''"''') + k=k.replace(":", "_") + k=k.replace("0", "") + k=k.replace(".", "") + + if item.startswith("ATTR{index}=="): + i=item.split("==")[1].strip('''"''') + + tuner_hash="%s%s%s" %(card_type,k,i) + + return tuner_hash + + def escapeSpecialCharacters ( self, text, characters ): + for character in characters: + text = text.replace( character, '\\' + character ) + return text + + def create_udev_rule(self): + #DRIVERS=="ivtv", ATTR{name}=="ivtv? encoder MPG", KERNELS=="0000:08:09.0" SYMLINK+="myth/aivtv2" + line = ','.join(self.udev_props) + line += ' SYMLINK+="vstatic/%s"' %(self.get_tuner_hash()) + self.staticdevice = "/dev/vstatic/%s" %(self.get_tuner_hash()) + return self.escapeSpecialCharacters(line,'[]') + + def card_mpeg_values(self): + values = { + 'CardType' : 'MPEG' , + 'VideoDevice' : self.staticdevice, + 'Defaultinput' : 'Television', + 'HostName' : self.localhostname, + 'dvb_wait_for_seqstart' :'1', + 'signal_timeout' :'1000', + 'channel_timeout' :'12000', + 'diseqcid' :'NULL', + 'dvb_eitscan' :'1' + } + + return values + + def card_hdpvr_values(self): + values = { + 'CardType' : 'HDPVR' , + 'VideoDevice' : self.staticdevice, + 'Defaultinput' : 'Television', + 'HostName' : self.localhostname, + 'dvb_wait_for_seqstart' :'1', + 'signal_timeout' :'1000', + 'channel_timeout' :'12000', + 'diseqcid' :'NULL', + 'dvb_eitscan' :'1' + } + return values + + def do_insert(self,values): + try: + header = { 'User-Agent' : "autocard" } + url="http://127.0.0.1:6544/Capture/AddCaptureCard/" + data = urllib.urlencode(values) + req = urllib2.Request(url, data, header) + self.response = urllib2.urlopen(req) + except: + print " **Insert of %s failed" %self.staticdevice + + def insert_myth(self,myth_tuner_list): + #check if tuner is already in the db + if self.staticdevice in myth_tuner_list: + print " *%s %s already in mythdb" %(self.get_card_type(),self.staticdevice) + else: + #determine values to use based on card type + print " Inserting %s" %self.staticdevice + if self.is_hdpvr() == True: + values = self.card_hdpvr_values() + self.do_insert(values) + elif self.is_mpeg() == True: + values = self.card_mpeg_values() + self.do_insert(values) + else: + print " Unknown V4l type, not adding to myth database" + return + + def set_hostname(self,hostname): + self.localhostname = hostname + + def set_tuner_index(self,index): + #only used by dvb, but here to be complete + self.tuner_index = index + + def get_dev_node(self): + return self.device + + def get_full_attribs(self): + return self.full_attribs + + def get_full_udev_attribs(self): + return self.full_udev_attribs + + def get_card_type(self): + if self.is_hdpvr() == True : + rc = "v4l_hdpvr" + elif self.is_mpeg() == True: + rc = "v4l_mpeg" + else: + rc = "v4l" + return rc + + def get_description(self): + return self.description + + def get_udev_probs(self): + return self.udev_props + + def get_tuner_hash(self): + return self.tuner_hash + + def get_udev_rule(self): + return self.udev_rule + + def get_static_device(self): + return self.staticdevice + + +#----- +class hdhr_tuners(): + def __init__(self, device,ip): + self.device = device + self.ip = ip + self.description = self.find_description() + self.staticdevice = device + + def find_description(self): + command = '/usr/bin/hdhomerun_config %s get /sys/hwmodel' %self.device + results=os.popen(command,'r') + return results.readline().strip() + + def insert_myth(self,hdhr_list): + if self.device in hdhr_list: + print " *hdhr %s already in mythtdb" %self.device + else: + print " Inserting HDHR %s" %self.device + self.do_insert() + pass + + def do_insert(self): + try: + header = { 'User-Agent' : "autocard" } + url="http://127.0.0.1:6544/Capture/AddCaptureCard/" + values = self.card_hdhr_values() + data = urllib.urlencode(values) + req = urllib2.Request(url, data, header) + self.response = urllib2.urlopen(req) + except: + print " **Insert of %s failed" %self.device + + def card_hdhr_values(self): + values = { + 'CardType' : 'HDHOMERUN' , + 'VideoDevice' : self.device, + 'Defaultinput' : 'Television', + 'HostName' : self.localhostname, + 'dvb_wait_for_seqstart' :'1', + 'signal_timeout' :'1000', + 'channel_timeout' :'3000', + 'diseqcid' :'NULL', + 'dvb_eitscan' :'1' + } + return values + + def set_hostname(self,hostname): + self.localhostname = hostname + + def set_tuner_index(self,index): + #only used by dvb, but here to be complete + self.tuner_index = index + + + def get_dev_node(self): + return self.device + + def get_card_type(self): + return "hdhr" + + def get_description(self): + desc = "%s - %s" %(self.description,self.ip) + return desc + + def get_udev_rule(self): + return + + def get_tuner_hash(self): + return self.device + + def get_static_device(self): + return self.staticdevice + + + + +#----- +class dvb_tuners(): + def __init__(self, device): + self.device = device + self.tuner_index = 1 + self.dvb_number = self.find_dvb_number() + self.description = self.find_description() + self.full_udev_attribs = self.find_full_udev_attribs() + self.udev_props = self.parse_full_udev() + self.tuner_hash = self.find_tuner_hash() + self.udev_rule = self.create_udev_rule() + #self.staticdevice is set in create_udev_rule + + def find_description(self): + command = '/usr/bin/dvb-fe-tool -g -a %s' %self.dvb_number + results=os.popen(command,'r') + line = results.readline().strip() + d = line.split('''(''') + return d[0] + + def find_full_udev_attribs(self): + cmd = 'udevadm info -a -p $(udevadm info -q path -n %s)' %self.device + return os.popen(cmd).readlines() + + def find_dvb_number(self): + #/dev/dvb/adapter2/frontend0 + d=self.device.split("/")[3] + dvb_number=d.partition("adapter")[2] + return dvb_number + + def parse_full_udev(self): + udev_props = ['KERNEL=="dvb?.frontend?"'] + #ATTRS{serial}=="00A2023E"\n', + #SUBSYSTEMS=="usb"\n', + #SUBSYSTEM=="video4linux"\n', + #KERNELS=="0000:08:08.0"\n', + #DRIVERS=="hdpvr"\n' + #DRIVERS=="ivtv"\n', + #ATTR{index}=="0" + #KERNEL=="dvb1.frontend0" + + match = ['SUBSYSTEM', + 'SUBSYSTEMS', + 'DRIVERS', + 'KERNELS', + 'ATTRS{serial}', + 'ATTR{name}', + 'ATTR{index}' + ] + + for item in match: + regex = re.compile('%s.*$' %item) + for line in self.full_udev_attribs: + m = regex.search(line.strip()) + if m: + #print line + udev_props.append(line.strip()) + break + + #throw out kernels for usb subsystems. + if 'SUBSYSTEMS=="usb"' in udev_props: + #print "found usb" + new_udev_props=[] + for index, item in enumerate(udev_props): + #print item,index + if item.startswith("DRIVERS=="): + continue + elif item.startswith("KERNELS=="): + continue + else: + new_udev_props.append(item) + udev_props = new_udev_props + return udev_props + + def find_tuner_hash(self): + #tuner hash will be driven by card_type pci id and index + i='' + k='' + tuner_hash='' + card_type = self.get_card_type() + + for index, item in enumerate(self.udev_props): + if item.startswith("KERNELS=="): + k=item.split("==")[1].strip('''"''') + k=k.replace(":", "_") + k=k.replace("0", "") + k=k.replace(".", "") + + if item.startswith("ATTR{index}=="): + i=item.split("==")[1].strip('''"''') + + tuner_hash="%s%s%s" %(card_type,k,i) + return tuner_hash + def escapeSpecialCharacters ( self, text, characters ): + for character in characters: + text = text.replace( character, '\\' + character ) + return text + def create_udev_rule(self): + line = ','.join(self.udev_props) + line += ' RUN+="/usr/MythVantage/bin/udev_link.sh %s $env{DEVNAME} "' %(self.get_tuner_hash()) + self.staticdevice = "/dev/dvb/adapter_static_%s_%s/frontend0" %(self.get_tuner_hash(),self.tuner_index) + return self.escapeSpecialCharacters(line,'[]') -def PRINTINFO(): - global cardlist + def insert_myth(self,myth_tuner_list): + if self.staticdevice in myth_tuner_list: + print " *dvb %s already in mythtdb" %self.staticdevice + else: + print " Inserting DVB Tuner %s" %self.staticdevice + self.do_insert() + pass - for list in cardlist: - if list != "_placeholder_": - print list - #print "-------------" + def do_insert(self): + try: + header = { 'User-Agent' : "autocard" } + url="http://127.0.0.1:6544/Capture/AddCaptureCard/" + values = self.card_dvb_values() + data = urllib.urlencode(values) + req = urllib2.Request(url, data, header) + self.response = urllib2.urlopen(req) + except: + print " **Insert of %s failed" %self.staticdevice -def GATHER_HDR(): - global cardlist + def card_dvb_values(self): + values = { + 'CardType' : 'DVB' , + 'VideoDevice' : self.staticdevice, + 'Defaultinput' : 'Television', + 'HostName' : self.localhostname, + 'dvb_wait_for_seqstart' :'1', + 'signal_timeout' :'1000', + 'channel_timeout' :'12000', + 'diseqcid' :'NULL', + 'dvb_on_demand' :'0', + 'dvb_eitscan' :'1' + } + return values + + def set_tuner_index(self,index): + self.tuner_index = index + self.tuner_hash = self.find_tuner_hash() + self.udev_rule = self.create_udev_rule() + + def set_hostname(self,hostname): + self.localhostname = hostname + + def get_dev_node(self): + return self.device + + def get_card_type(self): + return "dvb" + + def get_description(self): + return self.description + + def get_full_udev_attribs(self): + return self.full_udev_attribs + + def get_tuner_hash(self): + return self.tuner_hash + + def get_udev_rule(self): + return self.udev_rule + + def get_static_device(self): + return self.staticdevice +#-- +class infinitv_tuner(): + def __init__(self, tuner_number,ip): + self.tuner_number = tuner_number + self.ceton_defined_tuner = tuner_number + 1 + self.ip = ip + self.serial_num = self.find_serial() + self.connection = self.find_connection() + self.description = self.find_description() + self.staticdevice = self.find_static() + + def find_static(self): + static="%s-RTP.%s" %(self.ip,self.tuner_number) + return static + + def find_connection(self): + uri='get_var.json?i=0&s=diag&v=Host_Connection' + try: + url="http://%s/%s" %(self.ip,uri) + req = urllib2.Request(url) + r = urllib2.urlopen(req).read() + response = r.split()[2].strip('''"''') + except: + response='unknown' + return response + + def find_serial(self): + uri='get_var.json?i=0&s=diag&v=Host_Serial_Number' + try: + url="http://%s/%s" %(self.ip,uri) + req = urllib2.Request(url) + r = urllib2.urlopen(req).read() + response = r.split()[2].strip('''"''') + except: + response='unknown' + return response + + def find_description(self): + desc="Ceton InfiniTV %s Tuner %s" %(self.connection, + self.ceton_defined_tuner) + return desc + + def do_insert(self): + try: + header = { 'User-Agent' : "autocard" } + url="http://127.0.0.1:6544/Capture/AddCaptureCard/" + values = self.card_ceton_values() + data = urllib.urlencode(values) + req = urllib2.Request(url, data, header) + self.response = urllib2.urlopen(req) + except: + print " **Insert of %s failed" %self.staticdevice + + def card_ceton_values(self): + values = { + 'CardType' : 'CETON' , + 'VideoDevice' : self.staticdevice, + 'Defaultinput' : 'Television', + 'HostName' : self.localhostname, + 'dvb_wait_for_seqstart' :'1', + 'signal_timeout' :'1000', + 'channel_timeout' :'3000', + 'diseqcid' :'NULL', + 'dvb_eitscan' :'1' + } + return values + + def insert_myth(self,myth_tuner_list): + if self.staticdevice in myth_tuner_list: + print " *infinitv %s already in mythtdb" %self.staticdevice + else: + print " Inserting Ceton InfinitTV Tuner %s" %self.staticdevice + self.do_insert() + return + + def write_proxy(self): + directory="/etc/ceton_proxy.d" + if not os.path.exists(directory): + os.makedirs(directory) + proxy_file = "%s/%s" %(directory,self.get_proxy_num()) + try: + f = open(proxy_file,'w') + line="port=%s\n" %(self.get_proxy_num()) + f.write(line) + line="ip=%s\n" %(self.ip) + f.write(line) + except: + print " *Problem creating proxy file %s" %proxy_file + return + + def get_static_device(self): + return self.staticdevice + + def get_tuner_hash(self): + return self.staticdevice + + def set_proxy(self,proxy_num): + self.proxy_num = 7000 + proxy_num + return + + def set_hostname(self,hostname): + self.localhostname = hostname + return + + def set_tuner_index(self,index): + #only used by dvb, but here to be complete + self.tuner_index = index + return + def get_proxy_num(self): + return self.proxy_num + + def get_udev_rule(self): + return + + def get_card_type(self): + return "infinitv" + + def get_description(self): + desc = "%s - %s" %(self.description,self.ip) + return desc + + def get_serial_number(self): + return self.serial_num +#-- end infinitv + +#------------------END TUNER CLASSES----------------------- + +#------------------START OF TUNER GATHERING----------------- +def find_hdhr_tuner(hdhrdevice): + htuner_list=[] + command="/usr/bin/hdhomerun_config %s get /tuner%s/status" + #loop over 4 possible tuners + for i in range(4): + c=command %(hdhrdevice,i) + results=os.popen(c,'r') + lines=results.readlines() + try: + #if the first line starts with error, assume it's not a tuner and + #there are no more tuners for this device. + if lines[0].strip().startswith("ERROR"): + break + else: + t="%s-%s" %(hdhrdevice,i) + htuner_list.append(t) + except: + pass + return htuner_list + +def gather_hdhr(tuner_list): command="/usr/bin/hdhomerun_config --discover" results=os.popen(command,'r') - line=results.readline() - if line.strip().split()[0] == "no": - print "HDHOMERUN not detected" - else: - print line - hdrdevice=line.strip().split()[2] - print hdrdevice - Driver="hdr" - Device=hdrdevice - Cardtype="HDHOMERUN" - Businfo=hdrdevice - cardprops = [Device,Driver , Cardtype , Businfo] - cardlist.append(cardprops) - - -def GATHER_v4l_CARDS(): - global cardlist - cardlist=["_placeholder_"] - # print "Looking for v4l cards" + lines=results.readlines() + try: + if lines[0].strip().split()[0] == "no": + print "HDHOMERUN not detected" + else: + for line in lines: + hdhrdevice=line.strip().split()[2] + hdhrip = line.strip().split()[5] + tuners = find_hdhr_tuner(hdhrdevice) + for t in tuners: + tuner_list.append(hdhr_tuners(t,hdhrip)) + except: + print "Error finding HDHOMERUN" + return tuner_list + +def gather_v4l(tuner_list): try: - filelist = os.listdir('/dev/v4l/') + filelist = os.listdir('/dev/v4l/by-path/') except OSError: - filelist=" " + pass #fakelist=['/dev/v4l/video3', 'ivtv', 'WinTV PVR 500 (unit #2)', '0000:04:09.0'] #cardlist.append(fakelist) try: - filelist = glob.glob("/dev/v4l/video?") - Driver="" - Cardtype="" - Businfo="" - numcards = 0 - for Device in filelist: - #print card - numcards = numcards+1 - cmd = 'v4l2-ctl -D -d' + Device - for line in os.popen(cmd).readlines(): - #print line - pos = string.find(line,"Driver name") - if pos >=0: - splitline= line.split(':') - Driver=splitline[1].strip() - pos = string.find(line,"Card type") - if pos >=0: - splitline= line.split(':') - Cardtype=splitline[1].strip() - - pos = string.find(line,"Bus info") - if pos >=0: - splitline= line.split(':',1) - Businfo=splitline[1].strip() - - #print Device,Driver , Cardtype , Businfo,numcards - cardprops = [Device,Driver , Cardtype , Businfo] - cardlist.append(cardprops) + p = re.compile('^/dev/video?\d$') + filelist = glob.glob("/dev/v4l/by-path/*video*") + for device in filelist: + Device=os.path.realpath(device) + if not p.search(Device): + continue + #print "real device node" + #print Device + tuner_list.append(v4l_tuners(Device)) except IOError: - print "no v4l cards found" - sys.exit(2) - - -def WRITEUDEV_IVTV(): - global insertmyth - cursor = db.cursor() - #add ivtv,cid lookup loop through until empty. - cursor.execute("select distinct(uniqid) from autocard where driver='ivtv' and devicestatus='will-add'") - cidrows = cursor.fetchall() - for row in cidrows: - cid=row[0] - cursor.execute("select dev,driver,description,devicestatus,hostname from autocard where uniqid=%s limit 1;",(cid)) - result = cursor.fetchone() - description=result[2] - driver='DRIVERS==\"ivtv\"' - ATTRNAME='ATTR{name}=="ivtv? encoder MPG"' - KERNELS='KERNELS==\"' - KERNELS+=cid - KERNELS+="\"" - #filter out non digit or chars - keep=letters.join(digits) - description=filter(lambda c: c in keep, description) - devnode="ivtv/" - #devnode+=description + "_" - udevcid=cid.partition(":") - devnode+=udevcid[2] - devnode+="_video" - UDEV_RULE=driver +', '+ATTRNAME+', '+ KERNELS +', ' + 'NAME=\"' + devnode + '"' - print "Here is the udev rule" - print UDEV_RULE - filename='/etc/udev/rules.d/11-ivtv-'+cid+'.rules' - file = open(filename,'w') - file.write(UDEV_RULE) - if ( insertmyth == "true"): - devnode="/dev/"+devnode - INSERTCARD_INTOMYTH(devnode,"ivtv",description) - cursor.execute("update autocard set devicestatus='done' where uniqid=%s;",(cid)) -#now insert HDR - cursor.execute("select distinct(uniqid),description from autocard where driver='hdr' and devicestatus='will-add'") - cidrows = cursor.fetchall() - for row in cidrows: - if ( insertmyth == "true"): - deviceid=row[0] - #cardtype="HDHOMRUN" - #defaultinput="MPEG2TS" - dbox2_port=row[1] - tuner_number=dbox2_port.rpartition(' ')[2] - INSERTHDR_INTOMYTH(deviceid,tuner_number) - cursor.execute("update autocard set devicestatus='done' where uniqid=%s and description=%s;",(deviceid,dbox2_port)) - - - -def CLEARAUTOCARD(): - cursor = db.cursor() - cursor.execute("delete from autocard") - -def RELOADUDEV(): - print "relaoding udev rules" - os.system('udevcontrol reload_rules') - os.system('rmmod ivtv') - os.system('udevtrigger') - - -def usage(): - print " -h help" - print " -g gather and print out the found cards" - print " -w write out the udev rules" - print " -i insert cards into myth that are marked will-add(only used with -w)" - print " -r reload udev rules" - print " -c clear the autocard db" + print "no v4l cards found" + return tuner_list + +def gather_dvb(tuner_list): + try: + filelist = os.listdir('/dev/dvb/') + except OSError: + pass -def main(argv): - global db - global cardlist - global currenthostname - currenthostname="" - writeudev="false" - global insertmyth - insertmyth ="false" - - db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="mythconverg") try: - cursor = db.cursor() - cursor.execute("describe autocard;") - except MySQLdb.Error, e: - cursor.execute("create table autocard(dev varchar(50),driver varchar(50),description varchar(50),uniqid varchar(50), devicestatus varchar(50),hostname varchar(50));") - print "table created" + for d in filelist: + if os.path.islink("/dev/dvb/"+d): + continue + Device=os.path.realpath("/dev/dvb/"+d+"/frontend0") + tuner_list.append(dvb_tuners(Device)) + except: + print "no dvb cards found" + return tuner_list - if ( currenthostname == "" ): - currenthostname = socket.gethostname() +def gather_ceton(tuner_list): + #find and configure ctn network interfaces + ceton_network_list = find_ceton_network_list() + #find all the cards on a network interface + for iface in ceton_network_list: + #command="cat /tmp/find_ceton.txt" + print "Scanning %s network for ceton infinitv" %iface + command="/usr/MythVantage/bin/discover_infinitv.py %s" %iface + results=os.popen(command,'r') + lines=results.readlines() + #try: + if lines[0].strip().split()[0] == "no": + print "Ceton not detected" + else: + for line in lines: + #Found InfiniTV. Location URL: http://192.168.200.1/description.xml + #cetondevice = line.strip().split()[0] + cetonip = line.strip().split("/")[2] + tuners = [0,1,2,3] + for t in tuners: + tuner_list.append(infinitv_tuner(t,cetonip)) + #except: + # print "Error finding Ceton InfinitTV" + + return tuner_list + +#------------------END OF TUNER GATHERING----------------- +#----linhes specific for networking +def config_ctn_network(ctn_iface): + etcnetdir = "/etc/net/ifaces/%s" %ctn_iface + if not os.path.exists(etcnetdir): + print "Creating config for interface %s" %ctn_iface + os.mkdir(etcnetdir) + outline=''' +TYPE=eth +DISABLED=no +BOOTPROTO=dhcp +ONBOOT=yes +CONFIG_WIRELESS=no +DHCP_ARGS="-C resolv.conf" + ''' + optionfile="%s/options" %etcnetdir + f = open(optionfile, 'w') + f.write(outline) + f.close() + command="/etc/net/scripts/network.init start" + os.system(command) + else: + pass #config is present + + +def find_ceton_network_list(): + import netifaces + + netinterfaces = netifaces.interfaces() + ctnip=[] + for i in netinterfaces: + if i.startswith("ctn") or i.startswith("usb"): + #configure and start ctn network + config_ctn_network(i) + + #read ip + ctnip.append(netifaces.ifaddresses(i) + [netifaces.AF_INET][0]['addr']) + return ctnip + +#--end of linhes specific + +def gather_tuners(): + tuner_list = [] + tuner_list = gather_hdhr(tuner_list) + tuner_list = gather_v4l(tuner_list) + tuner_list = gather_dvb(tuner_list) + tuner_list = gather_ceton(tuner_list) + #set the number of times we have seen a specific tuner_hash + #This will be used by dvb when tuner_hashs conflict + tuner_count = {} + for i in tuner_list: + th = i.get_tuner_hash() + if th in tuner_count: + tuner_count[th] += 1 + else: + tuner_count[th] = 1 + i.set_tuner_index(tuner_count[th]) + return tuner_list + +def trigger_udev(): + print "Reloading udev rules" + command = '/usr/bin/udevadm control --reload' + results=os.popen(command,'r') + + print "Triggering udev events" + command = '/usr/bin/udevadm trigger' + results=os.popen(command,'r') + +def write_udev_file(rule_list): + udevfile = '/etc/udev/rules.d/99-mv-persistent-video.rules' + try: + f = open(udevfile, 'w') + line = "#Do not edit this file, it is auto generated by autocard.py \n\n" + f.write(line) + for rule in rule_list: + if rule: + line = "%s \n" %(rule) + f.write(line) + f.close() + except: + print "Error creating %s" %udevfile + trigger_udev() + +def write_udev_map(tuner_list): + udevfile = '/etc/udev/mv-persistent-video.description' + try: + f = open(udevfile, 'w') + line = "#Do not edit this file, it is auto generated by autocard.py \n" + f.write(line) + line = "#This file is used to generate the static tuner card web page\n" + f.write(line) + for i in tuner_list: + if i.get_card_type() == "hdhr": + pass + line="hdhr:%s:%s" %(i.get_description(),i.get_static_device()) + f.write(line) + f.write("\n") + elif i.get_card_type() == "v4l_mpeg": + pass + line="V4L_mpeg:%s: %s " %(i.get_description(),i.get_static_device()) + f.write(line) + f.write("\n") + elif i.get_card_type() == "v4l": + pass + line="V4L:%s:%s " %(i.get_description(),i.get_static_device()) + f.write(line) + f.write("\n") + elif i.get_card_type() == "v4l_hdpvr": + pass + line="hdpvr:%s: %s " %(i.get_description(),i.get_static_device()) + f.write(line) + f.write("\n") + elif i.get_card_type() == "dvb": + line="dvb:%s: %s " %(i.get_description(),i.get_static_device()) + f.write(line) + f.write("\n") + elif i.get_card_type() == "infinitv": + line="infinitv:%s:%s:%s" %(i.get_description(), + i.get_static_device(), + i.get_proxy_num()) + f.write(line) + f.write("\n") + else: + print i + line = i + f.write(line) + f.write("\n") + except: + print "Error creating %s" %udevfile + f.close() + +def checkURL(url): try: - opts, args = getopt.getopt(argv, "hgwircd", ["help", "gathercards", "writeudev" ,"insert" , "reloadudev" , "clearautocard"] ) - except getopt.GetoptError: - sys.exit(2) - for opt, arg in opts: - if opt in ("-h", "--help"): - usage() - sys.exit() - elif opt in ( "-g" , "--gathercards"): - GATHER_v4l_CARDS() - GATHER_HDR() - INSERTAUTOCARD() - PRINTINFO() - elif opt in ("-w", "--writeudev"): - writeudev="true" - elif opt in ("-i", "--insert"): - insertmyth="true" - elif opt in ( "-r" , "--reloadudev"): - RELOADUDEV() - elif opt in ( "-c" , "--clearautocard"): - CLEARAUTOCARD() - elif opt in ( "-d" ): - INSERTCARD_INTOMYTH("file:/myth/video/TripThe1939.mpeg","ivtv","Dummy tuner") - INSERTNULL_SOURCE("dummy","/bin/true","","default","NULL","NULL","0") - - if ( writeudev == "true"): - WRITEUDEV_IVTV() + connection = urllib2.urlopen(url,None,3) + code=connection.getcode() + connection.close() + if code == 200: + rc=0 + #except urllib2.HTTPError, e: + except: + rc=1 + return rc +def getURL(url): + dom = None + try: + connection = urllib2.urlopen(url,None,3) + data = connection.read() + connection.close() + dom = parseString(data) + #except urllib2.HTTPError, e: + except: + pass + return dom +def find_hdhr_in_use(): + hdhr_list = [] + url='http://127.0.0.1:6544/Capture/GetCaptureCardList?CardType=HDHOMERUN' + data = getURL(url) + if data: + xmlTags = data.getElementsByTagName('VideoDevice') + for i in xmlTags: + xmlTag=i.toxml() + xmlData=xmlTag.replace('<VideoDevice>','').replace('</VideoDevice>','') + hdhr_list.append(xmlData) + return hdhr_list +def find_in_use_card_list(): + in_use_tuner_list=[] + url='http://127.0.0.1:6544/Capture/GetCaptureCardList?HostName=%s' %localhostname + data = getURL(url) -if __name__ == "__main__": - main(sys.argv[1:]) + if data: + xmlTags = data.getElementsByTagName('VideoDevice') + for i in xmlTags: + xmlTag=i.toxml() + xmlData=xmlTag.replace('<VideoDevice>','').replace('</VideoDevice>','') + in_use_tuner_list.append(xmlData) + return in_use_tuner_list + +def usuage(): + help=''' + Autocard.py is a program that will take the guess work out of setting up tuner/capture cards. + There are 4 options: + help : This help screen + print: Will find and printout any detected capture cards, including network based tuners like the hdhomerun_config + udev : This option creates a set of static device nodes for the local capture cards. + Rules are based on pci/usb path so moving the card into a different expansion slot will nullify the udev rule + HDPVR devices use the serial number as the primary key for the udev rule_list + + insertdb : This option will insert any detected cards into the MythTV database using the static device generated by udev. + This option will also generate udev rules. Tuners that are already defined will not be readded. + + write_proxy: This will write out the config used by the service ceton_proxy + all : The same as using print udev insertdb write_proxy + + + EX: + autocard.py print + autocard.py insertdb + ''' + print help + +def main(argv): + listcards = False + udev = False + insertdb = False + write_proxy = False + + if argv==[] or "help" in argv: + usuage() + sys.exit(0) + + if "print" in argv: + listcards = True + + if "udev" in argv: + udev = True + write_proxy = True + + if "insertdb" in argv: + insertdb = True + udev = True + write_proxy = True + if "write_proxy" in argv: + write_proxy = True + if "all" in argv: + udev = True + insertdb = True + listcards = True + write_proxy = True + tuner_list = gather_tuners() + rule_list = [] + #setting the proxy port for ceton webpage + ceton_proxy = 1 + for i in tuner_list: + if i.get_card_type() == "infinitv": + i.set_proxy(ceton_proxy) + ceton_proxy = ceton_proxy + 1 -#mysql> create table autocard(dev varchar(50),driver varchar(50),description varchar(50),uniqid varchar(50), devicestatus varchar(50),hostname varchar(50)); -#Query OK, 0 rows affected (0.14 sec) + #setting the hostname for each tuner + i.set_hostname(localhostname) + rule_list.append(i.get_udev_rule()) + if listcards == True: + print i.get_card_type() + print "----------------" + print "\t" , i.get_description() + print "\t" , i.get_static_device() -#mysql> describe autocard; -#+--------------+-------------+------+-----+---------+-------+ -#| Field | Type | Null | Key | Default | Extra | -#+--------------+-------------+------+-----+---------+-------+ -#| dev | varchar(50) | YES | | NULL | | -#| driver | varchar(50) | YES | | NULL | | -#| description | varchar(50) | YES | | NULL | | -#| uniqid | varchar(50) | YES | | NULL | | -#| devicestatus | varchar(50) | YES | | NULL | | -#| hostname | varchar(50) | YES | | NULL | | -#+--------------+-------------+------+-----+---------+-------+ + print("Writing out tuner map") + write_udev_map(tuner_list) + restart_proxy=False + if write_proxy == True: + for i in tuner_list: + if i.get_card_type() == "infinitv": + i.write_proxy() + restart_proxy=True + if restart_proxy == True: + command="add_service.sh cetonproxy" + os.system(command) + print" Restarting ceton proxy" + command="sv restart cetonproxy" + os.system(command) + if udev == True: + print("Writing out udev rules") + write_udev_file(rule_list) + if insertdb == True: + be_ready = False + i = 0 + while i < 10 or be_ready : + if checkURL('http://127.0.0.1:6544') == 0: + be_ready = True + break + i = i + 1 + print "Waiting for MythTV backend connection: %s/10" %i + time.sleep(5) + if be_ready == True : + #find all HDHR + in_use_hdhr_list = find_hdhr_in_use() + #find other cards local + in_use_local_card_list = find_in_use_card_list() + print "Adding cards to mythtv database" + for i in tuner_list: + if i.get_card_type() == "hdhr": + i.insert_myth(in_use_hdhr_list) + else: + i.insert_myth(in_use_local_card_list) + + +if __name__ == "__main__": + localhostname = socket.gethostname() + applock = ApplicationLock ('/var/run/autocard.lock') + if (applock.lock ()): + #print ("Obtained lock") + main(sys.argv[1:]) + #print ("Unlocking") + applock.unlock () + else: + print ("Unable to obtain lock, exiting") diff --git a/abs/core/LinHES-config/backend_control.sh b/abs/core/LinHES-config/backend_control.sh new file mode 100755 index 0000000..bbc7362 --- /dev/null +++ b/abs/core/LinHES-config/backend_control.sh @@ -0,0 +1,66 @@ +#!/bin/bash +#. /etc/systemconfig +#echo $@ > /tmp/parms +#start Slavebackend: fusion 192.168.1.120 +COMMAND=$1 +BETYPE=$2 +eval LAST=\$$# +dbhost=`echo $LAST` +hostname=`hostname` +MESSAGE="" + +case $COMMAND in + stop) MESSAGE=`/usr/bin/curl http://$dbhost:1337/bestop.cgi 2>/dev/null` + rc=$? + + if [ $rc != 0 ] + then + msg_client.py --msg "Could not stop the backend." + else + echo "$MESSAGE" | grep -q "'$hostname': 'Message delivered'" + rc=$? + if [ $rc != 0 ] + then + msg_client.py --msg "* Backend Stopped" > /dev/null + fi + fi + ;; + + start ) + MESSAGE=`/usr/bin/curl http://$dbhost:1337/bestart.cgi 2>/dev/null` + rc=$? + if [ $rc != 0 ] + then + msg_client.py --msg "Could not start the backend" + else + echo "$MESSAGE" | grep -q "'$hostname': 'Message delivered'" + rc=$? + if [ $rc != 0 ] + then + msg_client.py --msg "* Backend Started" > /dev/null + fi + fi + ;; + + restart) + /usr/MythVantage/bin/backend_control.sh stop $dbhost + sleep 2 + /usr/MythVantage/bin/backend_control.sh start $dbhost + ;; + + clearcache) + MESSAGE2=`/usr/bin/curl http://$dbhost:1337/beclear.cgi 2>/dev/null` + rc=$? + if [ $rc != 0 ] + then + msg_client.py --msg "Could not clear the cache" + else + echo "$MESSAGE" | grep -q "'$hostname': 'Message delivered'" + rc=$? + if [ $rc != 0 ] + then + msg_client.py --msg "* cache cleared" > /dev/null + fi + fi +esac + diff --git a/abs/core/LinHES-config/blacklist_nouveau.conf b/abs/core/LinHES-config/blacklist_nouveau.conf new file mode 100644 index 0000000..e09e227 --- /dev/null +++ b/abs/core/LinHES-config/blacklist_nouveau.conf @@ -0,0 +1,2 @@ +blacklist nouveau +install nouveau /bin/false diff --git a/abs/core/LinHES-config/blacklist_pcspkr.conf b/abs/core/LinHES-config/blacklist_pcspkr.conf new file mode 100644 index 0000000..b46792e --- /dev/null +++ b/abs/core/LinHES-config/blacklist_pcspkr.conf @@ -0,0 +1 @@ +blacklist pcspkr diff --git a/abs/core/LinHES-config/config-sudo.rules b/abs/core/LinHES-config/config-sudo.rules new file mode 100644 index 0000000..67d5aba --- /dev/null +++ b/abs/core/LinHES-config/config-sudo.rules @@ -0,0 +1,3 @@ +mythtv ALL = NOPASSWD:/usr/MythVantage/bin/mythvantage +mythtv ALL = NOPASSWD:/usr/MythVantage/bin/MythVantage + diff --git a/abs/core/LinHES-config/LinHES.install b/abs/core/LinHES-config/config.install index fb967aa..2da71ff 100644 --- a/abs/core/LinHES-config/LinHES.install +++ b/abs/core/LinHES-config/config.install @@ -15,28 +15,6 @@ post_install() { echo "List of packages to ignore" > /etc/blacklist.package echo "one package per line" >> /etc/blacklist.package fi - -LINE="mythtv ALL = NOPASSWD:/usr/MythVantage/bin/mythvantage" -LINE1="mythtv ALL = NOPASSWD:/usr/MythVantage/bin/MythVantage" - for i in "$LINE" "$LINE1" - do - cp /etc/sudoers /etc/sudoers.bak - grep -q "$i" /etc/sudoers - if [ $? != 0 ] - then - echo "$i" >> /etc/sudoers - visudo -cf /etc/sudoers - if [ ! $? = 0 ] - then - cp /etc/sudoers.bak /etc/sudoers - echo $i - echo "Error adding files" - exit 1 - fi - fi - done - - } # arg 1: the new package version @@ -48,19 +26,11 @@ pre_upgrade() { # arg 1: the new package version # arg 2: the old package version post_upgrade() { - . /etc/profile - ps -ef|grep mysqld|grep -v grep - status=$? - echo "status $status" - if [ $status = 0 ] + if [ ! -f /etc/blacklist.package ] then - restore_default_settings.sh -c load + echo "List of packages to ignore" > /etc/blacklist.package + echo "one package per line" >> /etc/blacklist.package fi - if [ ! -f /etc/blacklist.package ] - then - echo "List of packages to ignore" > /etc/blacklist.package - echo "one package per line" >> /etc/blacklist.package - fi cat /etc/LinHES-release > /etc/os_myth_release if [ ! -f /usr/share/mythtv/config.xml ] diff --git a/abs/core/LinHES-config/discover_infinitv.py b/abs/core/LinHES-config/discover_infinitv.py new file mode 100755 index 0000000..5c39c59 --- /dev/null +++ b/abs/core/LinHES-config/discover_infinitv.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python2 +# Program to detect Ceton InfiniTV tuners on the network +# Program will only listen on a specific interface for a set amount of time. +# If during that time it finds a device it will print out the location. +# discover_infinitv $ip $timeout +# ex: discover_infinitv 192.168.200.2 + +import socket +import thread +import time,sys + + +class find_the_infiniTV(object): + + def __init__(self,UPNP_GROUP="239.255.255.250", UPNP_PORT=1900, interface_ip='127.0.0.1'): + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind(('', UPNP_PORT)) + mreq = socket.inet_aton(UPNP_GROUP)+socket.inet_aton(interface_ip) + sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) + self.sock=sock + self.devices = {} + self.emit_msearch() + + def emit_msearch(self): + msearch_string = 'M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 2\r\nST: urn:schemas-upnp-org:device:MediaRenderer:1\r\n\r\n' + msearch_encoded_string = msearch_string.encode() + self.sock.sendto( msearch_encoded_string, ('239.255.255.250', 1900 ) ) + + # Internally used method to read a notification + def _listen_notification(self, data): + upnp_header, upnp_body = data.split("\r\n\r\n") + + # Get header by line -- as fragments + upnp_hfrags = upnp_header.split("\r\n") + upnp_hfrags.pop(0) + + header = {} + + for frag in upnp_hfrags: + splitpoint = frag.find(": ") + header[frag[:splitpoint]] = frag[splitpoint+2:] + + if("USN" in header): + if("CetonFactory" in header["USN"]): + if(header["USN"] not in self.devices): + self.devices[header["USN"]] = header["USN"] + print("Found InfiniTV. Location URL: {0}".format(header["LOCATION"])) + + + def listen(self): + import select + self.listening = True + while self.listening: + upnp_data = self.sock.recv(10240).decode('utf-8') + #Filter by type (we only care about NOTIFY for now) + if(upnp_data[0:6] == "NOTIFY"): + self._listen_notification(upnp_data) + + def stop_listen(self): + self.listening = False + if len(self.devices) == 0: + print "No InfiniTV found" + + +if __name__ == "__main__": + # Create a default UPnP socket + try: + interface_ip=sys.argv[1] + except: + print "detect_infinitv $ip_address" + sys.exit(1) + + try: + timeout = float(sys.argv[2]) + except: + timeout=5 + L = find_the_infiniTV(interface_ip=interface_ip) + thread.start_new_thread(L.listen, ()) + time.sleep(timeout) + L.stop_listen() + + + diff --git a/abs/core/LinHES-config/hdhr.conf b/abs/core/LinHES-config/hdhr.conf new file mode 100644 index 0000000..51a3407 --- /dev/null +++ b/abs/core/LinHES-config/hdhr.conf @@ -0,0 +1,2 @@ +#icrease read buffers for the hdhr +net.core.rmem_max=1048576 diff --git a/abs/core/LinHES-config/install_db_chroot.sh b/abs/core/LinHES-config/install_db_chroot.sh index bb7bbcf..272b556 100644 --- a/abs/core/LinHES-config/install_db_chroot.sh +++ b/abs/core/LinHES-config/install_db_chroot.sh @@ -31,9 +31,14 @@ do then pacman --noconfirm -R mythdb-initial pacman --noconfirm -S mythdb-initial + + #This piece only populates the distro_default tables + #save off distro_default + $MV_ROOT/bin/myth_settings_wrapper.sh -c save-default + + #load default into distro_default tables $MV_ROOT/bin/myth_settings_wrapper.sh -c load - #change this to mythutil - #DISPLAY=127.0.0.1:0 $MV_ROOT/bin/MythVantage -t restore,default_1 + $MV_ROOT/bin/myth_settings_wrapper.sh -c restore -t syssettings $MV_ROOT/bin/systemconfig.sh misc,hostype,this_is_install diff --git a/abs/core/LinHES-config/install_functions.sh b/abs/core/LinHES-config/install_functions.sh index 08206fc..fd33e00 100755 --- a/abs/core/LinHES-config/install_functions.sh +++ b/abs/core/LinHES-config/install_functions.sh @@ -61,9 +61,10 @@ function bootsplash_setup (){ function setupremote { [ -e $BASE/etc/lircd.conf ] && mv -f $BASE/etc/lircd.conf $BASE/etc/lircd.conf.`date +%Y-%m-%d-%H-%M` - if [ -d $TEMPLATES/remotes/$Remotetype ] + remotepath="$TEMPLATES/remotes/$remotebucket/$Remotetype" + if [ -d ${remotepath} ] then - cd $TEMPLATES/remotes/$Remotetype + cd ${remotepath} for i in lircd* do cat $i >> $BASE/etc/lircd.conf @@ -71,6 +72,8 @@ function setupremote { cp -f lircrc* $BASE/etc/lircrc 2> /dev/null [ -e /etc/lircrc ] && chmod 755 /etc/lircrc update_db_settings HostRemoteType "$Remotetype" + update_db_settings HostRemotebucket "$remotebucket" + update_db_settings HostRemoteType_${remotebucket} "$Remotetype" #special case for special remote printhl "Starting with support for $Remotetype" if [ "$Remotetype" == "dvico" ] @@ -85,7 +88,7 @@ function setupremote { [ -e /root/.mythtv ] || mkdir /root/.mythtv 2>/dev/null ln -s /etc/lircrc /root/.mythtv/lircrc 2>/dev/null else - echo "Couldn't open directory $TEMPLATES/remotes/$Remotetype" + echo "Couldn't open directory ${remotepath}" fi } @@ -100,6 +103,8 @@ do FoundReceiverType=`echo "$line"|cut -d"|" -f2` Remotetype=`echo "$line"|cut -d"|" -f4` statusline=`echo "$line"|cut -d"|" -f2,4` + remotebucket=`echo "$line"|cut -d"|" -f5` + #echo $remotebucket #echo "Found $statusline , $Remotetype" echo "Found Hauppauge" echo "-------------------" @@ -139,6 +144,7 @@ do if [ $? -eq 0 ] then Remotetype=`echo "$line"|cut -d"|" -f2` + remotebucket=`echo "$line"|cut -d"|" -f4` printhl "Found $Remotetype" setupremote found_remote=0 @@ -159,6 +165,8 @@ if [ $found_remote -eq 1 ] then #No remote found_remote update_db_settings HostRemoteType "no_remote" + update_db_settings HostRemotebucket "favorites" + update_db_settings HostRemoteType_favorites "no_remote" fi } @@ -348,6 +356,8 @@ function init_remote { then TEMPVAR=${CMDLINE#*remoteport=} REMOTEPORT=${TEMPVAR%% *} + #port was given assume we are using a serial receiver + ReceiverType="Serial" if [ x"$ReceiverType" = "xSerial" ] then if [ -e /dev/$REMOTEPORT ] @@ -362,17 +372,44 @@ function init_remote { fi in_kernel_support "disable" + echo $CMDLINE | grep -q remotebucket + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*remotebucket=} + remotebucket=${TEMPVAR%% *} + else + remotebucket="favorites" + fi + + + echo $CMDLINE | grep -q remote if [ $? -eq 0 ] then TEMPVAR=${CMDLINE#*remote=} Remotetype=${TEMPVAR%% *} + setupremote else scan_for_usb_remote fi } +function home_check(){ + #This bit of code is used to determine where mythhome is located + if [ x$MYTHHOME = x ] + then + . /etc/profile.d/MythVantage.sh + fi + + if [ x$MYTHHOME = x ] + then + echo "MYTHHOME not defined!" + exit 1 + fi + + } + #----------------------- diff --git a/abs/core/LinHES-config/install_proxy.sh b/abs/core/LinHES-config/install_proxy.sh index c2a450d..99609cc 100755 --- a/abs/core/LinHES-config/install_proxy.sh +++ b/abs/core/LinHES-config/install_proxy.sh @@ -1,6 +1,6 @@ #!/bin/bash export TERM=vt100 -MVHOSTNAME=larch5 +MVHOSTNAME=apheleia . /etc/profile TEMP_TEMPLATES=/tmp/templates disk=$2 @@ -30,7 +30,8 @@ progress () { case $1 in full_install_it ) - mv_install.py --rootdisk=$disk --rootfs=$rootfs --rootsize=$rootsize --datafs=$datafs --datasize=$datasize --datadisk=$disk --swapsize=$swapsize -c full_install + #mv_install.py --rootdisk=$disk --rootfs=$rootfs --rootsize=$rootsize --datafs=$datafs --datasize=$datasize --datadisk=$disk --swapsize=$swapsize -c full_install + mv_install.py -c full_install rc=$? echo "mv_install.py exit code $rc" if [ $rc != 0 ] @@ -47,10 +48,13 @@ case $1 in find_update) mv_install.py --rootdisk=$disk -c find_upgrade + #mv_install.py -c find_upgrade ;; upgrade_it) - mv_install.py --rootdisk=$disk --rootfs=$rootfs -c upgrade + install_proxy.sh network_check_it setup_network + #mv_install.py --rootdisk=$disk --rootfs=$rootfs -c upgrade + mv_install.py -c upgrade ;; disk_model_it) @@ -76,7 +80,8 @@ case $1 in ;; check_self) - myipdefault=`ifconfig | grep -C1 $default_interface| grep -v $default_interface | cut -d: -f2 | awk '{ print $1}'` + #myipdefault=`ifconfig | grep -C1 $default_interface| grep -v $default_interface | cut -d: -f2 | awk '{ print $1}'` + myipdefault=`ip addr show $default_interface| grep inet |grep -v inet6 | cut -d/ -f1 | awk '{ print $2}'` echo "network check myself" ifconfig ping -c 1 $myipdefault diff --git a/abs/core/LinHES-config/issue b/abs/core/LinHES-config/issue index 00d4abd..8b13789 100644 --- a/abs/core/LinHES-config/issue +++ b/abs/core/LinHES-config/issue @@ -1,2 +1 @@ -LinHes diff --git a/abs/core/LinHES-config/mv_advanced.py b/abs/core/LinHES-config/mv_advanced.py index fdcd1e2..de10d78 100755 --- a/abs/core/LinHES-config/mv_advanced.py +++ b/abs/core/LinHES-config/mv_advanced.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import logging, os, re import mv_common +import glob def setup_pacman(create_link): if create_link: @@ -84,20 +85,27 @@ def setup_ncid_daemon(Runncidd): def setup_splash(Usebootsplash): if Usebootsplash == "1": logging.info(" Enabling splash") - cmd = ''' sed -i "s/^default.*0/default 1/g" /boot/grub/menu.lst''' + cmd = ''' sed -i "s/^set default.*$/set default="0"/g" /boot/grub/grub.cfg''' + mv_common.runcmd(cmd) + #this is needed in case grub-mkconfig is run + cmd = ''' sed -i "s/^GRUB_DEFAULT.*$/GRUB_DEFAULT="0"/g" /etc/default/grub''' mv_common.runcmd(cmd) else: logging.info(" Disabling splash") - cmd = ''' sed -i "s/^default.*1/default 0/g" /boot/grub/menu.lst''' + cmd = ''' sed -i "s/^set default.*$/set default="1"/g" /boot/grub/grub.cfg''' + mv_common.runcmd(cmd) + #this is needed in case grub-mkconfig is run + cmd = ''' sed -i "s/^GRUB_DEFAULT.*$/GRUB_DEFAULT="1"/g" /etc/default/grub''' mv_common.runcmd(cmd) return -def setup_rrd(UseRRD): - if UseRRD == "1": - logging.info(" Enabling rrd_stats") - mv_common.pacinstall("rrd_stats") - else: - logging.info(" Disabling rrd_stats") - mv_common.pacremove("rrd_stats") + +#def setup_rrd(UseRRD): + #if UseRRD == "1": + #logging.info(" Enabling rrd_stats") + #mv_common.pacinstall("rrd_stats") + #else: + #logging.info(" Disabling rrd_stats") + #mv_common.pacremove("rrd_stats") def setup_hobbit(UseHobbit,SystemType,dbhost): @@ -227,141 +235,7 @@ def setup_mythweb(UseMythWEB): logging.info(" Removing mythweb") # mv_common.pacremove("lighttpd") mv_common.pacremove("mythweb") - # mv_common.remove_service("lighttpd") - return - -def setup_samba(systemconfig,data_config): - mythhome = data_config.MYTHHOME - if systemconfig.get("UseSamba") == "1": - logging.info(" Activating windows file sharing") - usersamba=mythhome+"/templates/smb.conf" - mv_common.pacinstall("samba") - if not os.path.exists("/etc/samba"): - logging.debug(" Creating directory /etc/samba") - try: - os.makedirs("/etc/samba") - except: - pass - - if os.path.exists(usersamba): - logging.debug(" Using user provided config file %s",usersamba) - cmd = "install -D -m755 %s /etc/samba/smb.conf" %usersamba - mv_common.runcmd(cmd) - else: - Samba_media = systemconfig.get("Samba_media") - Samba_home = systemconfig.get("Samba_home") - if systemconfig.get("Samba_mediareadonly") == "0": - smreadonly = "yes" - else: - smreadonly = "no" - - if systemconfig.get("Samba_homereadonly") == "0": - shreadonly = "yes" - else: - shreadonly = "no" - domain = systemconfig.get("Samba_domain") - servername = systemconfig.get("hostname") - - try: - f = open(systemconfig.get("TEMPLATES")+"/samba/smb.conf.template",'r') - t_smbconf = f.readlines() - f.close() - except: - logging.info(" Couldn't open samba template file") - return - - try: - f = open("/etc/samba/smb.conf",'w') - except: - logging.info(" Couldn't open samba file") - return - - for line in t_smbconf: - outline = line - if re.match("^.*workgroup", line): - logging.debug(" Setting workgroup to %s",domain) - outline="workgroup = %s\n" %domain - logging.debug(" %s",outline) - if re.match("^.* server string",line): - logging.debug(" Setting server name to %s",servername) - outline="server string = %s\n" %servername - logging.debug(" %s",outline) - f.write(outline) - outline="include = %s/templates/user.shares \n" %mythhome - f.write(outline) - if Samba_media == "1": - outline="include = /etc/samba/smb.conf.media\n" - f.write(outline) - if Samba_home == "1": - outline="include = /etc/samba/smb.conf.home\n" - f.write(outline) - f.close() - logging.info(" Writing smb.conf.media") - try: - f = open("/etc/samba/smb.conf.media","w") - except: - logging.info(" Couldn't open smb.conf.media") - return - medialines=''' -[%s] -path = %s -public = yes -only guest = yes -writeable = %s -printable = no -force user = mythtv -force group = mythtv -create mask = 0755''' %(data_config.SMEDIA,data_config.DATAMOUNT,smreadonly) - f.write(medialines) - f.close - logging.debug(" %s",medialines) - logging.info(" Writing smb.conf.home") - try: - f = open("/etc/samba/smb.conf.home","w") - except: - logging.info(" Couldn't open smb.conf.home") - return - homelines=''' -[home] -path = %s -public = yes -only guest = yes -writeable = %s -printable = no -force user = mythtv -force group = mythtv -create mask = 0755 ''' %(data_config.MYTHHOME,shreadonly) - f.write(homelines) - f.close - logging.debug(" %s",homelines) - - - mv_common.add_service("nmbd") - mv_common.add_service("smbd") - mv_common.restart_service("nmbd") - mv_common.restart_service("smbd") - - else: - logging.info(" Removing windows file sharing") - mv_common.remove_service("smbd") - mv_common.remove_service("nmbd") - mv_common.pacremove("samba") - mv_common.pacinstall("smbclient") - return - -def setup_NFSshares(UseNFS,templatefile): - if UseNFS == "1": - logging.info(" Activating NFS server") - mv_common.pacinstall("nfs-utils") - mv_common.pacinstall("rpcbind") - cmd = '''sed -e "s/REPLACEME/*/g" %s >/etc/exports''' %templatefile - mv_common.runcmd(cmd) - mv_common.add_service("nfsd") - mv_common.add_service("nfs-common") - mv_common.add_service("rpcbind") - else: - logging.info(" Removing NFS server") - mv_common.remove_service("nfsd") +# mv_common.remove_service("lighttpd") return def setup_dyndns(DDnsEnable): @@ -398,22 +272,19 @@ def setup_advanced(systemconfig,data_config): setup_hobbit(systemconfig.get("UseHobbit"), systemconfig.get("SystemType"), systemconfig.get("dbhost")) - if data_config.SYSTEMTYPE == "LinHES": - setup_rrd(systemconfig.get("UseRRD")) + #if data_config.SYSTEMTYPE == "LinHES": + #setup_rrd(systemconfig.get("UseRRD")) - setup_evrouter(systemconfig.get("UseEvrouter"), - systemconfig.get("EvrouterConfig"), - systemconfig.get("TEMPLATES")) + #setup_evrouter(systemconfig.get("UseEvrouter"), + #systemconfig.get("EvrouterConfig"), + #systemconfig.get("TEMPLATES")) setup_DNSmasq(systemconfig.get("RunDHCP"), - systemconfig.get("mythip"), - systemconfig.get("mythgw"), - systemconfig.get("mythdns")) + systemconfig.get("mythip"), + systemconfig.get("mythgw"), + systemconfig.get("mythdns")) setup_mythweb(systemconfig.get("UseMythWEB")) - setup_samba(systemconfig,data_config) - setup_NFSshares(systemconfig.get("UseNFS"), - systemconfig.get("TEMPLATES")+"/exports.template") setup_dyndns(systemconfig.get("DDnsEnable")) logging.info("__End of advanced configuration\n") diff --git a/abs/core/LinHES-config/mv_common.py b/abs/core/LinHES-config/mv_common.py index e4bef48..432c270 100755 --- a/abs/core/LinHES-config/mv_common.py +++ b/abs/core/LinHES-config/mv_common.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import logging, os, time import commands +import subprocess import ConfigParser import urllib2 config_file = "mv_config" @@ -62,6 +63,10 @@ def read_config(module_config,data): return rvalue + +def runcmd_bg(cmd): + subprocess.Popen(cmd) + def runcmd(cmd): if data_config.NOOPDEBUG=="FALSE": pass @@ -108,22 +113,24 @@ def link_file(srcfile,link_name): return -def mkdir_mythhome(mythhome): +def mkdir_mythhome(mythhome,user,grp=1000): if not os.path.exists(mythhome+"/.mythtv"): logging.debug(" Creating %s/.mythtv",mythhome) try: os.mkdir(mythhome+"/.mythtv") except: logging.debug(" Couldn't create .mythtv ") - return + try: - os.chown(mythhome+"/.mythtv", mythuid, mythgid) - logging.debug("* Couldn't chown of %s", mythhome) - except: - cmd = ''' chown -R mythtv %s/.mythtv''' %mythhome + #os.chown(mythhome+"/.mythtv", int(user), int(grp)) + #logging.debug("* Couldn't chown of %s", mythhome) + + cmd = ''' chown -R %s %s/.mythtv''' %(user,mythhome) runcmd(cmd) - cmd = ''' chgrp -R mythtv %s/.mythtv''' %mythhome + cmd = ''' chgrp -R %s %s/.mythtv''' %(grp,mythhome) runcmd(cmd) + except: + logging.debug("* Couldn't chown of %s", mythhome) pass @@ -162,6 +169,16 @@ def restart_service(daemon): cmd = "sv restart %s" %daemon runcmd(cmd) +def check_service(daemon): + logging.info(" Checking status of service %s",daemon) + cmd = "sv status %s" %daemon + results = runcmd_output(cmd) + status = results.split()[0] + if status == "run:": + return True + else: + return False + def hup_service(daemon): logging.info(" hup service %s",daemon) cmd = "sv hup %s" %daemon @@ -195,6 +212,7 @@ def pacinstall(pkg): elif pkg == "dvdcss": pacinstall("libdvdcss") elif pkg == "webmin": + pacinstall("webmin") add_service("webmin") elif pkg == "fuppes": pacinstall("fuppes-svn") @@ -204,6 +222,15 @@ def pacinstall(pkg): pacinstall("dolphin-emu") elif pkg == "webonlinhes": pacinstall("web-on-linhes") + elif pkg == "mame": + pacinstall("sdlmame") + elif pkg == "foldingathome": + add_service("fah") + + elif pkg == "xymonclient": + if os.path.exists('/home/xymon/client'): + cmd='''pacman --noconfirm --dbonly -Sddf xymonclient''' + runcmd(cmd) if not pkg_blacklist_check(pkg): if pkg_installed_check(pkg): @@ -231,6 +258,11 @@ def pacremove(pkg): pacremove("dolphin-emu") elif pkg == "webonlinhes": pacremove("web-on-linhes") + elif pkg == "mame": + pacremove("sdlmame") + elif pkg == "foldingathome": + remove_service("fah") + if not pkg_blacklist_check(pkg): if not pkg_installed_check(pkg): diff --git a/abs/core/LinHES-config/mv_config.py b/abs/core/LinHES-config/mv_config.py index 2904366..f15f41c 100755 --- a/abs/core/LinHES-config/mv_config.py +++ b/abs/core/LinHES-config/mv_config.py @@ -1,9 +1,26 @@ # -*- coding: utf-8 -*- SYSTEMTYPE="LinHES" -MVHOSTNAME="larch5" +MVHOSTNAME="apheleia" MOUNTPOINT="/new_boot" -DATAMOUNT="/myth" +DATAMOUNT="/data/storage/disk0" + +HOMEMOUNT="/home" +SQLMOUNT="/data/srv/mysql" + MYTHHOME="/home/mythtv" +VNCHOME="/home/vncsvc" +NOOPDEBUG="FALSE" +TEMP_TEMPLATES="/tmp/templates" +share_exclude_dir=['mysql','srv'] + +SG_MAP_AUTONFS_SKIP=['media/tv','media/video','media/video_stuff','media/streaming'] + +MAP_AUTONFS_SKIP=['lost+found','media','backup'] +nfs_options="hard,intr,actimeo=0" + + + + SQUASHFILE="/tmp/.squashlist" SQUASHLIST=("bin","boot","etc","home","lib","opt","root","sbin","usr","var","data","service") NOOPDEBUG="FALSE" @@ -15,3 +32,4 @@ SMEDIA="myth" + diff --git a/abs/core/LinHES-config/mv_fileshare.py b/abs/core/LinHES-config/mv_fileshare.py new file mode 100755 index 0000000..746dbbf --- /dev/null +++ b/abs/core/LinHES-config/mv_fileshare.py @@ -0,0 +1,461 @@ +# -*- coding: utf-8 -*- +import logging, os, re +import mv_common +import glob +from urllib2 import Request, urlopen, URLError, HTTPError +#client side +#CentralNFSallhosts= + +def setup_nfs_client(systemconfig,data_config): + nfslist=[] + nfsmap_serverfile ="nfsmap" + logging.info("____Start of setup_nfs__client____") + scrubnfs(systemconfig.get("TEMPLATES")) + + if systemconfig.get("HaveCentralNFS") == "yes": + logging.debug(" Using a Central NFS server") + logging.debug(" NFSserver:%s" %systemconfig.get("NFSserver")) + if systemconfig.get("NFSserver") == "file:nfsmap": + #if it's a file check for it, failure results in downloading attempt from MBE + nfsmap_file=data_config.MYTHHOME+"/templates/nfsmap" + if not os.path.exists(nfsmap_file): + logging.debug(" Couldn't find local %s",nfsmap_file) + logging.info(" Trying to download nfsmap from MBE") + nfsmap_file = download_nfsmap(systemconfig.get("dbhost"),nfsmap_serverfile) + nfslist = process_nfsmap_file(nfsmap_file) + + #check for other filesname: + + elif re.search("^file:",systemconfig.get("NFSserver")): + filename=systemconfig.get("NFSserver").split(":")[1] + nfsmap_file=data_config.MYTHHOME+"/templates/"+filename + nfslist = process_nfsmap_file(nfsmap_file) + + # if it's an ip parse ip and download file + elif re.search(":nfsmap$",systemconfig.get("NFSserver")): + ip=systemconfig.get("NFSserver").split(":")[0] + nfsmap_file = download_nfsmap(ip,nfsmap_serverfile) + nfslist = process_nfsmap_file(nfsmap_file) + #else treat it as a single mount point + else: + item = (systemconfig.get("NFSserver") , systemconfig["NFSmount"]) + nfslist.append(item) + else: + #if frontend_only or slave try to use MBE nfs_map_auto + if systemconfig.get("SystemType") == "Frontend_only" or systemconfig["SystemType"] == "Slave_backend": + logging.info(" Central NFS not found, trying to use MBE as nfs server") + nfsmap_serverfile = "nfsmap_auto" + ip=systemconfig.get("dbhost") + nfsmap_file = download_nfsmap(ip,nfsmap_serverfile) + nfslist = process_nfsmap_file(nfsmap_file) + + + setup_nfs_fstab(nfslist,data_config) + logging.info("__End of nfs\n") + return nfslist + + +def process_nfsmap_file(mapfile): + logging.debug(" processing nfsmap file %s",mapfile) + nfslist = [] + try: + f = open(mapfile,"r") + for line in f.readlines(): + if line.startswith("#"): + continue + item = line.split() + if len(item) <= 1 : + continue + logging.debug(" %s",item) + nfslist.append(item) + except : + logging.critical("Couldn't read file %s, or some other error",mapfile) + return nfslist + +def scrubnfs(templates): + logging.info(" Scrubbing nfs") + mv_common.cp_and_log("/etc/fstab",templates+"/fstab.conf.template") + #used this sed cmd because it's clean and took me forever to figure out =) + cmd='''sed '/^#STARTSCRUB.*$/,/^#ENDSCRUB.*$/d' %s/fstab.conf.template > /etc/fstab''' %templates + mv_common.runcmd(cmd) + +def download_nfsmap(ip,nfsmap_serverfile): + nfsmap_file="/tmp/nfsmap" + myurl="http://%s:1337/templates/%s" %(ip,nfsmap_serverfile) + req = Request(myurl) + + try: + f = urlopen(req) + logging.info(" downloading %s", myurl) + local_file = open(nfsmap_file, "w") + #Write to our local file + local_file.write(f.read()) + local_file.close() + #handle errors + except HTTPError, e: + logging.info(" File download failed") + logging.debug(" %s", myurl) + logging.debug(" HTTP Error: %s", e.code) + except URLError, e: + logging.info(" File download failed") + logging.debug(" %s",myurl) + logging.debug(" URL Error: %s ", e.reason) + + return nfsmap_file + +def setup_nfs_mkdir(nfs_dirname): + logging.info(" Creating NFS mount point %s" , nfs_dirname) + try: + os.makedirs(nfs_dirname) + except: + logging.debug(" Failed creating nfs mount point") + + + + + +def setup_nfs_fstab(nfslist,data_config): + logging.info(" Adding nfs paths to fstab") + nfs_options = mythhome = data_config.nfs_options + try: + f = open('/etc/fstab', 'a') + line = "#STARTSCRUB --------------anything in this block will be scrubbed\n" + f.write(line) + for s, m in nfslist: + line = "%s %s nfs %s \n" %(s,m,nfs_options) + setup_nfs_mkdir(m) + logging.debug(" %s",line) + f.write(line) + line = "#ENDSCRUB\n" + f.write(line) + f.close() + + for s, m in nfslist: + logging.info(" nfs mounting %s",m) + cmd = ['mount',m] + mv_common.runcmd_bg(cmd) + + + except: + logging.critical(" *Couldn't open /etc/fstab for writing") + logging.debug(" Done adding nfs paths to fstab") + + + + + +#server side +def setup_samba(systemconfig,data_config): + mythhome = data_config.MYTHHOME + excludes = data_config.share_exclude_dir + if systemconfig.get("UseSamba") == "1": + logging.info(" Activating windows file sharing") + usersamba=mythhome+"/templates/smb.conf" + mv_common.pacinstall("samba") + if not os.path.exists("/etc/samba"): + logging.debug(" Creating directory /etc/samba") + try: + os.makedirs("/etc/samba") + except: + pass + + if os.path.exists(usersamba): + logging.debug(" Using user provided config file %s",usersamba) + cmd = "install -D -m755 %s /etc/samba/smb.conf" %usersamba + mv_common.runcmd(cmd) + else: + Samba_media = systemconfig.get("Samba_media") + Samba_home = systemconfig.get("Samba_home") + if systemconfig.get("Samba_mediareadonly") == "0": + smreadonly = "yes" + else: + smreadonly = "no" + + if systemconfig.get("Samba_homereadonly") == "0": + shreadonly = "yes" + else: + shreadonly = "no" + domain = systemconfig.get("Samba_domain") + servername = systemconfig.get("hostname") + + try: + f = open(systemconfig.get("TEMPLATES")+"/samba/smb.conf.template",'r') + t_smbconf = f.readlines() + f.close() + except: + logging.info(" Couldn't open samba template file") + return + + try: + f = open("/etc/samba/smb.conf",'w') + except: + logging.info(" Couldn't open samba file") + return + + for line in t_smbconf: + outline = line + if re.match("^.*workgroup", line): + logging.debug(" Setting workgroup to %s",domain) + outline="workgroup = %s\n" %domain + logging.debug(" %s",outline) + if re.match("^.* server string",line): + logging.debug(" Setting server name to %s",servername) + outline="server string = %s\n" %servername + logging.debug(" %s",outline) + f.write(outline) + + outline="include = %s/templates/user.shares \n" %mythhome + f.write(outline) + if Samba_media == "1": + outline="include = /etc/samba/smb.conf.media\n" + f.write(outline) + if Samba_home == "1": + outline="include = /etc/samba/smb.conf.home\n" + f.write(outline) + f.close() + + logging.info(" Writing smb.conf.media") + try: + f = open("/etc/samba/smb.conf.media","w") + except: + logging.info("* Couldn't open smb.conf.media") + return + + shares = scan_for_shares() + medialines=''' +[%s] + path = %s + public = yes + only guest = yes + writeable = %s + printable = no + force user = mythtv + force group = mythtv + create mask = 0755\n''' + new_share=[] + excludes + for share in shares: + share_name = share.split("/")[-1] + share_path = share + #new_share.append(medialines %(share_name,share_patch,smreadonly) + f.write(medialines %(share_name,share_path,smreadonly) ) + logging.debug(" %s",medialines %(share_name,share_path,smreadonly) ) + excludeline = ' veto files = ' + for exclude in excludes: + excludeline+= ''' "/%s/" ''' %exclude + + if excludes != []: + f.write( excludeline) + logging.debug(excludeline) + f.write("\n") + + f.close() + logging.info(" Writing smb.conf.home") + try: + f = open("/etc/samba/smb.conf.home","w") + except: + logging.info(" Couldn't open smb.conf.home") + return + homelines=''' +[home] +path = %s +public = yes +only guest = yes +writeable = %s +printable = no +force user = mythtv +force group = mythtv +create mask = 0755 ''' %(data_config.MYTHHOME,shreadonly) + f.write(homelines) + f.close() + logging.debug(" %s",homelines) + + + mv_common.add_service("nmbd") + mv_common.add_service("smbd") + mv_common.restart_service("nmbd") + mv_common.restart_service("smbd") + + else: + logging.info(" Removing windows file sharing") + mv_common.remove_service("smbd") + mv_common.remove_service("nmbd") + mv_common.pacremove("samba") + mv_common.pacinstall("smbclient") + return + +def scan_for_shares(): + import ConfigParser + config = ConfigParser.RawConfigParser() + file_list=glob.glob("/etc/storage.d/*.conf") + share_list = [] + for conf_file in file_list: + try: + logging.debug(" mv_fileshare: reading in %s" %conf_file) + config.read(conf_file) + shareable = config.get('storage','shareable') + if shareable == "True" : + mp = config.get('storage','mountpoint') + share_list.append(mp) + if config.get('storage','mmount') == "True" : + share_list.append("/myth") + except: + logging.debug(" mv_fileshare: Couldn't open %s for reading" %conf_file) + + return share_list + +def setup_etc_exports(shares,data_config,servername,nfslist): + #read in /etc/ exports + conf_file="/etc/exports" + excludes = data_config.share_exclude_dir + nfsmap_sg_auto_skip = data_config.SG_MAP_AUTONFS_SKIP + nfsmap_auto_skip = data_config.MAP_AUTONFS_SKIP + + #print nfsmap_auto_skip + nfs_auto_line ="%s:%s %s" + nfs_map_auto = [] + share_list = [] + + #populate nfs_map_auto with nfs_list. nfs_list is populated from the + #central nfs options + #nfslist looks like [('silverraid:/raid0/data/media', '/data/storage/nfs/silverraid')] + for i in nfslist: + sharename = i[0] + mountpoint = i[1] + templine = "%s %s" %(sharename,mountpoint) + nfs_map_auto.append(templine) + + + #create the lists for both /etc/exports and nfs_map_auto + for share in shares: + if share == "/myth": + continue + os.chdir(share) + file_list=glob.glob("*") + for dirname in file_list: + if os.path.isdir(dirname): + tempname = "%s/%s" %(share,dirname) + if dirname not in nfsmap_auto_skip: + share_list.append(tempname) + if dirname not in nfsmap_sg_auto_skip: + templine = nfs_auto_line %(servername,tempname,tempname) + nfs_map_auto.append(templine) + + + file_list=glob.glob("media/*") + for dirname in file_list: + if os.path.isdir(dirname): + tempname = "%s/%s" %(share,dirname) + if dirname not in nfsmap_auto_skip: + share_list.append(tempname) + if dirname not in nfsmap_sg_auto_skip: + templine = nfs_auto_line %(servername,tempname,tempname) + nfs_map_auto.append(templine) + + new_exports=[] + new_exports.append("#This file was generated by systemconfig.py -m fileshare") + new_exports.append("#Use exportfs -arv to reread. \n\n") + #for exclude in excludes: + # share_line='''/%s *(noaccess)''' %exclude + # new_exports.append(share_line) + + for share in share_list: + share_line='''%s *(rw,all_squash,anonuid=1000,anongid=1000,no_subtree_check)''' %share + new_exports.append(share_line) + #for exclude in excludes: + #share_line='''/%s *(noaccess)''' %exclude + #new_exports.append(share_line) + + #write out nfs_map_auto + try: + + logging.info(" writing nfsmap_auto") + try: + dirname ="%s/templates/" %data_config.MYTHHOME + os.makedirs(dirname) + cmd = "chmod 755 %s" %dirname + mv_common.runcmd(cmd) + cmd = "chown mythtv:users %s" %dirname + mv_common.runcmd(cmd) + except: + pass + try: + cmd = "chmod 755 %s" %dirname + mv_common.runcmd(cmd) + cmd = "chown mythtv:users %s" %dirname + mv_common.runcmd(cmd) + except: + pass + conf_file_nfs = "%s/templates/nfsmap_auto" %(data_config.MYTHHOME) + f=open(conf_file_nfs,'w') + for line in nfs_map_auto: + f.write(line) + f.write("\n") + logging.debug("%s" %line) + f.close() + except: + logging.info("* error writing %s" %conf_file_nfs) + + try: + logging.info(" writing /etc/exports") + f=open(conf_file,'w') + for line in new_exports: + f.write(line) + f.write("\n") + logging.debug("%s" %line) + f.close() + except: + logging.info("* error writing /etc/exports") + + + +def setup_NFSshares(UseNFS,templatefile,data_config,servername,nfslist): + if UseNFS == "1": + logging.info(" Activating NFS server") + mv_common.pacinstall("nfs-utils") + mv_common.pacinstall("rpcbind") + shares = scan_for_shares() + setup_etc_exports(shares,data_config,servername,nfslist) + mv_common.add_service("nfsd") + mv_common.add_service("nfs-common") + mv_common.add_service("rpcbind") + cmd="exportfs -arv" + mv_common.runcmd(cmd) + else: + logging.info(" Removing NFS server") + mv_common.remove_service("nfsd") + return + +def setup_dyndns(DDnsEnable): + if DDnsEnable == "1": + logging.info(" Installing Dynamic DNS client") + mv_common.pacinstall("inadyn") + mv_common.add_service("inadyn") + else: + logging.info(" Removing Dynamic DNS client") + mv_common.pacremove("inadyn") + mv_common.remove_service("inadyn") + + +def setup_fileshare(systemconfig,data_config): + if mv_common.read_config(mv_common.module_config,"fileshare") == False : + logging.info("____Skipping of fileshare, config disabled____") + return + logging.info("____Start of fileshare configuration____") + + #client, nfslist will be used in case the central NFS needs to also be addressed + nfslist = setup_nfs_client(systemconfig,data_config) + + #server + if systemconfig.get("CentralNFSallhosts") == "0": + #reset nfslist to 0 so that central nfsshares do not get added to auto_nfs + nfslist = [] + + setup_NFSshares(systemconfig.get("UseNFS"), + systemconfig.get("TEMPLATES")+"/exports.template", + data_config,systemconfig.get("hostname"), + nfslist) + + setup_samba(systemconfig,data_config) + + logging.info("__End of fileshare configuration\n") diff --git a/abs/core/LinHES-config/mv_hostype.py b/abs/core/LinHES-config/mv_hostype.py index 59b05b6..ba9551f 100755 --- a/abs/core/LinHES-config/mv_hostype.py +++ b/abs/core/LinHES-config/mv_hostype.py @@ -38,7 +38,7 @@ def setup_db(): def setup_mysqlnetwork(EnableNetwork): logging.debug(" Setting up mysql network") - mysqlconf = "/etc/my.cnf" + mysqlconf = "/etc/mysql/my.cnf" cmd = '''grep "#skip-networking" %s ''' %mysqlconf status = mv_common.runcmd(cmd) @@ -49,7 +49,7 @@ def setup_mysqlnetwork(EnableNetwork): else: cmd = '''sed -ie "s/^skip-networking/#skip-networking/g" %s ''' %mysqlconf mv_common.runcmd(cmd) - mv_common.restart_service("mysqld") + mv_common.restart_service("mysql") else: logging.debug(" Disabling mysql networking") if status == 1 : @@ -57,97 +57,70 @@ def setup_mysqlnetwork(EnableNetwork): else: cmd = '''sed -ie "s/#skip-networking/skip-networking/g" %s ''' %mysqlconf mv_common.runcmd(cmd) - mv_common.restart_service("mysqld") - - -def generate_config_xml(uuid,dbhost): - configxml_t =''' -<Configuration> - <UPnP> - <UDN> - <MediaRenderer>%s</MediaRenderer> - </UDN> - <MythFrontend> - <DefaultBackend> - <DBHostName>%s</DBHostName> - <DBUserName>mythtv</DBUserName> - <DBPassword>mythtv</DBPassword> - <DBName>mythconverg</DBName> - <DBPort>0</DBPort> - </DefaultBackend> - </MythFrontend> - </UPnP> -</Configuration> - ''' - configxml= configxml_t %(uuid,dbhost) - return configxml - -def gen_uuid(): - cmd = "/usr/bin/uuidgen" - uuid = mv_common.runcmd_output(cmd) - return uuid + mv_common.restart_service("mysql") + + + + def setup_mysql_connection(systemconfig): - #setup mysql.txt and config.xml + logging.info(" Configuring database connection") mythip = systemconfig.get("mythip") systemtype = systemconfig.get("SystemType") - mv_root = systemconfig.get("MVROOT") - mysqltxt = "/usr/share/mythtv/mysql.txt" - configxml_file = "/usr/share/mythtv/config.xml" - - templates = systemconfig.get("TEMPLATES") - mysqltemplate = templates + "/mysql.txt" dbhost = systemconfig.get("dbhost") - uuid = gen_uuid() - config_xml=generate_config_xml(uuid,dbhost) - mv_common.mkdir_mythhome(data_config.MYTHHOME) - + mv_root = systemconfig.get("MVROOT") if systemtype == "Master_backend": logging.debug(" Setting dbhost to %s in systemconfig", mythip) dbhost = mythip - cmd = '''sed -ei "s/^dbhost=.*$/dbhost=\"%s\"/" /etc/systemconfig ''' %dbhost + cmd = '''sed -i "s/^dbhost=.*$/dbhost=\"%s\"/" /etc/systemconfig ''' %dbhost mv_common.runcmd(cmd) logging.debug(" Changing dbhost in settings table for master_backend") - cmd = '''%s/bin/restore_default_settings.sh -c BECONFIG -s master -a %s ''' %(mv_root, dbhost) - mv_common.runcmd(cmd) + #cmd = '''%s/bin/restore_default_settings.sh -c BECONFIG -s master -a %s ''' %(mv_root, dbhost) + cmd = '''%s/bin/myth_settings_wrapper.sh -c BECONFIG -s master -a %s ''' %(mv_root, dbhost) + b=mv_common.runcmd_output(cmd) + logging.debug(b) + #mv_common.reloadfe(systemconfig.get("dbhost"),True) if systemtype == "Slave_backend": slavehost = mythip logging.debug(" Changing slave in settings: %s", slavehost) - cmd = '''%s/bin/restore_default_settings.sh -c BECONFIG -s slave -a %s ''' %(mv_root, slavehost) - mv_common.runcmd(cmd) + cmd = '''%s/bin/myth_settings_wrapper.sh -c BECONFIG -s slave -a %s ''' %(mv_root, slavehost) + #cmd = '''%s/bin/restore_default_settings.sh -c BECONFIG -s slave -a %s ''' %(mv_root, slavehost) + b=mv_common.runcmd_output(cmd) + logging.debug(b) - if systemtype == "Master_backend": + if systemtype == "Frontend_only": + fehost = mythip + logging.debug(" Changing Frontend_only in settings BIP Null: %s", fehost) + cmd = '''%s/bin/myth_settings_wrapper.sh -c BECONFIG -s frontendonly ''' %(mv_root) + #cmd = '''%s/bin/restore_default_settings.sh -c BECONFIG -s slave -a %s ''' %(mv_root, slavehost) + b=mv_common.runcmd_output(cmd) + logging.debug(b) + + + + + if systemtype == "Standalone": + #THIS IS NEVER CALLED ANYMORE, need to move the mysql.txt stuff logging.debug(" changing mysql.txt file to use localhost") cmd = '''sed -e "s/^DBHostName=.*$/DBHostName="localhost"/" %s > %s ''' %(mysqltemplate, mysqltxt) mv_common.runcmd(cmd) - else: - logging.debug(" changing mysql.txt file to use %s", dbhost) - cmd = '''sed -e "s/^DBHostName=.*$/DBHostName=%s/" %s > %s ''' %(dbhost, mysqltemplate, mysqltxt) - mv_common.runcmd(cmd) - delfile = data_config.MYTHHOME + "/.mythtv/mysql.txt" - mv_common.remove_file(delfile) - delfile = mv_root + "/bin/mythtv/.mythtv/mysql.txt" - mv_common.remove_file(delfile) - filecheck = data_config.MYTHHOME + "/templates/mysql.txt" - if os.path.exists(filecheck): - logging.info(" Scrapping all the previous work and using %s for mysql.txt", filecheck) - mv_common.cp_and_log(filecheck, mysqltxt) - try: - f = open(configxml_file, 'w') + #mv_common.reloadfe(systemconfig.get("dbhost"),True) - for outline in config_xml: - f.write(outline) - f.close() - except: - logging.debug(" Couldn't write config.xml") + cmd = '''%s/bin/myth_settings_wrapper.sh -c BECONFIG -s standalone ''' %(mv_root) + b=mv_common.runcmd_output(cmd) + logging.debug(b) - home_xml_file=data_config.MYTHHOME + "/.mythtv/config.xml" - mv_common.link_file(configxml_file,home_xml_file) + #mv_common.reloadfe(systemconfig.get("dbhost"),True) + logging.debug(" Running beconfig a 2nd time") + cmd = '''%s/bin/myth_settings_wrapper.sh -c BECONFIG -s standalone ''' %(mv_root) + #mv_common.runcmd(cmd) + b=mv_common.runcmd_output(cmd) + logging.debug(b) @@ -260,7 +233,7 @@ def hostypeprint(systemconfig): daemon_list='' daemon_remove_list='' run_mysqlnetwork = False - + restart_mbe = False profile_status="/etc/profile.d/z_myth_status.sh" myth_status="/usr/LH/bin/myth_status.sh" @@ -271,9 +244,12 @@ def hostypeprint(systemconfig): EnableNetwork = False run_mysqlnetwork = True if systemconfig.get("hostypec"): - setup_db() - install_list=["nss-mdns", "mysql", "mythdb-initial", "avahi", "rpcbind", "nfs-utils", "local-website", "myth2ipod", "mythtv-status"] - daemon_list=["mysql", "mythbackend", "avahi", "rpcbind", "nfs-common", "netfs", "lighttpd"] + logging.info(" Host type change detected, queuing restart of backend") + restart_mbe = True + + + install_list=["nss-mdns", "mysql", "mythdb-initial", "avahi", "rpcbind", "nfs-utils", "local-website", "myth2ipod", "mythtv-status" , "udevil"] + daemon_list=["mysql", "mythbackend", "avahi", "rpcbind", "nfs-common", "netfs", "lighttpd" ,"msg_daemon", "udevil"] mv_common.link_file(myth_status,profile_status) @@ -289,8 +265,8 @@ def hostypeprint(systemconfig): logging.info("Master backend system being configured") setup_ntp(False,"null") setup_avahi(systemconfig.get("TEMPLATES")) - install_list=["nss-mdns", "mysql", "mythdb-initial", "avahi", "rpcbind", "nfs-utils", "local-website", "myth2ipod", "mythtv-status"] - daemon_list=["mysql", "mythbackend", "avahi", "rpcbind", "nfs-common", "netfs", "lighttpd"] + install_list=["nss-mdns", "mysql", "mythdb-initial", "avahi", "rpcbind", "nfs-utils", "local-website", "myth2ipod", "mythtv-status" ,"udevil"] + daemon_list=["mysql", "mythbackend", "avahi", "rpcbind", "nfs-common", "netfs", "lighttpd" ,"msg_daemon" ,"udevil" ] EnableNetwork = True run_mysqlnetwork = True mv_common.link_file(myth_status,profile_status) @@ -303,6 +279,9 @@ def hostypeprint(systemconfig): install_list.append('certmaster') daemon_list.append('certmaster') + if systemconfig.get("hostypec"): + logging.info(" Host type change detected, queuing restart of backend") + restart_mbe = True elif systemconfig.get("SystemType") == "Slave_backend": logging.info("Slave backend system being configured") @@ -310,10 +289,8 @@ def hostypeprint(systemconfig): remove_avahi_service() mv_common.link_file(myth_status,profile_status) - if systemconfig.get("hostypec"): - setup_db() - install_list = [ "nss-mdns", "rpcbind", "nfs-utils", "avahi", "libmysqlclient" ] - daemon_list = ["mythbackend", "rpcbind", "nfs-common", "netfs", "avahi" ] + install_list = [ "nss-mdns", "rpcbind", "nfs-utils", "avahi", "libmysqlclient","udevil","supplemental-web-slave"] + daemon_list = ["mythbackend", "rpcbind", "nfs-common", "netfs", "avahi" ,"msg_daemon","udevil","supplemental-slave" ] daemon_remove_list=["mysql", "lighttpd", "certmaster"] @@ -326,16 +303,19 @@ def hostypeprint(systemconfig): daemon_list.append('xymon-client') setup_rsyslog_client(systemconfig.get("dbhost")) + if systemconfig.get("hostypec"): + logging.info(" Host type change detected, queuing restart of backend") + restart_mbe = True elif systemconfig.get("SystemType") == "Frontend_only": logging.info("Frontend only system being configured") setup_ntp(True,systemconfig.get("dbhost")) remove_avahi_service() - install_list=["mysql-clients", "libmysqlclient", "avahi", "rpcbind", "nfs-utils"] + install_list=["mysql-clients", "libmysqlclient", "avahi", "rpcbind", "nfs-utils","udevil"] remove_list=["mysql","lighttpd"] - daemon_list=["nss-mdns", "mysql", "mythbackend", "avahi", "rpcbind", "nfs-common", "netfs" ] + daemon_list=["nss-mdns", "mysql", "mythbackend", "avahi", "rpcbind", "nfs-common", "netfs" ,"msg_daemon","udevil"] daemon_remove_list=["mysql", "mythbackend","lighttpd"] if xymon_supported: install_list.append('xymonclient') @@ -361,23 +341,33 @@ def hostypeprint(systemconfig): if systemconfig.get("RunFrontend") == "1": logging.debug(" Will run the frontend") mv_common.add_service("frontend") - mv_common.add_service("hal") + #mv_common.add_service("hal") if data_config.SYSTEMTYPE == "MythVantage": mv_common.add_service("ghosd") else: logging.debug(" Will NOT run the frontend") mv_common.remove_service("frontend") - mv_common.add_service("hal") + #mv_common.add_service("hal") if data_config.SYSTEMTYPE == "MythVantage": mv_common.remove_service("ghosd") + if restart_mbe == True : + setup_mysql_connection(systemconfig) + mv_common.stop_service("mythbackend") + + if run_mysqlnetwork: setup_mysqlnetwork(EnableNetwork) else: logging.debug(" Not running setup_mysql_connection") setup_mysql_connection(systemconfig) + + if restart_mbe == True : + mv_common.start_service("mythbackend") + + if func_supported: setup_func_minion(systemconfig.get("dbhost"),systemconfig.get("hostname")) diff --git a/abs/core/LinHES-config/mv_install.py b/abs/core/LinHES-config/mv_install.py index 2e60ab7..1128571 100755 --- a/abs/core/LinHES-config/mv_install.py +++ b/abs/core/LinHES-config/mv_install.py @@ -12,6 +12,20 @@ except: def usage(): print "help text:" print "example usage: --rootdisk=sda --rootfs=ext4 --rootsize=34240 --datafs=ext4 --datasize=3400 --datadisk=sda --swapsize=340 -c full_install" + print "" + print "Alt usage involves reading config from a file" + print "The conf file is read when no command line options are given" + print " /etc/systemconfig must also be present " + + print "Create /etc/install_layout, with contents similiar to this. Sizes are in MB" + print " rootdisk=sda" + print " rootfs=ext4" + print " rootsize=5000" + print " datafs=reiserfs" + print " datasize=all" + print " datadisk=sda" + print " swapsize=200" + print " op=full_install" def clean_upgrade(): return False @@ -66,6 +80,14 @@ def kill_dhcp_chroot(): os.chdir(stddir) except: pass + #force kill + try: + cmd = "lsof -t /new_boot|xargs kill -9" + runcmd(cmd) + except: + print " !!!Problem killing all /new_boot pids" + + def statgrab(disk): cmd = "statgrab -M disk. |grep %s.write_bytes" % hostoptions["rootdisk"] @@ -129,7 +151,7 @@ def mdadm_assemble_all(): def copy_updates(): try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug("MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" @@ -197,7 +219,7 @@ def mysqldb(cmd, inchroot): elif cmd == "stop": mycmd = " /etc/rc.d/mysqld stop" if inchroot == "chroot": - mycmd = " chroot /newboot %s" %mycmd + mycmd = " chroot /new_boot %s" %mycmd runcmd(mycmd) @@ -234,13 +256,18 @@ def blank_table(diskdevice): cmd = "echo w |fdisk %s" %diskdevice runcmd(cmd) + cmd = "parted %s --script -- mklabel msdos" %diskdevice + runcmd(cmd) + logging.debug("parition table after:") cmd = "fdisk -l %s" %diskdevice runcmd(cmd) def partitions_removeall(diskdevice, label): - logging.info("Removing all partitions for %s %s", label, diskdevice) + logging.info(" Removing all partitions for %s %s", label, diskdevice) try: + cmd = "parted %s --script -- mklabel msdos" %diskdevice + runcmd(cmd) device = parted.getDevice(diskdevice) partdisk = parted.Disk(device) partdisk.deleteAllPartitions() @@ -252,54 +279,76 @@ def partitions_removeall(diskdevice, label): logging.debug(" Error reading parition table, attempting to write a blank one") blank_table(diskdevice) +def find_next_start_sector(partition_list): + newstart = 0 + partlist = [] + for partition in partition_list: + if partition.type != parted.PARTITION_FREESPACE: + partlist.append((partition, + partition.path, + partition.getFlag(parted.PARTITION_BOOT), + partition.geometry.start, + partition.geometry.end, + partition.geometry.length, + partition.type, + partition.fileSystem)) + + for slice in partlist: + (usedpartition, usedpath, usedbootable, usedstart, usedend, usedlength, usedtype, usedfs) = slice + # print slice + #Start the new partition one after the end of last + newstart = usedend + 3 + return newstart def create_partitions(diskdevice, size, ptype, startsector): logging.debug("_____Create partitions______") if size == "NO": logging.info("Size is 0, skipping") return "NO" - partlist = [] - newstart = 0 + + # newstart = 0 totalused = 0 device = parted.getDevice(diskdevice) - logging.debug("Sector size is %s %s", diskdevice , device.sectorSize) + logging.debug(" Sector size is %s %s", diskdevice , device.sectorSize) partdisk = parted.Disk(device) - for partition in partdisk.partitions: - if partition.type != parted.PARTITION_FREESPACE: - partlist.append((partition, - partition.path, - partition.getFlag(parted.PARTITION_BOOT), - partition.geometry.start, - partition.geometry.end, - partition.geometry.length, - partition.type, - partition.fileSystem)) - for slice in partlist: - (usedpartition, usedpath, usedbootable, usedstart, usedend, usedlength, usedtype, usedfs) = slice - #Start the new partition one after the end of last - newstart = usedend+1 + #first set to all paritions + partition_list = partdisk.partitions + + if ptype == "LOGICAL": + #check for other logical: + logical_partitions=partdisk.getLogicalPartitions() + if logical_partitions == [] : + logging.info(" First Logical drive, working with extended partition") + newstart = partdisk.getExtendedPartition().geometry.start + 3 + else: + newstart = find_next_start_sector(logical_partitions) + else: + #all partitions + partitionlist = partdisk.partitions + newstart = find_next_start_sector(partition_list) if startsector == 0: newstart = 2048 - if size == "ALL": - logging.debug(" Using the rest of the disk %s", (device.length-newstart) ) + + if size == "all": + logging.debug(" Using the rest of the disk %s", (device.length-newstart - 2048) ) try: - geom = parted.Geometry(device=device, start=newstart, length=(device.length-newstart)) + geom = parted.Geometry(device=device, start=newstart, length=(device.length-newstart - 2048)) except: - logging.info("An error occured, probably invalid parition size") + logging.info("* An error occured, probably invalid parition size") return else: # convert size in MB to a length on the device in sectors length = (int(size) * (1024 * 1024)) / device.sectorSize - logging.debug("Size is %s", length) + logging.debug(" Size is %s", length) if length > device.length: length = device.length - newstart - logging.info("Size is larger then disk, reducing size") - logging.debug("New Size is %s", length) + logging.info("* Size is larger then disk, reducing size") + logging.debug("* New Size is %s", length) try: geom = parted.Geometry(device=device, start=newstart, length=length) except: - logging.info("An error occured, probably invalid parition size") + logging.info("* An error occured, probably invalid parition size") error_out("invalid parition size") #collect device constraint @@ -309,6 +358,15 @@ def create_partitions(diskdevice, size, ptype, startsector): # new partition if ptype == "NORMAL": newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_NORMAL, geometry=geom) + + elif ptype == "EXTENDED": + newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_EXTENDED, geometry=geom) + + + + elif ptype == "LOGICAL": + newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_LOGICAL, geometry=geom) + elif ptype == "SWAP": newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_NORMAL, geometry=geom) @@ -316,8 +374,8 @@ def create_partitions(diskdevice, size, ptype, startsector): partdisk.addPartition(partition=newpart, constraint=constraint) if data_config.NOOPDEBUG == "FALSE": partdisk.commit() - logging.info("created partition %s of %dMB and added it to %s" % - (newpart.getDeviceNodeName(), newpart.getSize(), diskdevice)) + logging.info(" created %s partition %s of %dMB and added it to %s" % + (ptype,newpart.getDeviceNodeName(), newpart.getSize(), diskdevice)) return newpart.getDeviceNodeName() def set_active_parition(diskdevice): @@ -346,15 +404,34 @@ def partition_disk(): partitions_removeall("/dev/"+datadisk, label) hostoptions["rootpartition"] = create_partitions("/dev/"+rootdisk, hostoptions["rootsize"], "NORMAL", 0) set_active_parition("/dev/"+rootdisk) + hostoptions["swappartition"] = create_partitions("/dev/"+rootdisk, hostoptions["swapsize"], "SWAP", 1) + + #create extended partition + hostoptions["extended_partition"] = create_partitions("/dev/"+rootdisk, "all", "EXTENDED", 1) + + #create the logical in the extended + hostoptions["home_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["homesize"], "LOGICAL", 1) + hostoptions["sql_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["sqlsize"], "LOGICAL", 1) + if datadisk != rootdisk: hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 0) else: - hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 1) + hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "LOGICAL", 1) + + logging.debug("sleeping for 5 seconds") time.sleep(5) + def fscmd(fstype): - fscmds = {"reiserfs":"mkreiserfs -q -l ROOT", "xfs": "mkfs -t xfs -f", "ext3": "mkfs.ext3", "jfs":"mkfs.jfs -q", "ext4":"mkfs.ext4", "Do_not_format":"noformat", "no_format":"noformat"} + fscmds = {"reiserfs":"mkreiserfs -q -l ROOT", + "xfs": "mkfs -t xfs -f", + "ext3": "mkfs.ext3", + "jfs":"mkfs.jfs -q", + "ext4":"mkfs.ext4", + "Do_not_format":"no_format", + "no_format":"no_format", + "btrfs":"mkfs.btrfs"} try: rc = fscmds[fstype] except: @@ -368,40 +445,76 @@ def format_disk(install_type): rootfs = fscmd(hostoptions["rootfs"]) datafs = fscmd(hostoptions["datafs"]) + sqlfs = fscmd(hostoptions["sqlfs"]) + homefs = fscmd(hostoptions["homefs"]) + + rootdisk = hostoptions["rootdisk"] datadisk = hostoptions["datadisk"] rootpartition = hostoptions["rootpartition"] datapartition = hostoptions["datapartition"] - if install_type != "upgrade": - swapsize = hostoptions["swapsize"] + + homepartition = hostoptions["home_partition"] + sqlpartition = hostoptions["sql_partition"] + + + #if install_type != "upgrade": + #swapsize = hostoptions["swapsize"] + #swappartition = hostoptions["swappartition"] + + if install_type == "install": swappartition = hostoptions["swappartition"] + if (hostoptions["swapsize"] != "NO"): + logging.info(" Starting format for swap %s", swappartition) + cmd = " mkswap /dev/%s" % swappartition + #os.system(cmd) + runcmd(cmd) + else: + logging.debug(" Swap is set to NO, will not run mkswap") logging.debug(" Format command for rootfs %s : %s ", rootfs, rootpartition) - if ( rootfs != "noformat"): - logging.info("Starting format of %s", rootpartition) + if ( rootfs != "no_format"): + logging.info(" Starting %s format of %s", rootfs, rootpartition) cmd = " %s /dev/%s" %( rootfs, rootpartition) #os.system(cmd) runcmd(cmd) else: - logging.info("Will not format root partition: %s", rootpartition) + logging.info(" Will not format root partition: %s", rootpartition) logging.debug(" Format command for datafs %s : %s ", datafs, datapartition) - if (datafs != "noformat"): - logging.info("Starting format of %s", datapartition) + if (datafs != "no_format"): + logging.info(" Starting format %s of %s", datafs, datapartition) cmd = " %s /dev/%s" %( datafs, datapartition) #os.system(cmd) runcmd(cmd) else: - logging.info("Will not format data partition: %s", datapartition) + logging.info(" Will not format data partition: %s", datapartition) - if install_type == "install": - if (hostoptions["swapsize"] != "NO"): - logging.info("Starting format for swap %s", swappartition) - cmd = " mkswap /dev/%s" % swappartition - #os.system(cmd) - runcmd(cmd) - else: - logging.debug(" Swap is set to NO, will not run mkswap") + #for upgrades format is set to no_format + if ( homefs != "no_format"): + logging.info(" Starting format %s of %s", homefs, homepartition) + cmd = " %s /dev/%s" %( homefs, homepartition) + #os.system(cmd) + runcmd(cmd) + else: + logging.info(" Will not format home partition: %s", homepartition) + + if ( sqlfs != "no_format"): + logging.info(" Starting format %s of %s", sqlfs, sqlpartition) + cmd = " %s /dev/%s" %( sqlfs, sqlpartition) + #os.system(cmd) + runcmd(cmd) + else: + logging.info(" Will not format sql partition: %s", sqlpartition) + + logging.debug(" Format command for datafs %s : %s ", datafs, datapartition) + if (datafs != "no_format"): + logging.info(" Starting format %s of %s", datafs, datapartition) + cmd = " %s /dev/%s" %( datafs, datapartition) + #os.system(cmd) + runcmd(cmd) + else: + logging.info(" Will not format data partition: %s", datapartition) logging.debug("_____End of format______") @@ -412,43 +525,89 @@ def mount_it(): try: mountpoint = data_config.MOUNTPOINT mp = mountpoint - logging.info("Creating mountpoints %s", mp) + logging.info(" Creating mountpoints %s", mp) os.makedirs(mp) except OSError: logging.debug(" Could not create %s", mp) -# Mount root + # Mount root cmd = "mount /dev/%s %s" %(hostoptions["rootpartition"], mountpoint) runcmd(cmd) - - - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) - #logging.debug(cmdout) -# Mount data -#make mountpoint after mounting / + # Mount data + #make mountpoint after mounting / try: mountpoint = data_config.MOUNTPOINT datapoint = data_config.DATAMOUNT mp = mountpoint+datapoint - logging.info("Creating mountpoints %s", mp) + logging.info(" Creating mountpoints %s", mp) os.makedirs(mp) except OSError: logging.debug(" Could not create %s", mp) cmd = "mount /dev/%s %s" %(hostoptions["datapartition"], mp) runcmd(cmd) - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) - #logging.debug(cmdout) + + #mount home + try: + mountpoint = data_config.MOUNTPOINT + homepoint = data_config.HOMEMOUNT + mp = mountpoint+homepoint + logging.info(" Creating mountpoints %s", mp) + os.makedirs(mp) + except OSError: + logging.debug(" Could not create %s", mp) + + cmd = "mount /dev/%s %s" %(hostoptions["home_partition"], mp) + runcmd(cmd) + + + #mount sql + try: + mountpoint = data_config.MOUNTPOINT + sqlpoint = data_config.SQLMOUNT + mp = mountpoint+sqlpoint + logging.info(" Creating mountpoints %s", mp) + os.makedirs(mp) + except OSError: + logging.debug(" Could not create %s", mp) + + cmd = "mount /dev/%s %s" %(hostoptions["sql_partition"], mp) + runcmd(cmd) + def unmount_it(): logging.info("______Unmounting disk______") + cmd = "mount -v |grep new_boot" + mp_list=[] + mplist=[] + mountpoint = runcmd(cmd)[1] + mplist="".join(mountpoint).split("\n") + for i in mplist: + mp = i.split()[2] + mp_list.append(mp) + mp_list.sort(key = len, reverse=True) + for i in mp_list: + cmd = "umount %s" %(i) + runcmd(cmd) + time.sleep(1) + + + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) runcmd(cmd) time.sleep(2) + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.HOMEMOUNT) + runcmd(cmd) + time.sleep(2) + + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.SQLMOUNT) + runcmd(cmd) + time.sleep(2) + + + cmd = "swapoff /dev/%s" %(hostoptions["swappartition"]) runcmd(cmd) @@ -475,33 +634,170 @@ def create_squashlist(): logging.debug(i) f.close() +def mount_for_copy_it(): + mounts = {} + + mounts['/image_mount/root'] = 'root-image' + mounts['/image_mount/usr/share'] = 'usr-share' + mounts['/image_mount/lib/modules'] = 'lib-modules' + mounts['/image_mount/var/lib/pacman'] = 'var-lib-pacman' + mounts['/image_mount/data/storage/disk0/pacman/pkg'] = 'data-storage-disk0-pacman-pkg' + #mounts['/image_mount/var/cache/pacman'] = 'var-cache-pacman' + for image_mount, fsimage in mounts.iteritems(): + try: + os.makedirs(image_mount) + except: + pass + cmd = 'mount /run/archiso/sfs/%s/%s.fs %s' %(fsimage,fsimage,image_mount) + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("Mount image %s" %fsimage) + + + + + #image_mount='/image_mount/root' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/usr/share' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/lib/modules' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/var/cache/pacman' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/var/lib/pacman' + #try: + #os.makedirs(image_mount) + #except: + #pass + + + #fsimage='root-image' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/root' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image root") + + #fsimage='lib-modules' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/lib/modules' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image lib-modules") + + #fsimage='usr-share' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/usr/share' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image usr share") + + #fsimage='var-lib-pacman' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/var/lib/pacman' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image var-lib-pacman") + + #fsimage='var-cache-pacman' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/var/cache/pacman' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image var-cahce-pacman") + + +def umount_for_copy_it(): + mounts = {} + + mounts['/image_mount/root'] = 'root-image' + mounts['/image_mount/usr/share'] = 'usr-share' + mounts['/image_mount/lib/modules'] = 'lib-modules' + mounts['/image_mount/var/lib/pacman'] = 'var-lib-pacman' + mounts['/image_mount/data/storage/disk0/pacman/pkg'] = 'data-storage-disk0-pacman-pkg' + #mounts['/image_mount/var/cache/pacman'] = 'var-cache-pacman' + for image_mount, fsimage in mounts.iteritems(): + cmd = 'mount /run/archiso/sfs/%s/%s.fs %s' %(fsimage,fsimage,image_mount) + cmd='umount %s' %(image_mount) + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("unMount image %s" %image_mount) + + + #cmd='umount %s' %('/image_mount/lib/modules') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image lib_modules") + + #cmd='umount %s' %('/image_mount/usr/share') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image usr_share") + + #cmd='umount %s' %('/image_mount/root') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image /") + + #cmd='umount %s' %('/image_mount/var/cache/pacman') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image var-cache-pacman") + + #cmd='umount %s' %('/image_mount/var/lib/pacman') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image var-lib-pacman") + + def copy_it(install_type): logging.info("______Transferring to disk______") + mount_for_copy_it() logging.debug( install_type) if ( install_type == "install"): logging.info("Transferring system") - cmd = " unsquashfs -f -d %s /.livesys/medium/larch/system.sqf" %(data_config.MOUNTPOINT) - #runcmd(cmd) - rc = runcmd(cmd)[0] - if rc != 0 : - error_out("Running unsquashfs") + cmdlist = ['rsync -arp /image_mount/root/* /new_boot', + 'rsync -arp /image_mount/lib/* /new_boot/lib/', + 'rsync -arp /image_mount/usr /new_boot', + 'rsync -arp /image_mount/var /new_boot', + 'rsync -arp /image_mount/data/storage/disk0/* /new_boot/data/storage/disk0/' + ] + + for cmd in cmdlist: + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("Running %s" %cmd) + - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) if ( install_type == "upgrade"): logging.info("Upgrading system") - create_squashlist() - cmd = " unsquashfs -e %s -f -d %s /.livesys/medium/larch/system.sqf" %(data_config.SQUASHFILE, data_config.MOUNTPOINT) - #runcmd(cmd) - rc = runcmd(cmd)[0] - if rc != 0 : - error_out("Running unsquashfs") - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) -# Create the missing dir - i = ("sys", "proc", "dev", "tmp", "mnt", "media", "media/cdrom", "media/dvd", "var/log/mythtv", "var/lock", "var/tmp", "usr/lib/locale") + + cmdlist = ['rsync -arp --exclude /home --exclude /data/srv/mysql /image_mount/root/* /new_boot', + 'rsync -arp /image_mount/lib/* /new_boot/lib/', + 'rsync -arp /image_mount/usr /new_boot', + 'rsync -arp /image_mount/var /new_boot'] + + for cmd in cmdlist: + #runcmd(cmd) + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("Running %s" %cmd) + + # Create the missing dir + i = ("sys", "proc", "dev", "tmp", "mnt", "media", "media/cdrom", "media/dvd", "var/lock", "var/tmp", "usr/lib/locale") mountpoint = data_config.MOUNTPOINT for item in i: try: @@ -533,12 +829,11 @@ def copy_it(install_type): runcmd(cmd) cmd = "chmod +s %s/bin/mount" %(data_config.MOUNTPOINT) runcmd(cmd) - cmd = "rm %s/etc/*.larch*" %(data_config.MOUNTPOINT) - runcmd(cmd) - cmd = "rm %s/etc/mkinitcpio.d/larch*" %(data_config.MOUNTPOINT) - runcmd(cmd) - cmd = "rm %s/etc/rc.d/functions.d/*larch*" %(data_config.MOUNTPOINT) - runcmd(cmd) + #sys.exit(3) + apply_pristine() + post_process() + + umount_for_copy_it() logging.debug("__End of copy_it__") def create_fstab(extralines): @@ -555,10 +850,19 @@ def create_fstab(extralines): fstab_list.append(line) line = '''/dev/sr0 /media/cdrom auto ro,user,noauto,unhide 0 0\n''' fstab_list.append(line) - line = '''UUID=ROOTUID / auto defaults,noatime 0 1\n''' + line = '''UUID=ROOTUID / %s defaults,noatime 0 1\n''' %(hostoptions["rootfs"]) + fstab_list.append(line) + + line = '''UUID=DATAUID %s %s defaults,noatime 0 1\n''' %(data_config.DATAMOUNT,hostoptions["datafs"]) fstab_list.append(line) - line = '''UUID=DATAUID %s auto defaults,noatime 0 1\n''' %(data_config.DATAMOUNT) + + line = '''UUID=HOMEUID %s %s defaults,noatime 0 1\n''' %(data_config.HOMEMOUNT,hostoptions["homefs"]) + fstab_list.append(line) + + line = '''UUID=SQLUID %s %s defaults,noatime 0 1\n''' %(data_config.SQLMOUNT,hostoptions["sqlfs"]) fstab_list.append(line) + + line = '''UUID=SWAPUID swap swap defaults 0 0 \n''' fstab_list.append(line) for vline in extralines: @@ -569,16 +873,16 @@ def create_fstab(extralines): f.close() def find_uuid(partition): - logging.info("Finding the UUID for %s...", partition) + logging.info(" Finding the UUID for %s...", partition) cmd = "blkid -s UUID /dev/%s" %partition tmpuuid = runcmd(cmd)[1] splituuid = tmpuuid.partition("=") uuid = splituuid[2].replace('"', "") - logging.info("The uuid is %s", uuid) + logging.info(" The uuid is %s", uuid) return uuid.strip() def acl_options(partition): - logging.info("Finding mount options for %s...", partition) + logging.info(" Finding mount options for %s...", partition) acl_fs_list=["ext3","ext4"] options = "defaults,noatime" cmd = "/sbin/fsck -N /dev/%s" %partition @@ -601,7 +905,7 @@ def acl_options(partition): if i[0] == "/dev/%s" %partition: if i[1] in acl_fs_list: rc=True - logging.info("Will add acl to the list of options: %s ", rc ) + logging.info(" Will add acl to the list of options: %s ", rc ) return rc @@ -636,6 +940,7 @@ def fstab_it(install_type): elif os.path.exists("/tmp/etc/fstab"): logging.debug(" Upgrade and not Knoppmyth, using old fstab") cp_and_log("/tmp/etc/fstab", fstabfile) + # Catch all for creating new fstab if not os.path.exists(data_config.MOUNTPOINT+"/etc"): os.makedirs(data_config.MOUNTPOINT+"/etc") @@ -653,13 +958,24 @@ def fstab_it(install_type): rootuuid = find_uuid(hostoptions["rootpartition"]) rootacl = acl_options(hostoptions["rootpartition"]) + logging.info("____UUID check for %s", "home") + homeuuid = find_uuid(hostoptions["home_partition"]) + homeacl = acl_options(hostoptions["home_partition"]) + + logging.info("____UUID check for %s", "sql") + sqluuid = find_uuid(hostoptions["sql_partition"]) + sqlacl = acl_options(hostoptions["sql_partition"]) + fstabfile = data_config.MOUNTPOINT+"/etc/fstab" - logging.info("Correcting UUID's in %s", fstabfile) + logging.info(" Correcting UUID's in %s", fstabfile) f = open(fstabfile, 'r') oldfscontents = f.readlines() newfstab = [] f.close() for line in oldfscontents: + if line.strip("\n") == '': + continue + #FIX ALL MOUNTS THAT START WITH UUID if line.startswith("UUID"): templine = line.split() if ( templine[1] == "/"): @@ -678,7 +994,7 @@ def fstab_it(install_type): logging.debug( newline) newfstab.append(newline) - if ( templine[1] == data_config.DATAMOUNT): + elif ( templine[1] == data_config.DATAMOUNT): logging.debug(" Found DATA mount") logging.debug( templine) templine[0] = "UUID=%s" %(datauuid) @@ -693,7 +1009,37 @@ def fstab_it(install_type): logging.debug( newline) newfstab.append(newline) - if ( templine[1] == "swap"): + elif ( templine[1] == data_config.HOMEMOUNT): + logging.debug(" Found HOME mount") + logging.debug( templine) + templine[0] = "UUID=%s" %(homeuuid) + if homeacl: + templine[3] = templine[3]+",acl" + newline = '' + for i in templine: + newline+=i + newline+=" " + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + + elif ( templine[1] == data_config.SQLMOUNT): + logging.debug(" Found database mount") + logging.debug( templine) + templine[0] = "UUID=%s" %(sqluuid) + if sqlacl: + templine[3] = templine[3]+",acl" + newline = '' + for i in templine: + newline+=i + newline+=" " + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + + elif ( templine[1] == "swap"): if len(swapuuid) <= 5: logging.debug(" swapp uuid is to small") else: @@ -704,10 +1050,16 @@ def fstab_it(install_type): for i in templine: newline+=i newline+=" " - newline+="\n" - logging.debug(" New fstab line:") - logging.debug( newline) - newfstab.append(newline) + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + else: + logging.debug(" Line didn't match, adding to newfstab:") + logging.debug( line) + newfstab.append(line) + + elif line.startswith("none"): templine = line.split() if ( templine[1] == "/dev/pts" ): @@ -724,10 +1076,14 @@ def fstab_it(install_type): logging.debug(" Line didn't match, adding to newfstab:") logging.debug( line) newfstab.append(line) - logging.info("Writing out newfstab") + + logging.info(" Writing out newfstab") logging.debug("______This is the new fstab_____") + f = open(fstabfile, 'w') for line in newfstab: + if line.strip("\n") == '': + continue logging.debug(line) f.write(line) #f.write("\n") @@ -735,47 +1091,107 @@ def fstab_it(install_type): def grub_it(): logging.info("______Start of grub install______") - cmd = " grub-install --recheck --no-floppy --root-directory=%s \"(hd0)\" " % data_config.MOUNTPOINT - logging.info("Running grub-install") + cmd = "chroot %s grub-install --target=i386-pc --recheck --debug /dev/%s" %(data_config.MOUNTPOINT,hostoptions["rootdisk"]) + logging.info(" Running grub-install") runcmd(cmd) - rootuuid = find_uuid(hostoptions["rootpartition"]) - cmd = " mkinitcpio -b %s -g %s/boot/kernel26.img" %(data_config.MOUNTPOINT, data_config.MOUNTPOINT) + + cmd = " mkinitcpio -g %s/boot/initramfs-linux.img" %(data_config.MOUNTPOINT) logging.info("Running mkinitcpio") runcmd(cmd) - logging.info("Adding root uuid to grub menu") - grubfile = data_config.MOUNTPOINT+"/boot/grub/menu.lst" + newgrub = [] + grubfile = data_config.MOUNTPOINT+"/etc/default/grub" try: f = open(grubfile, 'r') oldgrub = f.readlines() - newgrub = [] - f.close() - for line in oldgrub: - if line.startswith("kernel"): - templine = line.split() - logging.debug(" Found kernel Root grubline:") - logging.debug( templine) - templine[2] = "root=/dev/disk/by-uuid/%s" %(rootuuid) - newline = '' - for i in templine: - newline+=i - newline+=" " - newline+="\n" - logging.debug(" New grub menu.lst line:") - logging.debug( newline) - newgrub.append(newline) - else: - logging.debug("Line didn't match, adding to newgrub:") - logging.debug( line) - newgrub.append( line) - logging.info("Writing out new grub file") - logging.debug("______This is the new grub_____") - f = open(grubfile, 'w') - for line in newgrub: - logging.debug(line) - f.write(line) + f.close() except: - logging.debug("Couldn't open grub file") + logging.debug(" Couldn't open grub file for reading") + pass + + time_line = "GRUB_TIMEOUT=" + hidden_time = "GRUB_HIDDEN_TIMEOUT=" + color_line_normal = "GRUB_COLOR_NORMAL" + color_line_highlight = "GRUB_COLOR_HIGHLIGHT" + + for line in oldgrub: + new_line=line + if line.find(time_line) != -1 : + new_line="GRUB_TIMEOUT=0\n" + + if line.find(color_line_normal) != -1 : + #new_line=line.lstrip('''#''') + new_line='''GRUB_COLOR_NORMAL="white/blue"\n''' + + if line.find(color_line_highlight) != -1 : + #new_line=line.lstrip('''#''') + new_line='''GRUB_COLOR_HIGHLIGHT="black/yellow"\n''' + + if line.find(hidden_time) != -1 : + new_line="GRUB_HIDDEN_TIMEOUT=5\n" + + newgrub.append(new_line) + + if len(newgrub) > 0: + try: + f = open(grubfile, 'w') + for line in newgrub: + logging.debug(line) + f.write(line) + f.close() + except: + logging.debug(" Couldn't open grub file for writing") + + + + cmd="chroot %s grub-mkconfig -o /boot/grub/grub.cfg" %data_config.MOUNTPOINT + runcmd(cmd) + +def double_mount(fe_only=False, upgrade=False): + logging.info(" double bind mount attempt") + cmd = "mkdir %s/run/dbus" %data_config.MOUNTPOINT + runcmd(cmd) + + cmd = " mount --bind /run/dbus %s/run/dbus" %data_config.MOUNTPOINT + runcmd(cmd) + for i in range(0,5): + if upgrade == True: + cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --reconstruct --no_mount" + else: + if fe_only == True: + cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --double_myth --no_mount" + else: + #cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --double_myth --no_mount" + cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --double_myth --add_fe_sg --add_be_sg " + + if runcmd(cmd)[0] == 0: + logging.debug(" Add storage worked, breaking out of loop") + break + cmd = " umount %s/run/dbus" %data_config.MOUNTPOINT + runcmd(cmd) + +def move_myth_home(op): + logging.debug(" storage op %s" %op ) + if op == "restore": + destfile = "/storage/data/" + srcfile = "/storage/data.old/*" + cmd = 'chroot %s bash -c "mv %s %s"' %(data_config.MOUNTPOINT,srcfile,destfile) + runcmd(cmd) + + rmfile = "%s/storage/data.old" %data_config.MOUNTPOINT + cmd = "rmdir %s" %rmfile + runcmd(cmd) + + + if op == "backup": + srcfile = "%s/storage/data" %data_config.MOUNTPOINT + destfile = "%s/storage/data.old" %data_config.MOUNTPOINT + cmd = "mv %s %s" %(srcfile,destfile) + runcmd(cmd) + + + + def genlocale(): return @@ -798,7 +1214,7 @@ def genlocale(): outline = line.replace('#','') f.write(outline) - f.close + f.close() #cp_and_log("/tmp/locale.gen.new", data_config.MOUNTPOINT+"/etc/locale.gen") cmd = "chroot " + data_config.MOUNTPOINT +" /usr/sbin/locale-gen" runcmd(cmd) @@ -818,12 +1234,14 @@ def fix_permissions(): runcmd(cmd) cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+"/var/log/mythtv") runcmd(cmd) + cmd = " chmod +s %s" %(data_config.MOUNTPOINT+"/usr/bin/ping") + runcmd(cmd) def apply_new_auth(): logging.info("_____Applying Password updates_______") passfile = "/root/myth_user_call.out" try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug("MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" @@ -845,75 +1263,83 @@ def apply_new_auth(): logging.debug def add_to_blacklist(module): - rcfile = data_config.MOUNTPOINT + "/etc/rc.conf" + rcfile = data_config.MOUNTPOINT + "/etc/modprobe.d/install-blacklist.conf" logging.debug(" Attempting to add %s to blacklist", module) newline='' - try: - f = open(rcfile, 'r') - conflines = f.readlines() - f.close() - except: - logging.critical(" *Couldn't open %s for reading",rcfile) - return + #try: + #f = open(rcfile, 'r') + #conflines = f.readlines() + #f.close() + #except: + #logging.critical(" *Couldn't open %s for reading",rcfile) + #return try: - f = open(rcfile, 'w') + f = open(rcfile, 'a') except: logging.critical(" *Couldn't open %s for reading",rcfile) return - - for line in conflines: - newline = line - if re.match("MOD_BLACKLIST",line): - logging.debug(line) - try: - lastpar = line.rindex(')') - logging.debug(" found ) at %s", lastpar) - newline = line[:lastpar] +" !" + module + " " + line[lastpar:] - logging.debug(newline) - except: - logging.debug("Couldn't find ending )") - newline = line - f.write(newline) + line = "blacklist %s \n" %module + f.write(line) + line = "install %s /bin/false \n" %module + f.write(line) f.close() + #for line in conflines: + #newline = line + #if re.match("MOD_BLACKLIST",line): + #logging.debug(line) + #try: + #lastpar = line.rindex(')') + #logging.debug(" found ) at %s", lastpar) + #newline = line[:lastpar] +" !" + module + " " + line[lastpar:] + #logging.debug(newline) + #except: + #logging.debug("Couldn't find ending )") + #newline = line + #f.write(newline) + #f.close() def add_to_modulelist(module): - rcfile = data_config.MOUNTPOINT + "/etc/rc.conf" + rcfile = data_config.MOUNTPOINT + "/etc/modules-load.d/install-autoload.conf" logging.debug(" Attempting to add %s to modulelist", module) newline='' - try: - f = open(rcfile, 'r') - conflines = f.readlines() - f.close() - except: - logging.critical(" *Couldn't open %s for reading",rcfile) - return + #try: + #f = open(rcfile, 'r') + #conflines = f.readlines() + #f.close() + #except: + #logging.critical(" *Couldn't open %s for reading",rcfile) + #return try: - f = open(rcfile, 'w') + f = open(rcfile, 'a+') except: - logging.critical(" *Couldn't open %s for reading",rcfile) + logging.critical(" *Couldn't open %s for writing",rcfile) return - - for line in conflines: - newline = line - if re.match("MODULES=",line): - logging.debug(line) - try: - lastpar = line.rindex(')') - logging.debug(" found ) at %s", lastpar) - newline = line[:lastpar] +" " + module + " " + line[lastpar:] - logging.debug(newline) - except: - logging.debug("Couldn't find ending )") - newline = line - f.write(newline) + line = "%s" %module + f.write(line) + f.write("\n") f.close() + #for line in conflines: + #newline = line + #if re.match("MODULES=",line): + #logging.debug(line) + #try: + #lastpar = line.rindex(')') + #logging.debug(" found ) at %s", lastpar) + #newline = line[:lastpar] +" " + module + " " + line[lastpar:] + #logging.debug(newline) + #except: + #logging.debug("Couldn't find ending )") + #newline = line + #f.write(newline) + #f.close() def special_hardware_check(): + outlist = [] logging.info("_____Applying special boot parameters_______") try: f = open('/proc/cmdline', 'r') @@ -926,14 +1352,16 @@ def special_hardware_check(): logging.debug(" Boot options: %s", bootoptions) for item in bootoptions: logging.debug(item) - if re.match("disablemodules",item) != None : + if (re.match("disablemodules",item) != None) or (re.match("modprobe.blacklist",item) != None ): logging.debug(" Found disabledmodules") + outlist.append(item) modulelist = item.split("=")[1] for module in modulelist.split(','): add_to_blacklist(module) if re.match("modules",item) != None : logging.debug(" Found modules") + outlist.append(item) modulelist = item.split("=")[1] for module in modulelist.split(','): add_to_modulelist(module) @@ -953,6 +1381,19 @@ def special_hardware_check(): if re.match("no_meth",item) != None : cmd = " touch %s%s/.no_meth" %(data_config.MOUNTPOINT, data_config.MYTHHOME) runcmd(cmd) + if len(outlist) != 0: + outfile = data_config.MOUNTPOINT + "/etc/grub.d/install_modules" + logging.debug(" Writing out %s" %outfile) + try: + f = open(outfile, 'w') + templine = ' '.join(outlist) + outline = '''install_modules='%s' \n''' %templine + f.write(outline) + f.write("\n") + f.close() + except: + logging.critical(" *Couldn't write %s" %outfile) + return def swapsearch(): #currently unused! @@ -1030,10 +1471,48 @@ def restore_default_settings(): copy_updates() fix_permissions() +def apply_pristine(): + logging.info("_____Applying Pristine files_______") + if data_config.NOOPDEBUG == "FALSE": + cmd = "chroot " + data_config.MOUNTPOINT + " " + "tar -xvf /pristine.tar" + else: + cmd = "echo chroot " + data_config.MOUNTPOINT + " " + "tar -xvf /pristine.tar" + try: +# Using os.system because runcmd fails + logging.debug(cmd) + os.system(cmd) + except: + logging.debug("Applying pristine files failed %s", passfile) + logging.debug + + try: + removefile="%s/pristine.tar" %(data_config.MOUNTPOINT) + os.remove(removefile) + except OSError: + logging.debug(" Couldn't remove pristine.tar") + pass + +def post_process(): + logging.info("_____Post processing_______") + if data_config.NOOPDEBUG == "FALSE": + cmd = "chroot " + data_config.MOUNTPOINT + " " + "/root/.post_process/go.sh" + else: + cmd = "echo chroot " + data_config.MOUNTPOINT + " " + "/root/.post_process/go.sh" + try: +# Using os.system because runcmd fails + logging.debug(cmd) + os.system(cmd) + except: + logging.debug("Applying post_process_failed %s", passfile) + logging.debug + + + + def full_install(hostoptions): logging.info("______Start of full install______") try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug(" MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" @@ -1066,77 +1545,99 @@ def full_install(hostoptions): mount_it() swapon() - -# Find number of bytes written to disk before starting copy. This is used -# to have a somewhat decent progress indication. + #Find number of bytes written to disk before starting copy. This is used + #to have a somewhat decent progress indication. statgrab( hostoptions["rootdisk"]) msg = "Creating %s" %(systemconfig["hostname"]) update_status(msg) -# Copy system to disk + #Copy system to disk copy_it("install") -# Remove old fstab so that a new one is created + #at this point /storage exisit and is populated with myth home dir + + + #Remove old fstab so that a new one is created fstabfile = data_config.MOUNTPOINT+"/etc/fstab" try: os.remove(fstabfile) except OSError: logging.debug(" ERROR: deleting %s", fstabfile) fstab_it("full_install") -# Configure system + + # Configure system msg = "Configuring system" update_status(msg) progress(98) - grub_it() - genlocale() + special_hardware_check() -# Configuring the system + + mount_bind_chroot() + grub_it() + umount_bind_chroot() + + genlocale() #currently does nothing + + logging.info("______Configuring system________") cp_and_log("/etc/systemconfig", data_config.MOUNTPOINT+"/etc/systemconfig") + cp_and_log("/etc/install_layout", data_config.MOUNTPOINT+"/etc/install_layout") cp_and_log("/root/xorg.conf.install", data_config.MOUNTPOINT+"/etc/X11/xorg.conf.install") - restore_default_settings() - #try: - #MVROOT=os.environ["MV_ROOT"] - #except: - #logging.debug(" MVROOT was not defined, using the default value") - #MVROOT="/usr/MythVantage" - #logging.info("Saving syssettings") - #cmd="%s/bin/myth_settings_wrapper.sh -c save -t syssettings -h %s -d localhost" %(MVROOT, data_config.MVHOSTNAME) - #runcmd(cmd) - #SE=os.environ["TEMPLATES"]+"/settings/syssettings" - #cp_and_log(SE, data_config.MOUNTPOINT+SE) - #cp_and_log("/etc/mtab", data_config.MOUNTPOINT+"/etc/mtab") - #cp_and_log2(MVROOT+"/bin/", data_config.MOUNTPOINT+MVROOT+"/bin/", "*.sh") - #cp_and_log2(MVROOT+"/bin/", data_config.MOUNTPOINT+MVROOT+"/bin/", "*.py") - #fix_permissions() + + restore_default_settings() #also calls copy_updates, fix permissions + + #setup symlink + mount_bind_chroot() + logging.info("Running systemconfig in chroot") + cmd = "chroot %s %s/bin/systemconfig.sh config_xml,this_is_install" %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + umount_bind_chroot() + + mount_bind_chroot() apply_new_auth() umount_bind_chroot() + if ( systemconfig["SystemType"] == "Master_backend" or systemconfig["SystemType"] == "Standalone" ): -# This install will need a DB, so install it + #This install will need a DB, so install it logging.info("______Installing Database in CHROOT________") mysqldb("stop", '') mount_bind_chroot() - cmd = " chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) + cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + logging.info("Running systemconfig in chroot") - #cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT) cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) rc = runcmd(cmd)[0] if rc != 0 : error_out("Running systemconfig") + #move_myth_home("backup") + + mysqldb("start","chroot") + double_mount() mysqldb("stop", "chroot") - kill_dhcp_chroot() + + #move_myth_home("restore") #restoring after the bind mound/symlink has occured + + #kill_dhcp_chroot() logging.info("____End Database in CHROOT____") mysqldb("start", '') umount_bind_chroot() else: logging.info("______No database required, continuing configuration________") mount_bind_chroot() - cmd = " chroot %s DISPLAY=127.0.0.1:0 %s/bin/MythVantage -t restore, default 1" %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) + #cmd = "chroot %s DISPLAY=127.0.0.1:0 %s/bin/MythVantage -t restore, default 1" %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) + + + #move_myth_home("backup") + if systemconfig["SystemType"] == "Slave_backend": + double_mount() + else: + double_mount(fe_only=True) + #move_myth_home("restore") # Need to check for to touch /tmp/.dbsysfailed #cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) #runcmd(cmd) @@ -1148,20 +1649,33 @@ def full_install(hostoptions): rc = runcmd(cmd)[0] if rc != 0 : error_out("Running systemconfig") + + #restore defaults here! + cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t distro_default " %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c ACCESSCONTROL " %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + + #run hostype again to set BackendServerIP. This value is overwritten with distro_default restore + cmd = "chroot %s %s/bin/systemconfig.sh hostype,this_is_install" %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + umount_bind_chroot() - cmd = " touch %s%s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + + cmd = "chroot %s touch %s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) runcmd(cmd) - cmd = " chmod 777 %s%s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + cmd = "chroot %s chmod 777 %s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) runcmd(cmd) msg = "Done" update_status(msg) cp_and_log("/tmp/mythvantage_install.log", data_config.MOUNTPOINT+"/var/log/mythvantage_install.log") cp_and_log("/tmp/mv_debug.log", data_config.MOUNTPOINT+"/var/log/mv_debug.log") + kill_dhcp_chroot() unmount_it() logging.debug("_____End of full install_____") @@ -1188,9 +1702,10 @@ def find_upgrade(): if os.path.exists(srcfile): logging.info("Found systemconfig file %s", srcfile) TEMPLATES = os.environ["TEMPLATES"]+"/settings/syssettings" + TEMPLATE_ = os.environ["TEMPLATES"]+"/settings" cp_and_log2(data_config.MOUNTPOINT+TEMPLATES, data_config.TEMP_TEMPLATES, '') sane_settings("/tmp/templates/settings/syssettings/settings.txt") - cp_and_log2(data_config.TEMP_TEMPLATES, TEMPLATES, '') + cp_and_log2(data_config.TEMP_TEMPLATES, TEMPLATE_, '*') cp_and_log(srcfile, "/etc/systemconfig") cp_and_log(data_config.MOUNTPOINT+"/etc/", "/tmp/etc/") cp_and_log(data_config.MOUNTPOINT+"/var/lib/alsa/", "/tmp/alsa") @@ -1280,15 +1795,18 @@ def upgrade_mount_search(): def upgrade(hostoptions): - try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug("MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" + hostoptions["backupfile"] = data_config.BACKUPPATH+data_config.BACKUPFILE + logging.info("______Start of upgrade______") cmd = "touch /tmp/.this_is_upgrade" runcmd(cmd) + + #format disk if hostoptions["rootfs"] == "Do_not_format": logging.info("Will not format root filesystem") else: @@ -1296,18 +1814,26 @@ def upgrade(hostoptions): update_status(statusmsg) progress(2) format_disk("upgrade") - #sys.exit(2) + + #mount partitions statusmsg = "Mounting %s" %( hostoptions["rootdisk"]) update_status(statusmsg) progress(3) mount_it() swapon() + hostoptions["backupfile"] = data_config.BACKUPPATH+data_config.BACKUPFILE + #Find number of bytes written to disk before starting copy. This is used to + #give a somewhat decent progress indication statgrab( hostoptions["rootdisk"]) msg = "Upgrading %s" %(systemconfig["hostname"]) update_status(msg) time.sleep(3) + + #copy system to disk copy_it("upgrade") + + #Restore /etc and key files. This is the copy found when running find_upgrade cmd = "rm -rf %s/etc.old" %data_config.MOUNTPOINT runcmd(cmd) cmd = "rm -rf %s/alsa.old" %data_config.MOUNTPOINT @@ -1317,12 +1843,19 @@ def upgrade(hostoptions): cp_and_log("/tmp/alsa/", data_config.MOUNTPOINT+"/alsa.old/") cp_and_log("/tmp/oss", data_config.MOUNTPOINT+"/var/lib/oss.old") + srcfile = "%s/etc.old/ssh/" %(data_config.MOUNTPOINT) destfile = "%s/etc/ssh/" %(data_config.MOUNTPOINT) cp_and_log2(srcfile, destfile, '*.pub') cp_and_log2(srcfile, destfile, '*.key') cp_and_log2(srcfile, destfile, '*key') + srcfile = "%s/etc.old/storage.d/" %(data_config.MOUNTPOINT) + destfile = "%s/etc/storage.d/" %(data_config.MOUNTPOINT) + cp_and_log2(srcfile, destfile, '*.conf') + cp_and_log2(srcfile, destfile, '*.pkl') + + mdfile = mdadm_find("/tmp") cp_and_log("/tmp"+mdfile, data_config.MOUNTPOINT+"/etc") @@ -1348,23 +1881,36 @@ def upgrade(hostoptions): cp_and_log(data_config.MOUNTPOINT+"/etc.old/passwd", data_config.MOUNTPOINT+"/etc/passwd") cp_and_log(data_config.MOUNTPOINT+"/etc.old/shadow", data_config.MOUNTPOINT+"/etc/shadow") cp_and_log(data_config.MOUNTPOINT+"/etc.old/group", data_config.MOUNTPOINT+"/etc/group") - msg = "Configuring system" + + #configure system + msg = "Configuring system" update_status(msg) progress(98) logging.info("______Configuring system________") cp_and_log("/etc/systemconfig", data_config.MOUNTPOINT+"/etc/systemconfig") - if not backup_sql_check(): - upgrade_mount_search() + #New partition layout, we do not need to search for backup file + #if not backup_sql_check(): + #upgrade_mount_search() + + #check fstab, see if it needs any updates fstab_it("upgrade") time.sleep(1) + + special_hardware_check() + + mount_bind_chroot() grub_it() + umount_bind_chroot() + genlocale() time.sleep(1) - #needed to get around a bug with pacman - special_hardware_check() + + cp_and_log("/root/xorg.conf.install", data_config.MOUNTPOINT+"/etc/X11/xorg.conf.install") + #this was needed to get around a pacman bug cp_and_log("/etc/mtab", data_config.MOUNTPOINT+"/etc/mtab") + if clean_upgrade() or os.path.exists("/tmp/etc/KnoppMyth-version"): logging.debug("clean upgrade or knoppmyth upgrade detected, running restore settings") restore_default_settings() @@ -1372,53 +1918,69 @@ def upgrade(hostoptions): file = "%s/%s/.kmupgrade" %(data_config.MOUNTPOINT, data_config.MYTHHOME) cmd = "touch %s && chmod 777 %s" %(file, file) runcmd(cmd) + + #these are also run by restore_default_settings in install copy_updates() fix_permissions() + mount_bind_chroot() - logging.info("Running systemconfig in chroot") - #cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT) - cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) - rc = runcmd(cmd)[0] - if rc != 0 : - error_out("Running systemconfig") - mysqldb("stop", "") + apply_new_auth() + umount_bind_chroot() + + + #logging.info("Running systemconfig in chroot") + #cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Running systemconfig") + #mysqldb("stop", "") + if ( systemconfig["SystemType"] == "Master_backend" or systemconfig["SystemType"] == "Standalone" ): - if clean_upgrade() or not backup_sql_check(): + if clean_upgrade(): + mysqldb("stop", "") + mount_bind_chroot() logging.info("Installing new database") - cmd = " chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) - else: - logging.info("Restoring database") - cmd = " chroot %s %s/bin/restore_km_db_chroot.sh %s|tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT, hostoptions["backupfile"]) + cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + umount_bind_chroot() + + #if clean_upgrade() or not backup_sql_check(): + #logging.info("Installing new database") + #cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) + #else: + #logging.info("Restoring database") + #cmd = "chroot %s %s/bin/restore_km_db_chroot.sh %s|tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT, hostoptions["backupfile"]) + #runcmd(cmd) + + #if os.path.exists("/tmp/etc/KnoppMyth-version"): + #cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t hostsettings " %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) + #logging.debug("Correcting permissions because of km->linhes upgrade") + #cmd = "chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) + #runcmd(cmd) + #cmd = "chown -R root:root %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT+"/backup") + #runcmd(cmd) + #else: + #cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) - if os.path.exists("/tmp/etc/KnoppMyth-version"): - cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t hostsettings " %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) - logging.debug("Correcting permissions because of km->linhes upgrade") - cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) - runcmd(cmd) - cmd = " chown -R root:root %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT+"/backup") - runcmd(cmd) - else: - cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) - - logging.info("Running systemconfig in chroot 2nd time") - #cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT) + #run systemconfig in chroot + mount_bind_chroot() + #make symlink only..no need to double_mount as fstab should already have that, unless it's a clean upgrade + double_mount(upgrade=True) + logging.info("Running systemconfig in chroot") cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) rc = runcmd(cmd)[0] if rc != 0 : error_out("Running systemconfig") - #logging.info("Running systemconfig in chroot") - #cmd = " chroot %s %s/bin/systemconfig.sh advanced" %(data_config.MOUNTPOINT, MVROOT) - #runcmd(cmd) - mysqldb("stop", 'chroot') - apply_new_auth() - kill_dhcp_chroot() umount_bind_chroot() + kill_dhcp_chroot() + + cp_and_log("/tmp/mythvantage_install.log", data_config.MOUNTPOINT+"/var/log/mythvantage_install.log") cp_and_log("/tmp/mv_debug.log", data_config.MOUNTPOINT+"/var/log/mv_debug.log") + unmount_it() msg = "Done" update_status(msg) @@ -1428,14 +1990,38 @@ def upgrade(hostoptions): def main(argv): + print install_conf global hostoptions + hostoptions = {} + conflist=["op", + "rootdisk","rootfs","rootsize", + "datafs","datasize","datadisk","datapartition", + "swapsize", + "homesize","homefs", + "sqlsize","sqlfs", + "uprootfs"] + + for i in conflist: + try: + hostoptions[i] = install_conf[i].lower() + except: + pass + try: #op is not set for find_upgrade + if hostoptions["op"] == "upgrade": + #rootfs is used by both upgrade and install + hostoptions["rootfs"] == hostoptions["uprootfs"] + except: + pass + + + try: opts, args = getopt.getopt(argv, 'c:h', ["help", "rootdisk=", "rootfs=", "rootsize=", "datafs=", "datasize=", "datadisk=", "swapsize=", "datapartition=" ] ) except getopt.GetoptError, why: print why usage() sys.exit(2) - hostoptions = {"op": 'null'} + #hostoptions = {"op": 'null'} for opt, arg in opts: if opt in ("-h", "--help"): usage() @@ -1465,24 +2051,51 @@ def main(argv): sys.exit(2) else: hostoptions["op"] = arg - try: - hostoptions["datadisk"] - except: - hostoptions["datadisk"] = hostoptions["rootdisk"] - hostoptions["datapartition"] = hostoptions["datadisk"]+str(3) - try: - hostoptions["datapartition"] - except: - hostoptions["datapartition"] = hostoptions["datadisk"]+str(3) - hostoptions["swappartition"] = hostoptions["rootdisk"] + str(2) + + validop = ["full_install", "upgrade", "netboot", "find_upgrade"] + if hostoptions["op"] not in validop: + logging.critical("-c %s is not a valid option", hostoptions["op"]) + sys.exit(2) + + + + if ( hostoptions["op"] == "upgrade") or ( hostoptions["op"] == "find_upgrade" ): + hostoptions["datafs"] = "no_format" + hostoptions["homefs"] = "no_format" + hostoptions["sqlfs"] = "no_format" + + #hardcoding partitions + hostoptions["rootpartition"] = hostoptions["rootdisk"]+str(1) ##hardcoded partition 1 + hostoptions["swappartition"] = hostoptions["rootdisk"] + str(2) + + try: + hostoptions["datadisk"] + except: + hostoptions["datadisk"] = hostoptions["rootdisk"] + #home/sql do not needed to be valid values for the upgrade, but using real values for reference + try: + hostoptions["home_partition"] + except: + hostoptions["home_partition"] = hostoptions["rootdisk"]+str(5) + + try: + hostoptions["sql_partition"] + except: + hostoptions["sql_partition"] = hostoptions["rootdisk"]+str(6) + + try: + hostoptions["datapartition"] + except: + hostoptions["datapartition"] = hostoptions["datadisk"]+str(7) if ( hostoptions["op"] == "full_install" ) : full_install(hostoptions) + elif (hostoptions["op"] == "upgrade" ) : - hostoptions["datafs"] = "no_format" find_upgrade() upgrade(hostoptions) + elif (hostoptions["op"] == "find_upgrade" ) : find_upgrade() return hostoptions @@ -1531,6 +2144,27 @@ for line in config_file: val = val.strip('"') systemconfig[var.strip()] = val.strip() +#Read in install_conf +global install_conf +install_conf = {} +file_name = "/etc/install_layout" +try: + config_file = open(file_name) +except: + logging.debug("%s could not be opened", file_name) + config_file = '' + +for line in config_file: + line = line.strip() + if line and line[0] is not "#" and line[-1] is not "=": + var, val = line.rsplit("=", 1) + val = val.strip('"') + install_conf[var.strip()] = val.strip() + + + + + if __name__ == "__main__": config_file = "mv_config" diff --git a/abs/core/LinHES-config/mv_ir.py b/abs/core/LinHES-config/mv_ir.py index 36f7545..d77f64f 100755 --- a/abs/core/LinHES-config/mv_ir.py +++ b/abs/core/LinHES-config/mv_ir.py @@ -56,14 +56,19 @@ def add_module(filename,module): cmd = ''' echo "%s" >> %s ''' %(module,filename) mv_common.runcmd(cmd) -def unload_all_lirc(): - logging.debug(" Unloading all remote modules") - cmd = "sv stop remotes" - mv_common.runcmd(cmd) - cmd = "killall -9 lircd" - mv_common.runcmd(cmd) - cmd = '''modprobe -r $(lsmod |grep ^lirc |awk '{print $1}') ''' - mv_common.runcmd(cmd) +def unload_all_lirc(Remotetype, this_is_install): + if this_is_install == False: + logging.debug(" Unloading all remote modules") + #ati bucket specific + if "snapstream_firefly" in Remotetype : + cmd = "rmmod ati_remote" + mv_common.runcmd(cmd) + cmd = "sv stop remotes" + mv_common.runcmd(cmd) + cmd = "killall -9 lircd" + mv_common.runcmd(cmd) + cmd = '''modprobe -r $(lsmod |grep ^lirc |awk '{print $1}') ''' + mv_common.runcmd(cmd) @@ -80,12 +85,12 @@ def include_file( incfile,filename): f.write("\n") f.close() -def setup_ir_remote(Remotetype,templates,mythhome,HostBlasterType): +def setup_ir_remote(Remotetype,templates,mythhome,HostBlasterType,remotebucket): logging.debug(" Setup of remote type %s",Remotetype) if Remotetype == "no_remote" and HostBlasterType == "None" : mv_common.remove_service("remotes") elif Remotetype == "tinker": - pass + pass #do nothing else: currenttime = strftime("%b-%d-%Y-%H:%M:%S", localtime()) cmd = "mv /etc/lircd.conf /etc/lircd.conf-%s" %currenttime @@ -94,65 +99,58 @@ def setup_ir_remote(Remotetype,templates,mythhome,HostBlasterType): mv_common.runcmd(cmd) cmd = "mv /etc/remote.run /etc/remote.run-%s" %currenttime mv_common.runcmd(cmd) - - - if os.path.isdir(mythhome+"/remotes/"+Remotetype): - logging.debug(" Found remote in home dir " ) - #search home dir - files = mythhome + "/remotes/" + Remotetype + "/lircd*" - logging.debug(" Using %s",files) - for filename in glob.glob(files): - # Ignore subfolders - if os.path.isdir (filename): - logging.debug(" %s is a dir, skipping",filename) - continue - include_file("/etc/lircd.conf",filename) - files = mythhome + "/remotes/" + Remotetype + "/lircrc*" - logging.debug(" Using %s",files) - for filename in glob.glob(files): - # Ignore subfolders - if os.path.isdir (filename): - logging.debug(" %s is a dir, skipping",filename) - continue - include_file("/etc/lircrc",filename) - files = mythhome + "/remotes/" + Remotetype + "/remote.run*" - logging.debug(" Using %s",files) - for filename in glob.glob(files): - # Ignore subfolders - if os.path.isdir (filename): - logging.debug(" %s is a dir, skipping",filename) - continue - cmd = "cp %s /etc/remote.run" %filename - mv_common.runcmd(cmd) + if remotebucket == "user": + remote_path = "%s/remotes/%s" %(mythhome,Remotetype) else: - #template dir - files = templates + "/remotes/" + Remotetype + "/lircd*" - logging.debug(" Using %s",files) - for filename in glob.glob(files): - # Ignore subfolders - if os.path.isdir (filename): - logging.debug(" %s is a dir, skipping",filename) - continue - include_file("/etc/lircd.conf",filename) - files = templates + "/remotes/" + Remotetype + "/lircrc*" - logging.debug(" Using %s",files) - for filename in glob.glob(files): - # Ignore subfolders - if os.path.isdir (filename): - logging.debug(" %s is a dir, skipping",filename) - continue - include_file("/etc/lircrc",filename) - files = templates + "/remotes/" + Remotetype + "/remote.run*" - logging.debug(" Using %s",files) - for filename in glob.glob(files): - # Ignore subfolders - if os.path.isdir (filename): - logging.debug(" %s is a dir, skipping",filename) - continue - cmd = "cp %s /etc/remote.run" %filename - mv_common.runcmd(cmd) + remote_path="%s/remotes/%s/%s" %(templates,remotebucket,Remotetype) + + files = remote_path + "/lircd*" + logging.debug(" Using %s",files) + # /etc/lircd.conf include + for filename in glob.glob(files): + # Ignore subfolders + if os.path.isdir (filename): + logging.debug(" %s is a dir, skipping",filename) + continue + include_file("/etc/lircd.conf",filename) + #files = templates + "/remotes/" + Remotetype + "/lircrc*" + + # inluce lircrc + files = remote_path + "/lircrc*" + logging.debug(" Using %s",files) + for filename in glob.glob(files): + # Ignore subfolders + if os.path.isdir (filename): + logging.debug(" %s is a dir, skipping",filename) + continue + include_file("/etc/lircrc",filename) + + #if remote has a special run file use it. + files = remote_path + "/remote.run*" + logging.debug(" Using %s",files) + for filename in glob.glob(files): + # Ignore subfolders + if os.path.isdir (filename): + logging.debug(" %s is a dir, skipping",filename) + continue + cmd = "cp %s /etc/remote.run" %filename + mv_common.runcmd(cmd) + + #remote has it's own modprobe.d/conf filename + cmd = "rm -f /etc/modprobe.d/mv_ir.conf" + mv_common.runcmd(cmd) + files = remote_path + "/ir.conf*" + logging.debug(" Using %s",files) + for filename in glob.glob(files): + # Ignore subfolders + if os.path.isdir (filename): + logging.debug(" %s is a dir, skipping",filename) + continue + cmd = "cp %s /etc/modprobe.d/mv_ir.conf" %filename + mv_common.runcmd(cmd) + #cleanup cmd = "chmod 755 /etc/lircrc /etc/remote.run" mv_common.runcmd(cmd) mv_common.add_service("remotes") @@ -160,7 +158,7 @@ def setup_ir_remote(Remotetype,templates,mythhome,HostBlasterType): def setup_ir_receiver(ReceiverType,TEMPLATES,HDHRlirc_device,myip): logging.info(" Configuring receiver %s", ReceiverType) - if ReceiverType == "Serial": + if ReceiverType == "serial": scrub_modules("/etc/modules.mythvantage","lirc") add_module("/etc/modules.mythvantage","lirc_serial #lirc") cmd = "load-modules-mythvantage.sh" @@ -187,6 +185,7 @@ def setup_ir_receiver(ReceiverType,TEMPLATES,HDHRlirc_device,myip): mv_common.runcmd(cmd) mv_common.remove_service("igdaemon") mv_common.remove_service("tatir") + elif ReceiverType == "pvr150": scrub_modules("/etc/modules.mythvantage","lirc") add_module("/etc/modules.mythvantage","lirc_i2c #lirc") @@ -211,10 +210,14 @@ def setup_ir_receiver(ReceiverType,TEMPLATES,HDHRlirc_device,myip): elif ReceiverType == "SiliconDust_HDHR": mv_common.remove_service("igdaemon") mv_common.remove_service("tatir") - cmd = '''hdhomerun_config %s set /ir/target %s:5000 store''' %(HDHRlirc_device,myip) + cmd = '''hdhomerun_config %s set /ir/target "%s:5000 no_clear"''' %(HDHRlirc_device,myip) + print cmd + mv_common.runcmd(cmd) + cmd = '''hdhomerun_config %s set /ir/target "%s:5000 store"''' %(HDHRlirc_device,myip) print cmd mv_common.runcmd(cmd) + else: logging.debug(" didn't match receiver, using genric case") scrub_modules("/etc/modules.mythvantage","lirc") @@ -239,7 +242,7 @@ def setup_blaster_proto(HostBlasterType,Hostnumblaster,TEMPLATES,systemconfig): include_file("/etc/lircd.conf",template) else: logging.debug(" template: %s is not present",template) - logging.info("------NEED TO SETUP CHANGE_CHANNEL------") + def setup_blaster_transmiter(HostBlasterType): @@ -252,7 +255,9 @@ def setup_blaster_transmiter(HostBlasterType): if HostBlasterType == "no blaster": scrub_modules("/etc/modules.mythvantage","blaster") - elif HostBlasterType == "Serial": + elif HostBlasterType == "iguanaIR-usb": + mv_common.add_service("igdaemon") + elif HostBlasterType == "serial": scrub_modules("/etc/modules.mythvantage","blaster") add_module("/etc/modules/.mythvantage","lirc_serial #blaster") cmd = "load-modules-mythvantage.sh" @@ -269,7 +274,7 @@ def setup_blaster_transmiter(HostBlasterType): else: scrub_modules("/etc/modules.mythvantage","blaster") -def setup_lcd(LCDtype, TEMPLATES, Remotetype): +def setup_lcd(LCDtype, TEMPLATES, Remotetype, this_is_install): logging.debug("____Start of setup_lcd____") logging.debug(" LCDType: %s", LCDtype) logging.debug(" Remotetype: %s", Remotetype) @@ -282,8 +287,9 @@ def setup_lcd(LCDtype, TEMPLATES, Remotetype): cmd = "sv stop lcdd" mv_common.runcmd(cmd) #sometimes it doesn't want to die - cmd = "killall -9 LCDd" - mv_common.runcmd(cmd) + if this_is_install == False: + cmd = "killall -9 LCDd" + mv_common.runcmd(cmd) cmd = "load-modules-mythvantage.sh UNLOAD LCD" mv_common.runcmd(cmd) scrub_modules("/etc/modules.mythvantage", "LCD") @@ -332,7 +338,7 @@ def setup_lcd(LCDtype, TEMPLATES, Remotetype): mv_common.restart_service("lcdd") logging.debug("__End of setup_lcd") -def setup_ir(systemconfig, data_config): +def setup_ir(systemconfig, data_config, this_is_install): rc = [ False , False ] if mv_common.read_config(mv_common.module_config,"ir") == False : logging.info("____Skipping of IR, config disabled____") @@ -355,7 +361,10 @@ def setup_ir(systemconfig, data_config): else: remotetype = systemconfig.get("Remotetype") - setup_ir_remote(remotetype,systemconfig.get("TEMPLATES"),data_config.MYTHHOME,systemconfig.get("HostBlasterType")) + setup_ir_remote(remotetype,systemconfig.get("TEMPLATES"), + data_config.MYTHHOME, + systemconfig.get("HostBlasterType"), + systemconfig.get("Remotebucket")) setup_lirc_links(data_config.MYTHHOME) if systemconfig.get("ReceiverType"): @@ -365,7 +374,7 @@ def setup_ir(systemconfig, data_config): systemconfig.get("mythip")) else: setup_ir_receiver("unknown", systemconfig.get("TEMPLATES"),'','127.0.0.1') - unload_all_lirc() + unload_all_lirc(remotetype, this_is_install) setup_blaster_proto(HostBlasterType, Hostnumblaster, systemconfig.get("TEMPLATES"), @@ -381,7 +390,8 @@ def setup_ir(systemconfig, data_config): if systemconfig.get("LCDtype"): setup_lcd(systemconfig.get("LCDtype"), systemconfig.get("TEMPLATES"), - systemconfig.get("Remotetype")) + systemconfig.get("Remotetype"), + this_is_install) else: logging.debug(" LCD not defined") logging.info("__End IR\n") diff --git a/abs/core/LinHES-config/mv_locale.py b/abs/core/LinHES-config/mv_locale.py new file mode 100644 index 0000000..973be31 --- /dev/null +++ b/abs/core/LinHES-config/mv_locale.py @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os, re +config_file = "mv_config" + +lan_map = {'bg':'bg_BG', + 'cs':'cs_CZ', + 'da':'da_DK', + 'de':'de_DE', + 'el':'el_GR', + 'en_ca':'en_CA', + 'en_ca':'en_CA', + 'en_gb':'en_US', + 'en_GB':'en_US', + 'en_us':'en_US', + 'es_es':'es_ES', + 'es':'es_ES', + 'et':'et_EE', + 'fi':'fi_FI', + 'fr':'fr_FR', + 'he':'he_IL', + 'hr':'hr_HR', + 'hu':'hu_HU', + 'it':'it_IT', + 'ja':'ja_JP', + 'nb':'nb_NO', + 'nl':'nl_NL', + 'pl':'pl_PL', + 'pt_br':'pt_BR', + 'pt':'pt_PT', + 'ru':'ru_RU', + 'sv':'sv_SE', + 'zh_cn':'zh_CN', + 'zh_hk':'zh_HK' } + + +def genlocale(locale_list): + logging.info(" Generating locales") + localefile="/etc/locale.gen" + f = open(localefile) + lines = f.readlines() + f.close() + + f = open(localefile,'w') + + for line in lines: + outline = line + for locale in locale_list: + #print locale, line + if locale in line: + outline = line.replace('#','') + f.write(outline) + f.close() + cmd = "/usr/sbin/locale-gen" + mv_common.runcmd(cmd) + + +def update_locale_conf(locale): + logging.info(" Updating /etc/locale.conf") + line='''LOCALE="%s"''' %locale + try: + f = open('/etc/locale.conf',"w") + f.write(line) + f.write("\n") + f.close() + except: + logging.debug("* couldn't update /etc/locale.conf") + + +def setup_locale(systemconfig): + logging.info("____Start of locale/lang config ____") + + if mv_common.read_config(mv_common.module_config,"lang") == False : + logging.info("____Skipping of lang, config disabled____") + return + + try: + language = systemconfig.get("language").lower() + except: + language = "en_us" + + try: + locale = lan_map[language]+".UTF-8" + except: + locale = "en_US.UTF-8" + logging.info(" locale is: %s" %locale) + + genlocale([locale]) + update_locale_conf(locale) + diff --git a/abs/core/LinHES-config/mv_misc.py b/abs/core/LinHES-config/mv_misc.py index 0cbf872..d03bdca 100755 --- a/abs/core/LinHES-config/mv_misc.py +++ b/abs/core/LinHES-config/mv_misc.py @@ -44,48 +44,19 @@ def setup_tz(timezone,TEMPLATES): os.symlink(srclink,"/etc/localtime") except: logging.critical(" Couldn't make symlink for /etc/localtime") - cmd = '''sed -e "s/^TIMEZONE=.*$/TIMEZONE=\\"%s\\" /" /etc/rc.conf > $TEMPLATES/rc.conf''' %re.escape(timezone) - mv_common.runcmd(cmd) + + #cmd = '''sed -e "s/^TIMEZONE=.*$/TIMEZONE=\\"%s\\" /" /etc/rc.conf > $TEMPLATES/rc.conf''' %re.escape(timezone) + #mv_common.runcmd(cmd) if os.path.exists("/etc/php/php.ini"): logging.info(" Changing timezone for php") cmd = '''sed -i "s/^.*date.timezone.*$/date.timezone=%s/" ${BASE}/etc/php/php.ini''' %re.escape(timezone) mv_common.runcmd(cmd) - mv_common.cp_and_log(TEMPLATES+"/rc.conf","/etc/rc.conf") + #mv_common.cp_and_log(TEMPLATES+"/rc.conf","/etc/rc.conf") logging.info("__End of timezone\n") -def setup_nfs(systemconfig): - nfslist=[] - logging.info("____Start of setup_nfs____") - scrubnfs(systemconfig.get("TEMPLATES")) - - if systemconfig.get("HaveCentralNFS") == "yes": - logging.debug(" Using a Central NFS server") - if systemconfig.get("NFSserver") == "file:nfsmap": - #if it's a file check for it, failure results in downloading attempt from MBE - nfsmap_file=data_config.MYTHHOME+"/templates/nfsmap" - if not os.path.exists(nfsmap_file): - logging.debug(" Couldn't find local %s",nfsmap_file) - logging.info(" Trying to download nfsmap from MBE") - nfsmap_file = download_nfsmap(systemconfig.get("dbhost")) - nfslist = process_nfsmap_file(nfsmap_file) - # if it's an ip parse ip and download file - elif re.search(systemconfig.get("NFSserver"),":nfsmap"): - ip=systemconfig.get("NFSserver").split(":")[0] - nfsmap_file = download_nfsmap(ip) - nfslist = process_nfsmap_file(nfsmap_file) - #else treat it as a single mount point - else: - item = (systemconfig.get("NFSserver") , systemconfig["NFSmount"]) - nfslist.append(item) - else: - #if standalone or slave try to use MBE - if systemconfig.get("SystemType") == "Frontend_only" or systemconfig["SystemType"] == "Slave_Backend": - item = (systemconfig.get("dbhost")+":"+ data_config.DATAMOUNT, data_config.DATAMOUNT) - nfslist.append(item) - setup_nfs_fstab(nfslist) - logging.info("__End of nfs\n") + def setup_sleep(systemconfig): logging.debug("____Setting up sleep____") @@ -114,67 +85,3 @@ def setup_sleep(systemconfig): logging.debug("__End of sleep\n") -def process_nfsmap_file(mapfile): - logging.debug(" processing nfsmap file %s",mapfile) - nfslist = [] - try: - f = open(mapfile,"r") - for line in f.readlines(): - if line.startswith("#"): - continue - item = line.split() - if len(item) <= 1 : - continue - logging.debug(" %s",item) - nfslist.append(item) - except : - logging.critical("Couldn't read file %s, or some other error",mapfile) - return nfslist - -def scrubnfs(templates): - logging.info(" Scrubbing nfs") - mv_common.cp_and_log("/etc/fstab",templates+"/fstab.conf.template") - #used this sed cmd because it's clean and took me forever to figure out =) - cmd='''sed '/^#STARTSCRUB.*$/,/^#ENDSCRUB.*$/d' %s/fstab.conf.template > /etc/fstab''' %templates - mv_common.runcmd(cmd) - -def download_nfsmap(ip): - nfsmap_file="/tmp/nfsmap" - myurl="http://%s:1337/templates/nfsmap" %ip - req = Request(myurl) - try: - f = urlopen(req) - logging.info(" downloading %s", myurl) - local_file = open(nfsmap_file, "w") - #Write to our local file - local_file.write(f.read()) - local_file.close() - #handle errors - except HTTPError, e: - logging.info(" File download failed") - logging.debug(" %s", myurl) - logging.debug(" HTTP Error: %s", e.code) - except URLError, e: - logging.info(" File download failed") - logging.debug(" %s",myurl) - logging.debug(" URL Error: %s ", e.reason) - - return nfsmap_file - -def setup_nfs_fstab(nfslist): - logging.info(" Adding nfs paths to fstab") - try: - f = open('/etc/fstab', 'a') - line = "#STARTSCRUB --------------anything in this block will be scrubbed\n" - f.write(line) - for s, m in nfslist: - line = "%s %s nfs \n" %(s,m) - logging.debug(" %s",line) - f.write(line) - line = "#ENDSCRUB\n" - f.write(line) - f.close() - except: - logging.critical(" *Couldn't open /etc/fstab for writing") - logging.debug(" Done adding nfs paths to fstab") - diff --git a/abs/core/LinHES-config/mv_network.py b/abs/core/LinHES-config/mv_network.py index aab1345..f011970 100755 --- a/abs/core/LinHES-config/mv_network.py +++ b/abs/core/LinHES-config/mv_network.py @@ -18,17 +18,32 @@ def setup_MYTH_DHCP(systemconfig): return defaultdhcp def all_interfaces(): - max_possible = 128 # arbitrary. raise if needed. - bytes = max_possible * 32 - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - names = array.array('B', '\0' * bytes) - outbytes = struct.unpack('iL', fcntl.ioctl( - s.fileno(), - 0x8912, # SIOCGIFCONF - struct.pack('iL', bytes, names.buffer_info()[0]) - ))[0] - namestr = names.tostring() - return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] + # read the file /proc/net/dev + ifacelist=[] + returnlist=[] + try: + f = open('/proc/net/dev','r') + # put the content to list + ifacelist = f.read().split('\n') + # close the file + f.close() + # remove 2 lines header + ifacelist.pop(0) + ifacelist.pop(0) + except: + logging.critical(" *Problem reading /proc/net/dev") + + # loop to check each line + for line in ifacelist: + ifacedata = line.replace(' ','').split(':') + # check the data have 2 elements + if len(ifacedata) == 2: + # check the interface is up (Transmit/Receive data) + if int(ifacedata[1]) > 0: + #print ifacedata[0] + returnlist.append(ifacedata[0]) + + return returnlist def get_ip(ifname): logging.debug(" Finding ip address for %s", ifname) @@ -43,12 +58,16 @@ def get_ip(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl( + + ip = socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) + logging.debug(" get_ip ip address is %s", ip) + return ip + def get_default_route(iface): rcroute = "127.0.0.1" f = open ('/proc/net/route', 'r') @@ -484,7 +503,7 @@ def hostname_change_check(systemconfig): logging.debug(" New hostname: %s", newhostname) if oldhostname != newhostname : logging.info(" Changing hostname in database to match new hostname") - cmd ="%s/bin/restore_default_settings.sh -cuhostname -o -h%s" %(mv_root, oldhostname) + cmd ="%s/bin/myth_settings_wrapper.sh -cuhostname -j %s -n %s " %(mv_root, oldhostname, newhostname) mv_common.runcmd(cmd) logging.info(" Changing hostname to %s", newhostname) cmd = "hostname %s" %newhostname @@ -494,6 +513,21 @@ def hostname_change_check(systemconfig): mv_common.stop_service("mythbackend") mv_common.start_service("mythbackend") restartfe = True + mv_common.stop_service("avahi") + mv_common.start_service("avahi") + + + mv_common.stop_service("xymon-client") + mv_common.start_service("xymon-client") + + mv_common.stop_service("funcd") + mv_common.start_service("funcd") + + + + + + else: logging.debug(" old and new hostnames matched, leaving things along") logging.debug(" __End of hostname_change_check") diff --git a/abs/core/LinHES-config/mv_screensaver.py b/abs/core/LinHES-config/mv_screensaver.py index 6a5ce1c..a1d1530 100755 --- a/abs/core/LinHES-config/mv_screensaver.py +++ b/abs/core/LinHES-config/mv_screensaver.py @@ -40,7 +40,7 @@ def mplayer_saver_check (cmd,templatefile): def killxscreensaver(): - logging.info(" Stopping xscreensaver") + logging.info(" Stopping xscreensaver") cmd="xscreensaver-command --exit " mv_common.runcmd(cmd) cmd="killall xscreensaver " @@ -160,6 +160,25 @@ def setup_gnome_screensaver(theme,idletime): logging.info("__End gnome screensaver") +def start_screensaver(screensaver): + logging.info(" Checking if screensaver needs to be started") + if mv_common.check_service("frontend"): + killxscreensaver() + logging.info(" Frontend is running, starting screensaver") + line='''su mythtv -c "DISPLAY=localhost:0 xscreensaver -no-splash 2>&1 > /dev/null &" \n''' + #line='''su mythtv -c "DISPLAY=localhost:0 xscreensaver -no-splash \&" ''' + try: + fout = open("/tmp/cmd.sh", "w") + fout.write(line) + fout.close() + os.chmod("/tmp/cmd.sh",0755) + cmd="/tmp/cmd.sh" + os.system(cmd) + os.remove("/tmp/cmd.sh") + except: + logging.info(" Couldn't start screensaver") + + def setup_screensaver (systemconfig,data_config): @@ -179,6 +198,7 @@ def setup_screensaver (systemconfig,data_config): mv_common.pacremove("gnome-screensaver") setup_x_screensaver(idletime, theme, configfile, templatefile) mplayer_saver_check("/usr/bin/xscreensaver-command -deactivate &",mtemplate) + start_screensaver("xscreensaver") elif screensavertype == "gscreensaver": mv_common.pacinstall("xscreensaver") diff --git a/abs/core/LinHES-config/mv_software.py b/abs/core/LinHES-config/mv_software.py index c803a14..41ca7c7 100755 --- a/abs/core/LinHES-config/mv_software.py +++ b/abs/core/LinHES-config/mv_software.py @@ -1,6 +1,28 @@ # -*- coding: utf-8 -*- import logging, mv_common import os, re +def zoneminder_setup(systemconfig): + logging.info("____Start of mythzoneminder config____") + mv_root = systemconfig.get("MVROOT") + if ( systemconfig.get("SystemType") == "Standalone" or + systemconfig.get("SystemType") == "Master_backend" ): + logging.info(" Adding mythzmserver" ) + #add zoneminder + mv_common.pacinstall("zoneminder") + mv_common.add_service("zoneminder") + mv_common.add_service("mythzmserver") + + #now to add the settings. + cmd = '''%s/bin/myth_settings_wrapper.sh -c ZMCONFIG -h %s -a %s'''%( + mv_root, + systemconfig.get("hostname"), + systemconfig.get("dbhost")) + mv_common.runcmd(cmd) + logging.info("____End of mythzoneminder config____") + + + + def setup_software(systemconfig, data_config): if mv_common.read_config(mv_common.module_config,"software") == False : @@ -17,29 +39,53 @@ def setup_software(systemconfig, data_config): postfix = "-release-fixes" else: postfix = "-svn" -#This section is for MythVantage OS, not LINHES + #This section is for MythVantage OS, not LINHES default_disabled = ("mytharchive", "mythbrowser", "mythnews", "mythgame", "mythweather", "mythzoneminder","mythnetvision" ) default_installed=("mythgallery", "mythmusic") other_pkg=("miro", "mednafen", "romdb", "xine", "dvdcss", "webmin" , "fuppes", "foldingathome", "mythappletrailers", "mythstream", "mupen64") else: - default_disabled = ("mytharchive", "mythbrowser", "mythnews", - "mythgame", "mythweather", - "mythappletrailers", "mythstream", "mythzoneminder","mythnetvision" ) + #this is linhes section + default_disabled = ("mytharchive", + "mythbrowser", + "mythnews", + "mythgame", + "mythweather", + "mythzoneminder", + "mythnetvision" ) + + default_installed=("mythgallery", + "mythmusic") + other_pkg=("romdb", + "snes9x", + "fceux", + "mame", + "mednafen", + "mupen64", + "dolphinemu", + "xe", + "mythappletrailers", + "miro", + "webonlinhes", + "huludesktop", + "dvdcss", + "foldingathome") - default_installed=("mythgallery", "mythmovies", "mythmusic") - other_pkg=("miro", "mednafen", "romdb", "xine", "dvdcss", "webmin", - "fuppes", "foldingathome","mupen64","dolphinemu", - "webonlinhes","huludesktop") for pkg in default_disabled: pkgname=pkg+postfix try: if systemconfig[pkg] == "1": mv_common.pacinstall(pkgname) + if pkgname == "mythzoneminder": + zoneminder_setup(systemconfig) else: mv_common.pacremove(pkgname) + if pkgname == "mythzoneminder": + #should be a conditional check on system type + #but not worth the effort. + mv_common.remove_service("mythzmserver") except: logging.debug(" ERROR-- %s is not defined", pkg) diff --git a/abs/core/LinHES-config/mv_supplemental.py b/abs/core/LinHES-config/mv_supplemental.py index e25465e..2b8bd2f 100644..100755 --- a/abs/core/LinHES-config/mv_supplemental.py +++ b/abs/core/LinHES-config/mv_supplemental.py @@ -20,7 +20,7 @@ def windowmanager(systemconfig): style = "" if style == "1" and windowmanager != "default" : - style = "mythvantage" + style = "enhanced" else: style = "" @@ -31,7 +31,7 @@ def windowmanager(systemconfig): logging.info("__End of windowmanager \n") -def supplemental(systemconfig): +def supplemental(systemconfig,this_is_install = False): logging.info("____Start of supplemental config ____") try: supplemental=systemconfig.get("supplemental") @@ -39,6 +39,11 @@ def supplemental(systemconfig): supplemental = "0" if supplemental == "1": logging.info(" Installing supplemental system\n") + if this_is_install == True: + if os.path.exists('/home/xymon/server'): + cmd='''pacman --noconfirm --dbonly -Sddf xymonserver''' + mv_common.runcmd(cmd) + cmd='''/usr/LH/bin/install_supplemental_service.sh''' mv_common.runcmd(cmd) logging.info("__End of supplemental\n")
\ No newline at end of file diff --git a/abs/core/LinHES-config/mv_vnc.py b/abs/core/LinHES-config/mv_vnc.py new file mode 100755 index 0000000..0260494 --- /dev/null +++ b/abs/core/LinHES-config/mv_vnc.py @@ -0,0 +1,133 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os, re + +config_file = "mv_config" + +def setupvnc_system(systemconfig,data_config): + logging.info("____Start of vnc setup____") + mv_common.pacinstall("tigervnc") + vncdir=data_config.VNCHOME+"/.vnc" + try: + os.makedirs(vncdir) + os.chown(vncdir,78,78) + except: + logging.info(" couldn't create vnc dir:%s" %vncdir) + + vncfile="%s/xstartup" %vncdir + file_contents=''' +#!/bin/bash +xhost + localhost +xhost + 127.0.0.1 +vncconfig -iconic & +if [ ! -e ~GNUstep ] +then + wmaker.inst + cp -f /usr/share/wm_data/GNUstep/Defaults/WindowMaker ~/GNUstep/Defaults/ + cp -f /usr/share/wm_data/GNUstep/Defaults/WMState.vnc ~/GNUstep/Defaults/WMState + cp -f /usr/share/wm_data/GNUstep/Defaults/WMWindowAttributes ~/GNUstep/Defaults/ + cp -f /usr/share/wm_data/GNUstep/Defaults/WMRootMenu ~/GNUstep/Defaults/ +fi +exec wmaker +''' + try: + logging.debug(" Writing %s",vncfile) + f= open(vncfile,'w') + f.write(file_contents) + f.close() + os.chmod(vncfile,0755) + + except: + logging.debug(" Couldn't open %s",vncfile) + logging.debug(" Aborting vnc...") + + try: + vncuid = pwd.getpwnam('vncsvc')[2] + vncgid = pwd.getpwnam('vncsvc')[3] + except: + logging.critical("* vncsvc not found") + vncuid = '78' + vncgid = '78' + + + cmd="setfacl -m u:vncsvc:x %s" %data_config.MYTHHOME + mv_common.runcmd(cmd) + + srcmyth="%s/.mythtv" %data_config.MYTHHOME + destmyth="%s/.mythtv" %data_config.VNCHOME + + mv_common.link_file(srcmyth,destmyth) + + + + #mv_common.mkdir_mythhome(data_config.VNCHOME,vncuid,vncgid) + #home_xml_file=data_config.VNCHOME + "/.mythtv/config.xml" + #configxml_file="/usr/share/mythtv/config.xml" + #mv_common.link_file(configxml_file,home_xml_file) + + logging.info(" Writing out password") + vncpassfile="%s/passwd" %vncdir + cmd="echo %s|vncpasswd -f > %s" %(systemconfig.get("vncpassword"),vncpassfile) + mv_common.runcmd(cmd) + cmd="chmod 700 %s" %vncpassfile + mv_common.runcmd(cmd) + cmd="chown vncsvc %s" %vncpassfile + mv_common.runcmd(cmd) + + + + logging.info("__End of vnc \n") + + +def start_xvnc(xvncpasswd): + logging.info(" Checking if x11vnc needs to be started") + if mv_common.check_service("frontend"): + logging.info(" Frontend is running, starting x11vnc") + line='''su mythtv -c "DISPLAY=localhost:0 x11vnc -rfbport 5902 --passwd %s 2>&1 > /dev/null &" \n''' %xvncpasswd + #line='''su mythtv -c "DISPLAY=localhost:0 xscreensaver -no-splash \&" ''' + try: + fout = open("/tmp/cmd.sh", "w") + fout.write(line) + fout.close() + os.chmod("/tmp/cmd.sh",0755) + cmd="/tmp/cmd.sh" + os.system(cmd) + os.remove("/tmp/cmd.sh") + except: + logging.info(" Couldn't start x11vnc") + + +def setupvnc(systemconfig,data_config): + logging.info("____Start of vnc config ____") + if mv_common.read_config(mv_common.module_config,"vnc") == False : + logging.info("____Skipping of vnc, config disabled____") + return + #vncservice + try: + vnc=systemconfig.get("vncenable") + except: + vnc = "0" + + if vnc == "1": + logging.info(" Installing vnc system\n") + setupvnc_system(systemconfig,data_config) + mv_common.add_service("vnc") + else: + mv_common.remove_service("vnc") + #x11vnc + try: + xvnc=systemconfig.get("xvncenable") + xvncpasswd=systemconfig.get("xvncpassword") + except: + xvnc = "0" + xvncpassword="LinHES" + + if xvnc == "1": + logging.info(" Installing x11vnc system\n") + mv_common.pacinstall("x11vnc") + start_xvnc(xvncpasswd) + else: + mv_common.pacinstall("x11vnc") + + + logging.info("__End of vnc\n")
\ No newline at end of file diff --git a/abs/core/LinHES-config/mv_webuser.py b/abs/core/LinHES-config/mv_webuser.py index 3e383f2..e349e0b 100755 --- a/abs/core/LinHES-config/mv_webuser.py +++ b/abs/core/LinHES-config/mv_webuser.py @@ -8,16 +8,25 @@ def setup_web_auth(UseMythWEB_auth): return logging.info("____Start of setup_web_auth____") + include_file="/etc/gen_light_conf.d/auth.conf" if UseMythWEB_auth == str(1): - #enable auth logging.info(" Enabling authorization for mythweb") - cmd='''sed -i "s/^.*include.*auth-inc.conf.*$/include \\"\/etc\/lighttpd\/auth-inc.conf\\"/g" /etc/lighttpd/lighttpd.conf''' - mv_common.runcmd(cmd) + try: + fo = open(include_file, "w") + out_string='''include "/etc/lighttpd/auth-inc.conf"''' + fo.write(out_string) + fo.close() + except: + logging.info(" Couldn't open auth include file") + else: #disable auth logging.info(" Disabling authorization for mythweb") - cmd='''sed -i "s/^.*include.*auth-inc.conf.*$/#include \\"\/etc\/lighttpd\/auth-inc.conf\\"/g" /etc/lighttpd/lighttpd.conf''' + cmd="rm -f %s" %include_file mv_common.runcmd(cmd) + logging.debug("Running gen_light_include.py") + cmd="/usr/LH/bin/gen_light_include.py" + mv_common.runcmd(cmd) logging.debug("Restarting lighttpd") cmd="sudo sv restart lighttpd" mv_common.runcmd(cmd) diff --git a/abs/core/LinHES-config/myth_settings_wrapper.sh b/abs/core/LinHES-config/myth_settings_wrapper.sh index 33f401f..37d5e33 100644 --- a/abs/core/LinHES-config/myth_settings_wrapper.sh +++ b/abs/core/LinHES-config/myth_settings_wrapper.sh @@ -1,14 +1,15 @@ #!/bin/bash +MYTH_RUN_STATUS="1" . /etc/profile . /etc/systemconfig shopt -s -o nounset -echo $@ >> /tmp/restore.out +echo $@ >> /tmp/wrapper.out #TEMPLATES="/usr/share/templates/settings" TEMPLATES="$TEMPLATES/settings" TABLES="settings keybindings jumppoints" MYTHDBUSER=mythtv MYTHTVPASSWD=mythtv -declare -r OPTSTRING="c:e:t:d:h:s:a:z:Ho" +declare -r OPTSTRING="c:e:t:d:h:s:a:z:Ho:n:j:" Thistemplate="" declare -i OVERRIDE=0 declare -i EVERYTHING=0 @@ -67,7 +68,7 @@ EOF if [ $# -eq 0 ] then echo "Valid options are:" - echo " -c (save|restore|load|uhostname|BECONFIG|ZIP|ACCESSCONTROL)" + echo " -c (save|save-default|restore|load|uhostname|BECONFIG|ZIP|ACCESSCONTROL)" echo " -t (syssettings|hostsettings)" echo " -d databasename" echo " -h hostname" @@ -98,16 +99,27 @@ do then echo "template is syssettings" loadhost=false + elif [ x$Thistemplate = x"hostsettings" ] then echo "template is hostsettings" Thistemplate=syssettings loadhost=true + + elif [ x$Thistemplate = x"distro_default" ] + then + echo "template is distro_default" + loadhost=false + + elif [ x$Thistemplate = x"custom" ] + then + echo "template is custom" else echo "invalid template name" exit 1 fi ;; + d) echo "$SWITCH" "$OPTARG" ARG_ERR if [ $OVERRIDE = 1 ] @@ -140,6 +152,13 @@ do ARG_ERR ZIPCODE=$OPTARG ;; + n) echo "$SWITCH" "$OPTARG" + newhostname=$OPTARG + ;; + + j) echo "$SWITCH" "$OPTARG" + oldhostname=$OPTARG + ;; o) OVERRIDE=1 ;; @@ -152,7 +171,10 @@ case $OPERATION in restore) #used to restore settings from syssettings - if [ -d $TEMPLATES/$Thistemplate ] + if [ x$Thistemplate = "xdistro_default" ] + then + mythutil --restore-settings --groupname distro_default + elif [ -d $TEMPLATES/$Thistemplate ] then mythutil --import-settings --infile $TEMPLATES/$Thistemplate/syssettings.xml --hostname $hostname else @@ -170,18 +192,44 @@ case $OPERATION in ;; - load) - #this loads the distro default file, it's not active by any hosts - mythutil --import-settings --infile $TEMPLATES/$Thistemplate/distro_default.xml + save-default) + #export settings from database to xml file + Thistemplate="system-default" + if [ ! -d $TEMPLATES/$Thistemplate ] + then + mkdir -p $TEMPLATES/$Thistemplate + fi + mythutil --export-settings --outfile $TEMPLATES/$Thistemplate/distro_default.xml --distro-default + ;; + load) + if [ x$Thistemplate = "xcustom" ] + then + define_xml $5 $hostname settings $6 + load_xml $gen_xml > /tmp/load_xml_custom.log + + else + #this loads the distro default file, it's not active by any hosts + Thistemplate="system-default" + mythutil --import-settings --infile $TEMPLATES/$Thistemplate/distro_default.xml + fi + ;; + + ZMCONFIG) + define_xml ${IP_ADDRESS} $hostname settings ZoneMinderServerIP + load_xml $gen_xml + define_xml "6548" $hostname settings ZoneMinderServerPort + load_xml $gen_xml + ;; + BECONFIG) if [ $SYSTEMTYPE = "master" ] then define_xml ${IP_ADDRESS} $hostname settings BackendServerIP - load_xml + load_xml $gen_xml define_xml ${IP_ADDRESS} '' settings MasterServerIP load_xml $gen_xml @@ -192,7 +240,26 @@ case $OPERATION in define_xml ${IP_ADDRESS} $hostname settings BackendServerIP load_xml $gen_xml fi + + + if [ $SYSTEMTYPE = "standalone" ] + then + define_xml "127.0.0.1" $hostname settings BackendServerIP + load_xml $gen_xml + define_xml "127.0.0.1" '' settings MasterServerIP + load_xml $gen_xml + fi + + if [ $SYSTEMTYPE = "frontendonly" ] + then + define_xml '' $hostname settings BackendServerIP + load_xml $gen_xml + fi + + ;; + + ZIP) define_xml $ZIPCODE $hostname settings locale load_xml $gen_xml @@ -221,7 +288,8 @@ case $OPERATION in #used when the hostname is changed. # #call myth_util $oldhostname $hostname - + mythutil --change-hostname --new-host $newhostname --old-host $oldhostname + mythutil --import-settings --infile $TEMPLATES/$Thistemplate/syssettings.xml --hostname $newhostname ;; USERJOBALLOW) echo "UserJOBALLOW callremoved" diff --git a/abs/core/LinHES-config/myth_user_call b/abs/core/LinHES-config/myth_user_call index 0914b03..1b8d315 100644 --- a/abs/core/LinHES-config/myth_user_call +++ b/abs/core/LinHES-config/myth_user_call @@ -1,174 +1,159 @@ -#!/bin/bash +#!/usr/bin/python2 +# -*- coding: utf-8 -*- #Wrapper script to manage USERNAME accounts + web security # myth_USERNAME_all -c add -u USERNAME # myth_USERNAME_all -c delete -u USERNAME # myth_USERNAME_all -c pass -u USERNAME -p pass # myth_USERNAME_all -c web -u USERNAME -p pass -INIT_CHECK=TRUE -FULL_CALL="$@" -function CHROOT_CHECK { - INIT=`ps -p 1 -o comm=` - if [ x$INIT = xrunit ] - then - CHROOT_NEEDED=FALSE - else - CHROOT_NEEDED=TRUE - fi -} - -function store_commands () { - echo "$FULL_CALL" >> /root/myth_user_call.out - chmod 600 /root/myth_user_call.out -} - - -function add_user() { - if [ $CHROOT_NEEDED = TRUE ] - then - echo "calling myth_call_user in chroot to add user" - store_commands - else - echo "adding user $USERNAME" - useradd -m -s /bin/bash $USERNAME -G audio,video,optical,storage,users - usermod -a -G mythtv $USERNAME - - fi - -} - - -function del_user() { - if [ $CHROOT_NEEDED = TRUE ] - then - echo "calling myth_call_user in chroot to delete user" - store_commands - else - echo "removing user $USERNAME" - userdel $USERNAME - fi - -} - - -function pass_change() { - if [ $CHROOT_NEEDED = TRUE ] - then - echo "calling myth_call_user in chroot to change password" - store_commands - else - echo "changing password for $USERNAME" - echo $USERNAME:$PASSWORD | chpasswd - fi - -} - - -function web_security { - - grep -q ${USERNAME}: /etc/lighttpd/lighttpd.user - if [ $? = 0 ] - then - #delete user - sed -i "/${USERNAME}\:/d" /etc/lighttpd/lighttpd.user - fi - echo "${USERNAME}:${PASSWORD}" >> /etc/lighttpd/lighttpd.user - -} - -function ARG_ERR() { - if [ x$OPTARG = "x" ] - then - echo "$SWITCH NEEDS AND ARG" - exit 11 - fi -} - - -function print_help { - - echo "Valid options are:" - echo " -c (add|delete|pass|web)" - echo " -u USERNAMEname" - echo " -p password" - exit 1 -} - -if [ $# -eq 0 ] -then - print_help -fi - -declare -r OPTSTRING="c:u:p:i" -while getopts "$OPTSTRING" SWITCH -do - case $SWITCH in - - c) ARG_ERR - OPERATION=$OPTARG - ;; - u) ARG_ERR - USERNAME=$OPTARG - ;; - p) ARG_ERR - PASSWORD=$OPTARG - ;; - i) INIT_CHECK=FALSE - - esac -done - -if [ $INIT_CHECK = TRUE ] -then - CHROOT_CHECK -else - CHROOT_NEEDED=FALSE -fi - -case $OPERATION in - add) - if [ x$USERNAME = x ] - then - print_help - fi - add_user - ;; - delete) - if [ x$USERNAME = x ] - then - print_help - fi - del_user - ;; - pass) - if [ x$USERNAME = x ] - then - print_help - fi - - if [ x$PASSWORD = x ] - then - print_help - fi - pass_change - ;; - - web) - if [ x$USERNAME = x ] - then - print_help - fi - - - if [ x$PASSWORD = x ] - then - print_help - fi - echo "adding webUSERNAME $USERNAME with pass $PASSWORD" - web_security - ;; - *) print_help - ;; -esac - +import pexpect, sys, time +import os, re, getopt +import mv_common + + + + +def chroot_check(): + if not INIT_CHECK : + return False + cmd = '''ps -p 1 -o comm=''' + init = mv_common.runcmd_output(cmd).strip() + if init == "runit": + return False + else: + return True + + +def store_commands(full_call): + file_name = "/root/myth_user_call.out" + try: + f = open(file_name,'a') + except: + print "%s could not be opened" % file_name + sys.exit(1) + f.write(full_call) + f.write("\n") + f.close() + try: + os.chmod(600,file_name) + except: + pass + + +def add_user(username,full_call): + if chroot_check() : + print "calling myth_call_user in chroot to add user" + store_commands(full_call) + else: + print "Adding user %s" %username + cmd = '''useradd -m -s /bin/bash %s -G audio,video,optical,storage,users''' %username + mv_common.runcmd(cmd) + cmd = ''' usermod -a -G mythtv %s ''' %username + + +def del_user(username,full_call): + if chroot_check() : + print "calling myth_call_user in chroot to del user" + store_commands(full_call) + else: + print "Removing user %s" %username + cmd = '''userdel %s ''' %username + mv_common.runcmd(cmd) + + +def pass_change(username,password,full_call) : + if chroot_check() : + print "calling myth_call_user in chroot to change password" + store_commands(full_call) + else: + print "changing password for %s" %username + passwd = pexpect.spawn("/usr/bin/passwd %s" % username) + + for repeat in (1, 2): + passwd.expect("password: ") + passwd.sendline(password) + time.sleep(0.1) + +def web_security(username,password) : + file_name = "/etc/lighttpd/lighttpd.user" + file_contents = '' + if os.path.exists(file_name): + try: + f = open(file_name,'r') + file_contents = f.readlines() + except: + print " couldn't read %s" % file_name + try: + f = open(file_name,'w') + except: + print "%s could not be opened for writing" % file_name + return + + for line in file_contents: + if not re.search(username, line): + f.write(line) + line = "%s:%s" %(username, password) + f.write(line) + f.write("\n") + f.close() + + +def usage (): + print "Valid options are:" + print " -c (add|delete|pass|web)" + print " -u USERNAME" + print " -p password" + sys.exit(0) + +def main(argv): + global INIT_CHECK + full_call = "" + INIT_CHECK = True + try: + opts, args = getopt.getopt(argv, 'c:u:p:ih' ) + except getopt.GetoptError, why: + print why + usage() + print "exception happened" + sys.exit(2) + + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit(0) + elif opt in ("-c") : + module = arg + full_call += ''' -c %s ''' %re.escape(arg) + elif opt in ("-u") : + username = arg + full_call += ''' -u %s ''' %re.escape(arg) + elif opt in ("-p") : + password = arg + full_call += ''' -p %s ''' %re.escape(arg) + elif opt in ("-i") : + INIT_CHECK = False + full_call += ''' -i ''' + try: + username + except: + usage() + + if module == "add": + add_user(username,full_call) + elif module == "delete": + del_user(username,full_call) + elif module == "pass": + try: + password + except: + print "needs a password" + usage() + pass_change(username,password,full_call) + elif module == "web": + web_security(username,password) + else: + usage() + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/abs/core/LinHES-config/mythvantage.cfg b/abs/core/LinHES-config/mythvantage.cfg index eaa4865..1147d9f 100644 --- a/abs/core/LinHES-config/mythvantage.cfg +++ b/abs/core/LinHES-config/mythvantage.cfg @@ -18,4 +18,7 @@ ir = True user = True software = True smolt = True +vnc = True +fileshare = True +language = True diff --git a/abs/core/LinHES-config/networkconfig.sh b/abs/core/LinHES-config/networkconfig.sh index 770aa98..b044f20 100644 --- a/abs/core/LinHES-config/networkconfig.sh +++ b/abs/core/LinHES-config/networkconfig.sh @@ -206,7 +206,11 @@ function setup_interfaces() { function find_active () { #HostActiveeth1="1" -rm -f ${BASE}/etc/resolv.conf +if [ ! x$USEVNC = x0 ] +then + rm -f ${BASE}/etc/resolv.conf +fi + if [ x$MYTHDHCP = x1 ] then #add 127.0.0.1 to /etc/resolv.conf diff --git a/abs/core/LinHES-config/plymouth_config.py b/abs/core/LinHES-config/plymouth_config.py new file mode 100755 index 0000000..7c7546d --- /dev/null +++ b/abs/core/LinHES-config/plymouth_config.py @@ -0,0 +1,191 @@ +#!/usr/bin/python2 +# -*- coding: utf-8 -*- + +__author__ = "James Meyer" +__date__ = "Dec 11th 2012" + + +import subprocess + + +class plymouth_driver(): + def __init__(self): + self.videocard = self.find_video_card() + self.old_conf = self.read_mkinit() + self.set_old_hook(self.old_conf) + + + def getvc(self): + return self.videocard + + def get_old_hooks(self): + return self.old_hooks + + def get_old_modules(self): + return self.old_modules + + def get_new_hooks(self): + return self.new_hooks + + def get_new_modules(self): + return self.new_modules + + + def set_old_hook(self,conf): + self.old_hooks, self.old_modules = self.find_hooks_modules(conf) + + def find_video_card(self): + videocard="" + conf_file="/etc/X11/xorg.conf.d/20-automv.conf" + lines=[] + try: + f=open(conf_file,'r') + lines=f.readlines() + f.close() + except: + print " find_video_card: couldn't read in %s" %conf_file + videocard = "unknown" + + for line in lines: + parsed=line.split() + if parsed[0].strip() == "Driver": + videocard = parsed[1].strip('''"''') + break + + return videocard + + def read_mkinit(self): + conf_file="/etc/mkinitcpio.conf" + old_conf=[] + try: + f=open(conf_file,'r') + old_conf=f.readlines() + except: + print " plymouth_config: couldn't read %s" %conf_file + sys.exit(1) + return old_conf + + def find_hooks_modules(self,conf_list): + for line in conf_list: + if line.startswith('HOOKS='): + hooks=line.split('''"''')[1].split() + if line.startswith('MODULES='): + modules=line.split('''"''')[1].split() + return hooks,modules + + def add_hooks(self,add_hooks, hooks): + new_hooks = hooks + for i in add_hooks: + if not i in (new_hooks): + new_hooks.append(i) + return new_hooks + + def remove_hooks(self,remove_hooks, hooks): + for i in remove_hooks: + try: + while True: + hooks.remove(i) + except: + pass + + return hooks + + def add_modules(self, add_modules, modules): + new_modules = modules + for i in add_modules: + if not i in (new_modules): + new_modules.append(i) + return new_modules + + + def remove_modules(self,remove_modules, modules): + for i in remove_modules: + try: + while True: + modules.remove(i) + except: + pass + return modules + + def create_new_hooks_modules(self): + new_hooks = list(self.old_hooks) + new_modules = list(self.old_modules) + + add_hooks=[] + remove_hooks=[] + remove_modules=[] + add_modules=[] + + if self.videocard == "intel": + add_modules = ['i915'] + remove_hooks = ['v86d'] + else: + #add_modules = ['nfs','jm'] + remove_modules = ['i915'] + add_hooks = ['v86d'] + + new_hooks = self.add_hooks(add_hooks , new_hooks) + new_hooks = self.remove_hooks(remove_hooks, new_hooks) + new_modules = self.add_modules(add_modules, new_modules) + new_modules = self.remove_modules(remove_modules, new_modules) + + self.new_hooks = new_hooks + self.new_modules = new_modules + + def compare_hooks_modules(self): + h = cmp( self.old_hooks,self.new_hooks) + m = cmp( self.old_modules,self.new_modules) + if h == 0 and m == 0: + return True + else: + return False + + def create_newmkinitcpio(self): + if self.compare_hooks_modules() == True: + print " plymouth_config: no changes made" + + return False + else: + conf_file="/etc/mkinitcpio.conf" + try: + f=open(conf_file,'w') + for line in self.old_conf: + new_line=line + if line.startswith('HOOKS='): + new_line = 'HOOKS="%s"' %(" ".join(self.new_hooks)) + if line.startswith('MODULES='): + new_line = 'MODULES="%s"'%(" ".join(self.new_modules)) + f.write(new_line) + f.write("\n") + f.close() + except: + print " plymouth_config: couldn't write %s" %conf_file + return False + + return True + + def run_mkinitcpio(self): + print " plymouth_config: Running mkinitcpio " + subprocess.call(["/usr/bin/mkinitcpio", "-p" , "linux"]) + + +def go(): + p = plymouth_driver() + vc = p.getvc() + print " plymouth_config: found videocard %s" %vc + p.create_new_hooks_modules() + #print p.get_old_hooks() + #print p.get_new_hooks() + #print "==" + #print p.get_old_modules() + #print p.get_new_modules() + + if p.create_newmkinitcpio() == True: + p.run_mkinitcpio() + + + + +if __name__ == '__main__': + go() + diff --git a/abs/core/LinHES-config/print_xorg_res.py b/abs/core/LinHES-config/print_xorg_res.py new file mode 100755 index 0000000..3b7ce56 --- /dev/null +++ b/abs/core/LinHES-config/print_xorg_res.py @@ -0,0 +1,128 @@ +#!/usr/bin/python2 +# -*- coding: utf-8 -*- + +__author__ = "James Meyer" +__date__ = "August 23rd 2012" + + +from subprocess import Popen, PIPE +import re + +class available_display_res(): + def __init__(self): + + self.mode_list=[] + self.videocard = self.find_video_card() + + if self.videocard == "nvidia": + self.parse_modeline_nvidia() + else: + self.sizes_xrandr() + #elif self.videocard == "intel": + #self.sizes_xrandr() + #elif self.videocard == "vmware": + #self.sizes_xrandr() + #elif self.videocard == "vesa": + #self.sizes_parse_log() + + + def getlist(self): + return self.mode_list + + def getvc(self): + return self.videocard + + def find_video_card(self): + videocard="" + conf_file="/etc/X11/xorg.conf.d/20-automv.conf" + lines=[] + try: + f=open(conf_file,'r') + lines=f.readlines() + f.close() + except: + print " find_video_card: couldn't read in %s" %conf_file + videocard = "unknown" + + for line in lines: + parsed=line.split() + if parsed[0].strip() == "Driver": + videocard = parsed[1].strip('''"''') + break + + return videocard + + def parse_modeline_nvidia(self): + self.mode_list=[] + conf_file="/var/log/Xorg.0.log" + lines=[] + try: + f=open(conf_file,'r') + lines=f.readlines() + f.close() + except: + print " parse_modeline_nvidia: couldn't read in %s" %conf_file + self.mode_list=["Auto"] + #now parse the list looking for modelines + search="Modes in ModePool" + searchindex=[] + for line in lines: + if line.find(search) > 4 : + searchindex.append(lines.index(line)) + search="End of ModePool" + + if len(searchindex) == 2: + break + #extract the modelines + #[ 29.858] (II) NVIDIA(GPU-0): "nvidia-auto-select" : 2560 x 1600 @ 59.9 Hz (from: EDID) + try: + modelines = lines[searchindex[0]+1:searchindex[1]-1] + for i in modelines: + self.mode_list.append(i.split('''"''')[1]) + except: + self.mode_list=["nvidia-auto-select"] + + + def sizes_parse_log(self): + self.mode_list=["parse_log_list"] + + def sizes_xrandr(self): + """List all sizes detected by xrandr, + ordered by the next resolution to cycle to""" + size_re = re.compile("^ ([0-9]*x[0-9]*)\W*[0-9]*\.[0-9]*(\*)?") + p1 = Popen(['xrandr'], stdout=PIPE) + sizes = [] + current_size_index = 0 + for line in p1.communicate()[0].split("\n"): + m = size_re.match(line) + if m: + sizes.append(m.group(1)) + if m.group(2) == "*": + current_size_index = len(sizes) - 1 + #return sizes[current_size_index+1:] + sizes[:current_size_index+1] + self.mode_list = sizes[current_size_index+1:] + sizes[:current_size_index+1] + +def go(): + mode = available_display_res() + vc = mode.getvc() + modelist = mode.getlist() + print vc + + for i in modelist: + print i + conf_file="/tmp/modelines" + try: + f=open(conf_file,'w') + for i in modelist: + f.write(i) + f.write("\n") + f.close() + except: + print " print_xorg_res: couldn't write modelines to %s" %conf_file + + + + +if __name__ == '__main__': + go() + diff --git a/abs/core/LinHES-config/restore_default_settings.sh b/abs/core/LinHES-config/restore_default_settings.sh index ffd4b0d..ca27578 100755 --- a/abs/core/LinHES-config/restore_default_settings.sh +++ b/abs/core/LinHES-config/restore_default_settings.sh @@ -3,6 +3,20 @@ . /etc/systemconfig shopt -s -o nounset echo $@ >> /tmp/restore.out +echo "######################################################" +echo "######################################################" +echo "######################################################" +echo "######################################################" +cat /tmp/restore.out + +exit 0 + + + + + + + #TEMPLATES="/usr/share/templates/settings" TEMPLATES="$TEMPLATES/settings" TABLES="settings keybindings jumppoints" diff --git a/abs/core/LinHES-config/soundconfig.sh b/abs/core/LinHES-config/soundconfig.sh index c268136..b9eb906 100755 --- a/abs/core/LinHES-config/soundconfig.sh +++ b/abs/core/LinHES-config/soundconfig.sh @@ -4,10 +4,14 @@ echo $@ >/tmp/audio.call BASE="" +MYTH_RUN_STATUS="1" . /etc/profile TESTFILE="/usr/share/sounds/alsa/Front_Center.wav" OSSinstalled="false" + BLACKLIST=/etc/modprobe.d/soundconfig_blacklist.conf +. /usr/MythVantage/bin/install_functions.sh +home_check echo "---------------------------------------" @@ -75,7 +79,8 @@ function installOSS { fi soundon add_service.sh oss - echo "install soundcore /bin/false" >$BLACKLIST + echo "blacklist soundcore" > $BLACKLIST + echo "install soundcore /bin/false" >> $BLACKLIST } @@ -83,9 +88,9 @@ function installOSS { function SYNCXINE { echo "modify xine config file" - if [ -f /data/home/mythtv/.xine/config ] + if [ -f $MYTHHOME/.xine/config ] then - cp -f /data/home/mythtv/.xine/config $TEMPLATES/xine.config + cp -f $MYTHHOME/.xine/config $TEMPLATES/xine.config else cp $TEMPLATES/xine.config.template $TEMPLATES/xine.config fi @@ -97,9 +102,9 @@ echo "modify xine config file" -e "s/^.audio.device.oss_device_name.*$/audio.device.oss_device_name:\/dev\/dsp/" \ -e "s/^.audio.devic.oss_device_number.*$/audio.device.oss_device_number:$DEVICENUMER/" \ -e "s/^.*audio.output.speaker_arrangement:.*$/Audio.output.speaker_arrangement:PassThrough/" \ - $TEMPLATES/xine.config > /data/home/mythtv/.xine/config + $TEMPLATES/xine.config > $MYTHHOME/.xine/config else - cp $TEMPLATES/xine.config /data/home/mythtv/.xine/config + cp $TEMPLATES/xine.config $MYTHHOME/.xine/config fi } @@ -135,7 +140,7 @@ function checkOSSinstalled () { } function sound_config_system { - + SYNCMYTHFRONTEND # if [ x$syncXine = x1 ] # then diff --git a/abs/core/LinHES-config/systemconfig.py b/abs/core/LinHES-config/systemconfig.py index 9a9cd11..f7e3f5d 100755 --- a/abs/core/LinHES-config/systemconfig.py +++ b/abs/core/LinHES-config/systemconfig.py @@ -51,6 +51,84 @@ def setup_x(systemconfig): cmd = "%s/bin/xconfig.sh" %systemconfig.get("MVROOT") mv_common.runcmd(cmd) + +def generate_config_xml(uuid,dbhost): + configxml_t =''' +<Configuration> + <UPnP> + <UDN> + <MediaRenderer>%s</MediaRenderer> + </UDN> + <MythFrontend> + <DefaultBackend> + <DBHostName>%s</DBHostName> + <DBUserName>mythtv</DBUserName> + <DBPassword>mythtv</DBPassword> + <DBName>mythconverg</DBName> + <DBPort>0</DBPort> + </DefaultBackend> + </MythFrontend> + </UPnP> +</Configuration> + ''' + configxml= configxml_t %(uuid,dbhost) + return configxml + +def gen_uuid(): + cmd = "/usr/bin/uuidgen" + uuid = mv_common.runcmd_output(cmd) + return uuid + +def setup_config_xml(systemconfig): + #setup mysql.txt and config.xml + logging.info(" setup config xml") + + mv_root = systemconfig.get("MVROOT") + mysqltxt = "/usr/share/mythtv/mysql.txt" + configxml_file = "/usr/share/mythtv/config.xml" + + templates = systemconfig.get("TEMPLATES") + mysqltemplate = templates + "/mysql.txt" + dbhost = systemconfig.get("dbhost") + uuid = gen_uuid() + config_xml=generate_config_xml(uuid,dbhost) + mv_common.mkdir_mythhome(data_config.MYTHHOME,"mythtv","mythtv") + + + + delfile = data_config.MYTHHOME + "/.mythtv/mysql.txt" + mv_common.remove_file(delfile) + delfile = mv_root + "/bin/mythtv/.mythtv/mysql.txt" + mv_common.remove_file(delfile) + filecheck = data_config.MYTHHOME + "/templates/mysql.txt" + if os.path.exists(filecheck): + logging.info(" Scrapping all the previous work and using %s for mysql.txt", filecheck) + mv_common.cp_and_log(filecheck, mysqltxt) + try: + f = open(configxml_file, 'w') + + for outline in config_xml: + f.write(outline) + f.close() + except: + logging.debug(" Couldn't write config.xml") + + home_xml_file=data_config.MYTHHOME + "/.mythtv/config.xml" + mv_common.link_file(configxml_file,home_xml_file) + + #setup link for root user + mv_common.mkdir_mythhome("/root","root","root") + home_xml_file="/root/.mythtv/config.xml" + mv_common.remove_file(home_xml_file) + mv_common.link_file(configxml_file,home_xml_file) + + + + + + + + def main(argv): try: MVROOT = os.environ["MV_ROOT"] @@ -62,7 +140,21 @@ def main(argv): global systemconfig systemconfig["MVROOT"]=MVROOT restartlcd = False - cmdmodule={"misc":False , "sleep":False , "hostype":False , "hostypec":False , "advanced":False , "audio":False , "network":False , "advancedX":False , "webuser":False , "restartfe":False , "reloadfe":False , "ddns":False , "screensaver":False , "ir":False , "this_is_install":False , "user":False, "software":False, "plugins":False, "smolt":False, "all":False, "dhcp_request":False , "func":False, "supplemental":False} + cmdmodule={"misc":False , "sleep":False , + "hostype":False , "hostypec":False , + "advanced":False , "audio":False , + "network":False , "advancedX":False , + "webuser":False , "restartfe":False , + "reloadfe":False , "ddns":False , + "screensaver":False , "ir":False , + "this_is_install":False , + "user":False, "software":False, + "plugins":False, "smolt":False, + "all":False, "dhcp_request":False , + "func":False, "supplemental":False, + "vnc":False, "fileshare":False, + "config_xml":False, + "locale":False } try: opts, args = getopt.getopt(argv, 'c:hm:d:', ["help","modules" ] ) except getopt.GetoptError, why: @@ -85,6 +177,10 @@ def main(argv): systemconfig["hostypec"] = True #cmdmodule["smolt"] = True + if cmdmodule["hostypec"] == True : + cmdmodule["fileshare"] = True + cmdmodule["hostype"] = True + systemconfig["mythip"] = mv_network.setup_MYTH_IP(systemconfig) systemconfig["mythdhcp"] = mv_network.setup_MYTH_DHCP(systemconfig) systemconfig["mythgw"] = mv_network.setup_MYTH_DHCP(systemconfig) @@ -105,15 +201,35 @@ def main(argv): cmdmodule["advanced"] = True cmdmodule["software"] = True cmdmodule["advancedX"] = True - cmdmodule["smolt"] = True + #cmdmodule["smolt"] = True cmdmodule["user"] = True + cmdmodule["vnc"] = True + cmdmodule["fileshare"] = True + cmdmodule["config_xml"] = True + cmdmodule["locale"] = True + + + ##putting this here until I can create the seperate share module + #if cmdmodule["fileshare"]: + #cmdmodule["advanced"] = True + #cmdmodule["misc"] = True if cmdmodule["network"]: restartfe = mv_network.setup_network(systemconfig, cmdmodule["this_is_install"]) + systemconfig["mythip"] = mv_network.setup_MYTH_IP(systemconfig) + systemconfig["mythdhcp"] = mv_network.setup_MYTH_DHCP(systemconfig) + systemconfig["mythgw"] = mv_network.setup_MYTH_DHCP(systemconfig) + systemconfig["mythdns"] = mv_network.setup_MYTH_DHCP(systemconfig) + cmdmodule["hostype"] = True + if restartfe == True : logging.debug(" Setting the frontend to restart due to network change") cmdmodule["restartfe"] = True + if cmdmodule["config_xml"]: + setup_config_xml(systemconfig) + + if cmdmodule["func"]: from mv_hostype import setup_func_minion setup_func_minion(systemconfig.get("dbhost"),systemconfig.get("hostname")) @@ -127,19 +243,19 @@ def main(argv): setup_x(systemconfig) cmdmodule["ir"] = True mv_hostype.hostypeprint(systemconfig) - cmdmodule["smolt"] = True + #cmdmodule["smolt"] = True - if cmdmodule["network"]: - restartfe = mv_network.setup_network(systemconfig, cmdmodule["this_is_install"]) - if restartfe == True : - logging.debug(" Setting the frontend to restart due to network change") - cmdmodule["restartfe"] = True + #if cmdmodule["network"]: + #restartfe = mv_network.setup_network(systemconfig, cmdmodule["this_is_install"]) + #if restartfe == True : + #logging.debug(" Setting the frontend to restart due to network change") + #cmdmodule["restartfe"] = True if cmdmodule["ir"] == True: import mv_ir - restart = mv_ir.setup_ir(systemconfig,data_config) + restart = mv_ir.setup_ir(systemconfig,data_config,cmdmodule["this_is_install"]) restartfe = restart[0] restartlcd = restart[1] if restartfe == True : @@ -177,7 +293,7 @@ def main(argv): #zipcode is no longer used #mv_misc.setup_zip(MVROOT,systemconfig.get("zipcode")) mv_misc.setup_tz(systemconfig.get("timezone"),systemconfig["TEMPLATES"]) - mv_misc.setup_nfs(systemconfig) + #mv_misc.setup_nfs(systemconfig) if cmdmodule["sleep"]: if mv_common.read_config(mv_common.module_config,"sleep") == False : @@ -202,6 +318,11 @@ def main(argv): import mv_advanced mv_advanced.setup_advanced(systemconfig, data_config) + if cmdmodule["fileshare"]: + import mv_fileshare + mv_fileshare.setup_fileshare(systemconfig, data_config) + + if cmdmodule["software"] or cmdmodule["plugins"]: import mv_software mv_software.setup_software(systemconfig, data_config) @@ -218,13 +339,13 @@ def main(argv): if cmdmodule["reloadfe"]: mv_common.reloadfe(systemconfig.get("dbhost"),restartlcd) - if cmdmodule["smolt"]: - import mv_smolt - mv_smolt.setup_smolt_type(systemconfig.get("SystemType"), - systemconfig.get("Remotetype"), - systemconfig.get("RunFrontend"), - data_config.MYTHHOME, - data_config.SYSTEMTYPE) + #if cmdmodule["smolt"]: + #import mv_smolt + #mv_smolt.setup_smolt_type(systemconfig.get("SystemType"), + #systemconfig.get("Remotetype"), + #systemconfig.get("RunFrontend"), + #data_config.MYTHHOME, + #data_config.SYSTEMTYPE) if cmdmodule["user"]: logging.info("____Start of ssh user____") @@ -245,9 +366,19 @@ def main(argv): if cmdmodule["supplemental"] or cmdmodule["this_is_install"]: import mv_supplemental mv_supplemental.windowmanager(systemconfig) - mv_supplemental.supplemental(systemconfig) + mv_supplemental.supplemental(systemconfig,cmdmodule["this_is_install"]) + + if cmdmodule["vnc"]: + import mv_vnc + mv_vnc.setupvnc(systemconfig,data_config) + if cmdmodule["fileshare"]: + import mv_fileshare + mv_fileshare.setup_fileshare(systemconfig, data_config) + if cmdmodule["locale"]: + import mv_locale + mv_locale.setup_locale(systemconfig) if __name__ == "__main__": diff --git a/abs/core/LinHES-config/systemconfig.sh b/abs/core/LinHES-config/systemconfig.sh index dce8c74..76194dd 100755 --- a/abs/core/LinHES-config/systemconfig.sh +++ b/abs/core/LinHES-config/systemconfig.sh @@ -10,16 +10,16 @@ echo "----------------------start of systemconfig $@ ----------------------" . $MV_ROOT/bin/networkconfig.sh postfix=`cat ${BASE}/usr/local/share/mythtv/.releasetype` -for i in larch liblarch larch-profiles larch-live -do - pacman -Q $i - if [ $? == 0 ] - then - pacman -R $i --noconfirm - fi -done - - sed -i '/larch/d' /etc/pacman.conf +# for i in larch liblarch larch-profiles larch-live +# do +# pacman -Q $i +# if [ $? == 0 ] +# then +# pacman -R $i --noconfirm +# fi +# done +# +# sed -i '/larch/d' /etc/pacman.conf systemconfig.py -m $@ rc=$? diff --git a/abs/core/LinHES-config/timezip.py b/abs/core/LinHES-config/timezip.py index 4e494be..eb373b4 100755 --- a/abs/core/LinHES-config/timezip.py +++ b/abs/core/LinHES-config/timezip.py @@ -6,6 +6,26 @@ import MySQLdb import sys import getopt import socket +import urllib2 +socket.setdefaulttimeout(10) + +try: + from json import loads as jsonparse + nojson = False +except ImportError: + try: + from simplejson import loads as jsonparse + nojson = False + except ImportError: + def jsonparse(js): + if unsafe: + return eval(js) + raise RuntimeError("Neither the json or simplejson module is available.\nUse the --unsafe option to use python eval() as an ad-hoc json decoder") + + +def no_update(data): + print "* not updating %s, because a value is already present" %data + def usage(): @@ -14,19 +34,75 @@ def usage(): print " -m --masterdb" print " -n --hostname of current machine" +def latlong2_olsen(lat,lng): + olsenttz = '' + geo_url = "http://api.geonames.org/timezoneJSON?lat=%s&lng=%s&username=linhes_timezone" %(lat,lng) + try: + json_stream = urllib2.urlopen(geo_url,timeout=10) + json_dict = jsonparse(json_stream.read().replace("\r\n","")) + olsenttz = json_dict['timezoneId'] + except: + print "error with geonames" + + return olsenttz + +def geo_locate(): + print " Trying to geo locate in timezip.py" + gtz = '' + gtz_region = '' + gtz_subregion = '' + #get long/lat from ip + try: + geo_url = "http://www.geobytes.com/IpLocator.htm?GetLocation&template=json.txt" + json_stream = urllib2.urlopen(geo_url,timeout=10) + json_dict = jsonparse(json_stream.read().replace("\r\n",""))['geobytes'] + latitude = json_dict['latitude'] + longitude = json_dict['longitude'] + except: + print "error with geobytes/geolocate" + latitude = '' + longitude = '' + + if latitude != '': + try: + olsenttz = latlong2_olsen (latitude,longitude) + gtz = olsenttz + gtz_region , gtz_subregion = olsenttz.split("/") + except: + print "error with geolocate" + + + + return gtz, gtz_region , gtz_subregion + + def printvars(): print "masterdb: " + masterdb print "installdb:" + installdb print "hostname: " + thishostname print "BEhostname:" + BEhostname - print "zipcode:" + zipcode + #print "zipcode:" + zipcode print "timezone:" + tz print "timezone region:" + tz_region print "timezone subregion:" + tz_subregion print "nfsip:" + nfsip print "nfstoggle:" + nfstoggle print "nfsmount:" + nfsmount - print "hobbitclient:" + hobbitclient + print "nfsshare:" + nfsshareall + #print "hobbitclient:" + hobbitclient + print "windowmanager:" + windowmanager + print "windowmanager style:" + wmstyle + print "Gallery Dir:" + gallerydir + print "Music dir:" + musicdir + print "Music template:" + filenametemplate + + for key,value in video_dict.items(): + print "%s: %s" %(key,value) + + print "-----------------------------------" + print "\n\n\n" + + # connect def selectvars(): @@ -38,160 +114,308 @@ def selectvars(): global nfsip global nfstoggle global nfsmount - global hobbitclient + global nfsshareall + #global hobbitclient + global windowmanager + global wmstyle + global musicdir + global gallerydir + global filenametemplate + #video parent level + global video_dict db = MySQLdb.connect(host=masterdb, user="mythtv", passwd="mythtv", db="mythconverg") # create a cursor cursor = db.cursor() # execute SQL statement - cursor.execute("select hostname from settings where value='BackendServerIP' and data=(%s)",(masterdb)) - result = cursor.fetchone() + try: + cursor.execute("select hostname from settings where value='BackendServerIP' and data=(%s)",(masterdb)) + result = cursor.fetchone() BEhostname=result[0] except TypeError: BEhostname="" - cursor.execute("select data from settings where value='HostZipcode' and hostname=(%s)",(BEhostname)) - result = cursor.fetchone() - try: - zipcode = result[0] - except TypeError: - zipcode="" - - cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(BEhostname)) - result = cursor.fetchone() try: + cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() nfsip=result[0] except TypeError: nfsip="" - cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(BEhostname)) - result = cursor.fetchone() try: + cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() nfstoggle=result[0] except TypeError: - nfstoggle="" + nfstoggle="no" + - cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(BEhostname)) - result = cursor.fetchone() try: + cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() nfsmount=result[0] except TypeError: nfsmount="" - cursor.execute("select data from settings where value='HostTimeZone' and hostname=(%s)",(BEhostname)) - result = cursor.fetchone() try: + cursor.execute("select data from settings where value='HostCentralNFSallhosts' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + nfsshareall=result[0] + except TypeError: + nfsshareall="0" + + + + try: + #cursor.execute("select data from settings where value='HostTimeZonetemp' and hostname=(%s)",(BEhostname)) + cursor.execute("select data from settings where value='HostTimeZone' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() tz=result[0] except TypeError: - tz="" -########## - cursor.execute("select data from settings where value='HostTimeZoneRegion' and hostname=(%s)",(BEhostname)) - result = cursor.fetchone() + tz = "" + + if tz == "": + tz,tz_region, tz_subregion = geo_locate() + else: + try: + cursor.execute("select data from settings where value='HostTimeZoneRegion' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + tz_region=result[0] + except TypeError: + tz_region="" + + tempsubregion="HostTimeZoneRegion_" + tz_region + try: + cursor.execute("select data from settings where value=%s and hostname=(%s)",(tempsubregion,BEhostname)) + result = cursor.fetchone() + tz_subregion=result[0] + except TypeError: + tz_subregion="" + + +############### + #if ( thishostname != BEhostname ): + #cursor.execute("select data from settings where value='GlobalServiceHobbitserver'") + #result = cursor.fetchone() + #try: + #hobbitclient=result[0] + #except: + #hobbitclient="1" + #else: + #hobbitclient="1" + + + try: - tz_region=result[0] + cursor.execute("select data from settings where value='HostWindowManager' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + windowmanager=result[0] except TypeError: - tz_region="" - tempsubregion="HostTimeZoneRegion_" + tz_region + windowmanager="" + - cursor.execute("select data from settings where value=%s and hostname=(%s)",(tempsubregion,BEhostname)) - result = cursor.fetchone() try: - tz_subregion=result[0] + cursor.execute("select data from settings where value='HostEnhancedWMStyle' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + wmstyle=result[0] except TypeError: - tz_subregion="" -############### - if ( thishostname != BEhostname ): - cursor.execute("select data from settings where value='GlobalServiceHobbitserver'") + wmstyle="" + + + try: + cursor.execute("select data from settings where value='MusicLocation' and hostname=(%s)",(BEhostname)) result = cursor.fetchone() - try: - hobbitclient=result[0] - except: - hobbitclient="1" - else: - hobbitclient="1" + musicdir=result[0] + except TypeError: + musicdir="" + + + try: + cursor.execute("select data from settings where value='FilenameTemplate' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + filenametemplate=result[0] + except TypeError: + filenametemplate="" + + try: + cursor.execute("select data from settings where value='GalleryDir' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + gallerydir=result[0] + except TypeError: + gallerydir="" +# video parental level + video_list=['VideoAdminPassword', + 'VideoAdminPasswordThree', + 'VideoAdminPasswordTwo', + 'VideoAggressivePC', + 'VideoDefaultParentalLevel', + 'mythvideo.ParentalLevelFromRating'] + + for i in video_list: + sql_query="select data from settings where value='%s' and hostname='%s'" %(i,BEhostname) + try: + cursor.execute(sql_query) + result = cursor.fetchone() + video_dict[i]=result[0] + except TypeError: + video_dict[i]='' def insertvars(): db = MySQLdb.connect(host=installdb, user="mythtv", passwd="mythtv", db="mythconverg") cursor = db.cursor() -#inserting the zipcode - cursor.execute("select * from settings where value='HostZipcode' and hostname=(%s)",(thishostname)) - result = cursor.fetchone() - if ( zipcode!="" ): - if (result == None): - cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostZipcode',(%s),(%s))",(zipcode,thishostname)) - print "inserting zipcode" - else: - cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostZipcode'",(zipcode,thishostname)) - print "updating zipcode" +##inserting the zipcode + #cursor.execute("select * from settings where value='HostZipcode' and hostname=(%s)",(thishostname)) + #result = cursor.fetchone() + #if ( zipcode!="" ): + #if (result == None): + #cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostZipcode',(%s),(%s))",(zipcode,thishostname)) + #print "inserting zipcode" + #else: + #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostZipcode'",(zipcode,thishostname)) + #print "updating zipcode" #inserting the timezone - cursor.execute("select * from settings where value='HostTimeZone' and hostname=(%s)",(thishostname)) - result = cursor.fetchone() + if ( tz != ""): - if (result == None): + cursor.execute("select * from settings where value='HostTimeZone' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if (result == None): cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZone',(%s),(%s))",(tz,thishostname)) print "inserting timezone" - else: + else: cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostTimeZone'",(tz,thishostname)) print "updating timezone" - cursor.execute("select * from settings where value='HostTimeZoneRegion' and hostname=(%s)",(thishostname)) - result = cursor.fetchone() - if ( tz != ""): - if (result == None): + cursor.execute("select * from settings where value='HostTimeZoneRegion' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if (result == None): cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZoneRegion',(%s),(%s))",(tz_region,thishostname)) print "inserting timezone region" - else: + else: cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostTimeZoneRegion'",(tz_region,thishostname)) print "updating timezone region" - tempsubregion="HostTimeZoneRegion_" + tz_region - cursor.execute("select * from settings where value=%s and hostname=(%s)",(tempsubregion,thishostname)) - result = cursor.fetchone() - if ( tz != ""): - if (result == None): + tempsubregion="HostTimeZoneRegion_" + tz_region + + cursor.execute("select * from settings where value=%s and hostname=(%s)",(tempsubregion,thishostname)) + result = cursor.fetchone() + if (result == None): cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ((%s),(%s),(%s))",(tempsubregion,tz_subregion,thishostname)) print "inserting timezone subregion" - else: - cursor.execute("update settings set data=(%s) where hostname=(%s) and value=(%s)",(tempsubregion,tz_subregion,thishostname)) + else: + cursor.execute("update settings set data=(%s) where hostname=(%s) and value=(%s)",(tz_subregion,thishostname,tempsubregion)) print "updating timezone subregion" -#start of NFSIP - cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(thishostname)) - result = cursor.fetchone() - if ( nfsip != ""): +##start of NFSIP + if nfstoggle == "yes" : + print "BE has a central storage" + #if nfsshareall == "0": + #print "BE is not sharing central, starting config" + if ( nfsip != ""): + cursor.execute("select data from settings where value='HostCentralNFSIP' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if (result == None): + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostCentralNFSIP',(%s),(%s))",(nfsip,thishostname)) + print "inserting nfsip" + else: + no_update("HostCentralNFSIP") + #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostCentralNFSIP'",(nfsip,thishostname)) + #print "updating nfsip" + if ( nfsmount !="") : + cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if (result == None): + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostNFSmountpoint',(%s),(%s))",(nfsmount,thishostname)) + print "inserting nfsmountpoint" + else: + no_update("nfsmount") + #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostNFSmountpoint'",(nfsmount,thishostname)) + #print "updating nfsmount" + #else: + #print "BE is sharing, config sync skipped" + else: + print "BE has no central storage" + + #windowmanager + if windowmanager != "": + cursor.execute("select * from settings where value='HostWindowManager' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if (result == None): + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostWindowManager',(%s),(%s))",(windowmanager,thishostname)) + print "inserting windowmanager" + else: + no_update("windowmanager") + #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostWindowManager'",(windowmanager,thishostname)) + #print "updating windowmanager" + + + if wmstyle != "" : + cursor.execute("select * from settings where value='HostEnhancedWMStyle' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() if (result == None): - cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostCentralNFSIP',(%s),(%s))",(nfsip,thishostname)) - print "inserting nfsip" + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostEnhancedWMStyle',(%s),(%s))",(wmstyle,thishostname)) + print "inserting windowmanager style" + else: + no_update("wm_style") + #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostEnhancedWMStyle'",(wmstyle,thishostname)) + #print "updating windowmanager style" - if (nfstoggle != ""): - cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(thishostname)) +#music and gallery + + if ( musicdir != "" ): + cursor.execute("select * from settings where value='MusicLocation' and hostname=(%s)",(thishostname)) result = cursor.fetchone() if (result == None): - cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostHaveCentralNFS',(%s),(%s))",(nfstoggle,thishostname)) - print "inserting nfstoggle" + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('MusicLocation',(%s),(%s))",(musicdir,thishostname)) + print "inserting musicdir" + else: + #no_update("musicdir") + cursor.execute("update settings set data=(%s) where hostname=(%s) and value='MusicLocation'",(musicdir,thishostname)) + print "updating musicdir" - if ( nfsmount !="") : - cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(thishostname)) + if ( filenametemplate != "" ): + cursor.execute("select * from settings where value='FilenameTemplate' and hostname=(%s)",(thishostname)) result = cursor.fetchone() if (result == None): - cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostNFSmountpoint',(%s),(%s))",(nfsmount,thishostname)) - print "inserting nfsmountpoint" + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('FilenameTemplate',(%s),(%s))",(filenametemplate,thishostname)) + print "inserting filenametemplate" + else: + no_update("filenametemplate") + #cursor.execute("update settings set data=(%s) where hostname=(%s) and value='FilenameTemplate'",(filenametemplate,thishostname)) + #print "updating filenametemplate" + + if ( gallerydir != "" ): + cursor.execute("select * from settings where value='GalleryDir' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if (result == None): + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('GalleryDir',(%s),(%s))",(gallerydir,thishostname)) + print "inserting gallerydir" + else: + #no_update("gallerydir") + cursor.execute("update settings set data=(%s) where hostname=(%s) and value='GalleryDir'",(gallerydir,thishostname)) + print "updating gallerydir" + +# parental level + for key,value in video_dict.items(): + if ( value != "" ): + sql_query = "select * from settings where value='%s' and hostname='%s'" %(key,thishostname) + cursor.execute(sql_query) + result = cursor.fetchone() + if (result == None): + insert_sql ="INSERT INTO settings (value,data,hostname) VALUES ('%s','%s','%s')" %(key,value,thishostname) + cursor.execute(insert_sql) + print "inserting %s" %(key) + else: + no_update(key) + #update_sql="update settings set data='%s' where hostname='%s' and value='%s'" %(value,thishostname,key) + #cursor.execute(update_sql) + #print "updating %s" %(key) + -#hobbitclient - cursor.execute("select * from settings where value='HostServiceHobbitclient' and hostname=(%s)",(thishostname)) - result = cursor.fetchone() - if ( hobbitclient != ""): - if (result == None): - cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostServiceHobbitclient',(%s),(%s))",(hobbitclient,thishostname)) - print "inserting hobbitcleint" - else: - cursor.execute("update settings set data=(%s) where hostname=(%s) and value='HostServiceHobbitclient'",(hobbitclient,thishostname)) - print "updating hobbitclient" def main(argv): @@ -204,9 +428,15 @@ def main(argv): global tz global tz_region global tz_subregion + #global nfsip + #global hobbitclient + global musicdir + global gallerydir + global filenametemplate + + global video_dict + video_dict = {} - global nfsip - global hobbitclient try: opts, args = getopt.getopt(argv, "hm:d:n:", ["help", "masterdb=", "installdb=" , "hostname=" ] ) except getopt.GetoptError: diff --git a/abs/core/LinHES-config/udev_link.sh b/abs/core/LinHES-config/udev_link.sh new file mode 100755 index 0000000..ec8bdcf --- /dev/null +++ b/abs/core/LinHES-config/udev_link.sh @@ -0,0 +1,33 @@ +#!/bin/bash +my_base=$1 +dev_name=$2 +#DEVNAME=/dev/dvb/adapter2/frontend0 +#DVB_ADAPTER_NUM=2 + +lndir=`dirname $dev_name` +#for clink in `ls -d /dev/vstatic/dvb*` +for clink in `ls -d /dev/dvb/adapter_*` +do + if [ `readlink $clink` == $lndir ] + then + echo "link is already present $clink" + exit 0 + fi + +done +mkdir -p /dev/vstatic +for i in 1 2 3 4 +do + + #mydir="/dev/vstatic/${my_base}_$i" + mydir="/dev/dvb/adapter_static_${my_base}_$i" + if [ ! -e $mydir ] + then + ln -s $lndir $mydir + exit 0 + else + echo "dvb dir already exists " + fi +done +exit 0 + diff --git a/abs/core/LinHES-config/xconfig.sh b/abs/core/LinHES-config/xconfig.sh index a601352..eda67b4 100755 --- a/abs/core/LinHES-config/xconfig.sh +++ b/abs/core/LinHES-config/xconfig.sh @@ -11,184 +11,51 @@ do done BASE="" +MYTH_RUN_STATUS="1" . /etc/profile -NVIDIA_96XX="$TEMPLATES/xorg/96xx_supported.txt" -NVIDIA_173="$TEMPLATES/xorg/173_supported.txt" -NVIDIA_SUPPORTED="$TEMPLATES/xorg/nvidia_supported.txt" -MYTHHOME=$BASE/home/mythtv +#MYTHHOME=$BASE/home/mythtv + +. /usr/MythVantage/bin/install_functions.sh +home_check + function Xvalues { - CMDLINE=$(cat /proc/cmdline) - echo "$CMDLINE" | grep -q forceXvesa - if [ $? = 0 ] + if [ "x$VGACARDTYPE" = "x" ] then - echo "Forcing driver to vesa" - VGACARDTYPE=vesa - Xcardtype=$VGACARDTYPE + CMDLINE=$(cat /proc/cmdline) + echo "$CMDLINE" | grep -q forceXvesa + if [ $? = 0 ] + then + echo "Forcing driver to vesa" + VGACARDTYPE=vesa + Xcardtype=$VGACARDTYPE + else + VGACARDTYPE=`lspci | grep -i vga | grep -vi non-vga| sort -r | head -n 1 | cut -d: -f3 | cut -d" " -f2` + VGAPCIID=`lspci | grep -i vga |grep -vi non-vga| sort -r | head -n 1 | cut -d" " -f1` + CARDID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f2` + VENDORID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f1` + fi else - VGACARDTYPE=`lspci | grep -i vga | sort -r | head -n 1 | cut -d: -f3 | cut -d" " -f2` - VGAPCIID=`lspci | grep -i vga | sort -r | head -n 1 | cut -d" " -f1` - CARDID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f2` - VENDORID=`lspci -n | grep "$VGAPCIID" | grep 10de | cut -d" " -f3 | cut -d: -f1` + echo "VGACARDTYPE already set" fi - echo "Detected $VGACARDTYPE as the video card type" - #currentmode=`cat "$BASE/etc/X11/xorg.conf" | grep Modes | awk -Fs '{ print $2 }'` } function presetupX { - if [ -f /etc/sysconfig/IGNORE_X ] + if [ "$XIgnoreConfig" = 1 ] then - echo "Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X" - return 1 - else - if [ "$XIgnoreConfig" = 1 ] + echo "Using User supplied X" + if [ -f "$MYTHHOME/templates/xorg.user" ] then - echo "Using User supplied X" - if [ -f "$MYTHHOME/templates/xorg.user" ] - then - cp -f "$MYTHHOME/templates/xorg.user" "$XORG_CONF" - else - echo "Didn't find the file" - echo "Copy your config file to $MYTHHOME/templates/xorg.user" > "$XORG_CONF" - fi + cp -f "$MYTHHOME/templates/xorg.user" "$XORG_CONF" else - #if [ "$XUseAdvanced" = 1 ] - #then - # setupAdvancedX - #else - setupX - #fi + echo "Didn't find the file" + echo "Copy your config file to $MYTHHOME/templates/xorg.user" > "$XORG_CONF" fi + else + setupX fi - -} - -function setupAdvancedX { - - echo "#Doing the advanced X setup" >> $LOGFILE - #Xcategory=`echo "$Xresadvanced" | cut -d_ -f1` - #Xres=`echo "$Xresadvanced" | cut -d_ -f2` - - Xcategory=`echo "$Xresadvanced" | cut -d_ -f1` - Xres=${Xres} - #echo "$Xcategory" - #echo $Xres - if [ "$Xcategory" = "Nvidia" ] - then - #Xres="" - if [ "$XnVidia1080p" = "1" ] - then - Xres="${Xres} 1920x1080_60" - fi - if [ "$XnVidia1080i" = "1" ] - then - Xres="${Xres} 1920x1080_60i" - fi - if [ "$XnVidia720p" = "1" ] - then - Xres="${Xres} 1280x720_60" - fi - if [ "$XnVidia480p" = "1" ] - then - Xres="${Xres} 720x480_60" - fi - #ML="\t Modes ${Xres}" -# else -# ML="\t Modes \"${Xres}\"" - fi - - case $Xcardtype in - NVIDIA|nVidia|nvidia) - nvidia_driver_install - case $Xconnection in - DVI) ConnectedMonitor=DFP ;; - vga) ConnectedMonitor=CRT;; - Auto) ConnectedMonitor=Auto;; - TV) ConnectedMonitor=TV - nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --tv-standard="$XTVstandard" - nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --tv-out-format="$XTVconnection" - # echo "Option \"TVStandard\" \"$XTVstandard\"" >>/tmp/options - # echo "Option \"TVOutFormat\" \"$XTVconnection\"" >> /tmp/options - ;; - *) ConnectedMonitor=Auto;; - esac - if [ "$ConnectedMonitor" = Auto ] - then - echo "auto connection" - else - nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --connected-monitor="$ConnectedMonitor" - #echo "Option \"ConnectedMonitor\" \"$ConnectedMonitor\"" >> /tmp/options - #echo "Option \"FlatPanelProperties\" \"Scaling = centered, Dithering = enabled\"" >> /tmp/options - #echo "Option \"DigitalVibrance\" \"0\"" >> /tmp/options - fi -# -# if [ "$XignoreEDID" = 1 ] -# then -# EDIDvalue=true -# EDIDFREQ=false -# DS=" DisplaySize $XDisplaysize" -# HS=" HorizSync $XHsync" -# VR=" VertRefresh $XVrefresh" -# else -# EDIDvalue=false -# EDIDFREQ=true -# DS="# Display size edid used " -# HS="# Hsync edid used " -# VR="# Vertrefresh edid used " -# fi -# echo "Option \"UseEdidFreqs\" \"$EDIDFREQ\"" >> /tmp/options -# echo "Option \"IgnoreEDID\" \"$EDIDvalue\"" >> /tmp/options -# -# -# sed -e "s/^.*Modes.*$/${ML}/" \ -# -e "/INSERT MODELINE/r $TEMPLATES/xorg/modeline.$Xcategory" \ -# -e "s/^.*DisplaySize.*$/ $DS/" \ -# -e "s/^#.*HorizSync.*$/ $HS/g" \ -# -e "s/^#.*VertRefresh.*$/ $VR/g" \ -# -e "/INSERT HERE/r /tmp/options" "$TEMPLATES/xorg/xorg.conf.nvidia" > "$XORG_CONF" - - #nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --mode-list=\"${Xres}\" - eval nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --mode-list=\"${Xres}\" - ;; - - ati|ATI) - case $Xconnection in - DVI) ConnectedMonitor="tmds1,nocrt1,notv";; - VGA) ConnectedMonitor="crt1,notmds1,notv" ;; - TV) ConnectedMonitor="tv,nocrt1,notmds1" - echo "Option \"TVStandard\" \"$XTVstandard\"" >>/tmp/options - echo "Option \"TVFormat\" \"$XTVconnection\"" >> /tmp/options - ;; - esac - if [ "$XignoreEDID" = 1 ] - then - DS=" DisplaySize $XDisplaysize" - HS=" HorizSync $XHsync" - VR=" VertRefresh $XVrefresh" - else - DS="# Display size edid used " - HS="# Hsync edid used " - VR="# Vertrefresh edid used " - fi - - echo "Option \"ForceMonitors\" \"$ConnectedMonitor\"" >> /tmp/options - - sed -e "s/^.*Modes.*$/\t $ML/" \ - -e "/INSERT MODELINE/r $TEMPLATES/xorg/modeline.$Xcategory" \ - -e "s/^.*DisplaySize.*$/ $DS/" \ - -e "s/^#.*HorizSync.*$/ $HS/g" \ - -e "s/^#.*VertRefresh.*$/ $VR/g" \ - -e "/INSERT HERE/r /tmp/options" "$TEMPLATES/xorg/xorg.conf.ati" > "$XORG_CONF" - ;; - - - - *) - echo "unknown card type" - ;; - esac } function nvidia_prepare { @@ -201,198 +68,173 @@ function nvidia_prepare { do pacman --noconfirm -Rc $i >> $LOGFILE 2>&1 done +} - +function pkg_check () { + echo " Checking for $1 in cache or online" + pacman --noconfirm -Sw $1 >> $LOGFILE 2>&1 + rc=$? + if [ $rc != 0 ] + then + echo " Couldn't find $1 for install, aborting" + echo " Couldn't find $1 for install, aborting" >> $LOGFILE 2>&1 + exit 1 + fi } function nvidia_driver_install { + echo "Installing Nvidia driver" + cp "$TEMPLATES/xorg/xorg.nvidia" $BASE/etc/X11/xorg.conf.d/20-automv.conf + #install latest drivers + pkg_check nvidia-utils + echo "Installing current nvidia drivers" + nvidia_prepare + pacman --noconfirm -S nvidia nvidia-utils >> $LOGFILE 2>&1 + installed=1 + echo "/usr/lib/libXvMCNVIDIA_dynamic.so.1" > "$XVMC_CONFIG" +} +function vmware_driver_install { + echo "Installing VMware driver" + echo "Installing VMware driver" >> $LOGFILE 2>&1 + LIST="xf86-input-vmmouse xf86-video-vmware xf86-video-vesa svga-dri" + for i in `echo ${LIST}` + do + pkg_check $i + done + for i in `echo ${LIST}` + do + pacman -S --noconfirm $i >> $LOGFILE 2>&1 + done - cp "$TEMPLATES/xorg/xorg.conf.nvidia" $BASE/etc/X11/xorg.conf.d/20-automv.conf - - installed=0 - if [ "$TESTMODE" != "test" ] - then - - - grep -qi "$CARDID" "$NVIDIA_SUPPORTED" - if [ $? = 0 ] - then - #install latest drivers - echo "Installing current nvidia drivers" - nvidia_prepare - pacman --noconfirm -S nvidia nvidia-utils >> $LOGFILE 2>&1 - installed=1 - fi - - if [ $installed = 0 ] - then - #nvidia check right here - grep -qi "$CARDID" "$NVIDIA_96XX" - if [ $? = 0 ] - then - #install 96xx drivers - echo "Installing nvidia 96xx drivers" - nvidia_prepare - pacman --noconfirm -S nvidia-96xx nvidia-96xx-utils >> $LOGFILE 2>&1 - installed=1 - fi - fi - - if [ $installed = 0 ] - then - grep -qi "$CARDID" "$NVIDIA_173" - if [ $? = 0 ] - then - #install latest drivers - echo "Installing 173 nvidia drivers" - nvidia_prepare - pacman --noconfirm -S nvidia-173xx nvidia-173xx-utils >> $LOGFILE 2>&1 - installed=1 - fi - fi - - if [ $installed = 0 ] - then - #this is a failsafe, can't find the right driver, then use the latest' - #install latest drivers - echo "Couldn't find the card in the supported list" - echo "Installing current nvidia drivers" - - nvidia_prepare - pacman --noconfirm -S nvidia nvidia-utils >> $LOGFILE 2>&1 - installed=1 - fi - - - fi +} +function vesa_driver_install { + echo "Installing Vesa driver" + echo "Installing Vesa driver" >> $LOGFILE 2>&1 + pacman -S --noconfirm xf86-video-vesa >> $LOGFILE 2>&1 +} - if [ \"$Xres\" = "Auto" ] - then - nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --mode-list="nvidia-auto-select" - else - #nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --mode-list=$Xres - eval nvidia-xconfig -c /etc/X11/xorg.conf.d/20-automv.conf --mode-list=\"${Xres}\" - fi +function intel_driver_install { + echo "Installing Intel driver" + echo "Installing Intel driver" >> $LOGFILE 2>&1 + pkg_check xf86-video-intel + #this is used to remove nvidia + nvidia_prepare + pacman -S --noconfirm xf86-video-intel >> $LOGFILE 2>&1 + echo "/usr/lib/libIntelXvMC.so.1" > "$XVMC_CONFIG" +} - echo "/usr/lib/libXvMCNVIDIA_dynamic.so.1" > "$XVMC_CONFIG" - #rm $BASE/etc/X11/xorg.conf.d/20-nvidia.conf +# if [ "$Xcategory" = "Nvidia" ] +# then +# #Xres="" +# if [ "$XnVidia1080p" = "1" ] +# then +# Xres="${Xres} 1920x1080_60" +# fi +# if [ "$XnVidia1080i" = "1" ] +# then +# Xres="${Xres} 1920x1080_60i" +# fi +# if [ "$XnVidia720p" = "1" ] +# then +# Xres="${Xres} 1280x720_60" +# fi +# if [ "$XnVidia480p" = "1" ] +# then +# Xres="${Xres} 720x480_60" +# fi + +function set_res { + echo " Setting modeline to ${Xres}" + echo " Setting modeline to ${Xres}" >> $LOGFILE 2>&1 + cat > /etc/X11/xorg.conf.d/30-screen.conf <<EOF + Section "Screen" + Identifier "Screen0" #Collapse Monitor and Device section to Screen section + Device "Device0" + Monitor "Monitor0" + DefaultDepth 24 #Choose the depth (16||24) + SubSection "Display" + Depth 24 + Modes "${Xres}" #Choose the resolution + EndSubSection + EndSection +EOF } function setupX { Xvalues - #echo "$currentmode ____ ${Xres}" - #if [ "${currentmode}" != \"${Xres}\" ] if [ x = x ] then case $VGACARDTYPE in - nVidia) + NVIDIA|nVidia|nvidia) nvidia_driver_install - ;; - - # VMware) - # sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.vmware" > "$XORG_CONF" - # ;; - - VIA|S3) - # There are actually multiple options here - # xf86-video-openchrome - # xf86-video-unichrome - # There is also a seperate driver for the Unichrome Pro - if [ ${Xres} = Auto ] - then - sed -e "/^.*Modes.*$/d" "$TEMPLATES/xorg/xorg.conf.via" > "$XORG_CONF" - else - sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.via" > "$XORG_CONF" - fi - if [ "$TESTMODE" != "test" ] - then - if [ "$OPENCHROME" = "1" ] + if [ \"$Xres\" = "Auto" ] then - pacman --noconfirm -R nvidia nvidia-utils >> $LOGFILE 2>&1 - pacman --noconfirm -S libgl unichrome-dri xf86-video-openchrome >> $LOGFILE 2>&1 - else - pacman --noconfirm -R nvidia nvidia-utils >> $LOGFILE 2>&1 - pacman --noconfirm -S libgl unichrome-dri xf86-video-unichrome >> $LOGFILE 2>&1 + Xres="nvidia-auto-select" fi - fi - # I'm making educated guesses here... - if lspci | grep "VGA" | grep -qi "Unichrome Pro" - then - if [ -f "/usr/lib/libchromeXvMCPro.so.1" ] + + if [ ${Xres} != "Auto" ] then - echo "/usr/lib/libchromeXvMCPro.so.1" > "$XVMC_CONFIG" + set_res else - echo "/usr/lib/libviaXvMCPro.so.1" > "$XVMC_CONFIG" + rm -f /etc/X11/xorg.conf.d/30-screen.conf fi - else - if [ -f "/usr/lib/libchromeXvMC.so.1" ] + ;; + + VMware) + vmware_driver_install + cp $TEMPLATES/xorg/xorg.vmware /etc/X11/xorg.conf.d/20-automv.conf + echo "copy in autostart functions" >> $LOGFILE 2>&1 + mkdir -p /etc/X11/autostart >> $LOGFILE 2>&1 + echo "#!/bin/bash" > /etc/X11/autostart/vmware.sh + echo "/usr/bin/vmware-user-suid-wrapper" >> /etc/X11/autostart/vmware.sh + chmod 755 /etc/X11/autostart/vmware.sh + if [ ${Xres} != "Auto" ] then - echo "/usr/lib/libchromeXvMC.so.1" > "$XVMC_CONFIG" + set_res else - echo "/usr/lib/libviaXvMC.so.1" > "$XVMC_CONFIG" + rm -f /etc/X11/xorg.conf.d/30-screen.conf fi - fi - ;; + ;; Intel|intel) - if [ ${Xres} = Auto ] - then - sed -e "/^.*Modes.*$/d" "$TEMPLATES/xorg/xorg.conf.intel" > "$XORG_CONF" - else - sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.intel" > "$XORG_CONF" - fi - if [ "$TESTMODE" != "test" ] - then - pacman --noconfirm -R nvidia-utils >> $LOGFILE 2>&1 - pacman --noconfirm -S libgl >> $LOGFILE 2>&1 - fi - echo "/usr/lib/libIntelXvMC.so.1" > "$XVMC_CONFIG" - ;; - - vesa|InnoTek) - if [ ${Xres} = Auto ] - then - sed -e "/^.*Modes.*$/d" "$TEMPLATES/xorg/xorg.conf.vesa" > "$XORG_CONF" - else - sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.vesa" > "$XORG_CONF" - fi - ;; - - *) - XCONF=/root/xorg.conf.new - XCONFB=/etc/X11/xorg.conf.install - X -configure - if [ -f "$XCONF" ] - then - echo "Using $XCONF" - if [ ${Xres} = Auto ] + intel_driver_install + cp $TEMPLATES/xorg/xorg.intel /etc/X11/xorg.conf.d/20-automv.conf + if [ ${Xres} != "Auto" ] then - grep -v Modes "$XCONF" | sed -e 's/dev\/mouse/dev\/psaux/g'> "$XORG_CONF" + set_res else - grep -v Modes "$XCONF" | sed -e "/Depth.*16/a Modes \"${Xres}\" " -e "/Depth.*24/a Modes \"${Xres}\"" -e 's/dev\/mouse/dev\/psaux/g'> "$XORG_CONF" + rm -f /etc/X11/xorg.conf.d/30-screen.conf fi - elif [ -f "$XCONFB" ] - then - echo "Using $XCONFB" - if [ ${Xres} = Auto ] + ;; + + vesa|InnoTek|*) #leaving this as * and vesa for no real reason other then it's explicit to catch vesa + vesa_driver_install + cp $TEMPLATES/xorg/xorg.vesa /etc/X11/xorg.conf.d/20-automv.conf + if [ ${Xres} != "Auto" ] then - sed -e "/^.*Modes.*$/d" "$XCONFB" > "$XORG_CONF" + set_res else - sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$XCONFB" > "$XORG_CONF" + rm -f /etc/X11/xorg.conf.d/30-screen.conf fi - else - echo "Xorg configuration failed" - fi - rm -f "$XCONF" >> $LOGFILE 2>&1 + ;; + esac + #configure the ramdisk for kms + if [ x$RUNP != "x1" ] + then + echo "Running plymouth_config" + plymouth_config.py >> $LOGFILE 2>&1 + fi fi } + +#--------------------------------------------------------------------------------- #MAIN @@ -400,52 +242,43 @@ LINE=`grep -i xorg /etc/mythvantage.cfg|grep -q False` rc=$? if [ $rc = 0 ] then - echo "xorg configuration disabled in /etc/mythvantage.cfg" - exit 0 + echo "** xorg configuration disabled in /etc/mythvantage.cfg" + exit 1 fi -TESTMODE="$1" -if [ "$TESTMODE" = "test" ] +if [ -f /etc/sysconfig/IGNORE_X ] then - XORG_CONF="/tmp/xorg.conf.test" - XVMC_CONFIG="/tmp/XvMCConfig.test" - XUseAdvanced="1" - XIgnoreConfig="${2}" - Xcardtype="${3}" - XIgnoreEDID="${4}" - Xconnection="${5}" - XHsync="${6}" - XVrefresh="${7}" - Xresadvanced="${8}" - XTVstandard="${9}" - XTVconnection="${10}" - XDisplaysize="${11}" -else - if [ -f /etc/systemconfig ] - then - . /etc/systemconfig - else - Xres="800x600" - fi - CMDLINE=$(cat /proc/cmdline) - echo $CMDLINE | grep -q displayres - if [ $? = 0 ] - then - TEMPVAR=${CMDLINE#*displayres=} - DSR=${TEMPVAR%% *} - fi - if [ ! x$DSR = x ] - then - Xres=$DSR - fi - if [ ! x$DISPLAYRES = x ] - then - Xres=$DISPLAYRES - fi + echo "** Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X" + exit 1 +fi - XORG_CONF="/etc/X11/xorg.conf" - XVMC_CONFIG="/etc/X11/XvMCConfig" +if [ -f /etc/systemconfig ] +then + . /etc/systemconfig +else + Xres="800x600" +fi +CMDLINE=$(cat /proc/cmdline) +echo $CMDLINE | grep -q displayres +if [ $? = 0 ] +then + TEMPVAR=${CMDLINE#*displayres=} + DSR=${TEMPVAR%% *} fi +if [ ! x$DSR = x ] +then + Xres=$DSR +fi +if [ ! x$DISPLAYRES = x ] +then + Xres=$DISPLAYRES +fi + + + +XORG_CONF="/etc/X11/xorg.conf" +XVMC_CONFIG="/etc/X11/XvMCConfig" + presetupX |
