#! /bin/sh
#
# install
# Greg Hankins, 30 September 1995
#

LINUXDOCBIN=/usr/local/bin
LINUXDOCLIB=/usr/local/lib/linuxdoc-sgml
LINUXDOCDOC=/usr/local/doc/linuxdoc-sgml

echo "Installing linuxdoc-sgml:"
echo "Where do you want the linuxdoc binaries?"
echo -n "[/usr/local/bin] "
read linuxdocbin
if [ ! -z "$linuxdocbin" ]; then
    LINUXDOCBIN="$linuxdocbin"	
fi

echo "Where do you want the linuxdoc libraries?"
echo -n "[/usr/local/lib/linuxdoc-sgml] "
read linuxdoclib
if [ ! -z "$linuxdoclib" ]; then
    LINUXDOCLIB="$linuxdoclib"	
fi

echo "Where do you want the linuxdoc documentation?"
echo -n "[/usr/local/doc/linuxdoc-sgml] "
read linuxdocdoc
if [ ! -z "$linuxdocdoc" ]; then
    LINUXDOCDOC="$linuxdocdoc"
fi

sed -e "s!linuxdocbin!$LINUXDOCBIN!1" -e "s!linuxdoclib!$LINUXDOCLIB!1" < bin/sgml2html > /tmp/sgml2html	
sed -e "s!linuxdocbin!$LINUXDOCBIN!1" -e "s!linuxdoclib!$LINUXDOCLIB!1" < bin/sgml2info > /tmp/sgml2info	
sed -e "s!linuxdocbin!$LINUXDOCBIN!1" -e "s!linuxdoclib!$LINUXDOCLIB!1" < bin/sgml2ps > /tmp/sgml2ps	
sed -e "s!linuxdocbin!$LINUXDOCBIN!1" -e "s!linuxdoclib!$LINUXDOCLIB!1" < bin/sgml2txt > /tmp/sgml2txt	

echo "Compiling the SGML parsing tools..."
cd sgmls-1.1
make config.h
make 

echo "Compiling HTML conversion tools..."
cd ../html-fix
make
cd ..

echo "Installing binaries in $LINUXDOCBIN..."
if [ ! -d $LINUXDOCBIN ]; then
    mkdir -p $LINUXDOCBIN
    if [ $? -ne 0 ]; then
        echo "$0: Cannot create bin directory $LINUXDOCBIN"
        exit 2
    fi
    chmod 755 $LINUXDOCBIN
fi

# remove old versions
rm -f $LINUXDOCBIN/sgmls
rm -f $LINUXDOCBIN/sgmlsasp
rm -f $LINUXDOCBIN/fixref
rm -f $LINUXDOCBIN/html2html
rm -f $LINUXDOCBIN/sgmls2html
rm -f $LINUXDOCBIN/sgmls2info
rm -f $LINUXDOCBIN/sgmls2ps
rm -f $LINUXDOCBIN/sgmls2txt
# and copy in new ones
cp sgmls-1.1/sgmls sgmls-1.1/sgmlsasp $LINUXDOCBIN
cp html-fix/fixref html-fix/html2html $LINUXDOCBIN
mv /tmp/sgml2html $LINUXDOCBIN
mv /tmp/sgml2info $LINUXDOCBIN
mv /tmp/sgml2ps $LINUXDOCBIN
mv /tmp/sgml2txt $LINUXDOCBIN

echo "Installing library files in $LINUXDOCLIB..."
if [ ! -d $LINUXDOCLIB ]; then
    mkdir -p $LINUXDOCLIB
    if [ $? -ne 0 ]; then
        echo "$0: Cannot create lib directory $LINUXDOCLIB"
        exit 2
    fi
    chmod 755 $LINUXDOCLIB
fi
cd lib
cp -r ./* $LINUXDOCLIB
cd ..

echo "Installing documentation in $LINUXDOCDOC..."
if [ ! -d $LINUXDOCDOC ]; then
    mkdir -p $LINUXDOCDOC
    if [ $? -ne 0 ]; then
        echo "$0: Cannot create lib directory $LINUXDOCDOC"
        exit 2
    fi
    chmod 755 $LINUXDOCDOC
fi
cd doc
cp -r ./* $LINUXDOCDOC
cd ..

# fix permissions
cd $LINUXDOCDOC
find . -type d -print -exec chmod 755 {} \; > /dev/null
find . -type f -print -exec chmod 644 {} \; > /dev/null
cd $LINUXDOCLIB
find . -type d -print -exec chmod 755 {} \; > /dev/null
find . -type f -print -exec chmod 644 {} \; > /dev/null

# don't use wildcards, there could be other things in $LINUXDOCBIN!
#
# chmod bin files after lib and doc files, because they could be in the same 
# directory, and that would make them 644
#
chmod 755 $LINUXDOCBIN/sgmls $LINUXDOCBIN/sgmlsasp
chmod 755 $LINUXDOCBIN/fixref $LINUXDOCBIN/html2html 
chmod 755 $LINUXDOCBIN/sgml2html $LINUXDOCBIN/sgml2info $LINUXDOCBIN/sgml2ps $LINUXDOCBIN/sgml2txt

echo "Done!  Read the guide in $LINUXDOCDOC next."
exit 0
