All pastes #72500 Raw Edit

Miscellany

public text v1 · immutable
#72500 ·published 2006-06-26 22:24 UTC
rendered paste body
#!/bin/sh
#

# Make the mount point to mount the original dvd iso
#   mkdir /mnt/temp 

# Make the directory where the original files will be copied to from DVD ISO (including its empty updates directory)
#   mkdir /mnt/hdb1/opensuse/suse/iso/10.1

# Mount the original ISO
#   mount -t iso9660 -o loop /mnt/hdb1/opensuse/GM/SUSE-10.1-0-DVD.iso /mnt/temp

# Copy the data to the new directory
#   cp -af /mnt/temp/* /mnt/hdb1/opensuse/suse/iso/10.1

# rsync the updates to /mnt/hdb1/opensuse/suse/update/10.1
#   susemake.sh 1 

# Update the files in the iso based directory with those brought down via rsync
#   susemake.sh 2

# Make dvd iso
#   susemake.sh 3

set +x

case $1 in
    1)
        ###########################################################################################
        #   THIS SECTION SYNCS A LOCAL COPY OF I386 UPDATES WITH REMOTE SERVER USING RSYNC        #
        ###########################################################################################

        # No trailing slashes
        #RemoteServer="rsync://gd.tuwien.ac.at/opsys/linux/suse.com/suse/update/10.1"
        #RemoteServer="rsync://ftp.belnet.be/mirrors/ftp.suse.com/suse/update/10.1"
        #RemoteServer="rsync://ftp.gwdg.de/pub/suse/update/10.1"
        RemoteServer="rsync://ftp-1.gwdg.de/pub/suse/update/10.1"

        LocalServer="/mnt/hdb1/opensuse/suse/update/10.1"

        if [ ! -d $LocalServer ]; then
            echo "$LocalServer does not exist."
            exit 1
            echo
        fi

        RemoteLocation=/repodata/
        LocalLocation=/repodata/
        rsync -aurv --progress --delete --ignore-errors --force --exclude=*.patch.rpm --exclude=*.delta.rpm --delete-excluded $RemoteServer$RemoteLocation $LocalServer$LocalLocation

        RemoteLocation=/rpm/
        LocalLocation=/rpm/
        rsync -aurv --progress --delete --ignore-errors --force --exclude=ppc --exclude=ppc64 --exclude=src --exclude=x86_64 --exclude=*.patch.rpm --exclude=*.delta.rpm --delete-excluded $RemoteServer$RemoteLocation $LocalServer$LocalLocation

        RemoteLocation=/scripts/
        LocalLocation=/scripts/
        rsync -aurv --progress --delete --ignore-errors --force --exclude=*.patch.rpm --exclude=*.delta.rpm --delete-excluded $RemoteServer$RemoteLocation $LocalServer$LocalLocation

        echo
        echo "Rsync update complete"
        ;;

    2)
        ###########################################################################################
        #   THIS SECTION REPLACES OLDER FILES WITH UPDATED ONES                                   #
        ###########################################################################################

        # No trailing slashes
        Old="/mnt/hdb1/opensuse/suse/iso/10.1/suse"
        New="/mnt/hdb1/opensuse/suse/update/10.1/rpm"
        Rem="/mnt/hdb1/opensuse/suse/removed"

        if [ ! -d $Old ]; then
            echo "$Old does not exist."
            exit 1
            echo
        fi

        if [ ! -d $New ]; then
            echo "$New does not exist."
            exit 1
            echo
        fi

        if [ ! -d $Rem ]; then
            echo "$Rem does not exist."
            exit 1
            echo
        fi

        Rem2=$Rem/`date +%Y%m%d%H%M%S`
        mkdir $Rem2

        cd $New
        for d in *; do
            if [ -d $d ]; then
                cd "$New/$d"
                find *.rpm ! -name "*$d.*" |
                    while read a; do 
                        aa=${a%.rpm}
                        echo $aa |
                        while read aaa; do
                            cd "$Old/$d"
                            find *.rpm -name "$aaa-[0-9]*$d.rpm" |
                                while read bb; do
                                    cp $bb $Rem2
                                    rm $bb
                                done
                        done
                    done
            fi
            cd $New
        done
        echo
        echo "Removed old files"

        cd $New
        for d in *; do 
            if [ -d $d ]; then
                find $d/*$d.rpm | while read f; do cp $f $Old/$d/; done
            fi
        done
        echo
        echo "Copied new files"

        cd $New
        for d in *; do
            if [ -d $d ]; then
                find $d/*$d.rpm | 
                while read f; do
                    if [ ! -f $Old/$f ]; then
                        echo $f
                    fi
                done
            fi
        done
        echo
        echo "Missing files above"
        ;;

    3)
        ###########################################################################################
        #   THIS SECTION CREATES THE DVD ISO OF LOCAL SUSE TREE                                   #
        ###########################################################################################

        # No trailing slashes
        Version="060626"
        BaseDir="/mnt/hdb1/opensuse/suse/iso/10.1"
        OutputDir="/mnt/hdb1/opensuse"
        OutputDVD="SUSE-Linux-10.1.$Version-GM-DVD-i386.iso"

        if [ ! -d $BaseDir ]; then
            echo "$BaseDir does not exist."
            exit 1
            echo
        fi

        if [ ! -d $OutputDir ]; then
            echo "$OutputDir does not exist."
            exit 1
            echo
        fi

        LocalKey=`gpg --list-secret-keys $GpgKey|grep "^sec"|sed -e 's/.*\///;s/ .*//g;'|head -n 1`
	if [ "$LocalKey" == "" ]; then
	   echo "You ${bold}don't${off} seem to have a secret gpg key 
