#!/bin/sh
#  0install.sh - JE install EZinst -
#  Copyright (C) 1995 Takashi MANABE (manabe@Roy.dsl.tutics.tut.ac.jp)
#
#  EZinst is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#  See the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

SHDIR=/install
DOINST=$SHDIR/doinst.sh
EZVAR=/var/lib/ezinst
PKGS=$EZVAR/installed
SCRS=$EZVAR/scripts

# extract packages and run doinst.sh
installPackages() {
    while [ $# != 0 ]; do
	av="$1"; shift
	if [ -f $av ]; then
	    rm -f $DOINST
	    echo installing $av
	    base=`basename $av .tgz`
	    tar -zxvlpf $av -C / > /tmp/$base
	    if [ $? = 0 ]; then
		mv /tmp/$base $PKGS
		if [ -f $DOINST ]; then
		    echo running doinst.sh
		    (cd /; /bin/sh $DOINST -install)
		    mv $DOINST $SCRS/$base.p
		fi
	    else
	    echo $av
		rm -f $DOINST /tmp/$base
		exit 1
	    fi
	else
	    exit 1
	fi
    done
}

mkdir -p /install
mkdir -p /var/lib/ezinst/installed /var/lib/ezinst/scripts
mkdir -p /usr/man/ja_JP.ujis /usr/X11R6/man/ja_JP.ujis
for i in 1 2 3 4 5 6 7 8 9 n
do
    mkdir -p /usr/man/ja_JP.ujis/man$i /usr/man/ja_JP.ujis/cat$i
    mkdir -p /usr/X11R6/man/ja_JP.ujis/man$i /usr/X11R6/man/ja_JP.ujis/cat$i
done

for pkg in `ls *.tgz`
do
    installPackages $pkg
#    echo $pkg
done
exit
