From 0b2b9b97e95f8f8bfda1d1fe09136d121cd0750d Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Mon, 12 Jan 2009 13:12:50 -0600
Subject: Fixed UUID detection for upgrades when /myth is NOT partition 3 Fixed
 missing xorg.conf on install for "unsupported cards". The problem was due to
 X-configure not running because X was already running for the install.

---
 abs/core-testing/LinHES-config/PKGBUILD            |   2 +-
 .../LinHES-config/install_functions.sh             |   8 +-
 abs/core-testing/LinHES-config/install_proxy.sh    | 112 +++++++++++++++------
 .../LinHES-config/restore_km_db_chroot.sh          |   2 +-
 abs/core-testing/LinHES-config/xconfig.sh          |  23 ++++-
 5 files changed, 107 insertions(+), 40 deletions(-)

diff --git a/abs/core-testing/LinHES-config/PKGBUILD b/abs/core-testing/LinHES-config/PKGBUILD
index aac97cc..3e7d05e 100755
--- a/abs/core-testing/LinHES-config/PKGBUILD
+++ b/abs/core-testing/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=1.0
-pkgrel=154
+pkgrel=172
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev )
 pkgdesc="Install and configure your system"
 depends=(bc libstatgrab  mysql-python expect curl dnsutils parted sg3_utils nmbscan )
diff --git a/abs/core-testing/LinHES-config/install_functions.sh b/abs/core-testing/LinHES-config/install_functions.sh
index f9b2a4c..b412663 100755
--- a/abs/core-testing/LinHES-config/install_functions.sh
+++ b/abs/core-testing/LinHES-config/install_functions.sh
@@ -444,10 +444,16 @@ case $1 in
                       SWAPUUID=$FOUNDUUID
 
                       FOUNDUUID=""
-                      find_uuid ${2}3
+                      if [ x$4 = x ]
+                      then
+                        find_uuid ${2}3
+                      else
+                        find_uuid $4
+                      fi
                       DATAUUID=$FOUNDUUID
 
 
+
                      sed -i -e "s/.*\/\ .*$/UUID=$ROOTUUID \/  auto defaults,noatime 0 1/g"  /$mountpoint/etc/fstab
                      sed -i -e "s/.*\/myth\ .*$/UUID=$DATAUUID \/myth  auto defaults,noatime 0 1/g" /$mountpoint/etc/fstab
                      sed -i -e "s/.*swap\ .*$/UUID=$SWAPUUID swap swap defaults  0/g" /$mountpoint/etc/fstab
