diff options
author | James Meyer <james.meyer@operamail.com> | 2009-11-13 07:22:22 (GMT) |
---|---|---|
committer | James Meyer <james.meyer@operamail.com> | 2009-11-13 07:22:22 (GMT) |
commit | f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a (patch) | |
tree | 6b681fc663d7f8a07863185f4313d39cedba655a | |
parent | 420f4c0c8157237d3b4b682a27db498b80c9e0f3 (diff) | |
download | linhes_pkgbuild-f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a.zip linhes_pkgbuild-f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a.tar.gz linhes_pkgbuild-f1e3c5f9132ab7fdf1e1d33f6020a82a9869096a.tar.bz2 |
LinHES-config-22: first check in of LinHES-config-22
43 files changed, 7707 insertions, 0 deletions
diff --git a/abs/core-testing/LinHES-config-22/LinHES-release b/abs/core-testing/LinHES-config-22/LinHES-release new file mode 100644 index 0000000..6a885f4 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/LinHES-release @@ -0,0 +1 @@ +LinHES R6.01.00 (Chugu) diff --git a/abs/core-testing/LinHES-config-22/LinHES.install b/abs/core-testing/LinHES-config-22/LinHES.install new file mode 100644 index 0000000..a0a9d31 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/LinHES.install @@ -0,0 +1,78 @@ +# This is a default template for a post-install scriptlet. You can +# remove any functions you don't need (and this header). + +# arg 1: the new package version +pre_install() { + rm -f /etc/issue + rm -f /etc/arch-release + +} + +# arg 1: the new package version +post_install() { + if [ ! -f /etc/blacklist.package ] + then + 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 +# arg 2: the old package version +pre_upgrade() { + /bin/true +} + +# 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 ] + then + restore_default_settings.sh -c load + 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 +} + +# arg 1: the old package version +pre_remove() { + /bin/true +} + +# arg 1: the old package version +post_remove() { + /bin/true +} + +op=$1 +shift +$op $* diff --git a/abs/core-testing/LinHES-config-22/MythVantage.sh b/abs/core-testing/LinHES-config-22/MythVantage.sh new file mode 100755 index 0000000..286c908 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/MythVantage.sh @@ -0,0 +1,3 @@ +export MV_ROOT=/usr/MythVantage +export PATH=$PATH:$MV_ROOT/bin +export TEMPLATES=$MV_ROOT/templates diff --git a/abs/core-testing/LinHES-config-22/PKGBUILD b/abs/core-testing/LinHES-config-22/PKGBUILD new file mode 100644 index 0000000..8bbf862 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/PKGBUILD @@ -0,0 +1,103 @@ +pkgname=LinHES-config-22 +pkgver=2.1 +pkgrel=8 +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-22) +arch=('i686') + +source=(mv_install.py + mv_config.py + myth_user_call + file_time_offset.py + install-ui.xml + install_proxy.sh + install_functions.sh + systemconfig.sh + install_db_chroot.sh + restore_default_settings.sh + xconfig.sh + timezip.py + soundconfig.sh + LinHES-release + issue + MythVantage.sh + create_master.sh + build_diskless.sh + networkconfig.sh + autocard.py + restore_km_db_chroot.sh + README + mv_advanced.py + mv_common.py + mv_ddns.py + mv_ir.py + mv_misc.py + mv_network.py + mv_screensaver.py + mv_smolt.py + mv_software.py + mv_webuser.py + mv_hostype.py + systemconfig.py + myth_user_call.py) + +install=LinHES.install + +build() { + mkdir -p $startdir/pkg/etc + mkdir -p $startdir/pkg/usr/share/mythtv/themes/default + + MVDIR=$startdir/pkg/usr/MythVantage + mkdir $startdir/pkg/etc/profile.d + install -m 0755 MythVantage.sh $startdir/pkg/etc/profile.d/MythVantage.sh + mkdir -p $MVDIR/bin + 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 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 soundconfig.sh $MVDIR/bin/soundconfig.sh + install -m 0755 networkconfig.sh $MVDIR/bin/networkconfig.sh + install -m 0755 create_master.sh $MVDIR/bin/create_master.sh + 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 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/ + install -m 0755 mv_common.py $MVDIR/bin/ + install -m 0755 mv_ddns.py $MVDIR/bin/ + install -m 0755 mv_ir.py $MVDIR/bin/ + install -m 0755 mv_misc.py $MVDIR/bin/ + install -m 0755 mv_network.py $MVDIR/bin/ + install -m 0755 mv_screensaver.py $MVDIR/bin/ + install -m 0755 mv_smolt.py $MVDIR/bin/ + install -m 0755 mv_software.py $MVDIR/bin/ + install -m 0755 mv_webuser.py $MVDIR/bin/ + install -m 0755 mv_hostype.py $MVDIR/bin/ + install -m 0755 systemconfig.py $MVDIR/bin/ + + #README file displayed on install + install -m 0755 README $MVDIR/README + + 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 + + # copy over the ui files + install -m 0755 install-ui.xml $startdir/pkg/usr/share/mythtv/themes/default/ +} diff --git a/abs/core-testing/LinHES-config-22/README b/abs/core-testing/LinHES-config-22/README new file mode 100644 index 0000000..447678a --- /dev/null +++ b/abs/core-testing/LinHES-config-22/README @@ -0,0 +1,9 @@ +Thanks for choosing LinHES! At the moment, LinHES is compiled for i686. +If you have an i586 class system, LinHES won't work for you. I've not seen a great request for i586. If you want it, you have to drum up support for it. The PVR-350 TV out isn't supported at this time. I have to determine if it works with MythTV 0.22 first. + +Support for LinHES can be obtained at: +http://linhes.org +irc.freenode.net #linhes + +Bugs can be reported at: +http://linhes.org/flyspray diff --git a/abs/core-testing/LinHES-config-22/add_service.sh b/abs/core-testing/LinHES-config-22/add_service.sh new file mode 100755 index 0000000..190d604 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/add_service.sh @@ -0,0 +1,15 @@ +#!/bin/bash +SERVICE_DIR=/var/service +SCRIPT_DIR=/etc/sv +if [ -d $SCRIPT_DIR/$1 ] +then + if [ -d $SERVICE_DIR/$1 ] + then + echo "$1 already there" + else + ln -s $SCRIPT_DIR/$1 $SERVICE_DIR/$1 + echo "adding $1" + fi +else + echo "couldn't find $SCRIPT_DIR/$1" +fi diff --git a/abs/core-testing/LinHES-config-22/autocard.py b/abs/core-testing/LinHES-config-22/autocard.py new file mode 100755 index 0000000..03eecac --- /dev/null +++ b/abs/core-testing/LinHES-config-22/autocard.py @@ -0,0 +1,307 @@ +#!/usr/bin/python +# import MySQL module +#jm +import MySQLdb +import sys +import getopt +import socket +import os +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)) + + 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)) + + + +def PRINTINFO(): + global cardlist + + for list in cardlist: + if list != "_placeholder_": + print list + #print "-------------" + +def GATHER_HDR(): + global cardlist + 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" + try: + filelist = os.listdir('/dev/v4l/') + except OSError: + filelist=" " + #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) + 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" + +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" + + if ( currenthostname == "" ): + currenthostname = socket.gethostname() + + + 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() + + + + + + +if __name__ == "__main__": + main(sys.argv[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) + +#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 | | +#+--------------+-------------+------+-----+---------+-------+ + + + + + + + + diff --git a/abs/core-testing/LinHES-config-22/bpopup-ui.xml b/abs/core-testing/LinHES-config-22/bpopup-ui.xml new file mode 100755 index 0000000..df0598b --- /dev/null +++ b/abs/core-testing/LinHES-config-22/bpopup-ui.xml @@ -0,0 +1,164 @@ +<!-- + + This is a myth style theme file for mythwelcome + + (c) 2005 by a whole bunch of people associated with MythTV + +--> +<mythuitheme> + + <window name="welcome_screen"> + + <!-- + + First, define all the fonts we need on this screen + + --> + <font name="title" face="Arial"> + <color>#ffff00</color> + <dropcolor>#000000</dropcolor> + <size>24</size> + <shadow>3,3</shadow> + <bold>yes</bold> + </font> + + <font name="time" face="Arial"> + <color>#9999cc</color> + <size>18</size> + <bold>yes</bold> + </font> + + <font name="label" face="Arial"> + <color>#ffff00</color> + <dropcolor>#000000</dropcolor> + <size>18</size> + <shadow>3,3</shadow> + <bold>yes</bold> + </font> + + <font name="info" face="Arial"> + <color>#ffffff</color> + <size>18</size> + <bold>yes</bold> + </font> + + <font name="biginfo" face="Arial"> + <color>#ffffff</color> + <size>50</size> + <bold>yes</bold> + </font> + <font name="warning" face="Arial"> + <color>#ff0000</color> + <dropcolor>#000000</dropcolor> + <size>16</size> + <shadow>2,2</shadow> + <bold>yes</bold> + </font> + + <font name="buttons" face="Arial"> + <color>#ffff00</color> + <size>14</size> + <bold>yes</bold> + </font> + + <container name="main_display"> + <area>0,0,800,600</area> + + <textarea name="title" draworder="0" align="center"> + <multiline>no</multiline> + <font>title</font> + <area>50,40,700,40</area> + <value></value> + </textarea> + + <!-- + time + --> + <textarea name="time_text" draworder="0" align="right"> + <multiline>no</multiline> + <font>time</font> + <area>660,520,110,30</area> + <value></value> + </textarea> + + <textarea name="date_text" draworder="0" align="center"> + <multiline>no</multiline> + <font>time</font> + <area>0,60,800,70</area> + <value></value> + </textarea> + + <!-- + current myth status + --> + + <textarea name="status_text" draworder="1" align="center"> + <multiline>yes</multiline> + <font>info</font> + <area>20,70,760,60</area> + <value>MythTV is idle and will shutdown shortly.</value> + </textarea> + + <!-- + current recordings status + --> + + <textarea name="recording_label" draworder="1" align="center"> + <font>label</font> + <area>20,110,760,30</area> + <!--<value>Percent Complete </value>--> + <value></value> + </textarea> + + <textarea name="recording_text" draworder="1" align="hcenter"> + <multiline>yes</multiline> + <font>biginfo</font> + <area>20,110,760,150</area> + <value></value> + </textarea> + + <!-- + next scheduled recording status + --> + + <textarea name="scheduled_label" draworder="1" align="center"> + <font>label</font> + <area>20,320,760,30</area> + <value></value> + </textarea> + + <textarea name="scheduled_text" draworder="1" align="hcenter"> + <multiline>yes</multiline> + <font>biginfo</font> + <area>20,400,760,120</area> + <value></value> + </textarea> + + <!-- + scheduled recordings conflict warning + --> + + <textarea name="conflicts_text" draworder="1" align="center"> + <font>warning</font> + <area>20,490,760,30</area> + <value>WARNING: There are conflicting scheduled recordings!</value> + </textarea> + + <!-- + start frontend button + + <textbutton name="startfrontend_button" draworder="1"> + <position>81,535</position> + <font>buttons</font> + <image function="on" filename="mw_text_button_on.png"></image> + <image function="off" filename="mw_text_button_off.png"></image> + <image function="pushed" filename="mw_text_button_pushed.png"></image> + </textbutton> + + --> + + </container> + + </window> + +</mythuitheme> diff --git a/abs/core-testing/LinHES-config-22/build_diskless.sh b/abs/core-testing/LinHES-config-22/build_diskless.sh new file mode 100755 index 0000000..4dfd5fc --- /dev/null +++ b/abs/core-testing/LinHES-config-22/build_diskless.sh @@ -0,0 +1,143 @@ +#!/bin/bash +#CD=/mnt/cd +. /etc/profile +. /etc/systemconfig + +TFTP=/data/srv/tftp +CD=/data/srv/tftp/live +DESTCD=/data/srv/tftp/CD +BASE=/data/srv/tftp/masterbuild + +MODULES=$DESTCD/MythVantage/base/ +myip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n1` +SRCFILES=$BASE/mnt/live/mnt/MythVantage/base/ + +function log () { +echo $1 +} + +function check_xvfb () { +export DISPLAY=127.0.0.1:25 + Xvfb -ac :25 & + +} + + +function create_base_image() { +echo $SRCFILES +if [ -f $SRCFILES/data.lzm ] +then + mkdir $HOST_IMG_DIR + cd $SRCFILES + echo "Creating image.." > $BASE/tmp/.install_state + LIST=`ls *.lzm` + for i in $LIST + do + echo $i + echo $i > $BASE/tmp/.install_percent + lzm2dir $i \/$HOST_IMG_DIR + done + + for i in sys proc dev tmp + do + mkdir /$HOST_IMG_DIR/$i + done + + chmod 777 /$HOST_IMG_DIR/tmp + mknod /$HOST_IMG_DIR/dev/null c 1 3 + mknod /$HOST_IMG_DIR/dev/null c 1 5 + mknod /$HOST_IMG_DIR/dev/console c 5 1 + chmod +s /$HOST_IMG_DIR/usr/bin/Xorg + chmod +s /$HOST_IMG_DIR/usr/bin/crontab + chmod +s /$HOST_IMG_DIR/usr/bin/sudo + chmod +s /$HOST_IMG_DIR/bin/mount + #copy fstab from masterbuild + cp -f $BASE/etc/fstab /$HOST_IMG_DIR/etc/fstab + echo "Done: installing data" > $BASE/tmp/.install_state + return 0 +else + echo "Error: no modules" > $BASE/tmp/.install_state + log "couldn't find modules to install" + return 1 +fi +} + +function configure_image () { + echo "Configuring system" > $BASE/tmp/.install_state + cp -f $BASE/etc/systemconfig $HOST_IMG_DIR/etc/systemconfig + chown root:mythtv $HOST_IMG_DIR/etc/systemconfig + chmod 775 "$HOST_IMG_DIR" /etc/systemconfig + cp /etc/mtab $HOST_IMG_DIR/etc/mtab + mount --bind /dev $HOST_IMG_DIR/dev + + chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh misc,hostype,network,this_is_install +#copy syssettings template to here. + SE=$BASE$TEMPLATES/settings/syssettings + mkdir -p $HOST_IMG_DIR/$TEMPLATES/settings/syssettings + cp -rp $SE/* ${HOST_IMG_DIR}/$TEMPLATES/settings/syssettings + chown root:mythtv $HOST_IMG_DIR/etc/systemconfig + chown -R mythtv:mythtv $HOST_IMG_DIR/$TEMPLATES/settings/syssettings + chmod -R 775 $HOST_IMG_DIR/$TEMPLATES/settings/syssettings +#update remotedb with this host settings + OLDDISPLAY=$DISPLAY + check_xvfb + chroot $HOST_IMG_DIR $MV_ROOT/bin/MythVantage -t restore,default_1 + chroot $HOST_IMG_DIR $MV_ROOT/bin/restore_default_settings.sh -c restore -t syssettings + if [ ! $? = 0 ] + then + touch $mountpoint/tmp/.dbsysfailed + chmod 777 $mountpoint/tmp/.dbsysfailed + else + #Run second time + chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh misc,hostype,network,this_is_install + chroot "$HOST_IMG_DIR" $MV_ROOT/bin/restore_default_settings.sh -c ACCESSCONTROL + fi +chroot "$HOST_IMG_DIR" $MV_ROOT/bin/systemconfig.sh advanced,this_is_install +cp -f $BASE/etc/X11/xorg.conf $HOST_IMG_DIR/etc/X11/xorg.conf +echo "Done" > $BASE/tmp/.install_state +DISPLAY=$OLDDISPLAY + +#cp /tmp/mythvantage_install.log $HOST_IMG_DIR/var/log/ +} + +function create_tftp_boot () { + + CFGFILE=$TFTP/pxelinux.cfg/01-$2 + echo "DEFAULT mythfe" > $CFGFILE + echo "LABEL mythfe" >> $CFGFILE + echo "kernel masterbuild/boot/vmlinuz26STB" >> $CFGFILE + echo "append vga=normal root=/dev/nfs rw netboot nfsroot=$myip:/data/srv/tftp/$1 ip=dhcp init=/sbin/runit" >> $CFGFILE + echo "TIMEOUT 2" >> $CFGFILE +} + +function create_nfs_export () { +echo "/data/srv/tftp/$1 *(rw,no_root_squash,anonuid=1000,anongid=1000) " >> /etc/exports +exportfs -arv +} + +#-------------------------------------------------------------------------------MAIN PROGRAM --------------------------------------------------------------------- +if [ x$1 = x -o x$2 = x ] +then + echo "usage: hostname macaddress" + exit 1 +fi + +image_name=$1 +mac_address=`echo $2| tr "[:upper:]" "[:lower:]"` + +echo "using image_name of $image_name" +echo "using mac_address of $mac_address" + +HOST_IMG_DIR=$TFTP/$1 + +create_base_image $image_name +configure_image +umount $HOST_IMG_DIR/dev +create_tftp_boot $image_name $mac_address +create_nfs_export $image_name + + + + +#create_dhcp_entry $mac_address + diff --git a/abs/core-testing/LinHES-config-22/checkout_MythVantage.sh b/abs/core-testing/LinHES-config-22/checkout_MythVantage.sh new file mode 100755 index 0000000..944b9c6 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/checkout_MythVantage.sh @@ -0,0 +1,49 @@ +#!/bin/bash +MYDIR=`pwd` +MYTHPATH="\/data\/LinHES-PKGBUILD\/abs\/core-testing\/mythtv\/stable\/mythtv\/src\/mythtv-0.21" + +function setup_links { +rm mythinstall.bin +rm mythbeselect.bin +ln -s $MYDIR/src/MythVantage-app/mythinstall/mythinstall ./mythinstall.bin +ln -s $MYDIR/src/MythVantage-app/mythbeselect/mythbeselect ./mythbeselect.bin +} + +function dl_repo { +mkdir src +cd src +if [ ! -d MythVantage-app ] +then + git clone http://mythvantage.com/MythVantage-app.git/ + cd MythVantage-app + git checkout --track -b LinHES origin/LinHES + cd $MYDIR + setup_links + cd - +else + echo "updating exisiting tree" + cd MythVantage-app + git pull + git checkout master + git merge + cd - +fi + +cd MythVantage-app +git checkout master +#git checkout origin/LinHES + +} + +dl_repo +sed -i "s/^MYTHPATH.*$/MYTHPATH\=\"$MYTHPATH\"/g" $MYDIR/src/MythVantage-app/mythinstall/mythinstall.pro +sed -i "s/#define __MVAPP__/\/\/#define __MVAPP__/g" $MYDIR/src/MythVantage-app/mythinstall/mv_common.h +sed -i "s/mythvantage/LinHES/g" $MYDIR/src/MythVantage-app/mythinstall/mv_common.h + +echo "INCLUDEPATH += /usr/include/mythtv" >> $MYDIR/src/MythVantage-app/mythbeselect/mythberestart.pro +echo "INCLUDEPATH += /usr/include/mythtv" >> $MYDIR/src/MythVantage-app/mythinstall/mythinstall.pro +cd $MYDIR/src/MythVantage-app/mythinstall && qmake +make || exit 1 +cd $MYDIR/src/MythVantage-app/mythbeselect && qmake +make ||exit 1 + diff --git a/abs/core-testing/LinHES-config-22/create_master.sh b/abs/core-testing/LinHES-config-22/create_master.sh new file mode 100755 index 0000000..1e641b4 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/create_master.sh @@ -0,0 +1,57 @@ +#!/bin/bash +#CD=/mnt/cd +CD=/data/srv/tftp/live +DESTCD=/data/srv/tftp/CD +DEST=/data/srv/tftp/masterbuild +MODULES=$DESTCD/MythVantage/base/ +myip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'|head -n1` + +mkdir -p $DESTCD +mkdir -p $DEST + +mount $CD +status=0 +if [ -f $CD/MythVantage/base/data.lzm ] +then + status=0 +else + status=1 +fi +if [ x$status = x0 ] +then + echo "copying to disk" + cp -rp $CD/* $DESTCD + cd $MODULES + for i in *.lzm + do + echo $i + lzm2dir $i \/$DEST + done + for i in sys proc dev tmp + do + mkdir $DEST/$i + done + chmod 777 /$DEST/tmp + mknod $DEST/dev/null c 1 3 + mknod $DEST/dev/null c 1 5 + mknod $DEST/dev/console c 5 1 + chmod +s $DEST/usr/bin/Xorg + chmod +s $DEST/usr/bin/crontab + chmod +s $DEST/usr/bin/sudo + chmod +s $DEST/bin/mount +fi +if [ ! -f $DEST/etc/fstab.bak ] +then + cp $DEST/etc/fstab $DEST/etc/fstab.bak +fi +tac $DEST/etc/fstab.bak|tail +4|tac > $DEST/etc/fstab +echo "$myip:/data/srv/tftp/masterbuild / nfs" >> $DEST/etc/fstab +echo "/data/srv/tftp/masterbuild *(rw,no_root_squash,anonuid=1000,anongid=1000)" >> /etc/exports + + +exportfs -arv + +#copy in the modules +mkdir -p $DEST/mnt/live/mnt/ +mv $DESTCD/* $DEST/mnt/live/mnt/ + diff --git a/abs/core-testing/LinHES-config-22/file_time_offset.py b/abs/core-testing/LinHES-config-22/file_time_offset.py new file mode 100755 index 0000000..f2973d0 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/file_time_offset.py @@ -0,0 +1,39 @@ +#!/usr/bin/python + + +import time +import os +import glob +import getopt +import sys +def main(argv): + filecount=0 +# root = "/tmp" +# offset = 4 + now = int(time.time()) + + + try: + opts, args = getopt.getopt(argv, "hs:d:") + except getopt.GetoptError: + sys.exit(2) + for opt, arg in opts: + if opt in ("-h", "--help"): + print "-s seconds -d /testdir" + print "default if 4 seconds" + sys.exit() + elif opt in ( "-s" ): + offset = int(arg) + elif opt in ("-d"): + root = arg + + for item in glob.glob(root+"/*"): + lastmodDate = os.path.getmtime(item) + tdiff= now-lastmodDate + #print tdiff, offset + + if tdiff > offset: + filecount+=1 + print filecount +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/abs/core-testing/LinHES-config-22/install-ui.xml b/abs/core-testing/LinHES-config-22/install-ui.xml new file mode 100755 index 0000000..2b3a043 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/install-ui.xml @@ -0,0 +1,175 @@ +<!-- + + This is a myth style theme file for mythvantage + + (c) 2005 by a whole bunch of people associated with MythTV + +--> +<mythuitheme> + + <window name="welcome_screen"> + + <!-- + + First, define all the fonts we need on this screen + + --> + <font name="title" face="Arial"> + <color>#ffff00</color> + <dropcolor>#000000</dropcolor> + <size>20</size> + <shadow>3,3</shadow> + <bold>yes</bold> + </font> + + <font name="time" face="Arial"> + <color>#9999cc</color> + <size>18</size> + <bold>yes</bold> + </font> + + <font name="label" face="Arial"> + <color>#ffff00</color> + <dropcolor>#000000</dropcolor> + <size>18</size> + <shadow>3,3</shadow> + <bold>yes</bold> + </font> + + <font name="info" face="Arial"> + <color>#ffffff</color> + <size>18</size> + <bold>yes</bold> + </font> + + <font name="biginfo" face="Arial"> + <color>#ffffff</color> + <size>50</size> + <bold>yes</bold> + </font> + <font name="warning" face="Arial"> + <color>#ff0000</color> + <dropcolor>#000000</dropcolor> + <size>16</size> + <shadow>2,2</shadow> + <bold>yes</bold> + </font> + + <font name="buttons" face="Arial"> + <color>#ffff00</color> + <size>14</size> + <bold>yes</bold> + </font> + <font name="tinyinfo" face="Arial"> + <color>#9999cc</color> + <size>12</size> + <bold>no</bold> + </font> + + <container name="main_display"> + <area>0,0,800,600</area> + + <textarea name="title" draworder="0" align="center"> + <multiline>no</multiline> + <font>title</font> + <area>50,40,700,40</area> + <value>LinHES: The Linux Home Entertainment System </value> + </textarea> + + <!-- + time + --> + <textarea name="time_text" draworder="0" align="right"> + <multiline>no</multiline> + <font>time</font> + <area>660,520,110,30</area> + <value></value> + </textarea> + + <textarea name="date_text" draworder="0" align="hcenter"> + <multiline>yes</multiline> + <font>time</font> + <area>20,75,740,100</area> + <value></value> + </textarea> + + <!-- + current myth status + --> + + <textarea name="status_text" draworder="1" align="center"> + <multiline>yes</multiline> + <font>info</font> + <area>20,100,760,60</area> + <value>MythTV is idle and will shutdown shortly.</value> + </textarea> + + <!-- + current recordings status + --> + + <textarea name="recording_label" draworder="1" align="center"> + <font>label</font> + <area>20,140,760,30</area> + <!--<value>Percent Complete </value>--> + <value></value> + </textarea> + + <textarea name="recording_text" draworder="1" align="hcenter"> + <multiline>yes</multiline> + <font>biginfo</font> + <area>20,140,760,150</area> + <value></value> + </textarea> + + <!-- + next scheduled recording status + --> + + <textarea name="scheduled_label" draworder="1" align="center"> + <font>label</font> + <area>20,320,760,30</area> + <value></value> + </textarea> + + <textarea name="scheduled_text" draworder="1" align="hcenter"> + <multiline>yes</multiline> + <font>biginfo</font> + <area>20,400,760,120</area> + <value></value> + </textarea> + + <textarea name="mythvantage_text" draworder="1" align="right"> + <multiline>no</multiline> + <font>tinyinfo</font> + <area>20,560,760,30</area> + <value></value> + </textarea> + <!-- + scheduled recordings conflict warning + --> + + <textarea name="conflicts_text" draworder="1" align="center"> + <font>warning</font> + <area>20,490,760,30</area> + <value>WARNING: There are conflicting scheduled recordings!</value> + </textarea> + + <!-- + start frontend button + + <textbutton name="startfrontend_button" draworder="1"> + <position>81,535</position> + <font>buttons</font> + <image function="on" filename="mw_text_button_on.png"></image> + <image function="off" filename="mw_text_button_off.png"></image> + <image function="pushed" filename="mw_text_button_pushed.png"></image> + </textbutton> + + --> + + </container> + + </window> + +</mythuitheme> diff --git a/abs/core-testing/LinHES-config-22/install_db_chroot.sh b/abs/core-testing/LinHES-config-22/install_db_chroot.sh new file mode 100644 index 0000000..94305d2 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/install_db_chroot.sh @@ -0,0 +1,63 @@ +#!/bin/bash +. /etc/profile +. /etc/systemconfig + + +myhost=$hostname +hostname $myhost +echo $myhost > /etc/hostname +echo "install_db_chroot hostname is $hostname" + +. $MV_ROOT/bin/install_functions.sh +#myhost=`cat /etc/hostname` + +#mount -t proc none /proc +pacman --noconfirm -Sf mysql +/etc/rc.d/mysqld + +status=1 +mysqlstatus=1 +while [ ! $status = 0 ] +do + /etc/rc.d/mysqld stop + sleep 1 + /etc/rc.d/mysqld start + mysqlstatus=$? + if [ $mysqlstatus = 0 ] + then + mysql -e "show databases;" + showstatus=$? + if [ $showstatus = 0 ] + then + pacman --noconfirm -R mythdb-initial + pacman --noconfirm -S mythdb-initial + $MV_ROOT/bin/restore_default_settings.sh -c load + DISPLAY=127.0.0.1:0 $MV_ROOT/bin/MythVantage -t restore,default_1 + $MV_ROOT/bin/restore_default_settings.sh -c restore -t syssettings + $MV_ROOT/bin/systemconfig.sh misc,hostype,this_is_install + + update_db_settings HostServiceMythWEB "1" + echo 'UseMythWEB="1"' >> /etc/systemconfig + + #update database to allow user jobs on this host. + $MV_ROOT/bin/restore_default_settings.sh -c USERJOBALLOW + $MV_ROOT/bin/restore_default_settings.sh -c ACCESSCONTROL + if [ -d /data/srv/mysql/mythconverg ] + #if [ -d /var/lib/mysql/mythconverg ] + then + # pacman --noconfirm -R webcalendar + # pacman --noconfirm --nodeps -S webcalendar + status=0 + fi +# if [ $SystemType = "Master_backend" ] +# then +# $MV_ROOT/bin/restore_default_settings.sh -c BECONFIG -s master -a $dbhost +# fi + fi + fi +done +/etc/rc.d/mysqld stop +#umount /proc + + + diff --git a/abs/core-testing/LinHES-config-22/install_functions.sh b/abs/core-testing/LinHES-config-22/install_functions.sh new file mode 100755 index 0000000..83a2bed --- /dev/null +++ b/abs/core-testing/LinHES-config-22/install_functions.sh @@ -0,0 +1,344 @@ +#!/bin/bash +. /etc/profile + +disk=$2 +mountpoint=new_boot + +#------------------------------------------- +MYTHDBUSER=mythtv +MYTHTVPASSWD=mythtv +CMDLINE=$(cat /proc/cmdline) +hostname=`hostname` +MYSQLCMD_C="mysql -u$MYTHDBUSER -p$MYTHTVPASSWD mythconverg -B --exec" +BASE="" +found_remote=1 + +function update_db_settings () { + + printhl " setting database value $1 to $2 for $hostname" + $MYSQLCMD_C "delete from settings where value='${1}' and hostname=\"$hostname\";" 2>/dev/null + $MYSQLCMD_C "REPLACE INTO settings set value='${1}', data='${2}' , hostname=\"$hostname\";" 2>/dev/null +} + +function random_theme () { +THEMES="basic-blue +basic-green +basic-red +basic-purple +basic-amber" + +theme=($THEMES) # Read into array variable. + +num_themes=${#theme[*]} # Count how many elements. + +pick=${theme[$((RANDOM%num_themes))]} +printhl " Selected $pick as the theme" +update_db_settings Theme "$pick" +} + +function parse_cmdline_2_db(){ + echo $CMDLINE | grep -q displayres + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*displayres=} + update_db_settings HostXres $TEMPVAR + fi + +} + + +function bootsplash_setup (){ + echo $CMDLINE | grep -q splash=silent + if [ $? -eq 0 ] + then + update_db_settings Hostbootsplash 1 + else + update_db_settings Hostbootsplash 0 + fi +} + + +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 ] + then + cd $TEMPLATES/remotes/$Remotetype + for i in lircd* + do + cat $i >> $BASE/etc/lircd.conf + done + cp -f lircrc* $BASE/etc/lircrc 2> /dev/null + [ -e /etc/lircrc ] && chmod 755 /etc/lircrc + update_db_settings HostRemoteType "$Remotetype" + #special case for special remote + printhl "Starting with support for $Remotetype" + if [ "$Remotetype" == "dvico" ] + then + /usr/sbin/lircd -d /dev/usb/hiddev0 --driver=dvico + elif [ "$Remotetype" == "Dvico-Dual-Digital4-rev2" ] + then + /usr/sbin/lircd -d /dev/input/irremote --driver=devinput + else + /usr/sbin/lircd -d /dev/lirc0 + fi + [ -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" + fi +} + +function scan_for_hpg_receiver() { +printhl " Scanning for Hauppauge receiver" +for hpgid in `lspci -nm -d4444: |cut -d" " -f6- |tr -d '"'|tr " " :` +do + line=`grep $hpgid $TEMPLATES/remotes/i2c.id` + if [ $? -eq 0 ] + then + modprobe lirc_i2c + FoundReceiverType=`echo "$line"|cut -d"|" -f2` + Remotetype=`echo "$line"|cut -d"|" -f4` + statusline=`echo "$line"|cut -d"|" -f2,4` + #echo "Found $statusline , $Remotetype" + echo "Found Hauppauge" + echo "-------------------" + echo " 1) Hauppauge black" + echo " 2) Hauppauge silver" + echo " 3) hauppauge-grey-g3" + echo "" + read -p "Which Hauppauge remote (5 sec): " -t 5 ans + echo + if [ "$?" != "0" ]; then + echo + echo "Using default $Remotetype" + else + case $ans in + 1) Remotetype="hauppauge-black";; + 2) Remotetype="hauppauge-silver";; + 3) Remotetype="hauppauge-grey-g3" ;; + *) echo "Using default $Remotetype";; + esac + fi + update_db_settings HostReceiverType $FoundReceiverType + found_remote=0 + setupremote + break + fi +done +} + + +function scan_for_usb_remote () { +#found_remote=1 +printhl " Scanning for usb receiver/remote" +while read line +do + USBID=`echo "$line"|cut -d"|" -f1` + lsusb -d "$USBID" > /dev/null 2>/dev/null + if [ $? -eq 0 ] + then + Remotetype=`echo "$line"|cut -d"|" -f2` + printhl "Found $Remotetype" + setupremote + found_remote=0 + break + fi +done <$BASE/$TEMPLATES/remotes/receiver_usb.id +if [ $found_remote -eq 1 ] +then + scan_for_hpg_receiver +fi +printhl " Scanning for TatIR" +if lsusb | grep 04d8:0004 > /dev/null 2>/dev/null +then + /usr/bin/PyroUsb.py > /dev/null 2>&1 & +fi + +if [ $found_remote -eq 1 ] +then +#No remote found_remote + update_db_settings HostRemoteType "no_remote" +fi + +} + +function rest_of_network () { + #netmask + echo $CMDLINE | grep -q cnetmask + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*cnetmask=} + NETMASK=${TEMPVAR%% *} + /sbin/ifconfig eth0 $IP netmask $NETMASK + nm=`/usr/bin/nmconv.py -obits $NETMASK` + NETMASK="/$nm $NETMASK" + #echo $NETMASK + update_db_settings HostNETMASK${MYTHDEFAULT} "$NETMASK" + else + printhl " Netmask not found" + fi + #gateway + echo $CMDLINE | grep -q cgateway + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*cgateway=} + GATEWAY=${TEMPVAR%% *} + /sbin/route add default gw $GATEWAY + update_db_settings HostGW${MYTHDEFAULT} "$GATEWAY" + else + printhl " Gateway not found" + fi + + #dns + echo $CMDLINE | grep -q cdns + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*cdns=} + DNS=${TEMPVAR%% *} + echo "nameserver $DNS" >> /etc/resolv.conf + update_db_settings HostDNS${MYTHDEFAULT} "$DNS" + else + printhl " DNS not found" + fi + echo $CMDLINE | grep -q chostname + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*chostname=} + MYHOST=${TEMPVAR%% *} + update_db_settings HostMyhostname "$MYHOST" + else + printhl " hostname not found" + fi +} + +function init_network { + echo $CMDLINE |grep -q cnetdev + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*cnetdev=} + MYTHDEFAULT=${TEMPVAR%% *} + else + MYTHDEFAULT="eth0" + fi + + echo $CMDLINE | grep -q ip + if [ $? -eq 0 ] + then + update_db_settings HostDefaulteth0 0 + update_db_settings HostDefault${MYTHDEFAULT} 1 + + update_db_settings HostActiveonbooteth0 0 + update_db_settings HostActiveonboot${MYTHDEFAULT} 1 + update_db_settings HostNetDevice ${MYTHDEFAULT} + + TEMPVAR=${CMDLINE#*cip=} + IP=${TEMPVAR%% *} + if [ "$IP" == "dhcp" ] + then + /sbin/dhcpcd $MYTHDEFAULT + update_db_settings HostUseDHCP${MYTHDEFAULT} 0 + else + /sbin/ifconfig ${MYTHDEFAULT} $IP + update_db_settings HostUseDHCP${MYTHDEFAULT} 1 + update_db_settings HostIP${MYTHDEFAULT} "$IP" + rest_of_network + fi + fi + + + + +} + +function dev_up_check(){ + /sbin/ifconfig $1 1>/dev/null 2>/dev/null + status=$? + if [ $status -eq 1 ] + then + return 0 + else + devip=`/sbin/ifconfig | grep -C1 $1| grep inet|grep -v inet6 | cut -d: -f2 | awk '{ print $1}'` + if [ "x$devip" = "x" ] + then + return 1 + else + return 0 + fi + fi +} + +function request_dhcp(){ + echo $CMDLINE |grep -q cnetdev + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*cnetdev=} + MYTHDEFAULT_NET=${TEMPVAR%% *} + else + MYTHDEFAULT_NET="eth0" + fi + for ndev in eth0 eth1 wlan0 wlan1 ath0 + do + dev_up_check $ndev + status=$? + if [ $status -eq 1 ] + then + #interface is down, lets see if dhcp responds + dhcpcd -Td -t2 $ndev -h "" > /tmp/dhcpinfo.$ndev 2>/dev/null + #check for hostname here + + TEMPVAR=`grep new_ip_address /tmp/dhcpinfo.$ndev |cut -d\= -f2` + if [ ! x$TEMPVAR = x ] + then + update_db_settings HostIP$ndev "$TEMPVAR" + TEMPVAR=`grep new_subnet_mask /tmp/dhcpinfo.$ndev |cut -d\= -f2` + nm=`/usr/bin/nmconv.py -obits $TEMPVAR` + TEMPVAR="/$nm $TEMPVAR" + update_db_settings HostNETMASK$ndev "$TEMPVAR" + TEMPVAR=`grep new_routers /tmp/dhcpinfo.$ndev |cut -d\= -f2` + update_db_settings HostGW$ndev "$TEMPVAR" + TEMPVAR=`grep new_domain_name_servers /tmp/dhcpinfo.$ndev |cut -d\= -f2| tr -d \"|tr -d \'|cut -d" " -f 1` + update_db_settings HostDNS$ndev "$TEMPVAR" + fi + fi + done + TEMPVAR=`grep new_host_name /tmp/dhcpinfo.$MYTHDEFAULT_NET |cut -d\= -f2` + if [ ! x$TEMPVAR = x ] + then + update_db_settings HostMyhostname "$TEMPVAR" + fi + +} + +function init_remote { + echo $CMDLINE | grep -q remoteport + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*remoteport=} + REMOTEPORT=${TEMPVAR%% *} + if [ x"$ReceiverType" = "xSerial" ] + then + if [ -e /dev/$REMOTEPORT ] + then + /usr/bin/setserial /dev/$REMOTEPORT uart none + /sbin/modprobe lirc_serial + update_db_settings HostReceiverType Serial + update_db_settings HostSerialPortlirc "$REMOTEPORT" + fi + fi + + fi + + echo $CMDLINE | grep -q remote + if [ $? -eq 0 ] + then + TEMPVAR=${CMDLINE#*remote=} + Remotetype=${TEMPVAR%% *} + setupremote + else + scan_for_usb_remote + fi +} + +#----------------------- + + diff --git a/abs/core-testing/LinHES-config-22/install_proxy.sh b/abs/core-testing/LinHES-config-22/install_proxy.sh new file mode 100755 index 0000000..71b675b --- /dev/null +++ b/abs/core-testing/LinHES-config-22/install_proxy.sh @@ -0,0 +1,234 @@ +#!/bin/bash +export TERM=vt100 +MVHOSTNAME=larch5 +. /etc/profile +TEMP_TEMPLATES=/tmp/templates +disk=$2 +rootfs=$3 +rootsize=$4 +datafs=$5 +datasize=$6 +swapsize=$7 +mountpoint="/new_boot" +run=$MV_ROOT/bin/install_functions.sh +. /etc/systemconfig 2>/dev/null +. $MV_ROOT/bin/networkconfig.sh +CMDLINE=$(cat /proc/cmdline) +BACKUPFILE="/myth/backup/mythconverg.sql.gz" + + +progress () { + mypercent=`echo "$1" | cut -d. -f1` + if [ x$mypercent = x ] + then + echo "" > /tmp/.install_percent + else + echo "${mypercent}% complete" > /tmp/.install_percent + fi +} + + +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 + rc=$? + echo "mv_install.py exit code $rc" + if [ $rc != 0 ] + then + echo "mv_install error" >> /tmp/.install_error + fi + exit $rc + ;; + + NETBOOT) + echo "-----------------------------------------------------------------------3-----" + netboot-full_install + ;; + + find_update) + mv_install.py --rootdisk=$disk -c find_upgrade + ;; + + upgrade_it) + mv_install.py --rootdisk=$disk --rootfs=$rootfs -c upgrade + ;; + + disk_model_it) + model="unknown" + size="xxx" + case $2 in + h* ) + model=`cat /proc/ide/$2/model` + ;; + s*) model=`sginfo /dev/$2|grep Product|awk ' { print $2 } '` + ;; + esac + size=`parted /dev/$2 print |grep Disk|awk ' { print $3 } ' ` + echo ""$model" $size " >/tmp/model + ;; + + network_check_it) + #Should never return from check_network + case $2 in + setup_network) + vnc_check + install_network_setup + ;; + + check_self) + myipdefault=`ifconfig | grep -C1 $default_interface| grep -v $default_interface | cut -d: -f2 | awk '{ print $1}'` + echo "network check myself" + ifconfig + ping -c 1 $myipdefault + if [ ! $? = 0 ] + then + exit 3 + #can't ping yourself + fi + ;; + check_gw) + #check gateway + echo "network check gateway" + /sbin/route -n + mygwdefault=`/sbin/route -n |grep $default_interface|grep UG|awk '{ print $2}'` + echo "Default gateway seems to be $mygwdefault" + if [ ! x$mygwdefault = x ] + then + sleep 2 + ping -c 5 $mygwdefault + if [ ! $? = 0 ] + then + exit 4 + fi + fi + ;; + check_ns) + #check nameserver + echo " network check nameserver" + mydns=`cat /etc/resolv.conf|grep nameserver|head -1|awk '{ print $2}'` + ping -c 1 $mydns + if [ ! $? = 0 ] + then + exit 5 + fi + ;; + check_names) + echo "network check resolve names" + host google.com + if [ ! $? = 0 ] + then + exit 6 + fi + ;; + host_names) + #if host is found, then check to see if it's online + #if hoip matchs my ip assume it's ok + echo "network check my hostname $hostname" + hout=`host $hostname|head -n1` + status=$? + hoip=`echo $hout|awk '{print $4}'` + if [ $hoip = found: ] + then + status=1 + fi + + if [ $hoip = "out;" ] + then + #;; connection timed out; no servers could be reached + echo "DNS servers not found" + status=1 + fi + + unkownhost=`host unkown.linhes.org |head -n1 ` + unkownhostip=`echo $unkownhost |awk '{print $4}'` + + #found host, now grab the ip + if [ $status = 0 ] + then + hoip=`echo $hout|awk '{print $4}'` + /sbin/ifconfig -a |grep -q $hoip + if [ $? = 0 ] + then + echo "DNS ip matches on of my ips $hoip" + status=0 + else + if [ $unkownhostip = $hoip ] + then + echo "Bad DNS returning false hits" + echo "Assuming hostname is OK" + echo "DNS unknown: $unkownhostip" + echo " HOSTDNS: $hoip " + /sbin/ifconfig -a |grep "inet addr" + else + echo "IP in DNS but doesn't match mine, hostname is not safe to use" + echo "DNS:$hoip" + echo "HOST: " + /sbin/ifconfig -a |grep "inet addr" + status=7 + fi + fi + else + echo "Couldn't find hostname in DNS, must be safe to use" + status=0 + fi + exit $status + ;; + + esac + exit 0 + ;; + + * ) + if [ -f /tmp/.install_state ] + then + state=`cat /tmp/.install_state` + else + state=" " + fi + if [ x"${state}" = "xConfiguring system" ] + then + progress "" + else + + if [ -f /tmp/.startsize.io ] + then + . /tmp/.startsize.io + #finding the drive + ddrive=`df | grep $mountpoint | head -n1 | awk -F/ ' { print $3 } ' | cut -d" " -f 1|cut -b1,2,3 ` + used=`statgrab -M disk.|grep ${ddrive}.write_bytes|cut -d= -f 2|tr -d " "` + used=`echo $used-$STARTSIZE|bc` + #echo $used + fi + + if [ ! x$used = x ] + then + . /root/.install_size + #somehow find if it's an install or update + if [ -f /tmp/.this_is_upgrade ] + then + total=$UPGRADESIZE + else + total=$TOTALSIZE + fi + percent=`echo "scale=2 ; ($used/$total) * 100 " |bc ` + cond2=$(echo "$percent > 98" |bc ) + if [ $cond2 -eq 1 ] + then + percent=98 + fi + if [ x"${state}" = "xDone" ] + then + percent=100 + fi + cond3=$(echo "$percent < 3" |bc ) + if [ $cond3 -eq 0 ] + then + progress $percent + fi + fi + fi + ;; +esac + + + diff --git a/abs/core-testing/LinHES-config-22/issue b/abs/core-testing/LinHES-config-22/issue new file mode 100644 index 0000000..00d4abd --- /dev/null +++ b/abs/core-testing/LinHES-config-22/issue @@ -0,0 +1,2 @@ +LinHes + diff --git a/abs/core-testing/LinHES-config-22/live-install.sh b/abs/core-testing/LinHES-config-22/live-install.sh new file mode 100755 index 0000000..573bb1f --- /dev/null +++ b/abs/core-testing/LinHES-config-22/live-install.sh @@ -0,0 +1,28 @@ +#!/bin/bash +#redirect stderr to stdout, then rediret stdout to file +. /etc/profile +exec 2>&1 +exec > /tmp/mythvantage_install.log +. /etc/X11/STBWINDOWMANAGER +/usr/bin/nvidia-settings -a InitialPixmapPlacement=2 +keylaunch & +/usr/bin/tilda & +/usr/X11R6/bin/unclutter -root -idle 0 -jitter 400 -noevents & +export MALLOC_CHECK_=0 +if [ -f /opt/vmware/bin32/vmware-user-wrapper ] +then + /opt/vmware/bin32/vmware-user-wrapper & +fi +xhost + +CMDLINE=$(cat /proc/cmdline) +echo $CMDLINE |grep -q nfsroot +NFSROOT=$? +if [ x$NFSROOT = x1 ] +then + + unbuffer MythVantage & +else + NETBOOT=YES MythVantage & +fi + +exec $STBWINDOWMANAGER diff --git a/abs/core-testing/LinHES-config-22/mv_advanced.py b/abs/core-testing/LinHES-config-22/mv_advanced.py new file mode 100755 index 0000000..4790fcf --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_advanced.py @@ -0,0 +1,384 @@ +# -*- coding: utf-8 -*- +import logging, os, re +import mv_common + +def setup_pacman(create_link): + if create_link: + logging.info(" Creating pacman link") + #LOOK + #This is not implmented yet, below is the bash code for reference + #if [ ! x$1 = x ] + #then + #ln -s ${BASE}/data/var ${BASE}/data/srv/httpd/htdocs/repo + #echo "creating the link for the pacman repo mirror" + #fi + + #for i in mv-core mv-core-testing mv-extra mv-extra-testing + #do + #echo "[$i]" > ${BASE}/etc/pacman.d/$i + ##add mirror if needed + #if [ x$PKG_MIRROR = x1 ] + #then + #echo " Server = http://$dbhost/repo/$i " >> ${BASE}/etc/pacman.d/$i + #fi + ##add user templates + #USERTEMPLATES="/data/home/mythtv/templates" + #if [ -f $USERTEMPLATES/sources/$i ] + #then + #echo "Adding user $i" + #cat $USERTEMPLATES/sources/$i >> ${BASE}/etc/pacman.d/$i + #fi + #cat $TEMPLATES/sources/$i >> ${BASE}/etc/pacman.d/$i + #echo "setting local mirror to $dbhost for $i " + #done + else: + logging.info(" Pacman link will not be created") + return + +def setup_ncid_client(dbhost,templatefile): + #This always runs + logging.debug(" Configuring ncid client with server %s",dbhost) + cmd = '''sed -e "s/^set Host.*$/set Host %s /" %s >/etc/ncid/ncid.conf''' %(dbhost, templatefile) + return + +def setup_ncid_daemon(port,templatefile,Runncidd): + logging.info(" Configuring callerid daemon") + if Runncidd == "1": + logging.debug(" Port: %s",port) + mv_common.cp_and_log("/etc/ncid/ncidd.conf",templatefile) + cmd = '''sed -e "s/.*set ttyport.*$/set ttyport = \/dev\/%s /" %s >/etc/ncid/ncidd.conf''' %(port,templatefile) + mv_common.runcmd(cmd) + mv_common.pacinstall("ncidd") + mv_common.add_service("ncidd") + else: + logging.debug(" Callerid will not run") + mv_common.pacremove("ncidd") + mv_common.remove_service("ncidd") + return + +def setup_splash(Usebootsplash): + if Usebootsplash == "1": + logging.info(" Enabling splash") + cmd = ''' sed -i "s/^default.*0/default 1/g" /boot/grub/menu.lst''' + mv_common.runcmd(cmd) + else: + logging.info(" Disabling splash") + cmd = ''' sed -i "s/^default.*1/default 0/g" /boot/grub/menu.lst''' + 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_hobbit(UseHobbit,SystemType,dbhost): + if UseHobbit == "1": + if SystemType == "Standalone" or SystemType == "Master_backend": + logging.info(" Installing hobbit server") + mv_common.pacinstall("hobbitserver") + mv_common.add_service("hobbit") + else: + logging.info(" Installing hobbit client") + mv_common.pacinstall("hobbit-client") + setup_hobbit_client(dbhost) + mv_common.add_service("hobbit-client") + + else: + logging.info(" Removing Hobbit") + mv_common.pacremove("hobbit") + mv_common.pacremove("hobbit-client") + mv_common.remove_service("hobbit-client") + mv_common.remove_service("hobbitserver") + cmd = "rm -f /data/srv/httpd/htdocs/hobbit/index.html" + mv_common.runcmd(cmd) + return + +def setup_hobbit_client(dbhost): + logging.info(" Configuring hobbit client") + logging.debug(" hobbit server is %s:", dbhost) + cmd='''sed -i "s/^BBDISP.*$/BBDISP=%s/g" /data/srv/hobbit/client/etc/hobbitclient.cfg ''' %dbhost + mv_common.runcmd(cmd) + return + +def setup_evrouter(UseEvrouter,EvrouterConfig,template): + if UseEvrouter == "1": + logging.info(" Configuring everouter") + logging.debug(" EvrouterConfig is %s:",EvrouterConfig) + if EvrouterConfig == "tinker": + logging.debug(" tinker mode, not changing the config") + return + mv_common.pacinstall("evrouter") + mv_common.pacinstall("Xvfb") + mv_common.cp_and_log(template+"/evrouter/"+EvrouterConfig,"/etc/evrouter.cfg") + mv_common.add_service("evrouter") + mv_common.add_service("Xvfb") + else: + logging.info(" Not using evrouter") + mv_common.pacremove("evrouter") + mv_common.remove_service("evrouter") + mv_common.remove_service("Xvfb") + + return + +def setup_DNSmasq(RunDHCP,ip,gw,nameserver): + if RunDHCP == "1": + logging.info(" Configuring dhcp server(dnsmasq)") + logging.debug(" ip: %s", ip) + logging.debug(" gw: %s", gw) + logging.debug(" ns: %s", nameserver) + mv_common.pacinstall("dnsmasq") + mv_common.pacinstall("mvpmc") + mv_common.add_service("dnsmasq") + logging.debug(" Setting default route to my gw: %s",gw) + try: + f = open("/etc/dnsmasq.conf",'r') + dnsconf = f.readlines() + f.close() + except: + logging.info(" Couldn't open dnsmasq.conf") + return + for line in dnsconf: + outline = line + if re.match("^dhcp-option=3",line): + logging.debug(" Setting default route to my gw: %s",gw) + outline = "dhcp-option=3,%s\n" %gw + if re.match("^dhcp-option=6",line): + logging.debug(" Setting dns to my ip: %s",ip) + outline = "dhcp-option=6,%s\n" %ip + f.write(outline) + f.close() + + logging.debug(" change nfsroot to my ip:%s",ip) + cmd = '''sed -i "s/nfsroot=.*:/nfsroot=%s:/g" /data/srv/tftp/pxelinux.cfg/default''' %ip + mv_common.runcmd(cmd) + + logging.debug(" Adding 127.0.0.1 to resolv.conf") + logging.debug(" other nameserver is %s",nameserver) + try: + f = open("/etc/resolv.conf",'r') + dns = f.readlines() + f.close() + except: + dns='' + logging.debug(" Couldn't open resolv.conf for reading") + try: + f = open("/etc/resolv.conf",'w') + line="search lan\n" + f.write(line) + line="nameserver 127.0.0.1\n" + f.write(line) + line="nameserver %s\n" %nameserver + f.write(line) + for line in dns: + f.write(line) + f.close() + except: + logging.debug(" Couldn't open resolv.conf for writing") + + logging.debug(" setup dongle.config") + cmd = ''' sed -i "s/mvpmc -f .*/mvpmc -f \/etc\/helvR10.fon -s %s \& /" /data/srv/tftp/dongle.bin.config ''' %ip + #COMMAND="%s/mvpmc -f .*/mvpmc -f \/etc\/helvR10.fon -s ${ip} \& /" + #ex ${BASE}/data/srv/tftp/dongle.bin.config <<EOF + mv_common.runcmd(cmd) + else: + logging.info(" removing dhcp server(dnsmasq)") + mv_common.pacremove("dnsmasq") + mv_common.pacremove("mvpmc") + mv_common.remove_service("dnsmasq") + return + +def setup_mythweb(UseMythWEB): + if UseMythWEB == "1": + logging.info(" Activating mythweb") + mv_common.pacinstall("lighttpd") + mv_common.pacinstall("mythweb") + mv_common.add_service("lighttpd") + else: + 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["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["Samba_media"] + Samba_home = systemconfig["Samba_home"] + if systemconfig["Samba_mediareadonly"] == "1": + smreadonly = "yes" + else: + smreadonly = "no" + + if systemconfig["Samba_homereadonly"] == "1": + shreadonly = "yes" + else: + shreadonly = "no" + domain = systemconfig["Samba_domain"] + servername = systemconfig["hostname"] + + try: + f = open(systemconfig["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") + 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("portmap") + cmd = '''sed -e "s/REPLACEME/*/g" %s >/etc/exports''' %templatefile + mv_common.add_service("nfsd") + mv_common.add_service("nfs-utils") + mv_common.add_service("portmap") + 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_advanced(systemconfig,data_config): + logging.info("____Start of advanced configuration____") + create_link = False + if systemconfig["SystemType"] == "Master_backend": + create_link = True + setup_pacman(create_link) + setup_ncid_client(systemconfig["dbhost"], + systemconfig["TEMPLATES"]+"/ncid.conf.template") + + setup_ncid_daemon(systemconfig["nciddSerialPort"], + systemconfig["TEMPLATES"]+"/ncidd.conf.template", + systemconfig["Runncidd"]) + + setup_splash(systemconfig["Usebootsplash"]) + if data_config.SYSTEMTYPE == "MythVantage": + setup_hobbit(systemconfig["UseHobbit"], + systemconfig["SystemType"], + systemconfig["dbhost"]) + if data_config.SYSTEMTYPE == "LinHES": + setup_rrd(systemconfig["UseRRD"]) + + setup_evrouter(systemconfig["UseEvrouter"], + systemconfig["EvrouterConfig"], + systemconfig["TEMPLATES"]) + + setup_DNSmasq(systemconfig["RunDHCP"], + systemconfig["mythip"], + systemconfig["mythgw"], + systemconfig["mythdns"]) + + setup_mythweb(systemconfig["UseMythWEB"]) + setup_samba(systemconfig,data_config) + setup_NFSshares(systemconfig["UseNFS"], + systemconfig["TEMPLATES"]+"/exports.template") + + setup_dyndns(systemconfig["DDnsEnable"]) + logging.info("__End of advanced configuration\n") diff --git a/abs/core-testing/LinHES-config-22/mv_common.py b/abs/core-testing/LinHES-config-22/mv_common.py new file mode 100755 index 0000000..a492597 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_common.py @@ -0,0 +1,201 @@ +# -*- coding: utf-8 -*- +import logging, os, time +import commands +config_file = "mv_config" +data_config = __import__(config_file, globals(), locals(), []) + +def runcmd(cmd): + if data_config.NOOPDEBUG=="FALSE": + pass + else: + cmd = "echo "+cmd + logging.debug(" %s",cmd) + cmdout = commands.getstatusoutput(cmd) + logging.debug(" %s",cmdout) + return cmdout[0] + +def runcmd_output(cmd): + if data_config.NOOPDEBUG=="FALSE": + pass + else: + cmd = "echo "+cmd + logging.debug(" %s",cmd) + cmdout = commands.getstatusoutput(cmd) + logging.debug(" %s",cmdout) + return cmdout[1] + +def services(systemconfig): + logging.debug("______Start of services______") + logging.debug("__End services") + +def cp_and_log(srcfile,destfile): + #return + if not os.path.exists(srcfile): + logging.info("%s is not present, skipping...",srcfile) + else: + cmd = ("rsync -arhp %s %s") %(srcfile,destfile) + runcmd(cmd) + + +def add_service(daemon): + logging.info(" Adding service %s",daemon) + cmd = "add_service.sh %s" %daemon + runcmd(cmd) + +def remove_service(daemon): + logging.info(" Removing service %s",daemon) + stop_service(daemon) + cmd = "remove_service.sh %s" %daemon + runcmd(cmd) + +def start_service(daemon): + logging.info(" start service %s",daemon) + cmd = "sv start %s" %daemon + runcmd(cmd) + +def stop_service(daemon): + logging.info(" stop service %s",daemon) + cmd = "sv stop %s" %daemon + runcmd(cmd) + +def restart_service(daemon): + logging.info(" Restarting service %s",daemon) + if daemon == "lcdd": + stop_service(daemon) + logging.debug(" killing all lcdd") + cmd = "killall -9 LCDd" + runcmd(cmd) + time.sleep(2) + start_service(daemon) + else: + cmd = "sv restart %s" %daemon + runcmd(cmd) + +def hup_service(daemon): + logging.info(" hup service %s",daemon) + cmd = "sv hup %s" %daemon + runcmd(cmd) + + + +def pkg_blacklist_check(pkg): + cmd = '''grep -q %s /etc/blacklist.package''' %pkg + rc = runcmd(cmd) + if rc == 0: + return True + else: + return False + +def pkg_installed_check(pkg): + logging.debug(" Checking if %sis installed",pkg) + cmd = "pacman -Q %s " %pkg + rc = runcmd(cmd) + if rc == 0: + return True + else: + return False + + +def pacinstall(pkg): + logging.info(" Checking %s for install",pkg) + #extra pkg check + if pkg == "xine": + pacinstall("xine-ui") + elif pkg == "dvdcss": + pacinstall("libdvdcss") + elif pkg == "webmin": + add_service("webmin") + elif pkg == "fuppes": + pacinstall("fuppes-svn") + + if not pkg_blacklist_check(pkg): + if pkg_installed_check(pkg): + logging.info(" %s is already installed, will not install",pkg) + else: + logging.info(" Installing %s",pkg) + cmd ='''pacman --noconfirm -Sf %s ''' %pkg + runcmd(cmd) + else: + logging.info(" %s is blacklisted, will not install",pkg) + +def pacremove(pkg): + logging.info(" Checking %s for removal",pkg) + if pkg == "xine": + pacremove("xine-ui") + elif pkg == "dvdcss": + pacremove("libdvdcss") + elif pkg == "webmin": + remove_service("webmin") + + if not pkg_blacklist_check(pkg): + if not pkg_installed_check(pkg): + logging.info(" %s is not installed, will not remove",pkg) + else: + logging.info(" Removing %s",pkg) + cmd ='''pacman --noconfirm -R %s ''' %pkg + runcmd(cmd) + else: + logging.info(" %s is blacklisted, will not remove",pkg) + +def getpid(process): + return commands.getoutput('pidof %s' % process) + +def remove_file(filename): + logging.debug(" Removing %s", filename) + try: + os.remove(filename) + except: + logging.debug("* Could not remove %s", filename) + + +def restartLCD(RESTART_LCD): + if RESTART_LCD : + logging.info(" Restarting lcd server") + cmd = "killall -9 mythlcdserver" + runcmd(cmd) + else: + logging.debug(" Not restarting MYTHLCD server") + + +def reloadfe(dbhost,RESTART_LCD): + logging.debug("____Start of reloadfe____") + if data_config.SYSTEMTYPE == "MythVantage": + logging.info(" Clearing Backend cache") + cmd = '''/usr/bin/backend_control.sh clearcache behost %s''' %dbhost + runcmd(cmd) + + restartLCD(RESTART_LCD) + for pid in getpid("mythfrontend"): + cmd = ''' kill -s USR1 %s ''' %pid + #runcmd(cmd) + logging.info(" Reloading frontend with pid of %s",pid) + + logging.debug("__End of reloadfe\n") + + +def restartfe(RESTART_LCD): + logging.debug("____Start of restartfe____") + if data_config.SYSTEMTYPE=="LinHES": + logging.debug(" LinHES seems to be running will not restartfe") + return + logging.info(" Restarting frontend") + restartLCD(RESTART_LCD) + cmd="killall -9 mythfrontend" + runcmd(cmd) + cmd="killall -9 welcome" + runcmd(cmd) + logging.debug("__End of restartfe\n") + + +def udev_trigger(): + logging.info(" Triggering udev") + cmd = "udevadm settle" + runcmd(cmd) + cmd = "udevadm trigger" + runcmd(cmd) + cmd = "udevadm settle" + runcmd(cmd) + cmd = "udevadm trigger" + runcmd(cmd) + + diff --git a/abs/core-testing/LinHES-config-22/mv_config.py b/abs/core-testing/LinHES-config-22/mv_config.py new file mode 100755 index 0000000..1ac4fea --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_config.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +SYSTEMTYPE="LinHES" +MVHOSTNAME="larch5" +MOUNTPOINT="/new_boot" +DATAMOUNT="/myth" +MYTHHOME="/home/mythtv" +SQUASHFILE="/tmp/.squashlist" +SQUASHLIST=("bin","boot","etc","home","lib","opt","root","sbin","usr","var","data") +NOOPDEBUG="FALSE" +BACKUPFILE="mythconverg.sql.gz" +BACKUPPATH="/myth/backup/" +TEMP_TEMPLATES="/tmp/templates" +SMEDIA="myth" + + + + diff --git a/abs/core-testing/LinHES-config-22/mv_ddns.py b/abs/core-testing/LinHES-config-22/mv_ddns.py new file mode 100755 index 0000000..7ac7d3a --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_ddns.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os, re + +config_file = "mv_config" + +def setup_ddns(systemconfig): + logging.info("____Start of setup_ddns____") + + if systemconfig["DDnsEnable"] == "1": + logging.debug(" Enabling DDNS") + mv_common.pacinstall("ddclient") + mv_common.cp_and_log("/etc/ddclient/ddclient.conf.dynamic.dyndns.sample", + "/etc/ddclient/ddclient.conf") + cmd = ''' sed -i -e "s/your-dynamic-dyndns-login/%s/g" /etc/ddclient/ddclient.conf''' %(systemconfig["DDnslogin"]) + mv_common.runcmd(cmd) + cmd = ''' sed -i -e "s/your-dynamic-dyndns-password/%s/g" /etc/ddclient/ddclient.conf''' %(systemconfig["DDnspassword"]) + mv_common.runcmd(cmd) + cmd = ''' sed -i -e "s/your-dynamic-dyndns-host/%s/g" /etc/ddclient/ddclient.conf''' %(systemconfig["DDnshostname"]) + mv_common.runcmd(cmd) + mv_common.add_service("ddclient") + else: + logging.debug(" Disabling DDNS") + mv_common.remove_service("ddclient") + + logging.info("__End of ddns\n") diff --git a/abs/core-testing/LinHES-config-22/mv_hostype.py b/abs/core-testing/LinHES-config-22/mv_hostype.py new file mode 100755 index 0000000..d6ec0ed --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_hostype.py @@ -0,0 +1,230 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os + +config_file = "mv_config" +data_config = __import__(config_file, globals(), locals(), []) + +def setup_ntp(usepool,ntpserver): + if usepool: + logging.info("Setting ntp server to %s",ntpserver) + print '''sed -i "s/pool.ntp.org/$dbhost/g" ${BASE}/etc/ntp.conf''' + else: + logging.info("Not changing ntp configuration") + +def setup_avahi(templates): + file="/etc/avahi/services/mysql.service" + if not os.path.exists(file): + logging.debug(" copying in mysql.service for avahi") + try: + os.makedirs("/etc/avahi/services") + except: + logging.debug(" Couldn't create /etc/avahi/services") + mv_common.cp_and_log(templates+"/mysql.service",file) + cmd="sudo sv restart avahi" + mv_common.runcmd(cmd) + +def remove_avahi_service(): + file="/etc/avahi/services/mysql.service" + if os.path.exists(file): + logging.debug(" Removing avahi mysql.service file") + cmd="rm -rf %s" %file + mv_common.runcmd(cmd) + cmd="sudo sv restart avahi" + mv_common.runcmd(cmd) + +def setup_db(): + logging.debug(" Setting up the database") + +def setup_mysqlnetwork(EnableNetwork): + logging.debug(" Setting up mysql network") + mysqlconf = "/etc/my.cnf" + cmd = '''grep "#skip-networking" %s ''' %mysqlconf + status = mv_common.runcmd(cmd) + + if EnableNetwork : + logging.debug(" Enabling mysql networking") + if status == 0 : + logging.debug(" Network is already enabled for mysql") + else: + cmd = '''sed -ie "s/^skip-networking/#skip-networking/g" %s ''' %mysqlconf + mv_common.runcmd(cmd) + mv_common.restart_service("mysqld") + else: + logging.debug(" Disabling mysql networking") + if status == 1 : + logging.debug(" Network is already disabled for mysql") + else: + cmd = '''sed -ie "s/#skip-networking/skip-networking/g" %s ''' %mysqlconf + mv_common.runcmd(cmd) + mv_common.restart_service("mysqld") + +def setup_mysql_connection(systemconfig): + logging.info(" Configuring database connection") + mythip = systemconfig["mythip"] + systemtype = systemconfig["SystemType"] + mv_root = systemconfig["MVROOT"] + mysqltxt = "/usr/share/mythtv/mysql.txt" + templates = systemconfig["TEMPLATES"] + mysqltemplate = templates + "/mysql.txt" + dbhost = systemconfig["dbhost"] + + 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 + 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) + + 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) + + if systemtype == "Master_backend": + 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) + + + +def setup_func_key(): + if data_config.SYSTEMTYPE == "MythVantage": + logging.debug(" Grabbing the key for Func") + cmd="/usr/MythVantage/bin/grabkey.py" + mv_common.runcmd(cmd) + +def setup_func_minion(dbhost): + logging.info(" Setting up the func minion:") + logging.debug(" certmaster is %s:",dbhost) + #cmd='''sed -i "s/^certmaster.*$/certmaster = %s/" /etc/func/minion.conf ''' %dbhost + #mv_common.runcmd(cmd) + cmd='''sed -i "s/^certmaster.*$/certmaster = %s/" /etc/certmaster/minion.conf ''' %dbhost + mv_common.runcmd(cmd) + +def setup_syslog(dbhost): + logging.debug(" Setting syslog to log to %s",dbhost) + cmd ='''sed -i "s/^destination d_remote.*$/destination d_remote \{tcp\(\"%s\" port\(514\)\) \;\} \;/" /etc/syslog-ng.conf''' %dbhost + return + +def hostypeprint(systemconfig): + logging.info("______Start of hostype config_____") + mv_common.services(systemconfig) + install_list='' + remove_list='' + daemon_list='' + daemon_remove_list='' + run_mysqlnetwork = False + + if systemconfig["SystemType"] == "Standalone": + logging.info("Stand alone system being configured") + setup_ntp(False,"null") + remove_avahi_service() + EnableNetwork = False + run_mysqlnetwork = True + if systemconfig["hostypec"]: + setup_db() + install_list=["mysql", "mythdb-initial", "avahi", "portmap", "nfs-utils", "local-website", "myth2ipod", "mythtv-status"] + daemon_list=["mysql", "mythbackend", "avahi", "portmap", "nfs-utils", "netfs", "lighttpd"] + if data_config.SYSTEMTYPE == "MythVantage": + install_list.append('ghosd') + + elif systemconfig["SystemType"] == "Master_backend": + logging.info("Master backend system being configured") + setup_ntp(False,"null") + setup_avahi(systemconfig["TEMPLATES"]) + install_list=["mysql", "mythdb-initial", "avahi", "portmap", "nfs-utils", "local-website", "myth2ipod", "mythtv-status"] + daemon_list=["mysql", "mythbackend", "avahi", "portmap", "nfs-utils", "netfs", "lighttpd"] + EnableNetwork = True + run_mysqlnetwork = True + if data_config.SYSTEMTYPE == "MythVantage": + install_list.append('func') + daemon_list.append('func') + install_list.append('certmaster') + daemon_list.append('certmaster') + install_list.append('ghosd') + + elif systemconfig["SystemType"] == "Slave_backend": + logging.info("Slave backend system being configured") + setup_ntp(True,systemconfig["dbhost"]) + remove_avahi_service() + if systemconfig["hostypec"]: + setup_db() + install_list = ["portmap", "nfs-utils", "local-website", "avahi", "libmysqlclient" ] + daemon_list = ["mythbackend", "portmap", "nfs-utils", "netfs", "lighttpd", "avahi" ] + daemon_remove_list=('mysql') + if data_config.SYSTEMTYPE == "MythVantage": + install_list.remove("local-website") + daemon_list.remove("lighttpd") + install_list.append('func') + daemon_list.append('funcd') + remove_list.append("lighttpd") + install_list.append('ghosd') + + + elif systemconfig["SystemType"] == "Frontend_only": + logging.info("Frontend only system being configured") + setup_ntp(True,systemconfig["dbhost"]) + remove_avahi_service() + install_list=["mysql-clients", "libmysqlclient", "avahi", "portmap", "nfs-utils", "local-website"] + remove_list=["mysql"] + daemon_list=["mysql", "mythbackend", "avahi", "portmap", "nfs-utils", "netfs", "lighttpd"] + daemon_remove_list=("mysql", "mythbackend") + if data_config.SYSTEMTYPE == "MythVantage": + install_list.remove("local-website") + daemon_list.remove("lighttpd") + install_list.append('func') + daemon_list.append('funcd') + remove_list.append("lighttpd") + install_list.append('ghosd') + + + for pkg in install_list: + mv_common.pacinstall(pkg) + for pkg in remove_list: + mv_common.pacinstall(pkg) + for daemon in daemon_list: + mv_common.add_service(daemon) + for daemon in daemon_remove_list: + mv_common.remove_service(daemon) + if systemconfig["RunFrontend"] == "1": + logging.debug(" Will run the frontend") + mv_common.add_service("frontend") + 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.remove_service("hal") + if data_config.SYSTEMTYPE == "MythVantage": + mv_common.remove_service("ghosd") + + + if run_mysqlnetwork: + setup_mysqlnetwork(EnableNetwork) + else: + logging.debug(" Not running setup_mysql_connection") + + setup_mysql_connection(systemconfig) + if data_config.SYSTEMTYPE == "MythVantage": + setup_func_minion(systemconfig["dbhost"]) + setup_func_key() + setup_syslog(systemconfig["dbhost"]) + logging.info("__End of hostype config\n") diff --git a/abs/core-testing/LinHES-config-22/mv_install.py b/abs/core-testing/LinHES-config-22/mv_install.py new file mode 100755 index 0000000..19295ca --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_install.py @@ -0,0 +1,1432 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import sys, os, commands, glob, time +import getopt, re, MySQLdb +import logging +try: + import parted +except: + print "module parted not found" + +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" + +def clean_upgrade(): + return False + +def error_out(errmsg): + cmd = '''echo %s >> /tmp/.install_error ''' %errmsg + runcmd(cmd) + logging.critical("***********************************") + logging.critical("error: %s",errmsg) + print "***********************************" + print "ERROR: mv_install.py: %s" %errmsg + print "***********************************" + sys.exit(1) + + +def update_db(value, data): + db = MySQLdb.connect(host="localhost", user="mythtv", passwd="mythtv", db="mythconverg") + try: + cursor = db.cursor() + cursor.execute("DELETE FROM settings where value=%s and hostname=%s;", (value, data_config.MVHOSTNAME)) + cursor.execute("REPLACE INTO settings set value=%s, data=%s, hostname=%s;", (value, data, data_config.MVHOSTNAME)) + logging.debug("Updated database with %s, %s", data, value) + except MySQLdb.Error, e: + logging.debug("Unable to update database with %s, %s", data, value) + + +def progress(pgnum): + progressline = str(pgnum) + "% complete" + logging.debug("Progress: %s", pgnum) + f = open('/tmp/.install_percent', 'w') + f.write(progressline) + f.close() + +def update_status(status): + logging.debug("Status: %s", status) + f = open('/tmp/.install_state', 'w') + f.write(str(status)) + f.close() + +def kill_dhcp_chroot(): + logging.debug("Killing off chroot dhcpcd") + stddir = os.getcwd() + piddir = ("%s/var/run/") %data_config.MOUNTPOINT + try: + os.chdir(piddir) + for FILE in glob.glob("dhcpcd-*.pid"): + f = open(FILE, 'r') + pid = f.readline() + f.close() + cmd = "kill -9 %s" %pid + runcmd(cmd) + os.remove(FILE) + os.chdir(stddir) + except: + pass + +def statgrab(disk): + cmd = "statgrab -M disk. |grep %s.write_bytes" % hostoptions["rootdisk"] + out = commands.getoutput(cmd) + try: + prewritebytes = out.split("=")[1].strip() + except: + prewritebytes = "1024" + outline = "STARTSIZE=%s" %prewritebytes + f = open('/tmp/.startsize.io', 'w') + f.write(str(outline)) + f.close() + +def backup_sql_check(): + logging.debug("Searching for backup file") + try: + hostoptions["backupfile"] + except: + logging.debug("Backup file var is empty") + return False + if os.path.exists(data_config.MOUNTPOINT+hostoptions["backupfile"]): + logging.debug("Backup file %s is present", data_config.MOUNTPOINT+hostoptions["backupfile"]) + return True + else: + logging.debug("Backup file %s is NOT present", data_config.MOUNTPOINT+hostoptions["backupfile"]) + return False + +def mdadm_find(PREFIX): + logging.debug("Searching for mdadm.conf") + if os.path.exists(PREFIX+"/etc/KnoppMyth-version"): + mdadmconf = "/etc/mdadm/mdadm.conf" + else: + mdadmconf = "/etc/mdadm.conf" + logging.debug("Using %s for mdadm.conf", mdadmconf) + return mdadmconf + +def mdadm_assemble_all(): + # read mdadm.conf and start the arrays + #ARRAY /dev/md5 uuid=19464854:03f71b1b:e0df2edd:246cc977 + logging.debug("Starting mdadm support") + mdadmconf_file = mdadm_find("/tmp") + cmd = "cdadm --assemble --scan -c /tmp/%s" %mdadmconf_file + runcmd(cmd) + mdadm_contents = '' + try: + f = open(mdadmconf_file, 'r') + mdadm_contents = f.readlines() + f.close() + except: + logging.debug(" Couldn't open mdadmconf file") + for line in mdadm_contents: + if line.startswith("ARRAY"): + logging.debug(" Found MD array: %s", line) + array = line.split()[1] + logging.info(" assembling array: %s", array) + cmd = "mdadm --assemble -c /tmp%s %s" %(mdadmconf_file, array) + runcmd(cmd) + time.sleep(2) + cmd = "fsck -p %s" %array + runcmd + +def copy_updates(): + try: + MVROOT = os.environ["MV_ROOT"] + except: + logging.debug("MVROOT was not defined, using the default value") + MVROOT = "/usr/MythVantage" + cp_and_log2(MVROOT+"/bin/", data_config.MOUNTPOINT+MVROOT+"/bin", "*.sh") + cp_and_log2(MVROOT+"/bin/", data_config.MOUNTPOINT+MVROOT+"/bin", "*.py") + +def timezone_to_db(timefile): + logging.info("importing timezone") + try: + f = open(timefile) + timezonecontents = f.readline().strip() + f.close() + except: + logging.debug("Couldn't open /tmp/etc/timezone, will not set the timezone") + return + update_db("HostTimeZone", timezonecontents); + tzsplit = timezonecontents.partition('/') + print tzsplit + if tzsplit[2] == '' : + update_db("HostTimeZoneRegion", tzsplit[0]) + else: + update_db("HostTimeZoneRegion", tzsplit[0]) + tztemp="HostTimeZoneRegion_%s" % tzsplit[0] + update_db(tztemp, tzsplit[2]) + + + +def cp_and_log(srcfile, destfile): + #return + if not os.path.exists(srcfile): + logging.info("%s is not present, skipping...", srcfile) + else: + cmd = ("rsync -arvp %s %s") %(srcfile, destfile) + runcmd(cmd) + +def cp_and_log2(srcfile, destfile, fileglob): + #return + logging.debug("cp_and_log2") + logging.debug("%s, %s, %s", srcfile, destfile, fileglob) + + if not os.path.exists(srcfile): + logging.info("%s is not present, skipping...", srcfile) + else: + if fileglob == '': + cmd = ("rsync -arvp %s %s") %(srcfile, destfile) + runcmd(cmd) + else: + fileglob = "*" + cmd = ("rsync -arvp %s/%s %s") %(srcfile, fileglob, destfile) + runcmd(cmd) + +def runcmd(cmd): + if data_config.NOOPDEBUG == "FALSE": + pass + else: + cmd = "echo "+cmd + logging.debug(" %s", cmd) + cmdout = commands.getstatusoutput(cmd) + logging.debug(" %s", cmdout) + return cmdout + +def mysqldb(cmd, inchroot): + if cmd == "start": + mycmd = " /etc/rc.d/mysqld start" + elif cmd == "stop": + mycmd = " /etc/rc.d/mysqld stop" + if inchroot == "chroot": + mycmd = " chroot /newboot %s" %mycmd + runcmd(mycmd) + + +def mount_bind_chroot(): + logging.debug("Mounting dev/proc/sysfs for chroot") + cmd = " mount --bind /dev %s" %data_config.MOUNTPOINT+"/dev" + runcmd(cmd) + cmd = " mount --bind /dev/pts %s" %data_config.MOUNTPOINT+"/dev/pts" + runcmd(cmd) + cmd = " mount --bind /proc %s" %data_config.MOUNTPOINT+"/proc" + runcmd(cmd) + cmd = " mount -t sysfs none %s" %data_config.MOUNTPOINT+"/sys" + runcmd(cmd) + + +def umount_bind_chroot(): + logging.debug("UnMounting dev/proc/sysfs for chroot") + cmd = " umount -l %s" %data_config.MOUNTPOINT+"/dev/pts" + runcmd(cmd) + cmd = " umount -l %s" %data_config.MOUNTPOINT+"/dev" + runcmd(cmd) + cmd = " umount -l %s" %data_config.MOUNTPOINT+"/proc" + runcmd(cmd) + cmd = " umount -l %s" %data_config.MOUNTPOINT+"/sys" + runcmd(cmd) + + +def blank_table(diskdevice): + logging.debug(" writing new parition table for %s", diskdevice) + logging.debug("parition table before:") + cmd = "fdisk -l %s" %diskdevice + runcmd(cmd) + + cmd = "echo w |fdisk %s" %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) + try: + device = parted.getDevice(diskdevice) + partdisk = parted.Disk(device) + partdisk.deleteAllPartitions() + if data_config.NOOPDEBUG == "FALSE": + partdisk.commit() + for partition in partdisk.partitions: + print "type: %s" %partition.type + except: + logging.debug(" Error reading parition table, attempting to write a blank one") + blank_table(diskdevice) + + +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 + totalused = 0 + device = parted.getDevice(diskdevice) + 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 + + if startsector == 0: + newstart = 0 + if size == "ALL": + logging.debug(" Using the rest of the disk %s", (device.length-newstart) ) + try: + geom = parted.Geometry(device=device, start=newstart, length=(device.length-newstart)) + except: + 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) + try: + geom = parted.Geometry(device=device, start=newstart, length=length) + except: + logging.info("An error occured, probably invalid parition size") + error_out("invalid parition size") + + #collect device constraint + constraint = device.getConstraint() + # new partition + if ptype == "NORMAL": + newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_NORMAL, geometry=geom) + elif ptype == "SWAP": + newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_NORMAL, geometry=geom) + + #add the partition to the disk and commit changes + 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)) + return newpart.getDeviceNodeName() + +def set_active_parition(diskdevice): + """ Set the bootable flag for this partition. """ + logging.debug(" Setting active parition") + device = parted.getDevice(diskdevice) + partdisk = parted.Disk(device) + try: + for partition in partdisk.partitions: + partition.setFlag(parted.PARTITION_BOOT) + partdisk.commit() + except: + logging.info(" Couldn't set the active partition") + logging.info(" Depending on your system this may not matter") + + +def partition_disk(): + global hostoptions + logging.info("Partitioning") + logging.debug("____start of partition_disk____") + rootdisk = hostoptions["rootdisk"] + datadisk = hostoptions["datadisk"] + label = "root" + partitions_removeall("/dev/"+rootdisk, label) + label = "data" + 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) + if datadisk != rootdisk: + hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 0) + else: + hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 1) + 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"} + try: + rc = fscmds[fstype] + except: + logging.critical(" %s is not a valid fs type, exiting now", fstype) + error_out("Error mvinstall during format") + return rc + + +def format_disk(install_type): + logging.info("______Starting Disk Format______") + rootfs = fscmd(hostoptions["rootfs"]) + datafs = fscmd(hostoptions["datafs"]) + + rootdisk = hostoptions["rootdisk"] + datadisk = hostoptions["datadisk"] + rootpartition = hostoptions["rootpartition"] + datapartition = hostoptions["datapartition"] + if install_type != "upgrade": + swapsize = hostoptions["swapsize"] + swappartition = hostoptions["swappartition"] + + logging.debug(" Format command for rootfs %s : %s ", rootfs, rootpartition) + if ( rootfs != "noformat"): + logging.info("Starting format of %s", rootpartition) + cmd = " %s /dev/%s" %( rootfs, rootpartition) + #os.system(cmd) + runcmd(cmd) + else: + 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) + cmd = " %s /dev/%s" %( datafs, datapartition) + #os.system(cmd) + runcmd(cmd) + else: + 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") + + logging.debug("_____End of format______") + + +def mount_it(): + logging.info("______Mounting disk______") +# Create mount points + try: + mountpoint = data_config.MOUNTPOINT + mp = mountpoint + logging.info("Creating mountpoints %s", mp) + os.makedirs(mp) + except OSError: + logging.debug(" Could not create %s", mp) + +# 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 / + try: + mountpoint = data_config.MOUNTPOINT + datapoint = data_config.DATAMOUNT + mp = mountpoint+datapoint + 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) + +def unmount_it(): + logging.info("______Unmounting disk______") + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) + runcmd(cmd) + time.sleep(2) + + cmd = "swapoff /dev/%s" %(hostoptions["swappartition"]) + runcmd(cmd) + + cmd = "sync" + runcmd(cmd) + + cmd = "umount %s" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "sync" + runcmd(cmd) + + +def create_squashlist(): + logging.debug("Creating squashlist") + squashfile = data_config.SQUASHFILE + f = open(squashfile, 'w') + for i in data_config.SQUASHLIST: + f.write(i) + f.write("\n") + logging.debug(i) + f.close() + + +def copy_it(install_type): + logging.info("______Transferring to disk______") + logging.debug( install_type) + if ( install_type == "install"): + logging.info("Transferring system") + cmd = " unsquashfs -f -d %s /.livesys/medium/system.sqf" %(data_config.MOUNTPOINT) + runcmd(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/system.sqf" %(data_config.SQUASHFILE, data_config.MOUNTPOINT) + runcmd(cmd) + #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") + mountpoint = data_config.MOUNTPOINT + for item in i: + try: + mp = mountpoint+"/"+item + logging.info("Creating mountpoints %s", mp) + os.makedirs(mp) + except OSError: + logging.debug(" __Could not create %s", mp) +# General fixup + cmd = "chmod 777 %s/tmp" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "mknod %s/dev/null c 1 5" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "mknod %s/dev/console c 5 1" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "chmod +s %s/usr/bin/Xorg" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "chmod +s %s/usr/bin/crontab" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "chmod +s %s/usr/bin/sudo" %(data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "chmod +s %s/bin/mount" %(data_config.MOUNTPOINT) + runcmd(cmd) + logging.debug("__End of copy_it__") + +def create_fstab(extralines): + logging.debug("______Creating new fstab file_______") + logging.info("Creating new fstab file") + fstabfile = data_config.MOUNTPOINT+"/etc/fstab" + fstab_list = [] + f = open(fstabfile, 'w') + line = '''# <file system> <dir> <type> <options> <dump> <pass> \n''' + fstab_list.append(line) + line = '''none /dev/pts devpts defaults 0 0 \n''' + fstab_list.append(line) + line = '''none /dev/shm tmpfs defaults 0 0\n''' + 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''' + fstab_list.append(line) + line = '''UUID=DATAUID %s auto defaults,noatime 0 1\n''' %(data_config.DATAMOUNT) + fstab_list.append(line) + line = '''UUID=SWAPUID swap swap defaults 0 0 \n''' + fstab_list.append(line) + for vline in extralines: + fstab_list.append(vline) + for outline in fstab_list: + logging.debug(outline) + f.write(outline) + f.close() + +def find_uuid(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) + return uuid.strip() + +def pick_out_vg(): + logging.info("Searching for Volume Groups in old fstab") + vglines = [] + f = open("/tmp/etc/fstab", 'r') + oldfscontents = f.readlines() + for line in oldfscontents: + if line.startswith("/dev/vg"): + vglines.append(line) + templine = line.split() + mdir = templine[1] + if not os.path.exists (mdir): + logging.debug("Creating dir %s for VG mount", mdir) + os.makedirs (mdir) +# Might need to os.chown to mythtv:users + else: + logging.debug("Directory %s for VG mount already present", mdir) + return vglines + +def fstab_it(install_type): + logging.info("______Checking fstab______") + kmvg = [] + fstabfile = data_config.MOUNTPOINT+"/etc/fstab" +# Check for knoppmyth install, if found create new + if install_type == "upgrade": + if os.path.exists("/tmp/etc/KnoppMyth-version"): + logging.debug(" KnoppMyth-Version found, creating new fstab") + kmvg = pick_out_vg() + create_fstab(kmvg) + 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") + if not os.path.exists(fstabfile): + create_fstab(kmvg) + + logging.info("____UUID check for %s", "swap") + swapuuid = find_uuid(hostoptions["swappartition"]) + + logging.info("____UUID check for %s", "data") + datauuid = find_uuid(hostoptions["datapartition"]) + + logging.info("____UUID check for %s", "root") + rootuuid = find_uuid(hostoptions["rootpartition"]) + + fstabfile = data_config.MOUNTPOINT+"/etc/fstab" + logging.info("Correcting UUID's in %s", fstabfile) + f = open(fstabfile, 'r') + oldfscontents = f.readlines() + newfstab = [] + f.close() + for line in oldfscontents: + if line.startswith("UUID"): + templine = line.split() + if ( templine[1] == "/"): + logging.debug(" Found Root fstab line:") + logging.debug( templine) + templine[0] = "UUID=%s" %(rootuuid) + newline = '' + for i in templine: + newline+=i + newline+=" " + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + + if ( templine[1] == data_config.DATAMOUNT): + logging.debug(" Found DATA mount") + logging.debug( templine) + templine[0] = "UUID=%s" %(datauuid) + newline = '' + for i in templine: + newline+=i + newline+=" " + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + + if ( templine[1] == "swap"): + if len(swapuuid) <= 5: + logging.debug(" swapp uuid is to small") + else: + logging.debug(" Found swap partition") + logging.debug( templine) + templine[0] = "UUID=%s" %(swapuuid) + newline = '' + for i in templine: + newline+=i + 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) + logging.info("Writing out newfstab") + logging.debug("______This is the new fstab_____") + f = open(fstabfile, 'w') + for line in newfstab: + logging.debug(line) + f.write(line) + #f.write("\n") + f.close() + +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") + runcmd(cmd) + rootuuid = find_uuid(hostoptions["rootpartition"]) + cmd = " mkinitcpio -g %s/boot/kernel26.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" + 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") + +def fix_permissions(): + logging.info("Fixing permissions") + SE = os.environ["TEMPLATES"]+"/settings/syssettings" + cmd = " chmod -R 755 %s" %(data_config.MOUNTPOINT+SE) + runcmd(cmd) + cmd = " chmod 775 %s" %(data_config.MOUNTPOINT+"/etc/systemconfig") + runcmd(cmd) + cmd = " chmod 755 %s" %(data_config.MOUNTPOINT+"/root") + runcmd(cmd) + cmd = " chown root:mythtv %s" %(data_config.MOUNTPOINT+"/etc/systemconfig") + runcmd(cmd) + cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+SE) + runcmd(cmd) + cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+"/var/log/mythtv") + runcmd(cmd) + +def apply_new_auth(): + logging.info("_____Applying Password updates_______") + passfile = "/root/myth_user_call.out" + try: + MVROOT = os.environ["MV_ROOT"] + except: + logging.debug("MVROOT was not defined, using the default value") + MVROOT = "/usr/MythVantage" + if data_config.NOOPDEBUG == "FALSE": + cmdprefix = "chroot " + data_config.MOUNTPOINT + " " + MVROOT+"/bin/myth_user_call -i " + else: + cmdprefix = "echo chroot " + data_config.MOUNTPOINT + " " + MVROOT+"/bin/myth_user_call -i " + try: + f = open(passfile, 'r') + passcmds = f.readlines() + f.close() + for cmd in passcmds: + execmd = cmdprefix+cmd +# Using os.system because runcmd fails + logging.debug(execmd) + os.system(execmd) + except: + logging.debug("Applying password updates failed, couldn't open %s", passfile) + logging.debug + +def add_to_blacklist(module): + rcfile = data_config.MOUNTPOINT + "/etc/rc.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, 'w') + 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) + f.close() + + +def add_to_modulelist(module): + rcfile = data_config.MOUNTPOINT + "/etc/rc.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, 'w') + except: + logging.critical(" *Couldn't open %s for reading",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) + f.close() + + + +def special_hardware_check(): + logging.info("_____Applying special boot parameters_______") + try: + f = open('/proc/cmdline', 'r') + bootoptions = f.readlines() + f.close() + except: + logging.critical(" *Couldn't open /proc/cmdline") + return + bootoptions = bootoptions[0].split() + logging.debug(" Boot options: %s", bootoptions) + for item in bootoptions: + logging.debug(item) + if re.match("disablemodules",item) != None : + logging.debug(" Found disabledmodules") + modulelist = item.split("=")[1] + for module in modulelist.split(','): + add_to_blacklist(module) + + if re.match("modules",item) != None : + logging.debug(" Found modules") + modulelist = item.split("=")[1] + for module in modulelist.split(','): + add_to_modulelist(module) + + if re.match("type",item) != None : + logging.debug(" Found special hardware type") + try: + typefile = open(data_config.MOUNTPOINT + "/myth/.special_hardware_type", 'w') + typelist = item.split("=")[1] + # there should be only one special hardware type, but this will handle multiples, just in case + for type in typelist.split(','): + typefile.write(type) + typefile.write("\n") + typefile.close() + except: + logging.debug("Couldn't write to file: ", typefile) + if re.match("no_meth",item) != None : + cmd = " touch %s%s/.no_meth" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + runcmd(cmd) + +def swapsearch(): +#currently unused! + partlist = [] + stddir = os.getcwd() + os.chdir("/sys/block") + partitionlist = glob.glob("*") + for item in partitionlist: + try: + newitem = item.strip().rpartition(" ")[2] + if (not newitem == '') and (not newitem.startswith("loop")): + path = "/dev/"+newitem.strip() + path = path.strip() + device = parted.getDevice(path) + (cylinders, heads, sectors) = device.biosGeometry + sizeInBytes = device.length * device.sectorSize + disk = parted.Disk(device) + for partition in disk.partitions: + if partition.type == parted.PARTITION_PROTECTED or \ + partition.type == parted.PARTITION_METADATA or \ + partition.type == parted.PARTITION_FREESPACE: + continue + + 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: + (partition, path, bootable, start, end, length, type, fs) = slice + if partition.getFlag(parted.PARTITION_SWAP) or fs.type == "linux-swap": + print "found swap" + print path + except: + pass + os.chdir(stddir) + +def sane_settings(file): + #Remove some settings from file_name + removeline = ("HOSTrootfstype", "HOSTrootfstype", "HOSTdatafstype", "HOSTOSsize", "HostUseALLdata", "HOSTDATAsize", "HOSTuprootfstype", "HostUseSWAP", "HOSTSWAPsize") + logging.debug("__Running sane settings") + try: + f = open(file, 'r') + filecontents = f.readlines() + f.close() + except: + logging.debug(" Couldn't find file %s to sane", file) + try: + f = open(file, 'w') + for line in filecontents: + for item in removeline: + if line.startsize(line.strip()): + logging.debug(" Found a line to remove in %s, %s", file, line) + else: + f.write(line) + except: + logging.debug(" Couldn't open file %s for writing", file) + logging.debug(" __End sane settings") + +def 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/restore_default_settings.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") + copy_updates() + fix_permissions() + +def full_install(hostoptions): + logging.info("______Start of full install______") + try: + MVROOT = os.environ["MV_ROOT"] + except: + logging.debug(" MVROOT was not defined, using the default value") + MVROOT = "/usr/MythVantage" + + try: + os.remove("/tmp/.this_is_upgrade") + except OSError: + logging.debug(" File /tmp/.this_is_upgrade not present, couldn't delete it") + pass +# Partition disk + statusmsg = "Partitioning %s" %( hostoptions["rootdisk"]) + update_status(statusmsg) + progress(1) + if data_config.NOOPDEBUG == "FALSE": + partition_disk() + else: + logging.debug(" Debug mode, skipping partitioning step") + +# Format disk + statusmsg = "Preparing %s" %( hostoptions["rootdisk"]) + update_status(statusmsg) + progress(2) + format_disk("install") + + +# Mount partitions + statusmsg = "Mounting %s" %( hostoptions["rootdisk"]) + update_status(statusmsg) + progress(3) + mount_it() + +# 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_it("install") +# 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 + msg = "Configuring system" + update_status(msg) + progress(98) + grub_it() + special_hardware_check() +# Configuring the system + logging.info("______Configuring system________") + cp_and_log("/etc/systemconfig", data_config.MOUNTPOINT+"/etc/systemconfig") + 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/restore_default_settings.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() + 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 + 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) + 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") + + mysqldb("stop", "chroot") + 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) +# Need to check for to touch /tmp/.dbsysfailed + cmd = " chroot %s %s/bin/restore_default_settings.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + if ( 'x' == '1' ): + logging.debug("touching /tmp/.dbsysfailed") + else: + #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") + cmd = "chroot %s %s/bin/restore_default_settings.sh -c ACCESSCONTROL " %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + umount_bind_chroot() + cmd = " touch %s%s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + runcmd(cmd) + cmd = " chmod 777 %s%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") + unmount_it() + logging.debug("_____End of full install_____") + +def find_upgrade(): + logging.info("_____Start of find_upgrade_____") + global hostoptions + #try to mount first partition of disk + #copy old /etc/systemconfig to live, import settings into db + #umount drive. + #check for clean upgrade + if ( clean_upgrade() ): + logging.info("Clean upgrade requested, not using old data") + return + mount_it() + oldbackupfile = data_config.MOUNTPOINT+"/root/backup/"+data_config.BACKUPFILE + newbackupfile = "/tmp/"+data_config.BACKUPFILE + if os.path.exists(oldbackupfile): + logging.debug("Setting backup file to %s", newbackupfile) + hostoptions["backupfile"] = newbackupfile + cp_and_log(oldbackupfile, newbackupfile) + + srcfile = data_config.MOUNTPOINT+"/etc/systemconfig" + logging.info("Searching for systemconfig file %s", srcfile) + if os.path.exists(srcfile): + logging.info("Found systemconfig file %s", srcfile) + TEMPLATES = os.environ["TEMPLATES"]+"/settings/syssettings" + 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_log(srcfile, "/etc/systemconfig") + cp_and_log(data_config.MOUNTPOINT+"/etc/", "/tmp/etc/") + cp_and_log(data_config.MOUNTPOINT+"/var/lib/alsa/", "/tmp/alsa") + cp_and_log(data_config.MOUNTPOINT+"/var/lib/oss/", "/tmp/oss") + cp_and_log("/tmp/etc/mdadm.conf", "/etc/mdadm.conf") + else: + logging.info("Could not find systemconfig file %s", srcfile) + cp_and_log(data_config.MOUNTPOINT+"/etc/", "/tmp/etc/") + cp_and_log(data_config.MOUNTPOINT+"/var/lib/alsa/", "/tmp/alsa") + cp_and_log("/tmp/etc/mdadm.conf", "/etc") + timezone_to_db("/tmp/etc/timezone") + unmount_it() + logging.debug("End of find_upgrade") + +def upgrade_mount_search(): + #Search for data/myth partition based on contents of fstab + logging.debug("______Start of upgrade_mount_search_____") + cmd = "umount %s%s" %(data_config.MOUNTPOINT, data_config.DATAMOUNT) + runcmd(cmd) + fstab_list = [] + fstab_data_mount = '' + try: + f = open("/tmp/etc/fstab", 'r') + oldfscontents = f.readlines() + f.close() + ## ['UUID=', '/myth', 'auto', 'defaults, noatime', '0', '1'] + #for line in oldfscontents: + #mountdir=line.split() + #if mountdir[1] == (data_config.DATAMOUNT): + #fstablist.append(mountdir) + except: + logging.debug(" Couldn't open /tmp/etc/fstab") + for line in oldfscontents: + if line.startswith("#"): + continue + mountdir=line.split() + try: + if mountdir[1] == (data_config.DATAMOUNT): + fstablist.append(mountdir) + except: + continue + #search fstab for data/myth mountpoint + for i in fstab_list: + if i[1] == data_config.DATAMOUNT: + fstab_data_mount = i[0] + break + + #start software raid support if needed + for i in fstab_list: + if i[0].startswith("/dev/md"): + logging.debug(" starting software raid support") + mdadm_assemble_all + + + if re.search("UUID", fstab_data_mount): + fstab_data_uuid = fstab_data_mount.split("=")[1] + cmd = "blkid -t UUID=%s" %fstab_data_uuid + retcode = call(cmd, shell=True) + if retcode != 0: + logging.debug(" Couldn't find uuid %s, starting md support", fstab_data_uuid) + mdadm_assemble_all + #hoping everything is up and running and data/myth will be available for mount + cmd = "mount -U %s %s" %(fstab_data_uuid, data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "blkid -t UUID=%s|cut -d: -f1" %fstab_data_uuid + logging.debug(cmd) + datadisk = commands.getoutput(cmd) + cmd = "basename %s" %datadisk + datadisk = commands.getoutput(cmd) + else: + cmd = "mount %s %s" %(fstab_data_mount, data_config.MOUNTPOINT) + runcmd(cmd) + cmd = "basename %s" %fstab_data_mount + datadisk = commands.getoutput(cmd) + time.sleep(3) +# hostoptions["backupfile"]=data_config.BACKUPPATH+data_config.BACKUPFILE + if not backup_sql_check(): + newbackupfile = "/tmp/"+data_config.BACKUPFILE + if os.path.exists(newbackupfile): + logging.debug("Setting backup file to %s", newbackupfile) + cp_and_log(newbackupfile, data_config.MOUNTPOINT+newbackupfile) + hostoptions["backupfile"] = newbackupfile + else: + logging.info("Couldn't find any database to restore, upgrade will continue with a new database") + + + +def upgrade(hostoptions): + + try: + MVROOT = os.environ["MV_ROOT"] + except: + logging.debug("MVROOT was not defined, using the default value") + MVROOT = "/usr/MythVantage" + logging.info("______Start of upgrade______") + cmd = "touch /tmp/.this_is_upgrade" + runcmd(cmd) + if hostoptions["rootfs"] == "Do_not_format": + logging.info("Will not format root filesystem") + else: + statusmsg = "Preparing %s" %( hostoptions["rootdisk"]) + update_status(statusmsg) + progress(2) + format_disk("upgrade") + #sys.exit(2) + statusmsg = "Mounting %s" %( hostoptions["rootdisk"]) + update_status(statusmsg) + progress(3) + mount_it() + hostoptions["backupfile"] = data_config.BACKUPPATH+data_config.BACKUPFILE + statgrab( hostoptions["rootdisk"]) + msg = "Upgrading %s" %(systemconfig["hostname"]) + update_status(msg) + time.sleep(3) + copy_it("upgrade") + cmd = "rm -rf %s/etc.old" %data_config.MOUNTPOINT + runcmd(cmd) + cmd = "rm -rf %s/alsa.old" %data_config.MOUNTPOINT + runcmd(cmd) + + cp_and_log("/tmp/etc/", data_config.MOUNTPOINT+"/etc.old/") + 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') + + mdfile = mdadm_find("/tmp") + cp_and_log("/tmp"+mdfile, data_config.MOUNTPOINT+"/etc") + + srcfile = "%s/etc.old/asound.conf" %(data_config.MOUNTPOINT) + destfile = "%s/etc/asound.conf" %(data_config.MOUNTPOINT) + cp_and_log(srcfile, destfile) + + # R5.5 -> R6 + srcfile = "%s/alsa.old/asound.state" %(data_config.MOUNTPOINT) + destfile = "%s/etc/asound.state" %(data_config.MOUNTPOINT) + cp_and_log(srcfile, destfile) + # R6 -> R6 + srcfile = "%s/etc.old/asound.state" %(data_config.MOUNTPOINT) + destfile = "%s/etc/asound.state" %(data_config.MOUNTPOINT) + cp_and_log(srcfile, destfile) + + srcfile = "%s/etc.old/mplayer/mplayer.conf" %(data_config.MOUNTPOINT) + destfile = "%s/etc/mplayer/mplayer.conf" %(data_config.MOUNTPOINT) + cp_and_log(srcfile, destfile) + + if not os.path.exists("/tmp/etc/KnoppMyth-version"): + logging.debug(" standard upgrade, restoring auth files") + 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" + + 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() + fstab_it("upgrade") + time.sleep(1) + grub_it() + 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") + 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() + if clean_upgrade(): + file = "%s/%s/.kmupgrade" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + cmd = "touch %s && chmod 777 %s" %(file, file) + runcmd(cmd) + 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", "") + if ( systemconfig["SystemType"] == "Master_backend" or systemconfig["SystemType"] == "Standalone" ): + 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/restore_default_settings.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/restore_default_settings.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) + 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() + 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) + mysqldb("start", '') + + + + +def main(argv): + global hostoptions + 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'} + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit(0) + elif opt in ( "--rootdisk"): + hostoptions["rootdisk"] = arg + hostoptions["rootpartition"] = arg+str(1) + elif opt in ("--rootfs"): + hostoptions["rootfs"] = arg + elif opt in ("--rootsize"): + hostoptions["rootsize"] = arg + elif opt in ("--datafs"): + hostoptions["datafs"] = arg + elif opt in ("--datasize"): + hostoptions["datasize"] = arg + elif opt in ("--datadisk"): + hostoptions["datadisk"] = arg + elif opt in ("--datapartition"): + hostoptions["datapartition"] = arg + elif opt in ("--swapsize"): + hostoptions["swapsize"] = arg + + elif opt in ("-c"): + validop = ["full_install", "upgrade", "netboot", "find_upgrade"] + if arg not in validop: + logging.critical("-c %s is not a valid option", arg) + 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) + + + 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 + + +#____________________________________________setup the logging______________________________________________________ +LOG_FILENAME = '/tmp/mv_status.log' +DEBUGLOG = '/tmp/mv_debug.log' +logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + datefmt='%m-%d %H:%M', + filename=DEBUGLOG, + filemode='a') +# define a Handler which writes INFO messages or higher to the sys.stderr +console = logging.StreamHandler() +console.setLevel(logging.INFO) +# set a format which is simpler for console use +#formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') +formatter = logging.Formatter("%(message)s") +# tell the handler to use this format +console.setFormatter(formatter) +# add the handler to the root logger +logging.getLogger('').addHandler(console) + +#infoformatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") +infoformatter = logging.Formatter("%(message)s") +infofile = logging.FileHandler(LOG_FILENAME, 'w') +infofile.setFormatter(infoformatter) +infofile.setLevel(logging.INFO) +logging.getLogger('').addHandler(infofile) + +#Read in systemconfig +global systemconfig +systemconfig = {} +file_name = "/etc/systemconfig" +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('"') + systemconfig[var.strip()] = val.strip() + + +if __name__ == "__main__": + config_file = "mv_config" + data_config = __import__(config_file, globals(), locals(), []) + logging.debug("___________START OF DEBUG_________________________") + cmdoptions = main(sys.argv[1:]) + logging.debug("______cmd line options______") + for i in cmdoptions.items(): + logging.debug (i) + logging.debug("______systemconfig______") + for i in systemconfig.items(): + logging.debug(i) + logging.debug("______hostoptions______") + for i in hostoptions.items(): + logging.debug(i) + pass + diff --git a/abs/core-testing/LinHES-config-22/mv_ir.py b/abs/core-testing/LinHES-config-22/mv_ir.py new file mode 100755 index 0000000..bc1ae37 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_ir.py @@ -0,0 +1,330 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os, re , glob +from time import time, localtime, strftime +import time +import pwd + +def setup_lirc_links(mythhome): + logging.debug(" Creating links for lirc") + try: + mythuid = pwd.getpwnam('mythtv')[2] + mythgid = pwd.getpwnam('mythtv')[3] + except: + logging.critical("* mythuid not found") + mythuid = '1000' + mythgid = '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 + mv_common.runcmd(cmd) + cmd = ''' chgrp -R mythtv %s/.mythtv''' %mythhome + mv_common.runcmd(cmd) + pass + + if os.path.exists("/etc/lircrc"): + if not os.path.exists(mythhome+"/.mythtv/lircrc"): + logging.debug(" Creating symlink for myth lircrc") + os.symlink("/etc/lircrc",mythhome+"/.mythtv/lircrc") + else: + logging.debug(" %s/lircrc already present",mythhome) + + if not os.path.exists(mythhome+"/.lircrc"): + logging.debug(" Creating symlink for lircrc") + os.symlink("/etc/lircrc",mythhome+"/.lircrc") + else: + logging.debug(" %s/.lircrc already present",mythhome) + else: + logging.debug(" /etc/lircrc does not exisit, can not link it") + +def scrub_modules(filename,module): + logging.debug(" scrubbing %s from %s",module,filename) + cmd = '''sed -i -e '/.*#%s/d' %s''' %(module,filename) + mv_common.runcmd(cmd) + +def add_module(filename,module): + logging.debug(" adding %s to %s",module,filename) + cmd = ''' echo "%s" >> %s ''' %(module,filename) + mv_common.runcmd(cmd) + +def unload_all_lirc(): + logging.debug(" Unloading all lirc modules") + cmd = "sv stop lircd" + 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 include_file( incfile,filename): + logging.debug(" including %s within %s",filename,incfile) + try: + f = open( incfile, 'a') + except: + logging.debug(" Couldn't open %s for writing",incfile) + return + line = '''include "%s" ''' %filename + logging.debug(" %s",line) + f.write(line) + f.write("\n") + f.close() + +def setup_ir_remote(Remotetype,templates): + logging.debug(" Setup of remote type %s",Remotetype) + if Remotetype == "no_remote": + mv_common.remove_service("lircd") + elif Remotetype == "tinker": + pass + else: + currenttime = strftime("%b-%d-%Y-%H:%M:%S", localtime()) + cmd = "mv /etc/lircd.conf /etc/lircd.conf-%s" %currenttime + mv_common.runcmd(cmd) + cmd = "mv /etc/lircrc /etc/lircrc-%s" %currenttime + mv_common.runcmd(cmd) + 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) + cmd = "chmod 755 /etc/lircrc" + mv_common.runcmd(cmd) + mv_common.add_service("lircd") + + +def setup_ir_receiver(ReceiverType,TEMPLATES): + logging.info(" Configuring receiver %s", ReceiverType) + if ReceiverType == "Serial": + scrub_modules("/etc/modules.mythvantage","lirc") + add_module("/etc/modules.mythvantage","lirc_serial #lirc") + cmd = "load-modules-mythvantage.sh" + mv_common.runcmd(cmd) + mv_common.remove_service("igdaemon") + mv_common.remove_service("tatir") + + elif ReceiverType == "Usb-imon": + scrub_modules("/etc/modules.mythvantage","lirc") + add_module("/etc/modules.mythvantage","lirc_imon #lirc") + cmd = "load-modules-mythvantage.sh" + mv_common.runcmd(cmd) + mv_common.remove_service("igdaemon") + mv_common.remove_service("tatir") + + elif ReceiverType == "Hauppauge": + scrub_modules("/etc/modules.mythvantage","lirc") + add_module("/etc/modules.mythvantage","lirc_i2c #lirc") + mv_common.cp_and_log(TEMPLATES+"/modules/lirc_i2c.conf" , + "/etc/modprobe.d/lirc_i2c.conf") + cmd = "rmmod lirc_i2c" + mv_common.runcmd(cmd) + cmd = "load-modules-mythvantage.sh" + 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") + mv_common.cp_and_log(TEMPLATES+"/modules/lirc_i2c.conf" , + "/etc/modprobe.d/lirc_i2c.conf") + cmd = "rmmod lirc_i2c" + mv_common.runcmd(cmd) + cmd = "load-modules-mythvantage.sh" + mv_common.runcmd(cmd) + mv_common.remove_service("igdaemon") + mv_common.remove_service("tatir") + elif ReceiverType == "iguanaIR-usb": + scrub_modules("/etc/modules.mythvantage","lirc") + mv_common.add_service("igdaemon") + mv_common.remove_service("tatir") + + elif ReceiverType == "tatir": + scrub_modules("/etc/modules.mythvantage","lirc") + mv_common.add_service("tatir") + mv_common.remove_service("igdaemon") + + else: + logging.debug(" didn't match receiver, using genric case") + scrub_modules("/etc/modules.mythvantage","lirc") + mv_common.remove_service("igdaemon") + mv_common.remove_service("tatir") + +def setup_blaster_proto(HostBlasterType,Hostnumblaster,TEMPLATES,systemconfig): + logging.debug(" Start of setup_blaster_proto") + logging.debug(" HostBlasterType: %s", HostBlasterType) + logging.debug(" Hostnumblaster: %s" , Hostnumblaster) + if not HostBlasterType == "pvr150" and not HostBlasterType == "None": + for i in range(int(Hostnumblaster)): + try: + proto = systemconfig["HostTransmitproto_"+str(i+1)] + logging.debug(" proto: %s",proto) + except: + logging.info(" unkown proto for %s",i+1) + continue + template=TEMPLATES+"/transmit/%s/lircd.conf" %proto + if os.path.exists(template): + logging.debug(" include blaster template: %s",proto) + 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): + logging.debug(" Start of setup_blaster_transmiter") + logging.info(" HostBlasterType : %s", HostBlasterType) + + if HostBlasterType == "Receiver": + logging.info(" Blaster is receiver, skipping module config for Blaster") + return + + if HostBlasterType == "no blaster": + scrub_modules("/etc/modules.mythvantage","blaster") + elif HostBlasterType == "Serial": + scrub_modules("/etc/modules.mythvantage","blaster") + add_module("/etc/modules/.mythvantage","lirc_serial #blaster") + cmd = "load-modules-mythvantage.sh" + mv_common.runcmd(cmd) + elif HostBlasterType == "pvr150": + scrub_modules("/etc/modules.mythvantage", "blaster") + scrub_modules("/etc/modules.mythvantage", "lirc") + add_module("/etc/modules.mythvantage", "lirc_pvr150 #blaster") + add_module("/etc/modules.mythvantage", "lirc_pvr150 #lirc") + cmd = "rmmod lirc_i2c" + mv_common.runcmd(cmd) + cmd = "load-modules-mythvantage.sh" + mv_common.runcmd(cmd) + else: + scrub_modules("/etc/modules.mythvantage","blaster") + +def setup_lcd(LCDtype, TEMPLATES, Remotetype): + logging.debug("____Start of setup_lcd____") + logging.debug(" LCDType: %s", LCDtype) + logging.debug(" Remotetype: %s", Remotetype) + if LCDtype == "tinker": + logging.info(" tinker mode detected") + return + + if LCDtype == "no_lcd": + logging.info(" Disabling LCD support") + cmd = "sv stop lcdd" + mv_common.runcmd(cmd) + #sometimes it doesn't want to die + 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") + mv_common.remove_service("lcdd") + else: + lcdmodule="%s/LCD/%s/modules" %(TEMPLATES,LCDtype) + if os.path.exists(lcdmodule): + logging.debug(" Adding module for LCD") + scrub_modules("/etc/modules.mythvantage", "LCD") + cmd = "cat %s >> /etc/modules.mythvantage" %lcdmodule + mv_common.runcmd(cmd) + if Remotetype != "tinker": + lcdconf = "%s/LCD/%s/LCDd.conf" %(TEMPLATES,LCDtype) + lcdlirc = "%s/LCD/%s" %(TEMPLATES,LCDtype) + mv_common.pacinstall("lcdproc") + if os.path.exists(lcdconf): + logging.debug(" Copying in lcdconf template file: %s",lcdconf) + mv_common.cp_and_log(lcdconf, "/etc/LCDd.conf") + else: + logging.debug(" %s is not present, will not copy it") + + if os.path.exists(lcdlirc+"/lircrc"): + logging.debug(" LCD seems to support lirc") + #setup the lirc aspect of the lcd + #copied from setup_ir_remote + files = lcdlirc+"/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 = lcdlirc+"/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) + cmd = "chmod 755 /etc/lircrc" + mv_common.runcmd(cmd) + + mv_common.add_service("lcdd") + mv_common.restart_service("lcdd") + logging.debug("__End of setup_lcd") + +def setup_ir(systemconfig, data_config): + rc = False + logging.info("____Start of IR____") + if systemconfig["Remotetype"] == "tinker": + logging.info(" Tinker mode detected") + else: + if not systemconfig["HostBlasterType"]: + HostBlasterType = "unknown" + Hostnumblaster = "0" + else: + HostBlasterType = systemconfig["HostBlasterType"] + Hostnumblaster = systemconfig["Hostnumblaster"] + + if systemconfig["HostBlasterType"] == "pvr150": + remotetype = "hauppauge-blaster" + logging.debug(" pvr150 blaster selected, setting remote to hauppauge-blaster") + else: + remotetype = systemconfig["Remotetype"] + + setup_ir_remote(remotetype,systemconfig["TEMPLATES"]) + setup_lirc_links(data_config.MYTHHOME) + + if systemconfig["ReceiverType"]: + setup_ir_receiver(systemconfig["ReceiverType"], + systemconfig["TEMPLATES"]) + else: + setup_ir_receiver("unknown", systemconfig["TEMPLATES"]) + unload_all_lirc() + setup_blaster_proto(HostBlasterType, + Hostnumblaster, + systemconfig["TEMPLATES"], + systemconfig) + setup_blaster_transmiter(HostBlasterType) + cmd = "load-modules-mythvantage.sh" + mv_common.runcmd(cmd) + time.sleep(2) + mv_common.udev_trigger() + cmd="sv start lircd" + mv_common.runcmd(cmd) + rc = [ True , True ] + if systemconfig["LCDtype"]: + setup_lcd(systemconfig["LCDtype"], + systemconfig["TEMPLATES"], + systemconfig["Remotetype"]) + else: + logging.debug(" LCD not defined") + logging.info("__End IR\n") + return rc
\ No newline at end of file diff --git a/abs/core-testing/LinHES-config-22/mv_misc.py b/abs/core-testing/LinHES-config-22/mv_misc.py new file mode 100755 index 0000000..9ea9c95 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_misc.py @@ -0,0 +1,180 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os, re +from urllib2 import Request, urlopen, URLError, HTTPError + +config_file = "mv_config" +data_config = __import__(config_file, globals(), locals(), []) + +def setup_zip(MVROOT,zipcode): + logging.debug("____Setting up the zipcode____") + + if zipcode: + cmd="%s/bin/restore_default_settings.sh -c ZIP -c %s" %(MVROOT,zipcode) + mv_common.runcmd(cmd) + #Let's also speed things up for those in North America + cmd="mkdir /usr/bin/perlbin/vendor/tv_grabbers_non_na" + mv_common.runcmd(cmd) + cmd="mv /usr/bin/perlbin/vendor/tv_grab_* /usr/bin/perlbin/vendor/tv_grabbers_non_na" + mv_common.runcmd(cmd) + cmd="mv /usr/bin/perlbin/vendor/tv_grabbers_non_na/tv_grab_na* /usr/bin/perlbin/vendor/" + mv_common.runcmd(cmd) + else: + logging.debug(" Zipcode is not set") + + logging.debug("__End of zipcode\n") + +def setup_tz(timezone,TEMPLATES): + logging.info("____Setting up the timezone____") + + if not timezone: + timezone="unknown" + logging.info(" Setting timezone to %s",timezone) + mv_common.remove_file("/etc/localtime") + #try: + #logging.debug(" Removing /etc/localtime") + #os.remove("/etc/localtime") + #except: + #logging.debug(" Couldn't remove /etc/localtime") + #pass + + srclink="/usr/share/zoneinfo/%s" %timezone + logging.debug(" symlinking %s to /etc/localtime",srclink) + try: + 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) + + 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") + logging.info("__End of timezone\n") + +def setup_nfs(systemconfig): + nfslist=[] + logging.info("____Start of setup_nfs____") + scrubnfs(systemconfig["TEMPLATES"]) + + if systemconfig["HaveCentralNFS"] == "yes": + logging.debug(" Using a Central NFS server") + if systemconfig["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["dbhost"]) + nfslist = process_nfsmap_file(nfsmap_file) + # if it's an ip parse ip and download file + elif re.search(systemconfig["NFSserver"],":nfsmap"): + ip=systemconfig["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["NFSserver"] , systemconfig["NFSmount"]) + nfslist.append(item) + else: + #if standalone or slave try to use MBE + if systemconfig["SystemType"] == "Frontend_only" or systemconfig["SystemType"] == "Slave_Backend": + item = (systemconfig["dbhost"] , 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____") + autoshutdown = systemconfig["AutoShutdown"] + stime1 = systemconfig["Shutdowntime"] + stime2 = systemconfig["Shutdowntime2"] + cstime1='' + + if autoshutdown == "1" : + if not stime1 == "-1" : + cstime1 = stime1 + cshutdown = cstime1 + if not stime2 == "-1" : + if cstime1 : + cshutdown = "%s,%s" %(cstime1,stime2) + else: + cshutdown = stime2 + logging.debug(" Shutdown time at %s",cshutdown) + cmd='''sed -e "s/HOUR/%s/g" %s/cron.template | crontab - -u mythtv''' %(cshutdown,systemconfig["TEMPLATES"]) + mv_common.runcmd(cmd) + else: + logging.info(" Shutdown not enabled") + cmd='''sed -e "/00 HOUR.*/d" %s/cron.template | crontab - -u mythtv''' %systemconfig["TEMPLATES"] + mv_common.runcmd(cmd) + + 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-testing/LinHES-config-22/mv_network.py b/abs/core-testing/LinHES-config-22/mv_network.py new file mode 100755 index 0000000..b80e4cc --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_network.py @@ -0,0 +1,507 @@ +# -*- coding: utf-8 -*- +import sys , os, commands , glob, time, re +import logging +import mv_common +import socket, fcntl, struct, array +import netifaces, iplib +global etcnetdir +etcnetdir = "/etc/net/ifaces" + +def setup_MYTH_DHCP(systemconfig): + default_interface = systemconfig["default_interface"] + try: + defaultdhcp = systemconfig["HostUSEDHCP"+default_interface] + except: + logging.critical(" *Error occured finding default dhcp") + defaultdhcp = "0" + logging.debug(" Using %s as dhcp value for %s", defaultdhcp, default_interface) + 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)] + +def get_ip(ifname): + logging.debug(" Finding ip address for %s", ifname) + all_if = all_interfaces() + logging.debug(" found interfaces:%s", all_if) + if ifname in all_if : + logging.debug(" Found %s in all_interfaces", ifname) + else: + logging.critical("* Couldn't find %s in list", ifname) + ifname = all_if[0] + logging.critical("* Using %s for interface name", ifname) + + + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', ifname[:15]) + )[20:24]) + +def get_default_route(iface): + rcroute = "127.0.0.1" + f = open ('/proc/net/route', 'r') + for line in f: + words = string.split (line) + netiface = words[0] + route = words[2] + flags = words[3] + try: + if ( netiface == iface ) and ( flags == "0003") : + route = iplib.IPv4Address(route, notation="hex") + t = str(route.get_dot()) + s = t.split(".") + rcroute = s[3] + "." + s[2] + "." + s[1] + "." + s[0] + break + except ValueError: + pass + return rcroute + +def setup_MYTH_IP(systemconfig): + default_interface = systemconfig["default_interface"] + #check for dhcp in use + if setup_MYTH_DHCP(systemconfig) == "0": + logging.debug(" dhcp is in use, finding dhcp ip") + defaultip = get_ip(default_interface) + else: + try: + defaultip = systemconfig["Hostip"+default_interface] + except: + logging.debug(" Error occured finding the defaultip") + defaultip = "127.0.0.1" + logging.debug(" Using %s as default ip", defaultip) + return defaultip + + +def setup_MYTH_GW(systemconfig): + default_interface = systemconfig["default_interface"] + #check for dhcp in use + if setup_MYTH_DHCP(systemconfig) == "0": + logging.debug(" dhcp is in use, finding dhcp ip") + defaultgw = get_default_route(default_interface) + else: + try: + defaultgw = systemconfig["Hostgw"+default_interface] + except: + logging.debug(" Error occured finding the defaultgw") + defaultgw = "127.0.0.1" + logging.debug(" Using %s as default gw", defaultgw) + return defaultgw + + +def setup_MTYH_DNS(): + returndns = "127.0.0.1" + try: + f = open ('/etc/resolv.conf', 'r') + for line in f: + if line.startswith("nameserver"): + print line + returndns = line.split()[1] + break + except: + logging.debug(" Couldn't open /etc/resolv.conf for myth_dns") + logging.debug(" using %s for myth_dns", returndns) + return returndns + + + + + +def flush(netdev): + logging.debug(" Flushing %s",netdev) + cmd = '''ip address flush dev %s''' %netdev + mv_common.runcmd(cmd) + +def kill_dhcp(basedir): + logging.debug(" _Start of kill_dhcp") + logging.debug(" Killing off dhcpd") + stddir = os.getcwd() + piddir = ("%s/var/run/") %basedir + try: + os.chdir(piddir) + for FILE in glob.glob("dhcpcd-*.pid"): + f = open(FILE,'r') + pid = f.readline() + f.close + cmd = "kill -9 %s" %pid + mv_common.runcmd(cmd) + mv_common.remove_file(FILE) + os.chdir(stddir) + except: + pass + +def setup_nameserver(dns): + logging.info(" Adding %s for DNS", dns) + cmd = '''grep -q %s /etc/resolv.conf''' %dns + status = mv_common.runcmd(cmd) + if not status == 0 : + cmd = ''' echo "nameserver %s" >> /etc/resolv.conf ''' %dns + mv_common.runcmd(cmd) + + + +def setup_hostname(systemconfig): + logging.debug(" _Start of setup_hostname") + try: + hostname = systemconfig["hostname"] + except: + logging.critical(" *Hostname could not be set") + logging.info(" Using default value of me") + hostname = "me" + logging.info(" Setting the hostname to %s", hostname) + cmd = ''' echo %s > /etc/hostname ''' %hostname + mv_common.runcmd(cmd) + cmd = "cat /etc/hosts | grep -v 127.0.0.1 | grep -v %s > /tmp/hosts" %hostname + mv_common.runcmd(cmd) + if systemconfig["mythdhcp"] == "1" : + logging.debug(" not using dhcp") + cmd = ''' echo 127.0.0.1 localhost > /etc/hosts ''' + mv_common.runcmd(cmd) + cmd = ''' echo %s %s > /etc/hosts ''' %(systemconfig["mythip"], systemconfig["hostname"]) + mv_common.runcmd(cmd) + else: + cmd = ''' echo 127.0.0.1 %s localhost > /etc/hosts ''' %systemconfig["hostname"] + mv_common.runcmd(cmd) + cmd = '''cat /tmp/hosts >> /etc/hosts ''' + mv_common.runcmd(cmd) + + +def write_wpafile(line,netdev): + logging.debug(" writing out wpa_supplicant.conf file") + logging.debug(line) + wpafile = etcnetdir+"/"+netdev+"/wpa_supplicant.conf" + try: + f = open(wpafile,'w') + f.write(line) + f.close() + except: + logging.debug(" Couldn't write to %s",wpafile) + +def setup_wpa(netinfo,netdev): + logging.info(" %s will use wpa for encryption",netdev) + line = ''' +#This file was automaticly generated, any changes may be lost +ctrl_interface=/var/run/wpa_supplicant +network={ + ssid="%s" + # Preshared key as an ASCII passphrase + psk="%s" + scan_ssid=1 + key_mgmt=WPA-EAP WPA-PSK NONE + pairwise=CCMP TKIP + proto=WPA RSN +}''' %(netinfo["ESSID"],netinfo["KEY"]) + write_wpafile(line,netdev) + +def setup_wep(netinfo,netdev): + logging.info(" %s will use wep for encryption",netdev) + logging.debug(" When a packet comes along, you must wep it") + line=''' +#This file was automaticly generated, any changes may be lost +ctrl_interface=/var/run/wpa_supplicant +network={ + ssid="%s" + key_mgmt=NONE + wep_key0=%s + wep_tx_keyidx=0 + scan_ssid=1 + auth_alg=SHARED +} +''' %(netinfo["ESSID"],netinfo["KEY"]) + write_wpafile(line,netdev) + + +def setup_none(netinfo,netdev): + logging.info(" %s will not use encryption",netdev) + line = ''' +#This file was automaticly generated, any changes may be lost +ctrl_interface=/var/run/wpa_supplicant +network={ + ssid="%s" + key_mgmt=NONE +} +''' %netinfo["ESSID"] + write_wpafile(line,netdev) + +def setup_interface(netdev,systemconfig): + logging.debug(" _Start of setup_interface for %s",netdev) + nettrans = {'Hostip':'ip', + 'Hostnetmask':'netmask', + 'HostActive':'isactive', + 'HostDNS':'dns', + 'HostUSEDHCP':'UseDHCP', + 'HostGW':'GW', + 'HostMTU':'mtu', + 'HOST_iswireless':"wireless", + 'HostESSID':'ESSID', + 'HostKey':'KEY', + 'HostUseEncryption':'ENCRYPT'} + netinfo = {} + #populate the netinfo dict + for netitem in nettrans: + if systemconfig[netitem+netdev]: + netinfo[nettrans[netitem]] = systemconfig[netitem+netdev] + else: + netinfo[nettrans[netitem]] = False + logging.debug(" %s:%s",netitem,netinfo[nettrans[netitem]]) + logging.info(" %s wireless: %s", netdev,netinfo["wireless"]) + try: + os.makedirs(etcnetdir) + except: + logging.debug(" Could not create %s",etcnetdir) + + optionfile=etcnetdir+"/"+netdev+"/options" + if not os.path.exists(optionfile): + try: + os.makedirs(etcnetdir+"/"+netdev) + except: + pass + mv_common.cp_and_log(systemconfig["TEMPLATES"]+"/etcnet/eth/options", optionfile) + + if netinfo["isactive"] == "1" : + change_iface_state(netdev,"enabled") + else: + change_iface_state(netdev,"disabled") + + if netinfo["wireless"] == "1" : + + logging.info(" Enabling wireless extensions") + cmd = ''' sed -i -e 's/^CONFIG_WIRELESS=.*$/CONFIG_WIRLESS=yes/g' %s/%s/options''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + if netinfo["ENCRYPT"] == "WEP": + setup_wep(netinfo,netdev) + elif netinfo["ENCRYPT"] == "WPA": + setup_wpa(netinfo,netdev) + elif netinfo["ENCRYPT"] == "none": + setup_none(netinfo,netdev) + + else: + logging.info(" Disabling wireless extensions") + cmd = '''sed -i -e 's/^CONFIG_WIRLESS=.*$/CONFIG_WIRLESS=no/g' %s/%s/options''' %(etcnetdir, netdev) + mv_common.runcmd(cmd) + #try: + wpafile=etcnetdir+"/"+netdev+"/wpa_supplicant.conf" + #os.remove(wpafile) + mv_common.remove_file(wpafile) + #except: + #logging.debug(" Couldn't remove %s",wpafile) + + if netinfo["UseDHCP"] == "0" : + logging.info(" Enabling DHCP support") + cmd = ''' sed -i -e 's/^BOOTPROTO=.*$/BOOTPROTO=dhcp/g' %s/%s/options''' %(etcnetdir, netdev) + mv_common.runcmd(cmd) + else: + logging.info(" Using static ip address of %s",netinfo["ip"]) + cmd = ''' sed -i -e 's/^BOOTPROTO=.*$/BOOTPROTO=static/g' %s/%s/options''' %(etcnetdir, netdev) + mv_common.runcmd(cmd) + cmd = '''echo "default via %s" > %s/%s/ipv4route''' %(netinfo["GW"], etcnetdir, netdev) + mv_common.runcmd(cmd) + cmd = '''echo "%s%s" > %s/%s/ipv4address ''' %(netinfo["ip"], netinfo["netmask"].split()[0], etcnetdir, netdev) + mv_common.runcmd(cmd) + setup_nameserver(netinfo["dns"]) + + if netinfo["mtu"] : + logging.info(" Setting mtu to %s", netinfo["mtu"]) + cmd = '''sed -i '/^mtu.*$/d' %s/%s/iplink''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + cmd = ''' echo "mtu %s" >> %s/%s/iplink''' %(netinfo["mtu"], etcnetdir,netdev) + mv_common.runcmd(cmd) + else: + logging.info(" Using default mtu value") + cmd = '''sed -i '/^mtu.*$/d' %s/%s/iplink''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + + +def change_iface_state(netdev, state): + if state == "enabled": + logging.info(" Activating %s", netdev) + cmd = '''sed -i -e 's/^ONBOOT=.*$/ONBOOT=yes/g' %s/%s/options''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + cmd = '''sed -i -e 's/^DISABLED=.*$/DISABLED=no/g' %s/%s/options ''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + else: + logging.info(" Disabling %s", netdev) + cmd = '''sed -i -e 's/^ONBOOT=.*$/ONBOOT=no/g' %s/%s/options''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + cmd = '''sed -i -e 's/^DISABLED=.*$/DISABLED=yes/g' %s/%s/options ''' %(etcnetdir,netdev) + mv_common.runcmd(cmd) + cmd = "/sbin/ifconfig %s down" %netdev + mv_common.runcmd(cmd) + cmd = "ip address flush %s" %netdev + mv_common.runcmd(cmd) + +def devcheck(netdev): + cmd = ''' /sbin/ifconfig %s''' %netdev + rc = mv_common.runcmd(cmd) + if rc == 0 : + return True + else: + return False + +def udev_rules(netdev): + filename = "/etc/udev/rules.d/net.rules" + if devcheck(netdev): + logging.info(" Finding macaddress for %s",netdev) + try: + macaddress = netifaces.ifaddresses(netdev)[netifaces.AF_LINK][0]['addr'] + logging.debug(" Macaddress: %s",macaddress) + except: + logging.debug(" Couldn't find mac address for %s",netdev) + return + try: + f = open(filename,'a') + except: + logging.debug(" Couldn't open %s for writing", filename) + return + if netdev.startswith('eth'): + line = '''KERNEL=="eth*", SYSFS{address}=="%s", NAME="%s"''' % ( macaddress , netdev) + elif netdev.startswith('wlan'): + line = '''KERNEL=="wlan*", SYSFS{address}=="%s", NAME="%s"'''% ( macaddress , netdev) + elif netdev.startswith('ath'): + line = '''KERNEL=="ath*", SYSFS{address}=="%s", NAME="%s"''' % ( macaddress , netdev) + logging.debug(" adding to net.rules ") + logging.debug(" %s",line) + f.write(line) + f.write("\n") + f.close() + +def find_active(systemconfig,this_is_install): + interfacelist=('eth0', 'eth1', 'wlan0', 'wlan1', 'ath0') + logging.debug(" _Start of find_active") + + if systemconfig["mythdhcp"] == "1": + mv_common.remove_file("/etc/resolv.conf") + cmd = ''' echo search lan > /etc/resolv.conf ''' + mv_common.runcmd(cmd) + cmd = ''' echo nameserver 127.0.0.1 >> /etc/resolv.conf ''' + mv_common.runcmd(cmd) + + for netdev in interfacelist: + if this_is_install: + udev_rules(netdev) + currentnet = "HostActive" + netdev + try: + systemconfig[currentnet] + except: + logging.debug(" %s is not defined",currentnet) + change_iface_state(netdev, "disabled") + continue + if systemconfig[currentnet] == "1" : + #check if device is present + if devcheck(netdev) : + setup_interface(netdev,systemconfig) + else: + logging.debug(" Interface %s not found in config", netdev) + #change_iface_state(netdev, "disabled") + else: + change_iface_state(netdev, "disabled") + +def vnc_netboot_check(): + logging.debug(" Start of VNC/NETBOOT check") + vnc = False + netboot = False + try: + f = open('/proc/cmdline', 'r') + bootoptions = f.readlines() + f.close() + except: + logging.critical(" *Couldn't open /proc/cmdline") + logging.debug(" Assuming it's ok to fiddle with the network") + return True + bootoptions = bootoptions[0] + if re.match("vnc",bootoptions) != None : + logging.debug(" Found VNC option") + vnc = True + if re.match("nfsroot",bootoptions) != None : + logging.debug(" Found netboot option") + netboot = True + + return (vnc or netboot) + +def start_network(): + if not vnc_netboot_check(): + logging.info(" Restarting network") + cmd ="/etc/net/scripts/network.init reload" + mv_common.runcmd(cmd) + cmd ="/etc/net/scripts/network.init restart" + mv_common.runcmd(cmd) + else: + logging.info(" Will not restart network due to netboot/vnc") + + +def stop_network(): + if not vnc_netboot_check(): + logging.info(" Stopping network") + cmd ="/etc/net/scripts/network.init stop" + mv_common.runcmd(cmd) + kill_dhcp("") + interfacelist=('eth0', 'eth1', 'wlan0', 'wlan1', 'ath0') + for i in interfacelist: + flush(i) + else: + logging.info(" Will not stop network due to netboot/vnc") + pass + +def hostname_change_check(systemconfig): + restartfe = False + logging.debug(" _Start of hostname_change_check") + oldhostname = socket.gethostname() + #oldhostname = "crap" + newhostname = systemconfig["hostname"] + mv_root = systemconfig["MVROOT"] + logging.debug(" Old hostname: %s", oldhostname) + 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) + mv_common.runcmd(cmd) + logging.info(" Changing hostname to %s", newhostname) + cmd = "hostname %s" %newhostname + mv_common.runcmd(cmd) + if systemconfig["SystemType"] != "Frontend_only" : + logging.info(" Restarting backend") + mv_common.stop_service("mythbackend") + mv_common.start_service("mythbackend") + restartfe = True + else: + logging.debug(" old and new hostnames matched, leaving things along") + logging.debug(" __End of hostname_change_check") + return restartfe + + + +def setup_network (systemconfig,this_is_install): + logging.info("____Start of network____") + logging.info(" Setting up the network") + restartfe = hostname_change_check(systemconfig) + setup_hostname(systemconfig) + find_active(systemconfig,this_is_install) + start_network() + logging.info("__End of network\n") + return restartfe + + + +##this is used by the install process to start the network +def install_network_setup(systemconfig): + logging.info("____Start of network_install____") + logging.info(" Setting up the network") + #setup_MYTH_vars + setup_hostname(systemconfig) + stop_network() + find_active(systemconfig) + start_network() + logging.info("__End of network install \n") + + diff --git a/abs/core-testing/LinHES-config-22/mv_screensaver.py b/abs/core-testing/LinHES-config-22/mv_screensaver.py new file mode 100755 index 0000000..2da970c --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_screensaver.py @@ -0,0 +1,199 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import re +import os + + +def mplayer_saver_check (cmd,templatefile): + logging.debug(" Checking for heartbeat command in mplayer.conf") + mplayerconf = "/etc/mplayer/mplayer.conf" + if not os.path.exists(mplayerconf): + logging.debug(" copying in mplayer template file") + mv_common.cp_and_log(templatefile, mplayerconf) + + try: + f = open(mplayerconf, 'r') + mplayerconf_contents = f.readlines() + f.close() + except: + logging.debug(" Couldn't open %s for reading",mplayerconf) + mplayerconf_contents = "#\n" + + try: + f = open(mplayerconf, 'w') + except: + logging.debug(" Couldn't open %s for writing",mplayerconf) + return + + for line in mplayerconf_contents: + if re.match("^.*stop-xscreensaver",line): + continue + elif re.match("^.*heartbeat-cmd",line): + continue + else: + f.write(line) + + f.write("stop-xscreensaver = 0\n") + line='''heartbeat-cmd="%s"\n''' %cmd + f.write(line) + f.close() + + +def killxscreensaver(): + logging.info(" Stopping xscreensaver") + cmd="xscreensaver-command --exit " + mv_common.runcmd(cmd) + cmd="killall xscreensaver " + mv_common.runcmd(cmd) + +def killgscreensaver(): + logging.info(" Stopping gnome-screensaver") + cmd="gnome-screensaver-command --exit " + mv_common.runcmd(cmd) + cmd="killall gnome-screensaver " + mv_common.runcmd(cmd) + + +def setup_x_screensaver(idle,theme,screenconfigfile,templatefile): + logging.info(" Configuring X screensaver") + killgscreensaver() + logging.debug(" Why can't xscreensaver have a nice configuration !") + + if not os.path.exists(screenconfigfile): + logging.debug(" copying in new template file") + mv_common.cp_and_log(templatefile,screenconfigfile) + + try: + f = open(screenconfigfile, 'r') + screenconfigcontents=f.readlines() + f.close() + except: + logging.info("Couldn't open %s for reading",screenconfigfile) + return + try: + f = open(screenconfigfile, 'w') + except: + logging.info("Couldn't open %s for writing",screenconfigfile) + return + + startline=0 + foundline=0 + + for k, line in enumerate(screenconfigcontents): + if re.match("programs:",line): + startline = k + if re.search(theme,line): + foundline = k + themenumber=foundline-startline-2 + + for line in screenconfigcontents: + if re.match("selected.*$",line): + continue + + if re.match("timeout",line): + logging.info(" Setting idletime to %s",idle) + outline = "timeout: 0:%s:00 \n" %idle + f.write(outline) + elif re.match("mode",line): + if theme == "Random": + logging.info(" Setting theme to %s", "Random") + outline = "mode: random \n" + f.write(outline) + outline = "selected: -1 \n" + f.write(outline) + continue + + elif theme == "Blank": + logging.info(" Setting theme to %s", "blank") + outline = "mode: blank \n" + f.write(outline) + outline = "selected: -1 \n" + f.write(outline) + continue + + else: + logging.info(" Setting theme to %s", theme) + outline = "mode: one\n" + f.write(outline) + logging.debug(" Theme number is %s",themenumber) + outline = "selected: %s\n" %themenumber + f.write(outline) + continue + + else: + outline = line + f.write(outline) + f.close() + logging.debug("__End of xscreensaver") + +def setup_gnome_screensaver(theme,idletime): + logging.info(" Configuring gnome screensaver") + + logging.info(" Disabling lock screen") + cmd='''gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type bool --set /apps/gnome-screensaver/lock_enabled false''' + mv_common.runcmd(cmd) + + logging.info(" Setting idletime to %s",idletime) + cmd='''gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type int -s "/apps/gnome-screensaver/idle_delay" %s''' %idletime + mv_common.runcmd(cmd) + + logging.info(" Setting mode to single") + cmd='''gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string -s "/apps/gnome-screensaver/mode" single''' + mv_common.runcmd(cmd) + + if theme == "Random": + logging.info(" setting theme to random") + cmd='''gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string -s "/apps/gnome-screensaver/mode" random''' + mv_common.runcmd(cmd) + + elif theme == "Blank": + logging.info(" setting theme to blank") + cmd='''gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --type string -s "/apps/gnome-screensaver/themes" blank''' + mv_common.runcmd(cmd) + + else: + logging.info(" setting theme to %s",theme) + cmd='''gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.mandatory --set --type list --list-type=string /apps/gnome-screensaver/themes [screensavers-%s]''' %theme + mv_common.runcmd(cmd) + + killxscreensaver() + logging.info("__End gnome screensaver") + + + + +def setup_screensaver (systemconfig,data_config): + logging.info("____Start of screensaver configuration____") + screensavertype = systemconfig["Screensavertype"] + theme = systemconfig["Screensavertheme"] + idletime = systemconfig["Screensaveridle"] + configfile = data_config.MYTHHOME+"/.xscreensaver" + templatefile = systemconfig["TEMPLATES"]+"/xscreensaver.template" + mtemplate = systemconfig["TEMPLATES"]+"/mplayer.conf.template" + + if screensavertype == "xscreensaver": + mv_common.pacinstall("xscreensaver") + mv_common.pacremove("gnome-screensaver") + setup_x_screensaver(idletime, theme, configfile, templatefile) + mplayer_saver_check("/usr/bin/xscreensaver-command -deactivate &",mtemplate) + + elif screensavertype == "gscreensaver": + mv_common.pacinstall("xscreensaver") + mv_common.pacinstall("gnome-screensaver") + setup_gnome_screensaver(theme,idletime) + mplayer_saver_check("/usr/bin/gnome-screensaver-command -p &",mtemplate) + + elif screensavertype == "none": + mv_common.pacremove("xscreensaver") + mv_common.pacremove("gnome-screensaver") + killgscreensaver() + killxscreensaver() + + elif screensavertype == "tinker" : + logging.debug(" screensaver tinker mode detected") + else: + logging.debug(" Unknown screensaver") + logging.info("__End of screensaver\n") + + + diff --git a/abs/core-testing/LinHES-config-22/mv_smolt.py b/abs/core-testing/LinHES-config-22/mv_smolt.py new file mode 100755 index 0000000..5fd3722 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_smolt.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +import logging +import mv_common + +def read_release(stype): + if stype == "LinHES": + rfile = "/etc/LinHES-release" + else: + rfile = "/etc/MythVantage-release" + + try: + f= open(rfile,'r') + releasename = f.readlines()[0] + f.close() + except: + logging.debug(" Couldn't open %s",rfile) + releasename = "unknown" + + return releasename + + +def setup_smolt_type(SystemType,Remotetype,RunFrontend,mythhome,stype): + logging.debug("____Start of setup_smolt_type____") + releasename = read_release(stype) + + if SystemType == "Standalone": + smoltsystem = 6 + MVRELEASE="%s (Standalone)" %releasename + elif SystemType == "Master_backend": + if RunFrontend == "1": + smoltsystem = 2 + MVRELEASE="%s (MBE with Frontend)" %releasename + else: + smoltsystem=1 + MVRELEASE="%s (MBE)" %releasename + elif SystemType == "Slave_backend": + if RunFrontend == "1" : + smoltsystem = 4 + MVRELEASE="%s (SLAVE with Frontend)" %releasename + else: + smoltsystem = 5 + MVRELEASE="%s (SLAVE)" %releasename + elif SystemType == "Frontend_only": + smoltsystem = 3 + MVRELEASE="%s ( Frontend only)" %releasename + + logging.debug(" smolt type is %s : %s", MVRELEASE,smoltsystem) + smoltfile = mythhome+"/.mythtv/smolt.info" + cmd = ''' echo "%s" > /etc/os_myth_release ''' %MVRELEASE + mv_common.runcmd(cmd) + + cmd = '''echo "systemtype=%s" > %s''' %(smoltsystem,smoltfile) + mv_common.runcmd(cmd) + + cmd = '''echo "remote=%s" >> %s ''' %(Remotetype,smoltfile) + mv_common.runcmd(cmd) + + logging.debug("__End of setup_smolt_type") + diff --git a/abs/core-testing/LinHES-config-22/mv_software.py b/abs/core-testing/LinHES-config-22/mv_software.py new file mode 100755 index 0000000..aabcf89 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_software.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +import os, re + +def setup_software(systemconfig, data_config): + logging.info("____Start of Software install____") + postfix='' + if data_config.SYSTEMTYPE == "MythVantage": + #look for the installed prefix + cmd="pacman -Q mythtv-release-fixes" + rc = mv_common.runcmd(cmd) + if rc == 0: + postfix = "-release-fixes" + else: + postfix = "-svn" + + default_disabled = ("mythphone", "mytharchive", "mythbrowser", "mythnews", + "mythgame", "mythflix", "mythweather", + "mythzoneminder" ) + + default_installed=("mythcontrols", "mythgallery", "mythmovies", + "mythmusic", "mythsmolt", "mythvideo") + other_pkg=("miro", "mednafen", "romdb", "xine", "dvdcss", "webmin" , "fuppes", "foldingathome", "mythappletrailers", "mythstream", "mythvodka") + else: + default_disabled = ("mythphone", "mytharchive", "mythbrowser", "mythnews", + "mythgame", "mythflix", "mythweather", + "mythappletrailers", "mythstream", "mythvodka", + "mythzoneminder" ) + + default_installed=("mythcontrols", "mythgallery", "mythmovies", + "mythmusic", "mythsmolt", "mythvideo") + other_pkg=("miro", "mednafen", "romdb", "xine", "dvdcss", "webmin" , "fuppes", "foldingathome") + + for pkg in default_disabled: + pkgname=pkg+postfix + try: + if systemconfig[pkg] == "1": + mv_common.pacinstall(pkgname) + else: + mv_common.pacremove(pkgname) + except: + logging.debug(" ERROR-- %s is not defined", pkg) + + for pkg in default_installed: + try: + if systemconfig[pkg] == "0": + mv_common.pacremove(pkgname) + else: + mv_common.pacinstall(pkgname) + except: + logging.debug(" ERROR-- %s is not defined", pkg) + + for pkg in other_pkg: + try: + if systemconfig[pkg] == "1": + mv_common.pacinstall(pkg) + elif systemconfig[pkg] == "0": + mv_common.pacremove(pkg) + except: + logging.debug(" ERROR-- %s is not defined", pkg) + logging.info("__End Software\n ") diff --git a/abs/core-testing/LinHES-config-22/mv_webuser.py b/abs/core-testing/LinHES-config-22/mv_webuser.py new file mode 100755 index 0000000..a8517a8 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/mv_webuser.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +import logging, mv_common +#import os + +def setup_web_auth(UseMythWEB_auth): + logging.info("____Start of setup_web_auth____") + 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) + 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''' + mv_common.runcmd(cmd) + logging.debug("Restarting lighttpd") + cmd="sudo sv restart lighttpd" + mv_common.runcmd(cmd) + logging.info("__End of webauth\n") + diff --git a/abs/core-testing/LinHES-config-22/myth_user_call b/abs/core-testing/LinHES-config-22/myth_user_call new file mode 100644 index 0000000..0914b03 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/myth_user_call @@ -0,0 +1,174 @@ +#!/bin/bash +#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 + + diff --git a/abs/core-testing/LinHES-config-22/myth_user_call.py b/abs/core-testing/LinHES-config-22/myth_user_call.py new file mode 100755 index 0000000..63915a4 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/myth_user_call.py @@ -0,0 +1,159 @@ +#!/usr/bin/python +# -*- 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 + +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-testing/LinHES-config-22/networkconfig.sh b/abs/core-testing/LinHES-config-22/networkconfig.sh new file mode 100644 index 0000000..770aa98 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/networkconfig.sh @@ -0,0 +1,341 @@ +#!/bin/bash +#. /etc/profile +#. /etc/systemconfig +#BASE=/tmp +ETCNETDIR=$BASE/etc/net/ifaces + + + +function kill_dhcp () +{ +#for i in ${BASE}/etc/dhcpc/dhcpcd-*.pid +for i in ${BASE}/var/run/dhcpcd-*.pid +do + if [ -f ${i} ] + then + pid=`cat ${i}` + kill -9 $pid + rm -f ${i} + fi + if [ x$1 = xflush ] + then + for ifdev in eth0 wlan0 eth1 wlan1 + do + echo ${i} |grep $ifdev + status=$? + if [ $status = 1 ] + then + ip address flush $ifdev + fi + done + fi + +done + +} + +function kill_dhcp_chroot () +{ +#for i in ${BASE}/etc/dhcpc/dhcpcd-*.pid +for i in ${mountpoint}/var/run/dhcpcd-*.pid +do + if [ -f ${i} ] + then + pid=`cat ${i}` + kill -9 $pid + rm -f ${i} + fi +done + +} + + + +function setup_nameserver(){ +grep -q $1 ${BASE}/etc/resolv.conf +status=$? +if [ ! $status = 0 ] +then + echo "nameserver $1" >> ${BASE}/etc/resolv.conf +fi + +} + +function change_iface_state () { + if [ x$2 = xenabled ] + then + echo "setting $1 to active" + sed -i -e 's/^ONBOOT=.*$/ONBOOT=yes/g' $ETCNETDIR/$1/options + sed -i -e 's/^DISABLED=.*$/DISABLED=no/g' $ETCNETDIR/$1/options + else + echo "setting $1 to inactive" + if [ -e $ETCNETDIR/$1/options ] + then + sed -i -e 's/^ONBOOT=.*$/ONBOOT=no/g' $ETCNETDIR/$1/options + sed -i -e 's/^DISABLED=.*$/DISABLED=yes/g' $ETCNETDIR/$1/options + fi + /sbin/ifconfig $1 down + ip address flush $1 + fi + +} + +function setup_interfaces() { + local IS_WIRELESS + local ip + local netmask + local isactive + local dns + local UseDHCP + local GW + local ESSID + local KEY + local ENCRYPT + local TEMPNET + local MTU + IS_WIRELESS=false + + #local ip + TEMPNET="Hostip"$1 + echo $TEMPNET + eval ip=\$${TEMPNET} + + TEMPNET=Hostnetmask$1 + eval netmask=\$${TEMPNET} + netmask=`echo "$netmask" | cut -d " " -f1` + + TEMPNET=HostActive$1 + eval isactive=\$${TEMPNET} + + TEMPNET=HostDNS$1 + eval dns=\$${TEMPNET} + + TEMPNET="HostUSEDHCP"$1 + eval UseDHCP=\$${TEMPNET} + + TEMPNET=HostGW$1 + eval GW=\$${TEMPNET} + + TEMPNET=HOST_iswireless$1 + eval wireless=\$${TEMPNET} + + TEMPNET=HostMTU$1 + eval MTU=\$${TEMPNET} + + + + if [ x$wireless = x1 ] + then + IS_WIRELESS=TRUE + TEMPNET=HostESSID$1 + eval ESSID=\$${TEMPNET} + + TEMPNET="HostKey"$1 + eval KEY=\$${TEMPNET} + + TEMPNET=HostUseEncryption$1 + eval ENCRYPT=\$${TEMPNET} + fi + + + echo "Setup $1 in progress, wireless: $IS_WIRELESS" + + if [ ! -d $ETCNETDIR/$1 ] + then + mkdir -p $ETCNETDIR/$1 + fi + + if [ ! -f $ETCNETDIR/$1/options ] + then + cp -f $TEMPLATES/etcnet/eth/options $ETCNETDIR/$1/options + fi + + if [ x$isactive = x1 ] + then + change_iface_state $1 enabled + #echo "setting $1 to active" + #sed -i -e 's/^ONBOOT=.*$/ONBOOT=yes/g' $ETCNETDIR/$1/options + #sed -i -e 's/^DISABLED=.*$/DISABLED=no/g' $ETCNETDIR/$1/options + else + change_iface_state $1 disabled + #echo "setting $1 to inactive" + #sed -i -e 's/^ONBOOT=.*$/ONBOOT=no/g' $ETCNETDIR/$1/options + #sed -i -e 's/^DISABLED=.*$/DISABLED=yes/g' $ETCNETDIR/$1/options + fi + + if [ x$IS_WIRELESS = xTRUE ] + then + echo "setting $1 wireless" + sed -i -e 's/^CONFIG_WIRELESS=.*$/CONFIG_WIRLESS=yes/g' $ETCNETDIR/$1/options + #set the key and essid + echo "essid $ESSID" > $ETCNETDIR/$1/iwconfig + if [ x$ENCRYPT = x1 ] + then + echo "key $KEY" >> $ETCNETDIR/$1/iwconfig + fi + + else + echo "disabling wireless" + sed -i -e 's/^CONFIG_WIRLESS=.*$/CONFIG_WIRLESS=no/g' $ETCNETDIR/$1/options + fi + + if [ x$UseDHCP = x0 ] + then + echo using dhcp + sed -i -e 's/^BOOTPROTO=.*$/BOOTPROTO=dhcp/g' $ETCNETDIR/$1/options + + else + echo "using static ip" + sed -i -e 's/^BOOTPROTO=.*$/BOOTPROTO=static/g' $ETCNETDIR/$1/options + echo "default via $GW" > $ETCNETDIR/$1/ipv4route + echo "$ip$netmask" > $ETCNETDIR/$1/ipv4address + setup_nameserver $dns + fi + + if [ x$MTU = x ] + then + echo "MTU is blank, card will use default values" + sed -i '/^mtu.*$/d' /etc/net/ifaces/$1/iplink + else + echo "setting mtu for $1 to $MTU" + sed -i '/^mtu.*$/d' /etc/net/ifaces/$1/iplink + echo "mtu $MTU " >> /etc/net/ifaces/$1/iplink + fi +} + + +function find_active () { +#HostActiveeth1="1" +rm -f ${BASE}/etc/resolv.conf +if [ x$MYTHDHCP = x1 ] + then + #add 127.0.0.1 to /etc/resolv.conf + echo "search lan" > ${BASE}/etc/resolv.conf + echo "nameserver 127.0.0.1" >> ${BASE}/etc/resolv.conf + fi + +for i in eth0 eth1 wlan0 wlan1 +do + CURRENTIF="HostActive"$i + eval IFSTATE=\$${CURRENTIF} + echo $IFSTATE "---" + echo $i + if [ x$IFSTATE = x1 ] + then + setup_interfaces $i + else + change_iface_state $i disabled + fi +done + +} + +function setup_hostname { +#set the hostname +if [ ! x$hostname = x ] +then + echo $hostname > ${BASE}/etc/hostname + cat $BASE/etc/hosts |grep -v 127.0.0.1|grep -v $hostname > /tmp/hosts + #cat $BASE/etc/hosts |grep -v 127.0.0.1|grep -v $hostname | grep -v $ip > /tmp/hosts + + if [ x$MYTHDHCP = x1 ] + then + echo "127.0.0.1 localhost " > ${BASE}/etc/hosts + echo "$MYTHIP $hostname " >> ${BASE}/etc/hosts + else + echo "127.0.0.1 $hostname localhost " > ${BASE}/etc/hosts + fi + cat /tmp/hosts >> ${BASE}/etc/hosts +fi + +kill_dhcp +} + +function vnc_check() { + CMDLINE=$(cat /proc/cmdline) + echo $CMDLINE |grep -q vnc + USEVNC=$? + echo $CMDLINE |grep -q nfsroot + NETBOOT=$? + echo $USEVNC + if [ ! x$USEVNC = x0 ] + then + echo "not using vnc" + if [ ! x$NETBOOT = x0 ] + then + echo "not using netboot" + else + echo "using netboot" + USEVNC=0 + fi + + else + echo " using vnc" + fi +} + +function setup_MYTH_vars { + TEMPMYTH="Hostip"$default_interface + #echo $TEMPMYTH + eval MYTHIP=\$${TEMPMYTH} + + TEMPMYTH="HostUSEDHCP"$default_interface + eval MYTHDHCP=\$${TEMPMYTH} + + + +} + + + + +function start_network { +if [ ! $USEVNC = 0 ] +then + /etc/net/scripts/network.init reload + /etc/net/scripts/network.init restart +else + echo "VNC/NETBOOT in use, will NOT restart network" +fi + +} + +function setup_network { + setup_MYTH_vars + setup_hostname + find_active +} + + +function stop_network { +if [ ! $USEVNC = 0 ] +then + echo "stopping the network" + kill_dhcp flush + ip address flush dev eth0 2>&1 >/dev/null + ip address flush dev eth1 2>&1 >/dev/null + ip address flush dev wlan0 2>&1 >/dev/null + ip address flush dev wlan1 2>&1 >/dev/null +else + echo "VNC/NETBOOT in use, will NOT restart network" +fi + +} + + +#this is used by the install process to start the network +function install_network_setup { + setup_MYTH_vars + setup_hostname + stop_network + find_active + start_network + +} + + + + + + + diff --git a/abs/core-testing/LinHES-config-22/remove_service.sh b/abs/core-testing/LinHES-config-22/remove_service.sh new file mode 100755 index 0000000..6cc4b4f --- /dev/null +++ b/abs/core-testing/LinHES-config-22/remove_service.sh @@ -0,0 +1,8 @@ +#!/bin/bash +SERVICE_DIR=/var/service +SCRIPT_DIR=/etc/sv +if [ -e $SERVICE_DIR/$1 ] +then + echo "removing" + rm $SERVICE_DIR/$1 +fi diff --git a/abs/core-testing/LinHES-config-22/restore_default_settings.sh b/abs/core-testing/LinHES-config-22/restore_default_settings.sh new file mode 100755 index 0000000..dcf5e23 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/restore_default_settings.sh @@ -0,0 +1,362 @@ +#!/bin/bash +. /etc/profile +. /etc/systemconfig +shopt -s -o nounset +echo $@ >> /tmp/restore.out +#TEMPLATES="/usr/share/templates/settings" +TEMPLATES="$TEMPLATES/settings" +TABLES="settings keybindings" +MYTHDBUSER=mythtv +MYTHTVPASSWD=mythtv +declare -r OPTSTRING="c:e:t:d:h:s:a:z:Ho" +Thistemplate="" +declare -i OVERRIDE=0 +declare -i EVERYTHING=0 + + +function CMD_DEFINE () { + #add override check + if [ x$Thistemplate = xsyssettings -a $OVERRIDE -eq 1 ] + then + MYSQLCMD="mysql --local-infile -s -u$MYTHDBUSER -p$MYTHTVPASSWD -h$ovdbhost mythconverg -B --exec" + MYSQLCMD_C="mysql -u$MYTHDBUSER -p$MYTHTVPASSWD -h$ovdbhost mythconverg -B --exec" + MYSQLCMD_UPDATE_HOST="UPDATE settings set data='$oldhostname' where value='HostMyhostname' and hostname=\"$hostname\";" + else + MYSQLCMD="mysql --local-infile -s -u$MYTHDBUSER -p$MYTHTVPASSWD -h$dbhost mythconverg -B --exec" + MYSQLCMD_C="mysql -u$MYTHDBUSER -p$MYTHTVPASSWD -h$dbhost mythconverg -B --exec" + MYSQLCMD_UPDATE_HOST="select hostname from settings;" + fi +} + +function SQL_DEFINE () { + thostname=`echo ${hostname}|tr -C [:alpha:] _` + echo "Using $thostname for temp table postfix" + + #$1 is the table name + if [ $1 = "settings" ] + then + ALTERSQL="Alter table temp_${1}_${thostname} add unique ( value )" + else + ALTERSQL=";" + fi + + CREATESQL="create table temp_${1}_${thostname} like $1;" + COPY_TMP_SQL="replace into temp_${1}_${thostname} (select * from $1 where hostname=\"$hostname\");" + INSERTSQL="LOAD DATA local INFILE '/tmp/$1.txt' REPLACE INTO TABLE temp_${1}_${thostname} FIELDS TERMINATED BY '\t';" + #INSERTSQL="LOAD DATA local INFILE '$TEMPLATES/$Thistemplate/$1.txt' REPLACE INTO TABLE temp_${1}_${hostname} FIELDS TERMINATED BY '\t';" + DROPSQL="delete from $1 where hostname=\"$hostname\";" + COPY_BCK_SQL="replace into $1 (select * from temp_${1}_${thostname} where hostname=\"$hostname\");" + DROP_TABLE="Drop table temp_${1}_${thostname}" +} + +function ARG_ERR() { + if [ x$OPTARG = "x" ] + then + echo "$SWITCH NEEDS AND ARG" + exit 11 + fi +} + +function ALSADEVICE () { +#ALSA:hw:1,4 + if [ x$Audiotype = xALSA ] + then + SoundDevice=ALSA:$SoundDevice + MixerDevice="ALSA:default" + else + MixerDevice="/dev/mixer" + fi + +} + + + +if [ $# -eq 0 ] +then + echo "Valid options are:" + echo " -c (save|restore|load|uhostname|BECONFIG|ZIP|ACCESSCONTROL)" + echo " -t (syssettings|hostsettings)" + echo " -d databasename" + echo " -h hostname" + echo " -s systemtype (master|slave|standalone|frontendonly)" + echo " -a ipaddress" + echo " -z zipcode" + echo " -o override (only used upgrade installs)" + exit 1 +fi + + + + +while getopts "$OPTSTRING" SWITCH +do + case $SWITCH in + # \?) echo "unkown option" + # exit 11 ;; + c) echo "$SWITCH" "$OPTARG" + ARG_ERR + OPERATION=$OPTARG + ;; + t) echo "$SWITCH" "$OPTARG" + ARG_ERR + Thistemplate=$OPTARG + + if [ x$Thistemplate = x"syssettings" ] + then + echo "template is syssettings" + loadhost=false + elif [ x$Thistemplate = x"hostsettings" ] + then + echo "template is hostsettings" + Thistemplate=syssettings + loadhost=true + else + echo "invalid template name" + exit 1 + fi + ;; + d) echo "$SWITCH" "$OPTARG" + ARG_ERR + if [ $OVERRIDE = 1 ] + then + ovdbhost=$OPTARG + else + dbhost=$OPTARG + fi + ;; + h) echo "$SWITCH" "$OPTARG" + ARG_ERR + if [ $OVERRIDE = 1 ] + then + oldhostname=$hostname + hostname=$OPTARG + else + hostname=$OPTARG + fi + + ;; + s) echo "$SWITCH" "$OPTARG" + ARG_ERR + SYSTEMTYPE=$OPTARG + ;; + a) echo "$SWITCH" "$OPTARG" + ARG_ERR + IP_ADDRESS=$OPTARG + ;; + z) echo "$SWITCH" "$OPTARG" + ARG_ERR + ZIPCODE=$OPTARG + ;; + o) OVERRIDE=1 + ;; + + esac +done + +echo $OVERRIDE + +#setup the Mysql commands +CMD_DEFINE + +$MYSQLCMD_C "show tables" > /dev/null +status=$? +if [ $status = 1 ] +then + echo "$@ failed" + echo "$@ failed" >> /tmp/restore.out + exit 1 +fi + + + + + + + +case $OPERATION in + + restore) + #used to restore settings from syssettings + if [ -d $TEMPLATES/$Thistemplate ] + then + cd $TEMPLATES/$Thistemplate + if [ $loadhost = false ] + then + for i in $TABLES + do + SQL_DEFINE $i + sed -e "s/REPLACEME/$hostname/g" $i.txt > /tmp/$i.txt + #echo $MYSQLCMD "$SELECTSQL" + echo $i + $MYSQLCMD "$CREATESQL" + $MYSQLCMD "$ALTERSQL" + $MYSQLCMD "$COPY_TMP_SQL" + $MYSQLCMD "$INSERTSQL" + $MYSQLCMD "$DROPSQL" + $MYSQLCMD "$COPY_BCK_SQL " + $MYSQLCMD "$DROP_TABLE " + #rm /tmp/$i.txt + done + fi + if [ $loadhost = true ] + then + #only load the settings table with values HOST + i=settings + SQL_DEFINE $i + sed -e "s/REPLACEME/$hostname/g" $i.txt > /tmp/$i.txt + echo $i + $MYSQLCMD "$CREATESQL" + $MYSQLCMD "$ALTERSQL" + $MYSQLCMD "$INSERTSQL" + $MYSQLCMD "$COPY_TMP_SQL" + $MYSQLCMD "$DROPSQL" + $MYSQLCMD "$COPY_BCK_SQL" + $MYSQLCMD "$DROP_TABLE " + fi + else + echo "couldn't find $TEMPLATES/$Thistemplate" + fi + ;; + + save) + + if [ ! -d $TEMPLATES/$Thistemplate ] + then + mkdir -p $TEMPLATES/$Thistemplate + fi + + cd $TEMPLATES/$Thistemplate + for i in $TABLES + do + EXTRACLAUSE="" + case $i in + settings) + EXTRACLAUSE="and not (value like \"BackendServerIP\") and not (value like \"locale\") order by value" + SQL="select value,data,'REPLACEME' as hostname from $i where hostname=\"$hostname\" "$EXTRACLAUSE" ;" + # SQL="select * from $i where hostname=\"$hostname\" "$EXTRACLAUSE" ;" + $MYSQLCMD_C "$SQL" > $TEMPLATES/$Thistemplate/$i.txt + ;; + keybindings) + SQL="select context,action,description,keylist,'REPLACEME' as hostname from $i where hostname=\"$hostname\" "$EXTRACLAUSE" ;" + $MYSQLCMD_C "$SQL" > $TEMPLATES/$Thistemplate/$i.txt + ;; + esac + # sed -e "s/$hostname/REPLACEME/g" $i > $i.txt && rm $i + + done + ;; + + load) + + #will load both default_1 and default_2 unless either file is not found + for i in default_1 default_2 + do + if [ -f $TEMPLATES/$i/settings.txt ] + then + echo $i + for tablename in $TABLES + do + #create table + CREATESQL="create table IF NOT EXISTS ${tablename}_${i} like $tablename;" + $MYSQLCMD_C "$CREATESQL" + #truncate table + TRUNCATESQL="truncate ${tablename}_${i} " + $MYSQLCMD_C "$TRUNCATESQL" + #load table + INSERTSQL="LOAD DATA local INFILE '$TEMPLATES/$i/$tablename.txt' REPLACE INTO TABLE ${tablename}_${i} FIELDS TERMINATED BY '\t';" + $MYSQLCMD_C "$INSERTSQL" + #update_hostname + UPDATEHOSTNAMESQL="update ${tablename}_${i} set hostname='$i' ; " + $MYSQLCMD_C "$UPDATEHOSTNAMESQL" + done + else + + echo "couldn't find $TEMPLATES/$i/settings.txt template to load" + fi + CREATESQL="create table IF NOT EXISTS settings_user1 like settings;" + $MYSQLCMD_C "$CREATESQL" + CREATESQL="create table IF NOT EXISTS settings_user2 like settings;" + $MYSQLCMD_C "$CREATESQL" + CREATESQL="create table IF NOT EXISTS settings_user3 like settings;" + $MYSQLCMD_C "$CREATESQL" + + CREATESQL="create table IF NOT EXISTS keybindings_user1 like keybindings;" + $MYSQLCMD_C "$CREATESQL" + CREATESQL="create table IF NOT EXISTS keybindings_user2 like keybindings;" + $MYSQLCMD_C "$CREATESQL" + CREATESQL="create table IF NOT EXISTS keybindings_user3 like keybindings;" + $MYSQLCMD_C "$CREATESQL" + done +;; + + + + BECONFIG) + if [ $SYSTEMTYPE = "master" ] + then + $MYSQLCMD_C "UPDATE settings set data='${IP_ADDRESS}' where value='MasterServerIP';" + $MYSQLCMD_C "delete from settings where value='BackendServerIP' and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='${IP_ADDRESS}' , value='BackendServerIP' , hostname=\"$hostname\";" + fi + + if [ $SYSTEMTYPE = "slave" ] + then + $MYSQLCMD_C "delete from settings where value='BackendServerIP' and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='${IP_ADDRESS}' , value='BackendServerIP' , hostname=\"$hostname\";" + fi + ;; + ZIP) + $MYSQLCMD_C "delete from settings where value='locale' and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='$ZIPCODE' , value='locale' , hostname=\"$hostname\";" + $MYSQLCMD_C "delete from settings where value='MythMovies.ZipCode' and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='$ZIPCODE', value='MythMovies.ZipCode' , hostname=\"$hostname\";" + ;; + MUSICFRONT) + ALSADEVICE + $MYSQLCMD_C "delete from settings where value='AudioOutputDevice' and hostname=\"$hostname\";" + $MYSQLCMD_C "delete from settings where value='MixerDevice' and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='$SoundDevice', value='AudioOutputDevice' , hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='$MixerDevice', value='MixerDevice' , hostname=\"$hostname\";" + #need to reload the settings. + systemconfig.sh reloadfe + ;; + MUSICMYTH) + ALSADEVICE + $MYSQLCMD_C "delete from settings where value='MusicAudioDevice' and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='$SoundDevice', value='MusicAudioDevice' , hostname=\"$hostname\";" + ;; + uhostname) + #used when the hostname is changed. + TABLES="settings capturecard keybindings storagegroup recorded" + for i in $TABLES + do + USQL="update $i set hostname=\"$oldhostname\" where hostname=\"$hostname\" ;" + $MYSQLCMD_C "$USQL" + done + + ;; + USERJOBALLOW) + SQL="update settings set data='1' where value like 'JobAllowUserJob%' and hostname=\"$hostname\" ;" + $MYSQLCMD_C "$SQL" + ;; + + ACCESSCONTROL) + LIST="Hostaccessnetwork Hostaccesshostype HostaccesshostypeSystemtype Hostaccessmisc Hostaccesssleep Hostaccessadvanced HostaccessadvancedX Hostaccesssound" + + for i in $LIST + do + $MYSQLCMD_C "delete from settings where value=\"$i\" and hostname=\"$hostname\";" + $MYSQLCMD_C "REPLACE INTO settings set data='1', value=\"$i\" , hostname=\"$hostname\";" + done + SQL="update settings set data='0' where value='HostaccesshostypeSystemtype' and hostname=\"$hostname\" ;" + $MYSQLCMD_C "$SQL" + SQL="update settings set data='0' where value='Hostaccessuser' and hostname=\"$hostname\" ;" + $MYSQLCMD_C "$SQL" + ;; + esac + +#SELECT * INTO OUTFILE 'data.txt' +# FIELDS TERMINATED BY ',' +# FROM table2; + + diff --git a/abs/core-testing/LinHES-config-22/restore_km_db_chroot.sh b/abs/core-testing/LinHES-config-22/restore_km_db_chroot.sh new file mode 100644 index 0000000..e72e8c2 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/restore_km_db_chroot.sh @@ -0,0 +1,61 @@ +#!/bin/bash +. /etc/profile +. /etc/systemconfig +. $MV_ROOT/bin/install_functions.sh + +myhost=$hostname +hostname $myhost +mount -t proc none /proc +DBFILE=$1 + +if [ $SystemType = "Master_backend" -o $SystemType = "Standalone" ] + then + #restore database + pacman --noconfirm -Sf mysql + status=1 + mysqlstatus=1 + while [ ! $status = 0 ] + do + /etc/rc.d/mysqld stop + sleep 1 + /etc/rc.d/mysqld start + mysqlstatus=$? + if [ $mysqlstatus = 0 ] + then + mysql -e "show databases;" + showstatus=$? + if [ $showstatus = 0 ] + then + #load database + pacman --noconfirm -R mythdb-initial + pacman --noconfirm -S mythdb-initial + + if [ -f $DBFILE ] + then + echo "restoring old database" + gunzip -c $DBFILE > /tmp/mythconverg.sql + mysql mythconverg < /tmp/mythconverg.sql + update_db_settings HostServiceMythWEB "1" + echo 'UseMythWEB="1"' >> /etc/systemconfig + else + echo "Could not restore old database, mythconverg.sql is missing." + touch /tmp/.upgrade_db_failed + fi + + if [ -d /data/srv/mysql/mythconverg ] + then + status=0 + fi + fi + fi + done + rm -f /tmp/mythconverg.sql + else + exit 0 + fi + +#/etc/rc.d/mysqld stop +#umount /proc + + + diff --git a/abs/core-testing/LinHES-config-22/soundconfig.sh b/abs/core-testing/LinHES-config-22/soundconfig.sh new file mode 100755 index 0000000..75998d6 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/soundconfig.sh @@ -0,0 +1,254 @@ +#!/bin/bash +. /etc/systemconfig +. /etc/profile +echo $@ >/tmp/audio.call +#set -x +BASE="" +. /etc/profile +#TEMPLATES="/usr/share/templates" +#TESTFILE="$TEMPLATES/audio/space_battle_A.wav" +TESTFILE="/usr/share/sounds/alsa/Front_Center.wav" +OSSinstalled="false" + +function testaudio () { + +ossplay -d$AUDIODEVICE $TESTFILE + +} + +function load_alsa() { + + remove_service.sh alsa-utils +# cd /lib/modules/2.6.21-STB + KER=`uname -r` + cd /lib/modules/$KER/kernel/ + tar -xvf /lib/modules/alsa-$KER.tar + pacman -Sf --noconfirm alsa-lib + + depmod -a + cd - + udevadm trigger + udevadm settle + udevadm trigger + + add_service.sh alsa-utils + sleep 4 + sv start alsa-utils +} + + +function unload_alsa () { +#kill $(lsof -t /dev/dsp* /dev/audio* /dev/mixer* /dev/snd/*) && modprobe -r $(lsmod |grep ^snd |awk '{print $1}') + sv stop alsa-utils + remove_service.sh alsa-utils + rm -rf /dev/adsp* + rm -rf /dev/snd/* + rm -rf /dev/audio + modprobe -r $(lsmod |grep ^snd |awk '{print $1}') +} + +function unload_oss { + sv stop oss + soundoff + rm -rf /dev/dsp* + rm -rf /dev/oss* + rm -rf /dev/sndstat + remove_service.sh oss +} + +function installOSS { + echo "installing oss" + pacman -Q oss 2>/dev/null + if [ ! $? = 0 ] + then + pacman --noconfirm -Sf oss + fi + add_service.sh oss + sleep 4 + sv start oss +} + + +function SYNCXINE { +echo "modify xine config file" + if [ -f /data/home/mythtv/.xine/config ] + then + cp -f /data/home/mythtv/.xine/config $TEMPLATES/xine.config + else + cp $TEMPLATES/xine.config.template $TEMPLATES/xine.config + fi + + if [ x$Audiotype = xOSS ] + then + DEVICENUMBER=`echo $SoundDevice|awk -F/ ' { print $3 } '|tr -d dsp ` + sed -e "s/^.*audio.driver.*$/audio.driver:oss/" \ + -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 + else + cp $TEMPLATES/xine.config /data/home/mythtv/.xine/config + fi + +} + +function SYNCMPLAYER { +echo "modify mplayer not implmented yet" +} + +function SYNCMYTHMUSIC { +echo "sync mythmusic" +$MV_ROOT/bin/restore_default_settings.sh -c MUSICMYTH +} + +function SYNCMYTHFRONTEND { +echo "sync mythfrontend" +$MV_ROOT/bin/restore_default_settings.sh -c MUSICFRONT +} + + +function checkOSSinstalled () { + ossinfo |grep Version |grep -q OSS >/dev/null + resultcode=$? + echo $resultcode + if [ $resultcode = 0 ] + then + OSSinstalled='true' + else + OSSinstalled='false' + fi +} + +function sound_config_system { + + if [ x$syncXine = x1 ] + then + SYNCXINE + fi + if [ x$syncMplayer = x1 ] + then + SYNCMPLAYER + fi + if [ x$syncMythMusic = x1 ] + then + SYNCMYTHMUSIC + fi + if [ x$syncMythFrontend = x1 ] + then + SYNCMYTHFRONTEND + fi + +} + +function loadsound (){ + checkOSSinstalled + if [ x$AUDIOTYPE = xOSS -o x$AUDIOTYPE = xoss ] + #then + # if [ $OSSinstalled = "false" ] + then + while [ $OSSinstalled = "false" ] + do + unload_alsa + rm /tmp/.alsatest + installOSS + installOSS + sleep 2 + checkOSSinstalled + done + # fi + else + touch /tmp/.alsatest + unload_oss + load_alsa + load_alsa + rm /tmp/.alsatest + + fi + +} + + + + +#####################MAIN PROGRAM########################## + +declare -r OPTSTRING="i:t:d:" + +if [ $# -eq 0 ] +then + echo "Valid options are:" + echo " -i (oss|alsa) oss or alsa subsystem " + echo " -t (test|real|LOAD) " + echo " -d device" + exit 1 +fi + + + + +while getopts "$OPTSTRING" SWITCH +do + case $SWITCH in + \?) echo "unkown option" + exit 11 ;; + i) echo "$SWITCH" "$OPTARG" + AUDIOTYPE="$OPTARG" + ;; + d) echo "$SWITCH" "$OPTARG" + AUDIODEVICE=$OPTARG + ;; + t) echo "$SWITCH" "$OPTARG" + SOUNDOPTYPE="$OPTARG" + if [ x"$OPTARG" = xtest ] + then + TEST=true + else + TEST=false + fi + + + ;; + + esac +done + + + + +case $SOUNDOPTYPE in + REAL|real ) + loadsound + sound_config_system + ;; + test|TEST) + echo $@ > /tmp/audio.test + #loadsound + if [ x$AUDIOTYPE = xOSS -o x$AUDIOTYPE = xoss ] + then + echo "testing OSS $AUDIODEVICE " + ossplay -d$AUDIODEVICE $TESTFILE + else + echo "testing ALSA $AUDIODEVICE " + aplay --device=$AUDIODEVICE $TESTFILE + fi + + ;; + + LOAD|load) + loadsound + ;; + esac + + +exit 0 + + + + + + + + + + + diff --git a/abs/core-testing/LinHES-config-22/startx b/abs/core-testing/LinHES-config-22/startx new file mode 100755 index 0000000..75ba06a --- /dev/null +++ b/abs/core-testing/LinHES-config-22/startx @@ -0,0 +1,29 @@ +#!/bin/bash +. /etc/profile + +export USER=root +export HOME=/root +#TEMPLATES=/usr/share/templates + +CMDLINE=$(cat /proc/cmdline) +TEMPVAR=${CMDLINE#*ip=} +IP=${TEMPVAR%% *} +echo $CMDLINE |grep -q vnc +USEVNC=$? + +if [ x$USEVNC = x1 ] +then + $MV_ROOT/bin/xconfig.sh + cat /etc/X11/xorg.conf | sed -e 's/dev\/mouse/dev\/psaux/g'> /root/xorg.conf.install + startx /root/live-install.sh -- -logverbose 6 -config /root/xorg.conf.install -allowMouseOpenFail + else + #VNC + pacman -Sf --noconfirm tightvnc + cd /root + mkdir .vnc + echo mythvantage |vncpasswd -f > /root/.vnc/passwd + chmod 500 /root/.vnc/passwd + rm /root/.vnc/xstartup + ln -s /root/live-install.sh /root/.vnc/xstartup + vncserver +fi diff --git a/abs/core-testing/LinHES-config-22/systemconfig.py b/abs/core-testing/LinHES-config-22/systemconfig.py new file mode 100755 index 0000000..28e2e7a --- /dev/null +++ b/abs/core-testing/LinHES-config-22/systemconfig.py @@ -0,0 +1,244 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import sys, os, commands, glob, time +import getopt, re, MySQLdb +import logging +import mv_common , mv_network +import inspect +#____________________________________________setup the logging______________________________________________________ +LOG_FILENAME = '/tmp/systemconfig.log' +DEBUGLOG = '/tmp/systemconfig_debug.log' +logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + datefmt='%m-%d %H:%M', + filename=DEBUGLOG, + filemode='w') +# define a Handler which writes INFO messages or higher to the sys.stderr +console = logging.StreamHandler() +console.setLevel(logging.INFO) +# set a format which is simpler for console use +#formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') +formatter = logging.Formatter("%(message)s") +# tell the handler to use this format +console.setFormatter(formatter) +# add the handler to the root logger +logging.getLogger('').addHandler(console) + +#infoformatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") +infoformatter = logging.Formatter("%(message)s") +infofile = logging.FileHandler(LOG_FILENAME, 'w') +infofile.setFormatter(infoformatter) +infofile.setLevel(logging.INFO) +logging.getLogger('').addHandler(infofile) + + +def usage(): + logging.info("tell people how to use this") + +def setup_x(systemconfig): + cmd = "%s/bin/xconfig.sh" %systemconfig["MVROOT"] + mv_common.runcmd(cmd) + +def main(argv): + try: + MVROOT = os.environ["MV_ROOT"] + except: + logging.debug("MVROOT was not defined, using the default value") + MVROOT = "/usr/MythVantage" + + global cmdmodule + 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 } + try: + opts, args = getopt.getopt(argv, 'c:hm:d:', ["help","modules" ] ) + 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 ("-m"): + for i in arg.split(","): + cmdmodule[i]=True + elif opt in ("-d"): + dhcp_dev = arg + + + if cmdmodule["this_is_install"] or cmdmodule["hostypec"]: + systemconfig["hostypec"] = True + cmdmodule["smolt"] = 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) + systemconfig["mythdns"] = mv_network.setup_MYTH_DHCP(systemconfig) + + if cmdmodule["all"]: + logging.info("*** WILL RUN ALL MODULES ***") + cmdmodule["hostype"] = True + cmdmodule["ir"]= True + cmdmodule["network"] = True + cmdmodule["audio"] = True + cmdmodule["misc"] = True + cmdmodule["sleep"] = True + cmdmodule["webuser"] = True + cmdmodule["ddns"] = True + cmdmodule["screensaver"] = True + cmdmodule["advanced"] = True + cmdmodule["software"] = True + cmdmodule["advancedX"] = True + cmdmodule["smolt"] = True + cmdmodule["user"] = True + + + if cmdmodule["hostype"]: + import mv_hostype + cmdmodule["advancedX"] = True + setup_x(systemconfig) + cmdmodule["ir"] = True + mv_hostype.hostypeprint(systemconfig) + 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["ir"] == True: + import mv_ir + restart = mv_ir.setup_ir(systemconfig,data_config) + restartfe = restart[0] + restartlcd = restart[1] + if restartfe == True : + logging.debug(" Setting the frontend to restart due to lirc change") + cmdmodule["restartfe"] = True + cmdmodule["smolt"] = True + + + if cmdmodule["audio"] == True: + logging.debug("______Start of Audio Configuration______") + if not systemconfig["Audiotype"] == "tinker": + cmd="%s/bin/soundconfig.sh -t real -i %s -d %s" %(MVROOT,systemconfig["Audiotype"],systemconfig["SoundDevice"]) + mv_common.runcmd(cmd) + else: + logging.debug(" Tinker mode(audio), not changing configuration") + logging.debug("__End of audio") + + if cmdmodule["misc"]: + import mv_misc + mv_misc.setup_zip(MVROOT,systemconfig["zipcode"]) + mv_misc.setup_tz(systemconfig["timezone"],systemconfig["TEMPLATES"]) + mv_misc.setup_nfs(systemconfig) + + if cmdmodule["sleep"]: + import mv_misc + mv_misc.setup_sleep(systemconfig) + + if cmdmodule["webuser"]: + import mv_webuser + mv_webuser.setup_web_auth(systemconfig["UseMythWEB_auth"]) + + if cmdmodule["ddns"]: + import mv_ddns + mv_ddns.setup_ddns(systemconfig) + + if cmdmodule["screensaver"]: + import mv_screensaver + mv_screensaver.setup_screensaver(systemconfig, data_config) + + if cmdmodule["advanced"]: + import mv_advanced + mv_advanced.setup_advanced(systemconfig, data_config) + + if cmdmodule["software"] or cmdmodule["plugins"]: + import mv_software + mv_software.setup_software(systemconfig, data_config) + + if cmdmodule["advancedX"]: + setup_x(systemconfig) + + if cmdmodule["restartfe"]: + mv_common.restartfe(restartlcd) + + if cmdmodule["reloadfe"]: + mv_common.reloadfe(systemconfig["dbhost"],restartlcd) + + if cmdmodule["smolt"]: + import mv_smolt + mv_smolt.setup_smolt_type(systemconfig["SystemType"], + systemconfig["Remotetype"], + systemconfig["RunFrontend"], + data_config.MYTHHOME, + data_config.SYSTEMTYPE) + + if cmdmodule["user"]: + logging.info("____Start of ssh user____") + if systemconfig["rootSSH"] == "1" : + logging.info(" Allowing ssh access for root") + cmd = '''sed -i "s/^.*PermitRootLogin.*$/PermitRootLogin yes/" /etc/ssh/sshd_config''' + mv_common.runcmd(cmd) + else: + logging.info(" Removing ssh access for root") + cmd = '''sed -i "s/^.*PermitRootLogin.*$/PermitRootLogin no/" /etc/ssh/sshd_config''' + mv_common.runcmd(cmd) + logging.info("__End of ssh user\n") + + if cmdmodule["dhcp_request"]: + cmd = '''dhcpcd -t4 -h' ' -Td %s > /tmp/mvnetwork.dhcpinfo ''' %dhcp_dev + mv_common.runcmd(cmd) + + +if __name__ == "__main__": + + config_file = "mv_config" + data_config = __import__(config_file, globals(), locals(), []) + #Read in systemconfig + global systemconfig + systemconfig = {"hostypec":False} + file_name = "/etc/systemconfig" + try: + config_file = open(file_name) + except: + logging.critical("%s could not be opened", file_name) + sys.exit(1) + + 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('"') + systemconfig[var.strip()] = val.strip() + try: + systemconfig["TEMPLATES"] = os.environ["TEMPLATES"] + except: + logging.critical(" *TEMPLATES is not defined") + logging.critical(" *using default value") + systemconfig["TEMPLATES"] = "/usr/MythVantage/templates" + + logging.debug("______START OF DEBUG______") + main(sys.argv[1:]) + logging.debug("______cmd line options______") + for i in cmdmodule.items(): + logging.debug (i) + logging.debug("______systemconfig______") + for i in systemconfig.items(): + logging.debug(i) + #pass + + + + + + + + + + diff --git a/abs/core-testing/LinHES-config-22/systemconfig.sh b/abs/core-testing/LinHES-config-22/systemconfig.sh new file mode 100755 index 0000000..218f705 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/systemconfig.sh @@ -0,0 +1,19 @@ +#!/bin/bash +################################################################### +#Script to configure your system based off the values in /etc/systemconfig +#Any changes made to config files will be removed when systemconfig.sh is run +# +#JM +echo $@ >/tmp/systemconfig.call +echo "----------------------start of systemconfig $@ ----------------------" +. /etc/profile +. $MV_ROOT/bin/networkconfig.sh +postfix=`cat ${BASE}/usr/local/share/mythtv/.releasetype` + +systemconfig.py -m $@ +rc=$? +echo "systemconfig.py exit code $rc" +exit $rc + + + diff --git a/abs/core-testing/LinHES-config-22/timezip.py b/abs/core-testing/LinHES-config-22/timezip.py new file mode 100755 index 0000000..bf6b389 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/timezip.py @@ -0,0 +1,232 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# import MySQL module +#used to import the zipcode/timezone/nfs info fromMBE +import MySQLdb +import sys +import getopt +import socket + + +def usage(): + print " -h --help" + print " -d --installdb" + print " -m --masterdb" + print " -n --hostname of current machine" + +def printvars(): + print "masterdb: " + masterdb + print "installdb:" + installdb + print "hostname: " + thishostname + print "BEhostname:" + BEhostname + 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 +# connect +def selectvars(): + + global BEhostname + global zipcode + global tz + global tz_region + global tz_subregion + global nfsip + global nfstoggle + global nfsmount + global hobbitclient + + 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: + 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: + nfsip=result[0] + except TypeError: + nfsip="" + + cursor.execute("select data from settings where value='HostHaveCentralNFS' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + try: + nfstoggle=result[0] + except TypeError: + nfstoggle="" + + cursor.execute("select data from settings where value='HostNFSmountpoint' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + try: + nfsmount=result[0] + except TypeError: + nfsmount="" + + cursor.execute("select data from settings where value='HostTimeZone' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + try: + tz=result[0] + except TypeError: + tz="" +########## + cursor.execute("select data from settings where value='HostTimeZoneRegion' and hostname=(%s)",(BEhostname)) + result = cursor.fetchone() + try: + tz_region=result[0] + except TypeError: + tz_region="" + tempsubregion="HostTimeZoneRegion_" + tz_region + + cursor.execute("select data from settings where value=%s and hostname=(%s)",(tempsubregion,BEhostname)) + result = cursor.fetchone() + try: + 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 TypeError: + hobbitclient="1" + + + +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 timezone + cursor.execute("select * from settings where value='HostTimeZone' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if ( tz != ""): + if (result == None): + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZone',(%s),(%s))",(tz,thishostname)) + print "inserting timezone" + 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("INSERT INTO settings (value,data,hostname) VALUES ('HostTimeZoneRegion',(%s),(%s))",(tz_region,thishostname)) + print "inserting timezone region" + 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): + 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)) + 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 != ""): + if (result == None): + cursor.execute("INSERT INTO settings (value,data,hostname) VALUES ('HostCentralNFSIP',(%s),(%s))",(nfsip,thishostname)) + print "inserting nfsip" + + if (nfstoggle != ""): + cursor.execute("select data from settings where value='HostHaveCentralNFS' 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" + + 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" + +#hobbitclient + cursor.execute("select * from settings where value='HostServiceHobbitclient' and hostname=(%s)",(thishostname)) + result = cursor.fetchone() + if ( tz != ""): + 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): + global masterdb + global installdb + global thishostname + thishostname="" + global BEhostname + global zipcode + global tz + global tz_region + global tz_subregion + + global nfsip + global hobbitclient + try: + opts, args = getopt.getopt(argv, "hm:d:n:", ["help", "masterdb=", "installdb=" , "hostname=" ] ) + except getopt.GetoptError: + sys.exit(2) + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit() + elif opt in ( "-d" , "--installdb"): + installdb = arg + elif opt in ("-m", "--masterdb"): + masterdb = arg + elif opt in ("-n", "--hostname"): + thishostname = arg + + if ( thishostname == "" ): + thishostname = socket.gethostname() + + selectvars() + printvars() + insertvars() +if __name__ == "__main__": + main(sys.argv[1:]) + diff --git a/abs/core-testing/LinHES-config-22/xconfig.sh b/abs/core-testing/LinHES-config-22/xconfig.sh new file mode 100755 index 0000000..2fad821 --- /dev/null +++ b/abs/core-testing/LinHES-config-22/xconfig.sh @@ -0,0 +1,363 @@ +#!/bin/bash +#SET DISPLAYCARD to force a cardtype +#SET DISPLAYRES to force Xres, ENV takes precendent over cmdline +#displayres=cmdline +#NVPKGS="ati-dri xf86-video-ati xf86-video-radeonhd intel-dri xf86-video-intel unichrome-dri xf86-video-unichrome xf86-video-mga xf86-video-savage xf86-video-trident" +NVPKGS="ati-dri xf86-video-ati xf86-video-radeonhd intel-dri xf86-video-intel xf86-video-mga xf86-video-savage xf86-video-trident unichrome-dri xf86-video-openchrome" +BASE="" +. /etc/profile +NVIDIA_96XX="$TEMPLATES/xorg/96xx_supported.txt" +#TEMPLATES="/usr/share/templates" +MYTHHOME=$BASE/home/mythtv + +function Xvalues { + CMDLINE=$(cat /proc/cmdline) + echo "$CMDLINE" | grep -q forceXvesa + if [ $? = 0 ] + then + VGACARDTYPE=vesa + Xcardtype=$VGACARDTYPE + 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` + fi + #force VGACARDTYPE + if [ ! x$DISPLAYCARD = x ] + then + VGACARDTYPE=$DISPLAYCARD + Xcardtype=$VGACARDTYPE + fi + echo "Will use $VGACARDTYPE" + currentmode=`cat "$BASE/etc/X11/xorg.conf" | grep Modes | awk -Fs '{ print $2 }'` +} + +function presetupX { + if [ -f /etc/sysconfig/IGNORE_X ] + then + echo "Will not run xconfig.sh due to presence of /etc/sysconfig/IGNORE_X" + return 1 + else + if [ "$XIgnoreConfig" = 1 ] + 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 + else + if [ "$XUseAdvanced" = 1 ] + then + setupAdvancedX + else + setupX + fi + fi + fi + +} + +function setupAdvancedX { + echo "#doing the advanced" > /tmp/options + Xcategory=`echo "$Xresadvanced" | cut -d_ -f1` + Xres=`echo "$Xresadvanced" | cut -d_ -f2` + echo "$Xcategory" + if [ "$Xcategory" = "nVidia Modeline" ] + 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 +# echo $ML + case $Xcardtype in + NVIDIA|nVidia|nvidia) + case $Xconnection in + DVI) ConnectedMonitor=DFP ;; + vga) ConnectedMonitor=CRT;; + Auto) ConnectedMonitor=Auto;; + TV) ConnectedMonitor=TV + echo "Option \"TVStandard\" \"$XTVstandard\"" >>/tmp/options + echo "Option \"TVOutFormat\" \"$XTVconnection\"" >> /tmp/options + ;; + esac + if [ "$ConnectedMonitor" = Auto ] + then + echo "auto connection" + else + 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" + ;; + + 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" + ;; + + via|VIA|Via|S3) + # Need to add appropriate Modules, Device and DRI sections + # See the http://www.mythtv.org/wiki/XvMC wiki page + echo "no via here" + ;; + + *) + echo "unknown card type" + ;; + esac +} + + +function setupX { + Xvalues + #echo "$currentmode ____ ${Xres}" + #if [ "${currentmode}" != \"${Xres}\" ] + if [ x = x ] + then + case $VGACARDTYPE in + nVidia) + if [ ${Xres} = Auto ] + then + sed -e "/^.*Modes.*$/d" "$TEMPLATES/xorg/xorg.conf.nvidia" > "$XORG_CONF" + else + sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$TEMPLATES/xorg/xorg.conf.nvidia" > "$XORG_CONF" + fi + if [ "$TESTMODE" != "test" ] + then + #nvidia check right here + grep -qi "$CARDID" "$NVIDIA_96XX" + if [ $? = 0 ] + then + #install 96xx drivers + echo "installing nvidia 96xx drivers" + pacman --noconfirm -Rd libgl > /dev/null 2>&1 + pacman --noconfirm -R $NVPKGS > /dev/null 2>&1 + pacman --noconfirm -S nvidia-96xx nvidia-96xx-utils > /dev/null 2>&1 + else + #install latest drivers + echo "installing current nvidia drivers" + pacman --noconfirm -Rd libgl > /dev/null 2>&1 + pacman --noconfirm -R $NVPKGS > /dev/null 2>&1 + pacman --noconfirm -S nvidia nvidia-utils > /dev/null 2>&1 + fi + fi + echo "/usr/lib/libXvMCNVIDIA_dynamic.so.1" > "$XVMC_CONFIG" + ;; + + # 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" ] + then + pacman --noconfirm -R nvidia nvidia-utils > /dev/null 2>&1 + pacman --noconfirm -S libgl unichrome-dri xf86-video-openchrome > /dev/null 2>&1 + else + pacman --noconfirm -R nvidia nvidia-utils > /dev/null 2>&1 + pacman --noconfirm -S libgl unichrome-dri xf86-video-unichrome > /dev/null 2>&1 + fi + fi + # I'm making educated guesses here... + if lspci | grep "VGA" | grep -qi "Unichrome Pro" + then + if [ -f "/usr/lib/libchromeXvMCPro.so.1" ] + then + echo "/usr/lib/libchromeXvMCPro.so.1" > "$XVMC_CONFIG" + else + echo "/usr/lib/libviaXvMCPro.so.1" > "$XVMC_CONFIG" + fi + else + if [ -f "/usr/lib/libchromeXvMC.so.1" ] + then + echo "/usr/lib/libchromeXvMC.so.1" > "$XVMC_CONFIG" + else + echo "/usr/lib/libviaXvMC.so.1" > "$XVMC_CONFIG" + 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 > /dev/null 2>&1 + pacman --noconfirm -S libgl > /dev/null 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 ] + then + grep -v Modes "$XCONF" | sed -e 's/dev\/mouse/dev\/psaux/g'> "$XORG_CONF" + 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" + fi + elif [ -f "$XCONFB" ] + then + echo "Using $XCONFB" + if [ ${Xres} = Auto ] + then + sed -e "/^.*Modes.*$/d" "$XCONFB" > "$XORG_CONF" + else + sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" "$XCONFB" > "$XORG_CONF" + fi + else + echo "Xorg configuration failed" + fi + rm -f "$XCONF" 2>&1 > /dev/null + ;; + esac + fi + +} + +#MAIN +TESTMODE="$1" +if [ "$TESTMODE" = "test" ] +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 + + XORG_CONF="/etc/X11/xorg.conf" + XVMC_CONFIG="/etc/X11/XvMCConfig" +fi +presetupX |