From 0afe907bbdea5161538713ca313d19ffc737a483 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Fri, 7 Sep 2012 22:24:55 -0500
Subject: LinHES-config: modify install for 5 partition layout

---
 abs/core/LinHES-config/PKGBUILD      |   6 +-
 abs/core/LinHES-config/mv_config.py  |   4 +
 abs/core/LinHES-config/mv_install.py | 339 ++++++++++++++++++++++++++++++-----
 3 files changed, 298 insertions(+), 51 deletions(-)

diff --git a/abs/core/LinHES-config/PKGBUILD b/abs/core/LinHES-config/PKGBUILD
index 8073599..092165e 100755
--- a/abs/core/LinHES-config/PKGBUILD
+++ b/abs/core/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=2.3
-pkgrel=121
+pkgrel=122
 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'
@@ -125,9 +125,9 @@ build() {
     install -o root -g root  -D -m 0755 blacklist_pcspkr.conf $startdir/pkg/etc/modprobe.d/blacklist_pcspkr.conf
     install -o root -g root  -D -m 0755 blacklist_nouveau.conf $startdir/pkg/etc/modprobe.d/blacklist_nouveau.conf
 }
-md5sums=('2dab193216dae3fe965c9ab7f93f822a'
+md5sums=('3ea478f8478cdbf47c652f37e2dab346'
          'f33e1a6f7985091b8d47cbaf7433f90f'
-         '88d0d57a5d2acaf9c0456c38218e513f'
+         '04c72de15178f1577ce40a8cb045930a'
          '2596460462cf6c889cf8f95485537b20'
          '985891a43f7c4c983eb2a362162f1a0f'
          '5e019ede24323a77f8d3812a93d38075'
diff --git a/abs/core/LinHES-config/mv_config.py b/abs/core/LinHES-config/mv_config.py
index 32ede47..fa8f3bd 100755
--- a/abs/core/LinHES-config/mv_config.py
+++ b/abs/core/LinHES-config/mv_config.py
@@ -3,6 +3,10 @@ SYSTEMTYPE="LinHES"
 MVHOSTNAME="apheleia"
 MOUNTPOINT="/new_boot"
 DATAMOUNT="/data/storage/disk0"
+
+HOMEMOUNT="/home"
+SQLMOUNT="/data/srv/mysql"
+
 MYTHHOME="/home/mythtv"
 VNCHOME="/home/vncsvc"
 NOOPDEBUG="FALSE"
diff --git a/abs/core/LinHES-config/mv_install.py b/abs/core/LinHES-config/mv_install.py
index 70f6604..3bdd791 100755
--- a/abs/core/LinHES-config/mv_install.py
+++ b/abs/core/LinHES-config/mv_install.py
@@ -261,7 +261,7 @@ def blank_table(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:
         device = parted.getDevice(diskdevice)
         partdisk = parted.Disk(device)
@@ -274,54 +274,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) )
         try:
             geom = parted.Geometry(device=device,  start=newstart,  length=(device.length-newstart))
         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
@@ -331,6 +353,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)
 
@@ -338,8 +369,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):
@@ -368,13 +399,25 @@ 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",
@@ -397,41 +440,77 @@ 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"]
+
+    homepartition = hostoptions["home_partition"]
+    sqlpartition = hostoptions["sql_partition"]
+
+
+
     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)
+        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)
+        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)
+            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")
 
+        if ( homefs != "noformat"):
+            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 != "noformat"):
+            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 != "noformat"):
+            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______")
 
 
@@ -441,36 +520,56 @@ 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______")
@@ -494,6 +593,14 @@ def unmount_it():
     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"])
@@ -544,6 +651,68 @@ def mount_for_copy_it():
 
 
 
+    #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 = {}
 
@@ -561,6 +730,31 @@ def umount_for_copy_it():
             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):
@@ -652,8 +846,17 @@ def create_fstab(extralines):
     fstab_list.append(line)
     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=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:
@@ -749,6 +952,14 @@ 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)
     f = open(fstabfile,  'r')
@@ -792,6 +1003,36 @@ def fstab_it(install_type):
                 logging.debug(      newline)
                 newfstab.append(newline)
 
+            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 HOME 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")
@@ -1276,7 +1517,6 @@ 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.
     statgrab( hostoptions["rootdisk"])
@@ -1298,7 +1538,7 @@ def full_install(hostoptions):
         logging.debug("     ERROR: deleting %s", fstabfile)
     fstab_it("full_install")
 
-#   Configure system
+    #   Configure system
     msg = "Configuring system"
     update_status(msg)
     progress(98)
@@ -1661,14 +1901,15 @@ def main(argv):
     hostoptions = {}
     conflist=["rootdisk","rootfs","rootsize",
               "datafs","datasize","datadisk","datapartition",
-              "swapsize","op"]
+              "swapsize","op","homesize","sqlsize"]
 
     for i in conflist:
         try:
             hostoptions[i] = install_conf[i]
         except:
             pass
-
+    hostoptions["sqlfs"] = hostoptions["rootfs"]
+    hostoptions["homefs"] = hostoptions["rootfs"]
 
 
 
@@ -1720,10 +1961,12 @@ def main(argv):
     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)
 
 
-- 
cgit v0.12