diff --git a/abs/core-testing/LinHES-config/install_proxy.sh b/abs/core-testing/LinHES-config/install_proxy.sh
index 670238b..175d7f9 100755
--- a/abs/core-testing/LinHES-config/install_proxy.sh
+++ b/abs/core-testing/LinHES-config/install_proxy.sh
@@ -21,7 +21,7 @@ BACKUPFILE="/myth/backup/mythconverg.sql.gz"
 #eval MYTHIP=\$${TEMPNET}
 
 function cp_and_log () {
-    ls $1 2>&1 >/dev/null
+    ls $1 >/dev/null 2>&1
     status=$?
     if [ $status = 0 ]
     then
@@ -33,6 +33,17 @@ function cp_and_log () {
 
 }
 
+function mdadm_find () {
+
+    PREFIX=$1
+    if [ -e $PREFIX/etc/KnoppMyth-version ]
+    then
+        MDADM_CONF="/etc/mdadm/mdadm.conf"
+    else
+        MDADM_CONF="/etc/mdadm.conf"
+    fi
+    echo "Using $MDADM_CONF"
+}
 
 progress () {
 mypercent=`echo "$1" | cut -d. -f1`
@@ -70,26 +81,44 @@ function apply_new_auth () {
 function backup_sql_check {
     if [ -f ${mountpoint}${BACKUPFILE} ]
     then
-
         echo "found ${mountpoint}${BACKUPFILE} "
-        return 0
+        rc=0
     else
         echo "did not find ${mountpoint}${BACKUPFILE} "
-        return 1
+        rc=1
     fi
+    return $rc
 }
 
 function upgrade_mount_search {
-    MYTH_P=`cat /tmp/etc/fstab |grep /myth| awk ' {print $1 '} `
+
+    MYTH_P=`cat /tmp/etc/fstab |grep -E /myth[[:space:]] | awk ' {print $1 '} `
     umount $mountpoint/myth
+    echo $MYTH_P |grep -q \/md.
+    if [ $? = 0 ]
+    then
+        mdadm_find /tmp
+        mdadm --assemble -c /tmp${MDADM_CONF} $MYTH_P
+        sleep 2
+        fsck -p $MYTH_P
+    fi
     mount $MYTH_P $mountpoint/myth
+    echo mount $MYTH_P $mountpoint/myth
+    sleep 2
     backup_sql_check
     if [ $? = 1  ]
     then
         mkdir -p /new_boot/root/backup
-        cp_and_log  /tmp/mythconverg.sql.gz  /new_boot/root/backup/mythconverg.sql.gz
-        BACKUPFILE="/root/backup/mythconverg.sql.gz"
-        echo "setting BACKUPFILE to $BACKUPFILE"
+        if [ ! -e /tmp/mythconverg.sql.gz ]
+        then
+            echo "Couldn't find ANY database to restore, upgrade will continue but a new database will be installed."
+        else
+            cp_and_log  /tmp/mythconverg.sql.gz  /new_boot/root/backup/mythconverg.sql.gz
+            BACKUPFILE="/root/backup/mythconverg.sql.gz"
+            echo "setting BACKUPFILE to $BACKUPFILE"
+        fi
+    else
+    MYTHMOUNT=`basename $MYTH_P`
     fi
     return 0
 }
@@ -135,6 +164,7 @@ full_install () {
         #progress 100
         sleep 1
         cp_and_log  /etc/systemconfig "$mountpoint"/etc
+        cp_and_log /root/xorg.conf.install "$mountpoint"/etc/X11/xorg.conf.install
         #run save syssettings to save settings, then copy to new mountpoint
         $MV_ROOT/bin/restore_default_settings.sh  -c save -t syssettings -h $MVHOSTNAME -d localhost
         SE=$TEMPLATES/settings/syssettings
@@ -247,7 +277,9 @@ function upgrade () {
         cp_and_log  "/new_boot/etc.old/ssh/*.pub"   /new_boot/etc/ssh/
         cp_and_log "/new_boot/etc.old/ssh/*.key"   /new_boot/etc/ssh/
         cp_and_log "/new_boot/etc.old/ssh/*key"  /new_boot/etc/ssh/
-        cp_and_log  /new_boot/etc.old/mdadm/mdadm.conf /new_boot/etc/
+        mdadm_find /tmp
+        cp_and_log /tmp${MDADM_CONF} /new_boot/etc
+        #cp_and_log  /new_boot/etc.old/mdadm/mdadm.conf /new_boot/etc/
         cp_and_log /new_boot/etc.old/asound.state /new_boot/etc/
         if [ ! -f /tmp/etc/KnoppMyth-version ]
         then
@@ -265,7 +297,13 @@ function upgrade () {
         cp_and_log  /etc/systemconfig "$mountpoint"/etc/systemconfig
         echo "Configuring system" > /tmp/.install_state
         progress 100
-        $run fstab_fix_it $disk UPGRADE
+        backup_sql_check
+        if [ $? = 1 ]
+        then
+            upgrade_mount_search
+        fi
+        echo $run fstab_fix_it $disk UPGRADE $MYTHMOUNT
+        $run fstab_fix_it $disk UPGRADE $MYTHMOUNT
 
 
         #echo "Writing boot sector" > /tmp/.install_state
@@ -277,12 +315,13 @@ function upgrade () {
         sleep 1
         cp_and_log /etc/mtab "$mountpoint"/etc/mtab
         cp_and_log  /etc/systemconfig "$mountpoint"/etc
+        cp_and_log /root/xorg.conf.install "$mountpoint"/etc/X11/xorg.conf.install
 #make sure mythconverg.sql.gz is present
-        backup_sql_check
-        if [ $? = 1 ]
-        then
-            upgrade_mount_search
-        fi
+        #backup_sql_check
+        #if [ $? = 1 ]
+        #then
+        #    upgrade_mount_search
+        #fi
         echo $CMDLINE | grep -q clean_upgrade
         status=$?
         if [  -f /tmp/etc/KnoppMyth-version -o  $status = 0 ]
@@ -355,8 +394,8 @@ function upgrade () {
         if [  -f /tmp/etc/KnoppMyth-version ]
         then
            chroot "$mountpoint" $MV_ROOT/bin/restore_default_settings.sh -c restore -t hostsettings
-	    #change permissions of /myth (only needed on km->linhes)
-	       chown -R mythtv:mythtv $mountpoint/myth
+        #change permissions of /myth (only needed on km->linhes)
+           chown -R mythtv:mythtv $mountpoint/myth
            chown -R root:root $mountpoint/myth/backup
         else
            chroot "$mountpoint" $MV_ROOT/bin/restore_default_settings.sh -c restore -t syssettings
@@ -365,6 +404,8 @@ function upgrade () {
         #Run second time
         chroot "$mountpoint" $MV_ROOT/bin/systemconfig.sh misc,hostype,network,advanced,this_is_install
         chroot "$mountpoint" $MV_ROOT/bin/systemconfig.sh advanced,this_is_install
+        echo "stopping mysql in chroot"
+        chroot "$mountpoint" /etc/rc.d/mysqld stop
         apply_new_auth
         kill_dhcp_chroot
         umount -l "$mountpoint/dev"
@@ -438,6 +479,8 @@ echo "-----------------------------------------------------------------------3--
             then
                 $run mount_it $disk
                 [ -e "/new_boot/root/backup/mythconverg.sql.gz" ] && cp /new_boot/root/backup/mythconverg.sql.gz /tmp
+
+
                 if [ -f /new_boot/etc/systemconfig ]
                 then
                 ###########ADD templates
@@ -449,6 +492,7 @@ echo "-----------------------------------------------------------------------3--
                     cp_and_log   /new_boot/etc /tmp/etc
                     cp_and_log  /new_boot/var/lib/oss  /tmp/oss
                     [ -e /tmp/etc/mdadm.conf ] && cp_and_log  /tmp/etc/mdadm.conf /etc/
+
                     $MV_ROOT/bin/restore_default_settings.sh -c restore -t syssettings -h $MVHOSTNAME  -d 127.0.0.1
                 else
                     cp_and_log   /new_boot/etc /tmp/etc
@@ -466,7 +510,11 @@ echo "-----------------------------------------------------------------------3--
                             $run update_db_it  HostTimeZoneRegion_$TZREGION "$TZSUB"
                     fi
                 fi
-            $run umount_it $disk
+                backup_sql_check
+                echo $?
+                upgrade_mount_search
+                echo $?
+                $run umount_it $disk
             fi
             ;;
 
@@ -512,15 +560,15 @@ echo "-----------------------------------------------------------------------3--
                                             /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
+                                            if  [ !  x$mygwdefault = x ]
+                                            then
                                                 sleep 2
-	                                            ping -c 5 $mygwdefault
-        	                                    if [ ! $? = 0 ]
-                	                            then
-                        	                        exit 4
-                                	      	    fi
-				                            fi
+                                                ping -c 5 $mygwdefault
+                                                if [ ! $? = 0 ]
+                                                then
+                                                    exit 4
+                                                fi
+                                            fi
                                 ;;
                                 check_ns)
                                             #check nameserver
@@ -573,12 +621,12 @@ echo "-----------------------------------------------------------------------3--
 
 
         * )
-	    if [ -f /tmp/.install_state ]
-	    then
-            	state=`cat /tmp/.install_state`
-	    else
-		state=" "
-	    fi
+        if [ -f /tmp/.install_state ]
+        then
+                state=`cat /tmp/.install_state`
+        else
+        state=" "
+        fi
             if  [  x"${state}" =  "xConfiguring system" ]
             then
                 progress ""
diff --git a/abs/core-testing/LinHES-config/restore_km_db_chroot.sh b/abs/core-testing/LinHES-config/restore_km_db_chroot.sh
index 71328f2..e72e8c2 100644
--- a/abs/core-testing/LinHES-config/restore_km_db_chroot.sh
+++ b/abs/core-testing/LinHES-config/restore_km_db_chroot.sh
@@ -54,7 +54,7 @@ if  [ $SystemType = "Master_backend" -o $SystemType = "Standalone"  ]
         exit 0
     fi
 
-/etc/rc.d/mysqld stop
+#/etc/rc.d/mysqld stop
 #umount /proc
 
 
diff --git a/abs/core-testing/LinHES-config/xconfig.sh b/abs/core-testing/LinHES-config/xconfig.sh
index ef3e836..1d845b0 100755
--- a/abs/core-testing/LinHES-config/xconfig.sh
+++ b/abs/core-testing/LinHES-config/xconfig.sh
@@ -189,9 +189,9 @@ function setupX {
                             fi
                     fi
                                 ;;
-            VMware )
-                    sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.vmware > $XORG_CONF
-                    ;;
+      #      VMware )
+      #              sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.vmware > $XORG_CONF
+      #              ;;
 
             VIA )
                     sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.via > $XORG_CONF
@@ -213,9 +213,22 @@ function setupX {
 
         vesa)  sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $TEMPLATES/xorg/xorg.conf.vesa > $XORG_CONF
         ;;
-    *)      XCONF=/root/xorg.conf.new
+    *)
+            XCONF=/root/xorg.conf.new
+            XCONFB=/etc/X11/xorg.conf.install
             X -configure
-            grep -v Modes  $XCONF | sed -e '/Depth.*16/a Modes "800x600"' -e '/Depth.*24/a Modes "800x600"' -e 's/dev\/mouse/dev\/psaux/g'> $XORG_CONF
+            if [ -f $XCONF ]
+            then
+                echo "Using $XCONF"
+                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
+
+            elif [ -f $XCONFB ]
+            then
+                echo "Using $XCONFB"
+               sed -e "s/^.*Modes.*$/\t Modes \"${Xres}\"/" $XCONFB > $XORG_CONF
+            else
+                echo "Xorg configuration failed"
+            fi
             rm -f $XCONF 2>&1 > /dev/null
         ;;
         esac
-- 
cgit v0.12