diff options
Diffstat (limited to 'abs/core/LinHES-config/mv_install.py')
-rwxr-xr-x | abs/core/LinHES-config/mv_install.py | 1170 |
1 files changed, 902 insertions, 268 deletions
diff --git a/abs/core/LinHES-config/mv_install.py b/abs/core/LinHES-config/mv_install.py index 2e60ab7..1128571 100755 --- a/abs/core/LinHES-config/mv_install.py +++ b/abs/core/LinHES-config/mv_install.py @@ -12,6 +12,20 @@ except: def usage(): print "help text:" print "example usage: --rootdisk=sda --rootfs=ext4 --rootsize=34240 --datafs=ext4 --datasize=3400 --datadisk=sda --swapsize=340 -c full_install" + print "" + print "Alt usage involves reading config from a file" + print "The conf file is read when no command line options are given" + print " /etc/systemconfig must also be present " + + print "Create /etc/install_layout, with contents similiar to this. Sizes are in MB" + print " rootdisk=sda" + print " rootfs=ext4" + print " rootsize=5000" + print " datafs=reiserfs" + print " datasize=all" + print " datadisk=sda" + print " swapsize=200" + print " op=full_install" def clean_upgrade(): return False @@ -66,6 +80,14 @@ def kill_dhcp_chroot(): os.chdir(stddir) except: pass + #force kill + try: + cmd = "lsof -t /new_boot|xargs kill -9" + runcmd(cmd) + except: + print " !!!Problem killing all /new_boot pids" + + def statgrab(disk): cmd = "statgrab -M disk. |grep %s.write_bytes" % hostoptions["rootdisk"] @@ -129,7 +151,7 @@ def mdadm_assemble_all(): def copy_updates(): try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug("MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" @@ -197,7 +219,7 @@ def mysqldb(cmd, inchroot): elif cmd == "stop": mycmd = " /etc/rc.d/mysqld stop" if inchroot == "chroot": - mycmd = " chroot /newboot %s" %mycmd + mycmd = " chroot /new_boot %s" %mycmd runcmd(mycmd) @@ -234,13 +256,18 @@ def blank_table(diskdevice): cmd = "echo w |fdisk %s" %diskdevice runcmd(cmd) + cmd = "parted %s --script -- mklabel msdos" %diskdevice + runcmd(cmd) + logging.debug("parition table after:") cmd = "fdisk -l %s" %diskdevice runcmd(cmd) def partitions_removeall(diskdevice, label): - logging.info("Removing all partitions for %s %s", label, diskdevice) + logging.info(" Removing all partitions for %s %s", label, diskdevice) try: + cmd = "parted %s --script -- mklabel msdos" %diskdevice + runcmd(cmd) device = parted.getDevice(diskdevice) partdisk = parted.Disk(device) partdisk.deleteAllPartitions() @@ -252,54 +279,76 @@ def partitions_removeall(diskdevice, label): logging.debug(" Error reading parition table, attempting to write a blank one") blank_table(diskdevice) +def find_next_start_sector(partition_list): + newstart = 0 + partlist = [] + for partition in partition_list: + if partition.type != parted.PARTITION_FREESPACE: + partlist.append((partition, + partition.path, + partition.getFlag(parted.PARTITION_BOOT), + partition.geometry.start, + partition.geometry.end, + partition.geometry.length, + partition.type, + partition.fileSystem)) + + for slice in partlist: + (usedpartition, usedpath, usedbootable, usedstart, usedend, usedlength, usedtype, usedfs) = slice + # print slice + #Start the new partition one after the end of last + newstart = usedend + 3 + return newstart def create_partitions(diskdevice, size, ptype, startsector): logging.debug("_____Create partitions______") if size == "NO": logging.info("Size is 0, skipping") return "NO" - partlist = [] - newstart = 0 + + # newstart = 0 totalused = 0 device = parted.getDevice(diskdevice) - logging.debug("Sector size is %s %s", diskdevice , device.sectorSize) + logging.debug(" Sector size is %s %s", diskdevice , device.sectorSize) partdisk = parted.Disk(device) - for partition in partdisk.partitions: - if partition.type != parted.PARTITION_FREESPACE: - partlist.append((partition, - partition.path, - partition.getFlag(parted.PARTITION_BOOT), - partition.geometry.start, - partition.geometry.end, - partition.geometry.length, - partition.type, - partition.fileSystem)) - for slice in partlist: - (usedpartition, usedpath, usedbootable, usedstart, usedend, usedlength, usedtype, usedfs) = slice - #Start the new partition one after the end of last - newstart = usedend+1 + #first set to all paritions + partition_list = partdisk.partitions + + if ptype == "LOGICAL": + #check for other logical: + logical_partitions=partdisk.getLogicalPartitions() + if logical_partitions == [] : + logging.info(" First Logical drive, working with extended partition") + newstart = partdisk.getExtendedPartition().geometry.start + 3 + else: + newstart = find_next_start_sector(logical_partitions) + else: + #all partitions + partitionlist = partdisk.partitions + newstart = find_next_start_sector(partition_list) if startsector == 0: newstart = 2048 - if size == "ALL": - logging.debug(" Using the rest of the disk %s", (device.length-newstart) ) + + if size == "all": + logging.debug(" Using the rest of the disk %s", (device.length-newstart - 2048) ) try: - geom = parted.Geometry(device=device, start=newstart, length=(device.length-newstart)) + geom = parted.Geometry(device=device, start=newstart, length=(device.length-newstart - 2048)) except: - logging.info("An error occured, probably invalid parition size") + logging.info("* An error occured, probably invalid parition size") return else: # convert size in MB to a length on the device in sectors length = (int(size) * (1024 * 1024)) / device.sectorSize - logging.debug("Size is %s", length) + logging.debug(" Size is %s", length) if length > device.length: length = device.length - newstart - logging.info("Size is larger then disk, reducing size") - logging.debug("New Size is %s", length) + logging.info("* Size is larger then disk, reducing size") + logging.debug("* New Size is %s", length) try: geom = parted.Geometry(device=device, start=newstart, length=length) except: - logging.info("An error occured, probably invalid parition size") + logging.info("* An error occured, probably invalid parition size") error_out("invalid parition size") #collect device constraint @@ -309,6 +358,15 @@ def create_partitions(diskdevice, size, ptype, startsector): # new partition if ptype == "NORMAL": newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_NORMAL, geometry=geom) + + elif ptype == "EXTENDED": + newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_EXTENDED, geometry=geom) + + + + elif ptype == "LOGICAL": + newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_LOGICAL, geometry=geom) + elif ptype == "SWAP": newpart = parted.Partition(disk=partdisk, type=parted.PARTITION_NORMAL, geometry=geom) @@ -316,8 +374,8 @@ def create_partitions(diskdevice, size, ptype, startsector): partdisk.addPartition(partition=newpart, constraint=constraint) if data_config.NOOPDEBUG == "FALSE": partdisk.commit() - logging.info("created partition %s of %dMB and added it to %s" % - (newpart.getDeviceNodeName(), newpart.getSize(), diskdevice)) + logging.info(" created %s partition %s of %dMB and added it to %s" % + (ptype,newpart.getDeviceNodeName(), newpart.getSize(), diskdevice)) return newpart.getDeviceNodeName() def set_active_parition(diskdevice): @@ -346,15 +404,34 @@ def partition_disk(): partitions_removeall("/dev/"+datadisk, label) hostoptions["rootpartition"] = create_partitions("/dev/"+rootdisk, hostoptions["rootsize"], "NORMAL", 0) set_active_parition("/dev/"+rootdisk) + hostoptions["swappartition"] = create_partitions("/dev/"+rootdisk, hostoptions["swapsize"], "SWAP", 1) + + #create extended partition + hostoptions["extended_partition"] = create_partitions("/dev/"+rootdisk, "all", "EXTENDED", 1) + + #create the logical in the extended + hostoptions["home_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["homesize"], "LOGICAL", 1) + hostoptions["sql_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["sqlsize"], "LOGICAL", 1) + if datadisk != rootdisk: hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 0) else: - hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 1) + hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "LOGICAL", 1) + + logging.debug("sleeping for 5 seconds") time.sleep(5) + def fscmd(fstype): - fscmds = {"reiserfs":"mkreiserfs -q -l ROOT", "xfs": "mkfs -t xfs -f", "ext3": "mkfs.ext3", "jfs":"mkfs.jfs -q", "ext4":"mkfs.ext4", "Do_not_format":"noformat", "no_format":"noformat"} + fscmds = {"reiserfs":"mkreiserfs -q -l ROOT", + "xfs": "mkfs -t xfs -f", + "ext3": "mkfs.ext3", + "jfs":"mkfs.jfs -q", + "ext4":"mkfs.ext4", + "Do_not_format":"no_format", + "no_format":"no_format", + "btrfs":"mkfs.btrfs"} try: rc = fscmds[fstype] except: @@ -368,40 +445,76 @@ def format_disk(install_type): rootfs = fscmd(hostoptions["rootfs"]) datafs = fscmd(hostoptions["datafs"]) + sqlfs = fscmd(hostoptions["sqlfs"]) + homefs = fscmd(hostoptions["homefs"]) + + rootdisk = hostoptions["rootdisk"] datadisk = hostoptions["datadisk"] rootpartition = hostoptions["rootpartition"] datapartition = hostoptions["datapartition"] - if install_type != "upgrade": - swapsize = hostoptions["swapsize"] + + homepartition = hostoptions["home_partition"] + sqlpartition = hostoptions["sql_partition"] + + + #if install_type != "upgrade": + #swapsize = hostoptions["swapsize"] + #swappartition = hostoptions["swappartition"] + + if install_type == "install": swappartition = hostoptions["swappartition"] + if (hostoptions["swapsize"] != "NO"): + logging.info(" Starting format for swap %s", swappartition) + cmd = " mkswap /dev/%s" % swappartition + #os.system(cmd) + runcmd(cmd) + else: + logging.debug(" Swap is set to NO, will not run mkswap") logging.debug(" Format command for rootfs %s : %s ", rootfs, rootpartition) - if ( rootfs != "noformat"): - logging.info("Starting format of %s", rootpartition) + if ( rootfs != "no_format"): + logging.info(" Starting %s format of %s", rootfs, rootpartition) cmd = " %s /dev/%s" %( rootfs, rootpartition) #os.system(cmd) runcmd(cmd) else: - logging.info("Will not format root partition: %s", rootpartition) + logging.info(" Will not format root partition: %s", rootpartition) logging.debug(" Format command for datafs %s : %s ", datafs, datapartition) - if (datafs != "noformat"): - logging.info("Starting format of %s", datapartition) + if (datafs != "no_format"): + logging.info(" Starting format %s of %s", datafs, datapartition) cmd = " %s /dev/%s" %( datafs, datapartition) #os.system(cmd) runcmd(cmd) else: - logging.info("Will not format data partition: %s", datapartition) + logging.info(" Will not format data partition: %s", datapartition) - if install_type == "install": - if (hostoptions["swapsize"] != "NO"): - logging.info("Starting format for swap %s", swappartition) - cmd = " mkswap /dev/%s" % swappartition - #os.system(cmd) - runcmd(cmd) - else: - logging.debug(" Swap is set to NO, will not run mkswap") + #for upgrades format is set to no_format + if ( homefs != "no_format"): + logging.info(" Starting format %s of %s", homefs, homepartition) + cmd = " %s /dev/%s" %( homefs, homepartition) + #os.system(cmd) + runcmd(cmd) + else: + logging.info(" Will not format home partition: %s", homepartition) + + if ( sqlfs != "no_format"): + logging.info(" Starting format %s of %s", sqlfs, sqlpartition) + cmd = " %s /dev/%s" %( sqlfs, sqlpartition) + #os.system(cmd) + runcmd(cmd) + else: + logging.info(" Will not format sql partition: %s", sqlpartition) + + logging.debug(" Format command for datafs %s : %s ", datafs, datapartition) + if (datafs != "no_format"): + logging.info(" Starting format %s of %s", datafs, datapartition) + cmd = " %s /dev/%s" %( datafs, datapartition) + #os.system(cmd) + runcmd(cmd) + else: + logging.info(" Will not format data partition: %s", datapartition) logging.debug("_____End of format______") @@ -412,43 +525,89 @@ def mount_it(): try: mountpoint = data_config.MOUNTPOINT mp = mountpoint - logging.info("Creating mountpoints %s", mp) + logging.info(" Creating mountpoints %s", mp) os.makedirs(mp) except OSError: logging.debug(" Could not create %s", mp) -# Mount root + # Mount root cmd = "mount /dev/%s %s" %(hostoptions["rootpartition"], mountpoint) runcmd(cmd) - - - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) - #logging.debug(cmdout) -# Mount data -#make mountpoint after mounting / + # Mount data + #make mountpoint after mounting / try: mountpoint = data_config.MOUNTPOINT datapoint = data_config.DATAMOUNT mp = mountpoint+datapoint - logging.info("Creating mountpoints %s", mp) + logging.info(" Creating mountpoints %s", mp) os.makedirs(mp) except OSError: logging.debug(" Could not create %s", mp) cmd = "mount /dev/%s %s" %(hostoptions["datapartition"], mp) runcmd(cmd) - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) - #logging.debug(cmdout) + + #mount home + try: + mountpoint = data_config.MOUNTPOINT + homepoint = data_config.HOMEMOUNT + mp = mountpoint+homepoint + logging.info(" Creating mountpoints %s", mp) + os.makedirs(mp) + except OSError: + logging.debug(" Could not create %s", mp) + + cmd = "mount /dev/%s %s" %(hostoptions["home_partition"], mp) + runcmd(cmd) + + + #mount sql + try: + mountpoint = data_config.MOUNTPOINT + sqlpoint = data_config.SQLMOUNT + mp = mountpoint+sqlpoint + logging.info(" Creating mountpoints %s", mp) + os.makedirs(mp) + except OSError: + logging.debug(" Could not create %s", mp) + + cmd = "mount /dev/%s %s" %(hostoptions["sql_partition"], mp) + runcmd(cmd) + def unmount_it(): logging.info("______Unmounting disk______") + cmd = "mount -v |grep new_boot" + mp_list=[] + mplist=[] + mountpoint = runcmd(cmd)[1] + mplist="".join(mountpoint).split("\n") + for i in mplist: + mp = i.split()[2] + mp_list.append(mp) + mp_list.sort(key = len, reverse=True) + for i in mp_list: + cmd = "umount %s" %(i) + runcmd(cmd) + time.sleep(1) + + + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) runcmd(cmd) time.sleep(2) + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.HOMEMOUNT) + runcmd(cmd) + time.sleep(2) + + cmd = "umount %s" %(data_config.MOUNTPOINT+data_config.SQLMOUNT) + runcmd(cmd) + time.sleep(2) + + + cmd = "swapoff /dev/%s" %(hostoptions["swappartition"]) runcmd(cmd) @@ -475,33 +634,170 @@ def create_squashlist(): logging.debug(i) f.close() +def mount_for_copy_it(): + mounts = {} + + mounts['/image_mount/root'] = 'root-image' + mounts['/image_mount/usr/share'] = 'usr-share' + mounts['/image_mount/lib/modules'] = 'lib-modules' + mounts['/image_mount/var/lib/pacman'] = 'var-lib-pacman' + mounts['/image_mount/data/storage/disk0/pacman/pkg'] = 'data-storage-disk0-pacman-pkg' + #mounts['/image_mount/var/cache/pacman'] = 'var-cache-pacman' + for image_mount, fsimage in mounts.iteritems(): + try: + os.makedirs(image_mount) + except: + pass + cmd = 'mount /run/archiso/sfs/%s/%s.fs %s' %(fsimage,fsimage,image_mount) + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("Mount image %s" %fsimage) + + + + + #image_mount='/image_mount/root' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/usr/share' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/lib/modules' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/var/cache/pacman' + #try: + #os.makedirs(image_mount) + #except: + #pass + + #image_mount='/image_mount/var/lib/pacman' + #try: + #os.makedirs(image_mount) + #except: + #pass + + + #fsimage='root-image' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/root' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image root") + + #fsimage='lib-modules' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/lib/modules' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image lib-modules") + + #fsimage='usr-share' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/usr/share' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image usr share") + + #fsimage='var-lib-pacman' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/var/lib/pacman' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image var-lib-pacman") + + #fsimage='var-cache-pacman' + #cmd = 'mount /run/archiso/sfs/%s/%s.fs /image_mount/var/cache/pacman' %(fsimage,fsimage) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Mount image var-cahce-pacman") + + +def umount_for_copy_it(): + mounts = {} + + mounts['/image_mount/root'] = 'root-image' + mounts['/image_mount/usr/share'] = 'usr-share' + mounts['/image_mount/lib/modules'] = 'lib-modules' + mounts['/image_mount/var/lib/pacman'] = 'var-lib-pacman' + mounts['/image_mount/data/storage/disk0/pacman/pkg'] = 'data-storage-disk0-pacman-pkg' + #mounts['/image_mount/var/cache/pacman'] = 'var-cache-pacman' + for image_mount, fsimage in mounts.iteritems(): + cmd = 'mount /run/archiso/sfs/%s/%s.fs %s' %(fsimage,fsimage,image_mount) + cmd='umount %s' %(image_mount) + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("unMount image %s" %image_mount) + + + #cmd='umount %s' %('/image_mount/lib/modules') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image lib_modules") + + #cmd='umount %s' %('/image_mount/usr/share') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image usr_share") + + #cmd='umount %s' %('/image_mount/root') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image /") + + #cmd='umount %s' %('/image_mount/var/cache/pacman') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image var-cache-pacman") + + #cmd='umount %s' %('/image_mount/var/lib/pacman') + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("unMount image var-lib-pacman") + + def copy_it(install_type): logging.info("______Transferring to disk______") + mount_for_copy_it() logging.debug( install_type) if ( install_type == "install"): logging.info("Transferring system") - cmd = " unsquashfs -f -d %s /.livesys/medium/larch/system.sqf" %(data_config.MOUNTPOINT) - #runcmd(cmd) - rc = runcmd(cmd)[0] - if rc != 0 : - error_out("Running unsquashfs") + cmdlist = ['rsync -arp /image_mount/root/* /new_boot', + 'rsync -arp /image_mount/lib/* /new_boot/lib/', + 'rsync -arp /image_mount/usr /new_boot', + 'rsync -arp /image_mount/var /new_boot', + 'rsync -arp /image_mount/data/storage/disk0/* /new_boot/data/storage/disk0/' + ] + + for cmd in cmdlist: + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("Running %s" %cmd) + - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) if ( install_type == "upgrade"): logging.info("Upgrading system") - create_squashlist() - cmd = " unsquashfs -e %s -f -d %s /.livesys/medium/larch/system.sqf" %(data_config.SQUASHFILE, data_config.MOUNTPOINT) - #runcmd(cmd) - rc = runcmd(cmd)[0] - if rc != 0 : - error_out("Running unsquashfs") - #logging.debug(cmd) - #cmdout=commands.getoutput(cmd) -# Create the missing dir - i = ("sys", "proc", "dev", "tmp", "mnt", "media", "media/cdrom", "media/dvd", "var/log/mythtv", "var/lock", "var/tmp", "usr/lib/locale") + + cmdlist = ['rsync -arp --exclude /home --exclude /data/srv/mysql /image_mount/root/* /new_boot', + 'rsync -arp /image_mount/lib/* /new_boot/lib/', + 'rsync -arp /image_mount/usr /new_boot', + 'rsync -arp /image_mount/var /new_boot'] + + for cmd in cmdlist: + #runcmd(cmd) + rc = runcmd(cmd)[0] + if rc != 0 : + error_out("Running %s" %cmd) + + # Create the missing dir + i = ("sys", "proc", "dev", "tmp", "mnt", "media", "media/cdrom", "media/dvd", "var/lock", "var/tmp", "usr/lib/locale") mountpoint = data_config.MOUNTPOINT for item in i: try: @@ -533,12 +829,11 @@ def copy_it(install_type): runcmd(cmd) cmd = "chmod +s %s/bin/mount" %(data_config.MOUNTPOINT) runcmd(cmd) - cmd = "rm %s/etc/*.larch*" %(data_config.MOUNTPOINT) - runcmd(cmd) - cmd = "rm %s/etc/mkinitcpio.d/larch*" %(data_config.MOUNTPOINT) - runcmd(cmd) - cmd = "rm %s/etc/rc.d/functions.d/*larch*" %(data_config.MOUNTPOINT) - runcmd(cmd) + #sys.exit(3) + apply_pristine() + post_process() + + umount_for_copy_it() logging.debug("__End of copy_it__") def create_fstab(extralines): @@ -555,10 +850,19 @@ def create_fstab(extralines): fstab_list.append(line) line = '''/dev/sr0 /media/cdrom auto ro,user,noauto,unhide 0 0\n''' fstab_list.append(line) - line = '''UUID=ROOTUID / auto defaults,noatime 0 1\n''' + line = '''UUID=ROOTUID / %s defaults,noatime 0 1\n''' %(hostoptions["rootfs"]) + fstab_list.append(line) + + line = '''UUID=DATAUID %s %s defaults,noatime 0 1\n''' %(data_config.DATAMOUNT,hostoptions["datafs"]) fstab_list.append(line) - line = '''UUID=DATAUID %s auto defaults,noatime 0 1\n''' %(data_config.DATAMOUNT) + + line = '''UUID=HOMEUID %s %s defaults,noatime 0 1\n''' %(data_config.HOMEMOUNT,hostoptions["homefs"]) + fstab_list.append(line) + + line = '''UUID=SQLUID %s %s defaults,noatime 0 1\n''' %(data_config.SQLMOUNT,hostoptions["sqlfs"]) fstab_list.append(line) + + line = '''UUID=SWAPUID swap swap defaults 0 0 \n''' fstab_list.append(line) for vline in extralines: @@ -569,16 +873,16 @@ def create_fstab(extralines): f.close() def find_uuid(partition): - logging.info("Finding the UUID for %s...", partition) + logging.info(" Finding the UUID for %s...", partition) cmd = "blkid -s UUID /dev/%s" %partition tmpuuid = runcmd(cmd)[1] splituuid = tmpuuid.partition("=") uuid = splituuid[2].replace('"', "") - logging.info("The uuid is %s", uuid) + logging.info(" The uuid is %s", uuid) return uuid.strip() def acl_options(partition): - logging.info("Finding mount options for %s...", partition) + logging.info(" Finding mount options for %s...", partition) acl_fs_list=["ext3","ext4"] options = "defaults,noatime" cmd = "/sbin/fsck -N /dev/%s" %partition @@ -601,7 +905,7 @@ def acl_options(partition): if i[0] == "/dev/%s" %partition: if i[1] in acl_fs_list: rc=True - logging.info("Will add acl to the list of options: %s ", rc ) + logging.info(" Will add acl to the list of options: %s ", rc ) return rc @@ -636,6 +940,7 @@ def fstab_it(install_type): elif os.path.exists("/tmp/etc/fstab"): logging.debug(" Upgrade and not Knoppmyth, using old fstab") cp_and_log("/tmp/etc/fstab", fstabfile) + # Catch all for creating new fstab if not os.path.exists(data_config.MOUNTPOINT+"/etc"): os.makedirs(data_config.MOUNTPOINT+"/etc") @@ -653,13 +958,24 @@ def fstab_it(install_type): rootuuid = find_uuid(hostoptions["rootpartition"]) rootacl = acl_options(hostoptions["rootpartition"]) + logging.info("____UUID check for %s", "home") + homeuuid = find_uuid(hostoptions["home_partition"]) + homeacl = acl_options(hostoptions["home_partition"]) + + logging.info("____UUID check for %s", "sql") + sqluuid = find_uuid(hostoptions["sql_partition"]) + sqlacl = acl_options(hostoptions["sql_partition"]) + fstabfile = data_config.MOUNTPOINT+"/etc/fstab" - logging.info("Correcting UUID's in %s", fstabfile) + logging.info(" Correcting UUID's in %s", fstabfile) f = open(fstabfile, 'r') oldfscontents = f.readlines() newfstab = [] f.close() for line in oldfscontents: + if line.strip("\n") == '': + continue + #FIX ALL MOUNTS THAT START WITH UUID if line.startswith("UUID"): templine = line.split() if ( templine[1] == "/"): @@ -678,7 +994,7 @@ def fstab_it(install_type): logging.debug( newline) newfstab.append(newline) - if ( templine[1] == data_config.DATAMOUNT): + elif ( templine[1] == data_config.DATAMOUNT): logging.debug(" Found DATA mount") logging.debug( templine) templine[0] = "UUID=%s" %(datauuid) @@ -693,7 +1009,37 @@ def fstab_it(install_type): logging.debug( newline) newfstab.append(newline) - if ( templine[1] == "swap"): + elif ( templine[1] == data_config.HOMEMOUNT): + logging.debug(" Found HOME mount") + logging.debug( templine) + templine[0] = "UUID=%s" %(homeuuid) + if homeacl: + templine[3] = templine[3]+",acl" + newline = '' + for i in templine: + newline+=i + newline+=" " + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + + elif ( templine[1] == data_config.SQLMOUNT): + logging.debug(" Found database mount") + logging.debug( templine) + templine[0] = "UUID=%s" %(sqluuid) + if sqlacl: + templine[3] = templine[3]+",acl" + newline = '' + for i in templine: + newline+=i + newline+=" " + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + + elif ( templine[1] == "swap"): if len(swapuuid) <= 5: logging.debug(" swapp uuid is to small") else: @@ -704,10 +1050,16 @@ def fstab_it(install_type): for i in templine: newline+=i newline+=" " - newline+="\n" - logging.debug(" New fstab line:") - logging.debug( newline) - newfstab.append(newline) + newline+="\n" + logging.debug(" New fstab line:") + logging.debug( newline) + newfstab.append(newline) + else: + logging.debug(" Line didn't match, adding to newfstab:") + logging.debug( line) + newfstab.append(line) + + elif line.startswith("none"): templine = line.split() if ( templine[1] == "/dev/pts" ): @@ -724,10 +1076,14 @@ def fstab_it(install_type): logging.debug(" Line didn't match, adding to newfstab:") logging.debug( line) newfstab.append(line) - logging.info("Writing out newfstab") + + logging.info(" Writing out newfstab") logging.debug("______This is the new fstab_____") + f = open(fstabfile, 'w') for line in newfstab: + if line.strip("\n") == '': + continue logging.debug(line) f.write(line) #f.write("\n") @@ -735,47 +1091,107 @@ def fstab_it(install_type): def grub_it(): logging.info("______Start of grub install______") - cmd = " grub-install --recheck --no-floppy --root-directory=%s \"(hd0)\" " % data_config.MOUNTPOINT - logging.info("Running grub-install") + cmd = "chroot %s grub-install --target=i386-pc --recheck --debug /dev/%s" %(data_config.MOUNTPOINT,hostoptions["rootdisk"]) + logging.info(" Running grub-install") runcmd(cmd) - rootuuid = find_uuid(hostoptions["rootpartition"]) - cmd = " mkinitcpio -b %s -g %s/boot/kernel26.img" %(data_config.MOUNTPOINT, data_config.MOUNTPOINT) + + cmd = " mkinitcpio -g %s/boot/initramfs-linux.img" %(data_config.MOUNTPOINT) logging.info("Running mkinitcpio") runcmd(cmd) - logging.info("Adding root uuid to grub menu") - grubfile = data_config.MOUNTPOINT+"/boot/grub/menu.lst" + newgrub = [] + grubfile = data_config.MOUNTPOINT+"/etc/default/grub" try: f = open(grubfile, 'r') oldgrub = f.readlines() - newgrub = [] - f.close() - for line in oldgrub: - if line.startswith("kernel"): - templine = line.split() - logging.debug(" Found kernel Root grubline:") - logging.debug( templine) - templine[2] = "root=/dev/disk/by-uuid/%s" %(rootuuid) - newline = '' - for i in templine: - newline+=i - newline+=" " - newline+="\n" - logging.debug(" New grub menu.lst line:") - logging.debug( newline) - newgrub.append(newline) - else: - logging.debug("Line didn't match, adding to newgrub:") - logging.debug( line) - newgrub.append( line) - logging.info("Writing out new grub file") - logging.debug("______This is the new grub_____") - f = open(grubfile, 'w') - for line in newgrub: - logging.debug(line) - f.write(line) + f.close() except: - logging.debug("Couldn't open grub file") + logging.debug(" Couldn't open grub file for reading") + pass + + time_line = "GRUB_TIMEOUT=" + hidden_time = "GRUB_HIDDEN_TIMEOUT=" + color_line_normal = "GRUB_COLOR_NORMAL" + color_line_highlight = "GRUB_COLOR_HIGHLIGHT" + + for line in oldgrub: + new_line=line + if line.find(time_line) != -1 : + new_line="GRUB_TIMEOUT=0\n" + + if line.find(color_line_normal) != -1 : + #new_line=line.lstrip('''#''') + new_line='''GRUB_COLOR_NORMAL="white/blue"\n''' + + if line.find(color_line_highlight) != -1 : + #new_line=line.lstrip('''#''') + new_line='''GRUB_COLOR_HIGHLIGHT="black/yellow"\n''' + + if line.find(hidden_time) != -1 : + new_line="GRUB_HIDDEN_TIMEOUT=5\n" + + newgrub.append(new_line) + + if len(newgrub) > 0: + try: + f = open(grubfile, 'w') + for line in newgrub: + logging.debug(line) + f.write(line) + f.close() + except: + logging.debug(" Couldn't open grub file for writing") + + + + cmd="chroot %s grub-mkconfig -o /boot/grub/grub.cfg" %data_config.MOUNTPOINT + runcmd(cmd) + +def double_mount(fe_only=False, upgrade=False): + logging.info(" double bind mount attempt") + cmd = "mkdir %s/run/dbus" %data_config.MOUNTPOINT + runcmd(cmd) + + cmd = " mount --bind /run/dbus %s/run/dbus" %data_config.MOUNTPOINT + runcmd(cmd) + for i in range(0,5): + if upgrade == True: + cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --reconstruct --no_mount" + else: + if fe_only == True: + cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --double_myth --no_mount" + else: + #cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --double_myth --no_mount" + cmd = "chroot " + data_config.MOUNTPOINT +" /usr/LH/bin/add_storage.py --double_myth --add_fe_sg --add_be_sg " + + if runcmd(cmd)[0] == 0: + logging.debug(" Add storage worked, breaking out of loop") + break + cmd = " umount %s/run/dbus" %data_config.MOUNTPOINT + runcmd(cmd) + +def move_myth_home(op): + logging.debug(" storage op %s" %op ) + if op == "restore": + destfile = "/storage/data/" + srcfile = "/storage/data.old/*" + cmd = 'chroot %s bash -c "mv %s %s"' %(data_config.MOUNTPOINT,srcfile,destfile) + runcmd(cmd) + + rmfile = "%s/storage/data.old" %data_config.MOUNTPOINT + cmd = "rmdir %s" %rmfile + runcmd(cmd) + + + if op == "backup": + srcfile = "%s/storage/data" %data_config.MOUNTPOINT + destfile = "%s/storage/data.old" %data_config.MOUNTPOINT + cmd = "mv %s %s" %(srcfile,destfile) + runcmd(cmd) + + + + def genlocale(): return @@ -798,7 +1214,7 @@ def genlocale(): outline = line.replace('#','') f.write(outline) - f.close + f.close() #cp_and_log("/tmp/locale.gen.new", data_config.MOUNTPOINT+"/etc/locale.gen") cmd = "chroot " + data_config.MOUNTPOINT +" /usr/sbin/locale-gen" runcmd(cmd) @@ -818,12 +1234,14 @@ def fix_permissions(): runcmd(cmd) cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+"/var/log/mythtv") runcmd(cmd) + cmd = " chmod +s %s" %(data_config.MOUNTPOINT+"/usr/bin/ping") + runcmd(cmd) def apply_new_auth(): logging.info("_____Applying Password updates_______") passfile = "/root/myth_user_call.out" try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug("MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" @@ -845,75 +1263,83 @@ def apply_new_auth(): logging.debug def add_to_blacklist(module): - rcfile = data_config.MOUNTPOINT + "/etc/rc.conf" + rcfile = data_config.MOUNTPOINT + "/etc/modprobe.d/install-blacklist.conf" logging.debug(" Attempting to add %s to blacklist", module) newline='' - try: - f = open(rcfile, 'r') - conflines = f.readlines() - f.close() - except: - logging.critical(" *Couldn't open %s for reading",rcfile) - return + #try: + #f = open(rcfile, 'r') + #conflines = f.readlines() + #f.close() + #except: + #logging.critical(" *Couldn't open %s for reading",rcfile) + #return try: - f = open(rcfile, 'w') + f = open(rcfile, 'a') except: logging.critical(" *Couldn't open %s for reading",rcfile) return - - for line in conflines: - newline = line - if re.match("MOD_BLACKLIST",line): - logging.debug(line) - try: - lastpar = line.rindex(')') - logging.debug(" found ) at %s", lastpar) - newline = line[:lastpar] +" !" + module + " " + line[lastpar:] - logging.debug(newline) - except: - logging.debug("Couldn't find ending )") - newline = line - f.write(newline) + line = "blacklist %s \n" %module + f.write(line) + line = "install %s /bin/false \n" %module + f.write(line) f.close() + #for line in conflines: + #newline = line + #if re.match("MOD_BLACKLIST",line): + #logging.debug(line) + #try: + #lastpar = line.rindex(')') + #logging.debug(" found ) at %s", lastpar) + #newline = line[:lastpar] +" !" + module + " " + line[lastpar:] + #logging.debug(newline) + #except: + #logging.debug("Couldn't find ending )") + #newline = line + #f.write(newline) + #f.close() def add_to_modulelist(module): - rcfile = data_config.MOUNTPOINT + "/etc/rc.conf" + rcfile = data_config.MOUNTPOINT + "/etc/modules-load.d/install-autoload.conf" logging.debug(" Attempting to add %s to modulelist", module) newline='' - try: - f = open(rcfile, 'r') - conflines = f.readlines() - f.close() - except: - logging.critical(" *Couldn't open %s for reading",rcfile) - return + #try: + #f = open(rcfile, 'r') + #conflines = f.readlines() + #f.close() + #except: + #logging.critical(" *Couldn't open %s for reading",rcfile) + #return try: - f = open(rcfile, 'w') + f = open(rcfile, 'a+') except: - logging.critical(" *Couldn't open %s for reading",rcfile) + logging.critical(" *Couldn't open %s for writing",rcfile) return - - for line in conflines: - newline = line - if re.match("MODULES=",line): - logging.debug(line) - try: - lastpar = line.rindex(')') - logging.debug(" found ) at %s", lastpar) - newline = line[:lastpar] +" " + module + " " + line[lastpar:] - logging.debug(newline) - except: - logging.debug("Couldn't find ending )") - newline = line - f.write(newline) + line = "%s" %module + f.write(line) + f.write("\n") f.close() + #for line in conflines: + #newline = line + #if re.match("MODULES=",line): + #logging.debug(line) + #try: + #lastpar = line.rindex(')') + #logging.debug(" found ) at %s", lastpar) + #newline = line[:lastpar] +" " + module + " " + line[lastpar:] + #logging.debug(newline) + #except: + #logging.debug("Couldn't find ending )") + #newline = line + #f.write(newline) + #f.close() def special_hardware_check(): + outlist = [] logging.info("_____Applying special boot parameters_______") try: f = open('/proc/cmdline', 'r') @@ -926,14 +1352,16 @@ def special_hardware_check(): logging.debug(" Boot options: %s", bootoptions) for item in bootoptions: logging.debug(item) - if re.match("disablemodules",item) != None : + if (re.match("disablemodules",item) != None) or (re.match("modprobe.blacklist",item) != None ): logging.debug(" Found disabledmodules") + outlist.append(item) modulelist = item.split("=")[1] for module in modulelist.split(','): add_to_blacklist(module) if re.match("modules",item) != None : logging.debug(" Found modules") + outlist.append(item) modulelist = item.split("=")[1] for module in modulelist.split(','): add_to_modulelist(module) @@ -953,6 +1381,19 @@ def special_hardware_check(): if re.match("no_meth",item) != None : cmd = " touch %s%s/.no_meth" %(data_config.MOUNTPOINT, data_config.MYTHHOME) runcmd(cmd) + if len(outlist) != 0: + outfile = data_config.MOUNTPOINT + "/etc/grub.d/install_modules" + logging.debug(" Writing out %s" %outfile) + try: + f = open(outfile, 'w') + templine = ' '.join(outlist) + outline = '''install_modules='%s' \n''' %templine + f.write(outline) + f.write("\n") + f.close() + except: + logging.critical(" *Couldn't write %s" %outfile) + return def swapsearch(): #currently unused! @@ -1030,10 +1471,48 @@ def restore_default_settings(): copy_updates() fix_permissions() +def apply_pristine(): + logging.info("_____Applying Pristine files_______") + if data_config.NOOPDEBUG == "FALSE": + cmd = "chroot " + data_config.MOUNTPOINT + " " + "tar -xvf /pristine.tar" + else: + cmd = "echo chroot " + data_config.MOUNTPOINT + " " + "tar -xvf /pristine.tar" + try: +# Using os.system because runcmd fails + logging.debug(cmd) + os.system(cmd) + except: + logging.debug("Applying pristine files failed %s", passfile) + logging.debug + + try: + removefile="%s/pristine.tar" %(data_config.MOUNTPOINT) + os.remove(removefile) + except OSError: + logging.debug(" Couldn't remove pristine.tar") + pass + +def post_process(): + logging.info("_____Post processing_______") + if data_config.NOOPDEBUG == "FALSE": + cmd = "chroot " + data_config.MOUNTPOINT + " " + "/root/.post_process/go.sh" + else: + cmd = "echo chroot " + data_config.MOUNTPOINT + " " + "/root/.post_process/go.sh" + try: +# Using os.system because runcmd fails + logging.debug(cmd) + os.system(cmd) + except: + logging.debug("Applying post_process_failed %s", passfile) + logging.debug + + + + def full_install(hostoptions): logging.info("______Start of full install______") try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug(" MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" @@ -1066,77 +1545,99 @@ def full_install(hostoptions): mount_it() swapon() - -# Find number of bytes written to disk before starting copy. This is used -# to have a somewhat decent progress indication. + #Find number of bytes written to disk before starting copy. This is used + #to have a somewhat decent progress indication. statgrab( hostoptions["rootdisk"]) msg = "Creating %s" %(systemconfig["hostname"]) update_status(msg) -# Copy system to disk + #Copy system to disk copy_it("install") -# Remove old fstab so that a new one is created + #at this point /storage exisit and is populated with myth home dir + + + #Remove old fstab so that a new one is created fstabfile = data_config.MOUNTPOINT+"/etc/fstab" try: os.remove(fstabfile) except OSError: logging.debug(" ERROR: deleting %s", fstabfile) fstab_it("full_install") -# Configure system + + # Configure system msg = "Configuring system" update_status(msg) progress(98) - grub_it() - genlocale() + special_hardware_check() -# Configuring the system + + mount_bind_chroot() + grub_it() + umount_bind_chroot() + + genlocale() #currently does nothing + + logging.info("______Configuring system________") cp_and_log("/etc/systemconfig", data_config.MOUNTPOINT+"/etc/systemconfig") + cp_and_log("/etc/install_layout", data_config.MOUNTPOINT+"/etc/install_layout") cp_and_log("/root/xorg.conf.install", data_config.MOUNTPOINT+"/etc/X11/xorg.conf.install") - restore_default_settings() - #try: - #MVROOT=os.environ["MV_ROOT"] - #except: - #logging.debug(" MVROOT was not defined, using the default value") - #MVROOT="/usr/MythVantage" - #logging.info("Saving syssettings") - #cmd="%s/bin/myth_settings_wrapper.sh -c save -t syssettings -h %s -d localhost" %(MVROOT, data_config.MVHOSTNAME) - #runcmd(cmd) - #SE=os.environ["TEMPLATES"]+"/settings/syssettings" - #cp_and_log(SE, data_config.MOUNTPOINT+SE) - #cp_and_log("/etc/mtab", data_config.MOUNTPOINT+"/etc/mtab") - #cp_and_log2(MVROOT+"/bin/", data_config.MOUNTPOINT+MVROOT+"/bin/", "*.sh") - #cp_and_log2(MVROOT+"/bin/", data_config.MOUNTPOINT+MVROOT+"/bin/", "*.py") - #fix_permissions() + + restore_default_settings() #also calls copy_updates, fix permissions + + #setup symlink + mount_bind_chroot() + logging.info("Running systemconfig in chroot") + cmd = "chroot %s %s/bin/systemconfig.sh config_xml,this_is_install" %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + umount_bind_chroot() + + mount_bind_chroot() apply_new_auth() umount_bind_chroot() + if ( systemconfig["SystemType"] == "Master_backend" or systemconfig["SystemType"] == "Standalone" ): -# This install will need a DB, so install it + #This install will need a DB, so install it logging.info("______Installing Database in CHROOT________") mysqldb("stop", '') mount_bind_chroot() - cmd = " chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) + cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + logging.info("Running systemconfig in chroot") - #cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT) cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) rc = runcmd(cmd)[0] if rc != 0 : error_out("Running systemconfig") + #move_myth_home("backup") + + mysqldb("start","chroot") + double_mount() mysqldb("stop", "chroot") - kill_dhcp_chroot() + + #move_myth_home("restore") #restoring after the bind mound/symlink has occured + + #kill_dhcp_chroot() logging.info("____End Database in CHROOT____") mysqldb("start", '') umount_bind_chroot() else: logging.info("______No database required, continuing configuration________") mount_bind_chroot() - cmd = " chroot %s DISPLAY=127.0.0.1:0 %s/bin/MythVantage -t restore, default 1" %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) + #cmd = "chroot %s DISPLAY=127.0.0.1:0 %s/bin/MythVantage -t restore, default 1" %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) + + + #move_myth_home("backup") + if systemconfig["SystemType"] == "Slave_backend": + double_mount() + else: + double_mount(fe_only=True) + #move_myth_home("restore") # Need to check for to touch /tmp/.dbsysfailed #cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) #runcmd(cmd) @@ -1148,20 +1649,33 @@ def full_install(hostoptions): rc = runcmd(cmd)[0] if rc != 0 : error_out("Running systemconfig") + + #restore defaults here! + cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t distro_default " %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c ACCESSCONTROL " %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + + #run hostype again to set BackendServerIP. This value is overwritten with distro_default restore + cmd = "chroot %s %s/bin/systemconfig.sh hostype,this_is_install" %(data_config.MOUNTPOINT, MVROOT) + runcmd(cmd) + umount_bind_chroot() - cmd = " touch %s%s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + + cmd = "chroot %s touch %s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) runcmd(cmd) - cmd = " chmod 777 %s%s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) + cmd = "chroot %s chmod 777 %s/.configure" %(data_config.MOUNTPOINT, data_config.MYTHHOME) runcmd(cmd) msg = "Done" update_status(msg) cp_and_log("/tmp/mythvantage_install.log", data_config.MOUNTPOINT+"/var/log/mythvantage_install.log") cp_and_log("/tmp/mv_debug.log", data_config.MOUNTPOINT+"/var/log/mv_debug.log") + kill_dhcp_chroot() unmount_it() logging.debug("_____End of full install_____") @@ -1188,9 +1702,10 @@ def find_upgrade(): if os.path.exists(srcfile): logging.info("Found systemconfig file %s", srcfile) TEMPLATES = os.environ["TEMPLATES"]+"/settings/syssettings" + TEMPLATE_ = os.environ["TEMPLATES"]+"/settings" cp_and_log2(data_config.MOUNTPOINT+TEMPLATES, data_config.TEMP_TEMPLATES, '') sane_settings("/tmp/templates/settings/syssettings/settings.txt") - cp_and_log2(data_config.TEMP_TEMPLATES, TEMPLATES, '') + cp_and_log2(data_config.TEMP_TEMPLATES, TEMPLATE_, '*') cp_and_log(srcfile, "/etc/systemconfig") cp_and_log(data_config.MOUNTPOINT+"/etc/", "/tmp/etc/") cp_and_log(data_config.MOUNTPOINT+"/var/lib/alsa/", "/tmp/alsa") @@ -1280,15 +1795,18 @@ def upgrade_mount_search(): def upgrade(hostoptions): - try: - MVROOT = os.environ["MV_ROOT"] + MVROOT = os.environ["MV_ROOT"].strip() except: logging.debug("MVROOT was not defined, using the default value") MVROOT = "/usr/MythVantage" + hostoptions["backupfile"] = data_config.BACKUPPATH+data_config.BACKUPFILE + logging.info("______Start of upgrade______") cmd = "touch /tmp/.this_is_upgrade" runcmd(cmd) + + #format disk if hostoptions["rootfs"] == "Do_not_format": logging.info("Will not format root filesystem") else: @@ -1296,18 +1814,26 @@ def upgrade(hostoptions): update_status(statusmsg) progress(2) format_disk("upgrade") - #sys.exit(2) + + #mount partitions statusmsg = "Mounting %s" %( hostoptions["rootdisk"]) update_status(statusmsg) progress(3) mount_it() swapon() + hostoptions["backupfile"] = data_config.BACKUPPATH+data_config.BACKUPFILE + #Find number of bytes written to disk before starting copy. This is used to + #give a somewhat decent progress indication statgrab( hostoptions["rootdisk"]) msg = "Upgrading %s" %(systemconfig["hostname"]) update_status(msg) time.sleep(3) + + #copy system to disk copy_it("upgrade") + + #Restore /etc and key files. This is the copy found when running find_upgrade cmd = "rm -rf %s/etc.old" %data_config.MOUNTPOINT runcmd(cmd) cmd = "rm -rf %s/alsa.old" %data_config.MOUNTPOINT @@ -1317,12 +1843,19 @@ def upgrade(hostoptions): cp_and_log("/tmp/alsa/", data_config.MOUNTPOINT+"/alsa.old/") cp_and_log("/tmp/oss", data_config.MOUNTPOINT+"/var/lib/oss.old") + srcfile = "%s/etc.old/ssh/" %(data_config.MOUNTPOINT) destfile = "%s/etc/ssh/" %(data_config.MOUNTPOINT) cp_and_log2(srcfile, destfile, '*.pub') cp_and_log2(srcfile, destfile, '*.key') cp_and_log2(srcfile, destfile, '*key') + srcfile = "%s/etc.old/storage.d/" %(data_config.MOUNTPOINT) + destfile = "%s/etc/storage.d/" %(data_config.MOUNTPOINT) + cp_and_log2(srcfile, destfile, '*.conf') + cp_and_log2(srcfile, destfile, '*.pkl') + + mdfile = mdadm_find("/tmp") cp_and_log("/tmp"+mdfile, data_config.MOUNTPOINT+"/etc") @@ -1348,23 +1881,36 @@ def upgrade(hostoptions): cp_and_log(data_config.MOUNTPOINT+"/etc.old/passwd", data_config.MOUNTPOINT+"/etc/passwd") cp_and_log(data_config.MOUNTPOINT+"/etc.old/shadow", data_config.MOUNTPOINT+"/etc/shadow") cp_and_log(data_config.MOUNTPOINT+"/etc.old/group", data_config.MOUNTPOINT+"/etc/group") - msg = "Configuring system" + + #configure system + msg = "Configuring system" update_status(msg) progress(98) logging.info("______Configuring system________") cp_and_log("/etc/systemconfig", data_config.MOUNTPOINT+"/etc/systemconfig") - if not backup_sql_check(): - upgrade_mount_search() + #New partition layout, we do not need to search for backup file + #if not backup_sql_check(): + #upgrade_mount_search() + + #check fstab, see if it needs any updates fstab_it("upgrade") time.sleep(1) + + special_hardware_check() + + mount_bind_chroot() grub_it() + umount_bind_chroot() + genlocale() time.sleep(1) - #needed to get around a bug with pacman - special_hardware_check() + + cp_and_log("/root/xorg.conf.install", data_config.MOUNTPOINT+"/etc/X11/xorg.conf.install") + #this was needed to get around a pacman bug cp_and_log("/etc/mtab", data_config.MOUNTPOINT+"/etc/mtab") + if clean_upgrade() or os.path.exists("/tmp/etc/KnoppMyth-version"): logging.debug("clean upgrade or knoppmyth upgrade detected, running restore settings") restore_default_settings() @@ -1372,53 +1918,69 @@ def upgrade(hostoptions): file = "%s/%s/.kmupgrade" %(data_config.MOUNTPOINT, data_config.MYTHHOME) cmd = "touch %s && chmod 777 %s" %(file, file) runcmd(cmd) + + #these are also run by restore_default_settings in install copy_updates() fix_permissions() + mount_bind_chroot() - logging.info("Running systemconfig in chroot") - #cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT) - cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) - rc = runcmd(cmd)[0] - if rc != 0 : - error_out("Running systemconfig") - mysqldb("stop", "") + apply_new_auth() + umount_bind_chroot() + + + #logging.info("Running systemconfig in chroot") + #cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) + #rc = runcmd(cmd)[0] + #if rc != 0 : + #error_out("Running systemconfig") + #mysqldb("stop", "") + if ( systemconfig["SystemType"] == "Master_backend" or systemconfig["SystemType"] == "Standalone" ): - if clean_upgrade() or not backup_sql_check(): + if clean_upgrade(): + mysqldb("stop", "") + mount_bind_chroot() logging.info("Installing new database") - cmd = " chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) - else: - logging.info("Restoring database") - cmd = " chroot %s %s/bin/restore_km_db_chroot.sh %s|tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT, hostoptions["backupfile"]) + cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) runcmd(cmd) + umount_bind_chroot() + + #if clean_upgrade() or not backup_sql_check(): + #logging.info("Installing new database") + #cmd = "chroot %s %s/bin/install_db_chroot.sh |tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) + #else: + #logging.info("Restoring database") + #cmd = "chroot %s %s/bin/restore_km_db_chroot.sh %s|tee /tmp/chrootdb.out" %(data_config.MOUNTPOINT, MVROOT, hostoptions["backupfile"]) + #runcmd(cmd) + + #if os.path.exists("/tmp/etc/KnoppMyth-version"): + #cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t hostsettings " %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) + #logging.debug("Correcting permissions because of km->linhes upgrade") + #cmd = "chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) + #runcmd(cmd) + #cmd = "chown -R root:root %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT+"/backup") + #runcmd(cmd) + #else: + #cmd = "chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) + #runcmd(cmd) - if os.path.exists("/tmp/etc/KnoppMyth-version"): - cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t hostsettings " %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) - logging.debug("Correcting permissions because of km->linhes upgrade") - cmd = " chown -R mythtv:mythtv %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT) - runcmd(cmd) - cmd = " chown -R root:root %s" %(data_config.MOUNTPOINT+data_config.DATAMOUNT+"/backup") - runcmd(cmd) - else: - cmd = " chroot %s %s/bin/myth_settings_wrapper.sh -c restore -t syssettings " %(data_config.MOUNTPOINT, MVROOT) - runcmd(cmd) - - logging.info("Running systemconfig in chroot 2nd time") - #cmd = " chroot %s %s/bin/systemconfig.sh misc, hostype, network, advanced, user, this_is_install" %(data_config.MOUNTPOINT, MVROOT) + #run systemconfig in chroot + mount_bind_chroot() + #make symlink only..no need to double_mount as fstab should already have that, unless it's a clean upgrade + double_mount(upgrade=True) + logging.info("Running systemconfig in chroot") cmd = "chroot %s %s/bin/systemconfig.sh all,this_is_install" %(data_config.MOUNTPOINT, MVROOT) rc = runcmd(cmd)[0] if rc != 0 : error_out("Running systemconfig") - #logging.info("Running systemconfig in chroot") - #cmd = " chroot %s %s/bin/systemconfig.sh advanced" %(data_config.MOUNTPOINT, MVROOT) - #runcmd(cmd) - mysqldb("stop", 'chroot') - apply_new_auth() - kill_dhcp_chroot() umount_bind_chroot() + kill_dhcp_chroot() + + cp_and_log("/tmp/mythvantage_install.log", data_config.MOUNTPOINT+"/var/log/mythvantage_install.log") cp_and_log("/tmp/mv_debug.log", data_config.MOUNTPOINT+"/var/log/mv_debug.log") + unmount_it() msg = "Done" update_status(msg) @@ -1428,14 +1990,38 @@ def upgrade(hostoptions): def main(argv): + print install_conf global hostoptions + hostoptions = {} + conflist=["op", + "rootdisk","rootfs","rootsize", + "datafs","datasize","datadisk","datapartition", + "swapsize", + "homesize","homefs", + "sqlsize","sqlfs", + "uprootfs"] + + for i in conflist: + try: + hostoptions[i] = install_conf[i].lower() + except: + pass + try: #op is not set for find_upgrade + if hostoptions["op"] == "upgrade": + #rootfs is used by both upgrade and install + hostoptions["rootfs"] == hostoptions["uprootfs"] + except: + pass + + + try: opts, args = getopt.getopt(argv, 'c:h', ["help", "rootdisk=", "rootfs=", "rootsize=", "datafs=", "datasize=", "datadisk=", "swapsize=", "datapartition=" ] ) except getopt.GetoptError, why: print why usage() sys.exit(2) - hostoptions = {"op": 'null'} + #hostoptions = {"op": 'null'} for opt, arg in opts: if opt in ("-h", "--help"): usage() @@ -1465,24 +2051,51 @@ def main(argv): sys.exit(2) else: hostoptions["op"] = arg - try: - hostoptions["datadisk"] - except: - hostoptions["datadisk"] = hostoptions["rootdisk"] - hostoptions["datapartition"] = hostoptions["datadisk"]+str(3) - try: - hostoptions["datapartition"] - except: - hostoptions["datapartition"] = hostoptions["datadisk"]+str(3) - hostoptions["swappartition"] = hostoptions["rootdisk"] + str(2) + + validop = ["full_install", "upgrade", "netboot", "find_upgrade"] + if hostoptions["op"] not in validop: + logging.critical("-c %s is not a valid option", hostoptions["op"]) + sys.exit(2) + + + + if ( hostoptions["op"] == "upgrade") or ( hostoptions["op"] == "find_upgrade" ): + hostoptions["datafs"] = "no_format" + hostoptions["homefs"] = "no_format" + hostoptions["sqlfs"] = "no_format" + + #hardcoding partitions + hostoptions["rootpartition"] = hostoptions["rootdisk"]+str(1) ##hardcoded partition 1 + hostoptions["swappartition"] = hostoptions["rootdisk"] + str(2) + + try: + hostoptions["datadisk"] + except: + hostoptions["datadisk"] = hostoptions["rootdisk"] + #home/sql do not needed to be valid values for the upgrade, but using real values for reference + try: + hostoptions["home_partition"] + except: + hostoptions["home_partition"] = hostoptions["rootdisk"]+str(5) + + try: + hostoptions["sql_partition"] + except: + hostoptions["sql_partition"] = hostoptions["rootdisk"]+str(6) + + try: + hostoptions["datapartition"] + except: + hostoptions["datapartition"] = hostoptions["datadisk"]+str(7) if ( hostoptions["op"] == "full_install" ) : full_install(hostoptions) + elif (hostoptions["op"] == "upgrade" ) : - hostoptions["datafs"] = "no_format" find_upgrade() upgrade(hostoptions) + elif (hostoptions["op"] == "find_upgrade" ) : find_upgrade() return hostoptions @@ -1531,6 +2144,27 @@ for line in config_file: val = val.strip('"') systemconfig[var.strip()] = val.strip() +#Read in install_conf +global install_conf +install_conf = {} +file_name = "/etc/install_layout" +try: + config_file = open(file_name) +except: + logging.debug("%s could not be opened", file_name) + config_file = '' + +for line in config_file: + line = line.strip() + if line and line[0] is not "#" and line[-1] is not "=": + var, val = line.rsplit("=", 1) + val = val.strip('"') + install_conf[var.strip()] = val.strip() + + + + + if __name__ == "__main__": config_file = "mv_config" |