Nils Olav Fossum wrote:
Torsdag 29 mars 2007 11:38, skrev Mario Gzuk:
Hi,
I will give it a try to involve you into the secrets behind the windows
installation. I will place a step by step howto on my side and hope you
will understand my bad english.

nice!

heh, youre English is better than mine.

Well... Both of your guys english is WAY better than my German or Swedish.. So, I greatly appreciate the translation!

Please find both the init.functions and my hacked up version of the 0install file ( previously included inline, now called 'begin' ).

I modified several of the routines in init.functions... Don't use dialog at all.. Check it out. :)

Thanks guys!
Michael


#!/bin/bash

LOGTTY=/dev/tty4
BASEDIR=/z/linuxaux/etc

source $BASEDIR/init.functions


function mbr_disk () {
  REPLACEMBR=`parse_ini_file /tmp/unattend.txt _meta replace_mbr`
  if [ "$REPLACEMBR" == "1" ]; then
    BOOTNUMBER=`parted /dev/dsk print | grep "boot" | awk '{print $1}'`
    dd if=$BASEDIR/binary/freedos-mbr.bin of=/dev/dsk bs=1 count=446 > $LOGTTY 
2>&1
    dd if=$BASEDIR/binary/ntldr_boot_code_sector0 of=/dev/dsk$BOOTNUMBER bs=1 
count=420 seek=90 > $LOGTTY 2>&1
    dd if=$BASEDIR/binary/ntldr_boot_code_sector12 of=/dev/dsk$BOOTNUMBER 
bs=512 count=1 seek=12 > $LOGTTY 2>&1
  fi
}

#disable kernel messages
echo "0" > /proc/sys/kernel/printk



active_part_line=`parted -s /dev/dsk print | grep 'boot'`
active_part=`echo $active_part_line | awk '{print $1}'`
if [ -z "$active_part" ]
then
        echo "Partition table:" >&2
        parted /dev/dsk print >&2
        die "No active partition found!"
fi
#replace of the dosemu part....
#write bootcode into mbr and the bootable fat32 partition
BOOTNUMBER=`parted /dev/dsk print | grep "boot" | awk '{print $1}'`
# parted -s /dev/dsk -- mkfs $BOOTNUMBER fat32 > $LOGTTY 2>&1
message_start "Formatting C: FAT32"
mkdosfs -F 32 /dev/dsk${BOOTNUMBER} > $LOGTTY 2>&1
message_end

message_start "Replace mbr"
mbr_disk
message_end