or the key ${bold}$GpgKey${off} you gave did not exist.
Lets now try to make one for you. Just follow instructions.
Use defaults, exept for the passphrase. Just press ${bold}ENTER${off} twice there.
The last that is added will be used.
"
	   gpg -q --gen-key
	   LocalKey=`gpg --list-secret-keys|grep "^sec"|sed -e 's/.*\///;s/ .*//g;'|tail -n 1`
	fi
	KeyLocal=`gpg --list-secret-keys $GpgKey|grep -A 1 $LocalKey|grep "^uid"|awk -Fuid '{print $NF}'`
	echo ""
	echo "The following key is being used. If you are asked to enter a passphrase,"
	echo "please enter the passphrase for that key."
	echo "${bold}$KeyLocal${off}"

        shopt -s nullglob
	for Initrd in $BaseDir/boot/*/loader/initrd $BaseDir/suseboot/initrd*; do
            echo ""
            echo "Initrd is $Initrd"
            if [ -f $Initrd ]; then
                gunzip < $Initrd > $Initrd.uncomp
                gpg --export -u 0x${LocalKey} > ${LocalKey}.gpg
                echo "${LocalKey}.gpg"|cpio -o -H newc -A -F $Initrd.uncomp
                gzip --best < $Initrd.uncomp > $Initrd
                rm $Initrd.uncomp ${LocalKey}.gpg
            fi
        done

        for d in $BaseDir/suse/*;
        do
            if [ -d $d ]; then
                cd $d
                if [ -f MD5SUMS ]; then
                    rm MD5SUMS
                fi
                find * -type f | while read ff; do md5sum $ff >> MD5SUMS 2>&1; done
            fi
        done

        Media1="$BaseDir/media.1"
        MediaText="Custom DVD"
        MediaDate= date +%Y%m%d%H%M%S
        mv $Media1 $Media1.bak
        rm $BaseDir/media.? -rf
        mv $Media1.bak $Media1
        cat > $Media1/media <<EOF
$MediaText
$MediaDate
1
EOF

        cat > $Media1/info.txt <<EOF

        Disclaimer

        This media is not produced by Novell or openSUSE!

        It is compiled using a custom script which has a few sections
        _borrowed_ from makeSUSEdvd :)

        makeSUSEdvd can be found at http://en.opensuse.org/Making_a_DVD_from_CDs

        If you are not 100% sure of the origin of this medium, please visit
        openSUSE and download from there or buy the boxed set.
        http://openSUSE.org

        If you want official support from Novell, please use the official  ISOs
        provided by them.

        Unofficial support can be found via http://en.opensuse.org/Communicate

        Also, many thanks to the guys in #bash for their time!

EOF

        ls -A1 $Media1 > $Media1/directory.yast

        cd $BaseDir/suse
        create_package_descr -x setup/descr/EXTRA_PROV -l english -l spanish -l french -l german -l czech -l hungarian -l italian -C

        cd $BaseDir/suse/setup/descr
        ls > directory.yast

        cd $BaseDir
        rm INDEX.gz ls-lR.gz
        ls -lR > ls-lR
        gzip ls-lR
        find . > INDEX
        gzip INDEX

        #Remove keys in content
	grep -v ^META $BaseDir/content > $BaseDir/content.bak
	mv $BaseDir/content.bak $BaseDir/content
	grep -v ^KEY $BaseDir/content > $BaseDir/content.bak
	mv $BaseDir/content.bak $BaseDir/content
	
        #Set the key
	gpg --export -a $LocalKey > $BaseDir/gpg-pubkey-${LocalKey}.asc
	
	# Sign files in /suse/setup/descr/
	for File in `ls $BaseDir/suse/setup/descr/`
	do
            echo "META SHA1 $(cd $BaseDir/suse/setup/descr/ && sha1sum ${File})" >> $BaseDir/content
	done
	#Sign *.asc files
	for FILE in `ls -1 $BaseDir/|grep ^gpg-pubkey`
	do
            echo "KEY SHA1 $(cd $BaseDir && sha1sum ${File})" >> $BaseDir/content
	done
        rm $BaseDir/content.asc
        gpg --detach-sign -u $LocalKey -a $BaseDir/content
        gpg --export -a -u $LocalKey > $BaseDir/content.key

        rm $BaseDir/media.1/products.asc
        gpg --detach-sign -u $LocalKey -a $BaseDir/media.1/products
        gpg --export -a -u $LocalKey > $BaseDir/media.1/products.key

        cd $BaseDir
        mkisofs -v -V SUSE10.1GM -r -J -l -L -P "OpenSuSE Linux 10.1" \
        -b "boot/i386/loader/isolinux.bin" \
        -c "boot/i386/loader/boot.cat" \
        -no-emul-boot -boot-load-size 4 -boot-info-table \
        -graft-points -o "$OutputDir/$OutputDVD" \
        $BaseDir

        echo
        echo "$OutputDir/$OutputDVD"
        ;;
    *)
    echo "Usage: $0 1/2/3 (1=rsync, 2=replace files, 3=make dvd iso)" 1>&2
    exit 1
    ;;
esac
echo
exit 0