#!/bin/ash

echo " *** copysys:   macht Installierung  incl. lilo *** "

mkdir -p /von  ; mkdir -p /nach 


# 1. Einlesen der Install-Details von  installinfo  ,  insbesondere nach welcher Partition NACH auf Platte NACO0 installieren

read TST SIZE NACH0  NACH  VON  KLEINER  WINDOWS REST  <  installinfo 
echo " Install-Platte:  "  $NACH0  "  Install-Partition:   " $NACH   " Groesse: " $SIZE 

echo  " Installieren  nach Partition  "   $NACH   "  auf Platte   "   $NACH0     


# 2. Suchen in welcher device VON das Install-CD/DVD ist  

VON=" "
for I0 in hda hdb hdc hdd sda sdb sdc sdd ; do
#test /dev/$I0 = $NACH ; if test $? -ne 0 ; then       # Abfrage z.Ausschluss v. Hard-Disk gibt Probleme / Halten / Rueckfrage 
/bin/mount /dev/$I0 /von -t iso9660 -o ro  ;  if test $? -ne 0 ; then VON=/dev/$IO ; fi  
#fi ; 
done
#if test $VON = " " ; then echo " Problem Install-Quelle " ; sleep 20 ; ./rescue ; fi ;        #  wurde keine Quelle gefunden 
# Ignorieren da a) Fehlermeldung falls schon gemountet und b) CD jedenfalls zum Start der Install da war
#echo  " 3. Installieren  von:  "   /dev/$IO 

# Jetzt ist jedenfalls das CD von dem zu installieren ist nach /von gemountet ...  auch wenn device VON unbestimmt ist :(



# 3. kompaktiertes System SYS_Linux.ext3.lmza in device VON   nach  Partition  NACH  deskompaktieren / kopieren

#/bin/dd if=/von/SYS_Linux.ext3 of=$NACH                # falls normal kopiert
/bin/bunzip2 -c /von/SYS_Linux.ext3.bz2 > $NACH         # falls kompaktiert  mit bzip2 -9 -fck $VON > /SYS_linux.ext3.bz2 
/bin/lzmacat /von/SYS_Linux.ext3.lzma > $NACH                 #   "   lzma -7 -fk  
sync 
resize2fs -fp $NACH
sync 
/bin/mount $NACH /nach    ; if test $? -ne 0 ; then echo " Problem Install-Ziel " ; sleep 20; ./problem ; fi ;
#ROOT=/nach upgradepkg --install-new --reinstall /von/"*".tgz
#/von/'*'.sh   
#echo  "System kopiert  und als  /nach  gemountet"

echo " was jetzt alles gemountet ist:  " 
/bin/mount
echo " gerade installiertes System:    device: "   $NACH  "gemountet: /nach"    
/bin/ls  /nach


# 4. fstab , lilo.conf   der Installierung   anpassen,  lilo im MBR von Platte   NACH0  installieren 

echo " 3. lilo.conf  und fstab  auf "  $NACH " einrichten:     Partition-Nr mit Windows: "  $WINDOWS
 
cd /nach/etc

cat lilo.conf > lilo.conf.old      
echo "  root = " $NACH  "  "  > lilo.conf     # neue root-Zeile
grep -v "root" lilo.conf.old  >> lilo.conf    # Kopie von lilo.conf  OHNE  alter  root -Zeile
if test $WINDOWS -ne 0 ; then  echo "#other = "  $NACH0$WINDOWS >> lilo.conf ;    echo "#  label = Windows " >> lilo.conf ; fi ;

mkdir  -p /nach/"$NACH0"1 ; mkdir -p /nach/"$NACH0"2 ; mkdir -p /nach/"$NACH0"3 ; mkdir -p /nach/"$NACH0"4   # kann schon vorher in SYS gemacht werden  
if test $WINDOWS -ne 0 ; then   mkdir -p /nach/Windows ; fi ;  

cat fstab > fstab.old
echo $NACH "   /  auto  defaults  0  1  " > fstab
echo "$NACH0"1  /hda1 "  auto   defaults    0    0 " >> fstab                 #     dgl.
echo "$NACH0"2  /hda2 "  auto   defaults    0    0 " >> fstab                 #     dgl.
echo "$NACH0"3  /hda3 "  auto   defaults    0    0 " >> fstab                 #     dgl.
echo "$NACH0"4  /hda4 "  auto   defaults    0    0 " >> fstab                 #     dgl.
if test $WINDOWS -ne 0 ; then echo $NACH0$WINDOWS "  /Windows  ntfs-3g   defaults   0   0   " >> fstab ; fi ;   # ntfs-3g muss in SYS vhd sein     
grep -v " / " fstab.old >> fstab 
sync 

rdev /nach/boot/vmlinuz $NACH ; rdev -R /nach/boot/vmlinuz 1  
rdev /nach/boot/initrd.gz $NACH ; redv -R /nach/boot/initrd.gz 1  

echo " jetzt in Ziel-Partition da:   "
/bin/ls  /nach

echo "  lilo auf " $NACH " mit boot-device " $NACH0 "  ausfuehren:  " 
chroot /nach  /bin/mount proc /proc -t proc
chroot /nach /sbin/lilo   -b $NACH0    # letzteres weg falls Probleme
chroot /nach sync 
#echo " lilo  auf erzeugter Part. nach chroot, vergleiche mit oben"
#chroot /nach ls -l  /sbin/lilo



# 5. Konfiguration  

echo " Alle sonstigen / komplizierteren Konfigs  im Zielsystem machen "

# /bin/umount  /von  
echo " *** Ende copysys " 