#mount /c
mv /c /OLDc
mkdir /c
message_start "Mount /c"
mount -t vfat /dev/dsk$BOOTNUMBER /c > $LOGTTY 2>&1
message_end
mv /OLDc/* /c/

#boot ini
message_start "Creating boot.ini"
echo "[Boot Loader]" >/c/boot.ini
echo "Timeout=2" >>/c/boot.ini
echo "Default=C:\\\$WIN_NT$.~BT\BOOTSECT.DAT" >>/c/boot.ini
echo "[Operating Systems]" >>/c/boot.ini
echo "C:\\\$WIN_NT$.~BT\BOOTSECT.DAT = \"Installation/Update 
Windows\"">>/c/boot.ini
message_end

#creating directorys
message_start "Creating /c/\$"
mkdir /c/\$ > $LOGTTY 2>&1
message_end
message_start "Creating /c/\$win_nt\$.~bt"
mkdir /c/\$win_nt\$.~bt > $LOGTTY 2>&1
message_end
message_start "Creating /c/\$win_nt\$.~bt/system32"
mkdir /c/\$win_nt\$.~bt/system32 > $LOGTTY 2>&1
message_end
message_start "Creating /c/\$win_nt\$.~ls"
mkdir /c/\$win_nt\$.~ls > $LOGTTY 2>&1
message_end

#bootsect.dat
message_start "Creating bootsect.dat"
dd if=/dev/dsk$BOOTNUMBER of=/c/\$win_nt\$.~bt/bootsect.dat bs=512 count=1 > 
$LOGTTY 2>&1
dd if=$BASEDIR/binary/ntldr_boot_code_install of=/c/\$win_nt\$.~bt/bootsect.dat 
bs=1 count=420 seek=90 conv=notrunc > $LOGTTY 2>&1
message_end

# exit 1;

#copy files
OS_media=`parse_ini_file /c/netinst/unattend.txt _meta OS_media`
OS_DIR=`echo $OS_media | awk -F: '{print $2}' | sed 's/\\\/\\//g'`
OS_DIR="/z$OS_DIR"

if [ -d "$OS_DIR/amd64" ]
then
        ARCH=amd64
        OS_INSTALL_DIR="$OS_DIR/amd64"
else
        ARCH=i386
        OS_INSTALL_DIR="$OS_DIR/i386"
fi
copy_files "$OS_INSTALL_DIR/" "/c/\$win_nt\$.~bt/" 2 "Copy installation files."
copy_files "$OS_INSTALL_DIR/system32/" "/c/\$win_nt\$.~bt/system32/" 2 "Copy 
system32."
copy_files "$OS_INSTALL_DIR/" "/c/\$win_nt\$.~ls/" 1 "Copy system"
if [ "$ARCH" == "amd64" ]

then
        copy_files "$OS_DIR/i386/" "/c/\$win_nt\$.~ls/" 1 "Copy i386 system"
fi

copy_files "$OS_DIR/i386/ntldr" "/c/" 3 "Copy ntldr."
copy_files "$OS_DIR/i386/ntdetect.com" "/c/" 3 "Copy ntdetect.com."
copy_files "$OS_DIR/i386/setupldr.bin" "/c/\$ldr\$" 3 "Copy setupldr.bin."
copy_files "$OS_INSTALL_DIR/txtsetup.sif" "/c/" 3 "Copy txtsetup.sif."
#write_ini_entry /c/netinst/unattend.txt "GuiUnattended" "AutoLogon" "Yes"
#write_ini_entry /c/netinst/unattend.txt "Data" "MsDosInitiated" "1"
#write_ini_entry /c/netinst/unattend.txt "Data" "floppyless" "1"
#write_ini_entry /c/netinst/unattend.txt "Data" "OriSrc" "A:\I386"
#write_ini_entry /c/netinst/unattend.txt "Data" "OriTyp" "5"
copy_files "/c/netinst/unattend.txt" "/c/\$win_nt\$.~bt/winnt.sif" 3 "Copy 
winnt.sif."
#move files/drivers to the right pace.....
message_start "Move driver direcory"
mv /c/\$win_nt\$.~ls/$ARCH/\$[Oo][eE][mM]\$/* /c/\$/ > $LOGTTY 2>&1
message_end

#end umount /c
message_start "Umount /c"
umount /c
message_end

exit 0
#functions for use with init scripts
#source the main configuration
# if [ -r "/z/etc/init.conf" ]
# then
#       source /z/etc/init.conf
# else
#       die "/z/etc/init.conf not found."
# fi

RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"

ZER_COL=0
MOVE_TO_ZERO="echo -en \\033[${ZER_COL}G"


#FUNCTIONS
function count_tabs()
        {
        STRLEN=`echo "$1" | wc -c`
        MAXLEN=$2
        TABS="" 
        let STRMOD="$STRLEN % 8"
        if [ $STRMOD != 0 ]; then
                let DIFF="8-$STRMOD+1"
                let STRLEN="$STRLEN+$DIFF"
        fi
        while [ $STRLEN -lt $MAXLEN ]; do
                TABS="$TABS\\t"
                let STRLEN="$STRLEN + 8"
        done

        echo $TABS
        }

function message_start()
        {
#       TABS=`count_tabs "$1" 60`\
        TABS=""
        if [ "$2" == "fail" ]
        then
                echo -en " \E[1;31m*\E[1;37m $1$TABS"
        else
                echo -en " \E[1;34m*\E[1;37m $1$TABS"
        fi
        $MOVE_TO_COL
        }
function message_end()
        {
        if [ "$?" == "0" ] && [ "$1" == "" ]
        then
                echo -e "[  \E[1;32mOK\E[1;37m  ]"
        else
                if [ "$1" == "fail" ]
                then
                        echo -e "[\E[1;31mFAILED\E[1;37m]"
                else
                        echo -e "[\E[1;31mFAILED\E[1;37m]"
                fi
        fi
        }

function die ()
        {
        echo -e "\E[1;[EMAIL PROTECTED];37m" >&2
        message_start "Dropping to shell"
        message_end
        exec /bin/bash --rcfile /.bashrc
        }

function get_cmdline_param ()
        {
        CMDLINE="$(cat /proc/cmdline)"
        for token in $CMDLINE $unattend
        do
                local var=${token%%=*}
                if [ "$var" == "$1" ]
                then
                        echo "$token"
                        return
                fi
        done
        }

function ask_sq ()
        {
        read -p "-> $1" ANSWER
        if [ "$ANSWER" ]
        then
                return
        else
                ANSWER=$2
                return
        fi
        }

function read_pass ()
        {
        PASS=
        echo "-> $1"
        echo -n "-> Enter password: "
        STTYSETTINGS=`stty -g`
        stty -echo
        read secret1
        stty $STTYSETTINGS 
        echo
        echo -n "-> Repeat password: "
        stty -echo
        read secret2
        stty $STTYSETTINGS 
        echo
        if [ "$secret1" == "$secret2" ]
        then
                PASS=$secret1
        else
                echo "Passwords do not match. Please try again."
                read_pass
        fi
        }

function parse_ini_file ()
        {
        # options are
        # 1 the ini file
        # 2 the sektion name
        # 3 the key name
        if [ -r $1 ]
        then
                cat $1 |  sed 's/;/#/' | sed -e 
's/[[:space:]]*\=[[:space:]]*/=/g'  -e 's/;.*$//'  -e 's/[[:space:]]*$//'  -e 
's/^[[:space:]]*//'  -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" | sed -n -e 
"/^\[$2\]/,/^\s*\[/{/^[^;].*\=.*/p;}" | sed 's/\\/\\\\/g' | while read LINE
                do
                        MATCH=`echo $LINE | awk -F\= '{print $1}'`
