#!/bin/sh
# $Id: geniso-mini,v 1.12 2002/10/29 17:52:51 malekith Exp $

set -x
umask 022
export LC_ALL=C
ROOT="/home/ftp/pub/Linux/PLD"
PATH=$ROOT/.stat/bin:$PATH; export PATH

ARCHLIST="i386 i586 i686"

DIST=ra

#ARCHLIST="i586"
#ROOT="/adm/ftp"

#MKISOFSOPT="-print-size"
MKISOFSOPT="-quiet"

#BOOTDISK="PLD/images/bootdisk.img"
BOOTDISK="PLD/images/bootdisk_iso.img"

#ISOTMPDIR=""
ISOTMPDIR="$HOME/tmp"

POLDEK=$ROOT/.stat/bin/poldek-$DIST

pld_info() {
echo "
*************************************************************
  ___ _    ___  
 | _ \ |  |   \  (MINI)
 |  _/ |__| |) | Linux 1.0 Ra
 |_| |____|___/  Development Version ISO image

     ftp://ftp.pld-linux.org/ && ftp://ftp.ipv6.pld-linux.org/

 Additional access is at http://www.pld-linux.org/distrib/ftp/.
 For questions and other contacts mailto:feedback@pld-linux.org

ISO Build: `LC_ALL=C date`.
*************************************************************
"
}

#cd $ROOT/.stat/packages && cvs -d:pserver:cvs@cvs.pld-linux.org:/cvsroot up -A poldek-iso.priority

test -r mini-iso.lst || {
  echo "please supply mini-iso.lst file (from cvs://cvs.pld-linux.org/admin/ftp)" 2>&1
  exit 1
}

test -x $POLDEK || {
  echo "can't find poldek ($POLDEK)" 2>&1
  exit 1
}

test -d $ROOT || {
  echo "can't find root dir ($ROOT)" 2>&1
  exit 1
}

for ARCH in ${ARCHLIST}; do
    echo "Generating mini-ISOs for ${ARCH}"

    rm -rf ${ISOTMPDIR}/pld-${ARCH}.iso*

    R=${ROOT}/dists/$DIST/PLD/${ARCH}/PLD
    T=${ISOTMPDIR}/pld-${ARCH}.iso-root/

    mkdir -p $T/PLD/{RPMS,inst,images}

    arch_pkgs=
    case $ARCH in
    ppc ) 
      arch_pkgs="pdisk pmac-utils hfsutils yaboot" 
      ;;
    i*86 | athlon )
      arch_pkgs="grub lilo rc-boot"
      ;;
    esac

    add_pkgs="reiserfsprogs e2fsprogs jfsutils xfsprogs dhcpcd raidtools mdadm syslog"

    pkgs=`$POLDEK -V -s ${ROOT}/dists/ra/PLD/${ARCH}/PLD/RPMS/ \
    	--pset mini-iso.lst $add_pkgs $arch_pkgs | \
    	egrep '(^mark | marks )' | sed -e 's/^mark //; s/.* marks //' | xargs`

    set +x
    for f in $pkgs ; do
	cp ${R}/RPMS/$f.*.rpm $T/PLD/RPMS
    done
    set -x
    
    $POLDEK -s $T/PLD/RPMS --mkidxz

    # please don't change it. installer relayes on presence of this
    # file in cd image root
    ISONAME="pld-${ARCH}-MINI"
    
    touch $T/${ISONAME}
    pld_info > $T/PLD-README.txt
    
    cp -r $R/inst/pkg $T/PLD/inst
    rm -f $T/PLD/inst/pkg/{root,ui}-pkg.tar.gz
    rm -rf $T/PLD/inst/pkg/*experimental

    common_iso_opt="-J -R -r -V MINI-ISO -A PLD-Linux \
    	-P '<feedback@pld-linux.org>' \
    	-abstract PLD-README.txt ${MKISOFSOPT}"
    
    case $ARCH in
      i*86 | athlon )
        cp $R/images/bootdisk_iso.img $T/PLD/images
        cp $R/images/slow/bootdisk_ide_slow.img $T/PLD/images
	BOOTOPT="-b ${BOOTDISK} -c PLD/images/boot.cat"
        echo "Running mkisofs for ${ISONAME}.iso"
	${ROOT}/.stat/bin/mkisofs \
	  ${common_iso_opt} \
	  -sysid ia32 \
	  ${BOOTOPT} \
	  -o ${ROOT}/iso/ra/${ARCH}/${ISONAME}.iso \
	  $T/ 
	;;
      ppc )
	echo "        Ascii   'ttxt'    'TEXT'   \"Text file\"" \
		> ${ISOTMPDIR}/mapping
        cp -r $R/boot $T/PLD/boot
        ${ROOT}/.stat/bin/mkisofs -part -hfs -l ${common_iso_opt} -sysid ppc \
		-hfs-volid PLD_Linux \
		-map ${ISOTMPDIR}/mapping \
	  	-o ${ISONAME}.iso \
		$T/ 
	rm -f ${ISOTMPDIR}/mapping
	# bless yaboot
	hmount ${ISONAME}.iso
	hattrib -b PLD/boot
	hcd PLD/boot
	hattrib -t tbxi -c UNIX ofboot.b
	hattrib -t boot -c UNIX vmlinux
	hattrib -t boot -c UNIX vmlinux-2.2
	hattrib -t boot -c UNIX yaboot
	hattrib -t conf -c UNIX yaboot.conf
	humount
        ;;
      * )
        echo "EVIL arch: $ARCH"
	exit 1
	;;
    esac
    
    rm -rf ${ISOTMPDIR}/pld-${ARCH}.iso*
done

