#!/bin/sh
#
# Copyright (C) 1998-1999 Florian La Roche
#
# Convert binary packages from .tgz to .jur-format.
#
# you need: jur-pack, jur-index

# what subdirs should be converted?
DIRS="base appl archiver editors x xappl network www mail news doc develop \
	tcl fun desktop"

convert() {
	SOURCE=$1
	DEST=$2
	test -d $SOURCE || return
	test -d $DEST || return

	cd $DEST
	for i in $DIRS; do
		mkdir -p $i
		cd $i || { echo "$i is not present"; exit 1; }
		for p in $SOURCE/$i/*.tgz; do
			#BASE=`basename $p .tgz`
			BASE="${p##*/}"
			BASE="${BASE%.tgz}"
			test -f ${BASE}.jur -a ${BASE}.jur -nt $p && continue
			test \! -s $p && continue
			echo $BASE
			rm -fr new
			mkdir new
			( cd new
			tar xzplf $p || exit 1
			if test -f install/doinst.sh; then
				sh install/doinst.sh
				rm -fr install
			fi
			jur-pack -d . ../$BASE.jur || exit 1
			) || exit 1
			rm -fr new
		done
		cd ..
	done
	for i in */*.jur ; do
		i="${i%.jur}"
		test -f $SOURCE/$i.tgz && continue
		echo "$i should be deleted from jur repository."
	done
	(for i in */*.jur; do echo $i; done | jur-index) || echo "No index"
	echo "Finished $SOURCE -> $DEST conversion."
}

# the following lines should be changed to match your directory layout

# my home machine:
convert ~ftp/pub/jurix/binary/tar /hdc1/jurix/libc5
convert ~ftp/pub/jurix/i386/tar /hdc1/jurix/glibc
convert ~ftp/pub/jurix/alpha/tar /hdc1/jurix/alpha
# DEC Alpha:
convert /jurix/tar /jurix/jur
# some other machines:
convert ~ftp/pub/jurix/binary/tar /local/jurix