#                       M1=`echo $MATCH | tr '[A-Z]' '[a-z]'`
#                       M2=`echo $3 | tr '[A-Z]' '[a-z]'`
#                       if [ "$M1" == "$M2" ]
                        M1=`echo $MATCH | grep -i "^$3"`
                        if [ x"$M1" != x"" ]
                        then
                                echo $LINE | awk -F\= '{print $2}' | sed 
's/^"//' | sed 's/"$//'
                        fi
                done
        fi
        }

# replace_ini(file, section, key, value)
#
# Write $key with $value into $section from $file.
# If it already exists, overwrite it.
#
# Unwanted side-effects:
#       * Double entries within a section get killed!
#         (They shouldn't be there anyway, though...)
#       * Entries may lose their order
#
function write_ini_entry()
        {
        local myfile=$1 mysec=$2 mykey=$3 myval=`echo $4 | sed 
's#\\\\#\\\\\\\\#g'` tmp=$1.$$
        cat /dev/null > $tmp
        awk "
                BEGIN   {
                        # Indicate if we are within the right section
                        in_desired_section = 0;

                        # Indicate if we should write the entry as
                        # fast as possible.
                        write_now = 0;

                        # If 1, delete any further occurences
                        have_written = 0;
                        }

                # Section matching
                /\[.*\]/ {
                        if (\$1 ~ /\[$mysec\]/) {
                                in_desired_section = 1;
                                write_now = 1;
                        } else {
                                in_desired_section = 0;
                        }

                        print \$0;
                }

                # Key assignment matching
                /.*=.*/ {
                        if (\$1 ~ /$mykey/) {
                                if (in_desired_section == 0) {
                                        print \$0;
                                } else {
                                        # Skip HERE to purge old value
                                }
                        } else {
                                print \$0;
                        }
                }

                # Run on every line
                {
                        if (write_now == 1) {
                                printf \"$mykey = \\\"$myval\\\"\n\";
                                write_now = 0;
                                have_written = 1;
                        }
                }
                END     {
                        if (have_written == 0)
                                {
                                printf \"[$mysec]\n$mykey = \\\"$myval\\\"\n\";
                                }
                        }
                                
        " $myfile >> $tmp
        mv $tmp $myfile
        }

function udhcp_back ()
        {
        cat /dev/null > /var/run/dhcp.out
        for INETADDR in `ifconfig | grep "inet addr" | grep -v "127.0.0.1" | 
awk -F: '{print $2}' | awk '{print $1}'`
        do
                INTERFACE=`ifconfig | grep -B 1 "$INETADDR" | grep "^[^ ]" | 
awk '{print $1}'`
                echo "interface=$INTERFACE" >> /var/run/dhcp.out
                echo "ip=$INETADDR" >> /var/run/dhcp.out
        done
        }

function copy_files ()
        {
        #$1 = file or directory
        #$2 = destination
        #$3 = 1 complete directory and subdirs
        #$3 = 2 only content from directory
        #$3 = 3 only file
        #$4 = title
        DIR=${1%/}
        DIR="$DIR/"
        case "$3" in
                "1")
                #check if directory exist
                DESTINATIONDIR="$2/`basename $1`"
                if [ ! -d $DESTINATIONDIR ]
                then
                         mkdir -p "$DESTINATIONDIR" > $LOGTTY 2>&1
                fi
                #first create directorys
                find $DIR -type d -follow | while read CREATEDIR
                do
                        NEWDIR=${CREATEDIR#$DIR}
                        mkdir -p "$DESTINATIONDIR/$NEWDIR" > $LOGTTY 2>&1
                done
                ORGCOUNTER=`find $DIR -type f -follow 2> /dev/null | wc -l`
                COUNTER=0
                echo $4
                find $DIR -type f -follow | while read FILE
                do
                        let COUNTER="$COUNTER+1"
                        let COPYSTATUS="100 * $COUNTER / $ORGCOUNTER"
                        status="Percent: $COPYSTATUS - Copy file: $FILE"
                        display_status "$status"
                        DEST=`dirname $FILE`/
                        NEWFILE=${DEST#$DIR}
                        cp "$FILE" "$DESTINATIONDIR/$NEWFILE/" > $LOGTTY 2>&1
                        LAST=$COPYSTATUS
                done
                echo
                ;;
                "2")
                ORGCOUNTER=`ls $DIR 2> /dev/null | wc -l`
                COUNTER=0
                echo $4
                ls $DIR | while read FILENAME
                do
                        FILE=${DIR}${FILENAME}
                        if [ -d $FILE ]; then continue; fi
                        let COUNTER="$COUNTER+1"
                        let COPYSTATUS="100 * $COUNTER / $ORGCOUNTER"
                        status="Percent: $COPYSTATUS - Copy file: $FILE"
                        display_status "$status"
                        #echo $COPYSTATUS | dialog --title "$4" --gauge "Copy 
file: $FILE" 10 60
                        cp "$FILE" "$2" > $LOGTTY 2>&1
                        LAST=$COPYSTATUS
                done
                echo
                ;;
                "3")
                message_start "$4"
                cp "$1" "$2" > $LOGTTY 2>&1
                message_end
                ;;
                *)
                #option not given dont do anything...
                ;;
        esac
        }

function display_status () {
  STRLEN=`echo $1 | wc -c`
  if [ $STRLEN -gt 75 ]; then
    let DIFF="$STRLEN-75"
    COUNT=0
    DOTS=""
    while [ $COUNT -lt $DIFF ]; do
      DOTS="$DOTS."
      let COUNT="$COUNT+1"
    done
    SPACED=`echo $1 | sed -e 's/file:\ '$DOTS'/file: .../'`
  else
    let DIFF="78-$STRLEN"
    COUNT=0
    DOTS=""
    while [ $COUNT -lt $DIFF ]; do
      DOTS="$DOTS."
      let COUNT="$COUNT+1"
    done
    SPACED="$1$DOTS"
  fi
  $MOVE_TO_ZERO
  echo -en " \E[1;31m*\E[1;37m $SPACED"
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
unattended-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unattended-devel

Reply via email to