#!/bin/sh
# -----------------------------------------------------------------------------
#
# Install KDE 3.0-beta1 on Tru64 machines, Version 1.7, 09.12.2001
#
# Dr. Tom Leitner, tom@radar.tu-graz.ac.at
#
# -----------------------------------------------------------------------------
# destination directory, do not change !!
#
D=/usr/local/kde3
D1=usr/local/kde3
#
# -----------------------------------------------------------------------------
# parse cmd line options.
#
yes=0;
instdir=$D
lang=
egd=
while [ $# -ge 1 ]; do  
    if [ "$1" = "-y" ]; then
        yes=1;
        shift;
    fi
    if [ "$1" = "-d" ]; then
        instdir=$2;
        shift; shift;
    fi
    if [ "$1" = "-l" ]; then
        lang=$2;
        shift; shift;
    fi
    if [ "$1" = "-egd" ]; then
        egd=$2;
        shift; shift;
    fi
    if [ "$1" = "-h" ]; then
        echo "Usage: install_kde [opts]"
        echo "Opts:  -y      ..... answer Y to all questions"
        echo "       -d dir  ..... specify installation directory"
        echo "       -l lang ..... specify list of languages to be installed"
        echo "       -h      ..... this help message"
        echo "       -egd s  ..... use an existing EDG with socket s"
        exit 1
    fi
done
#
# -----------------------------------------------------------------------------
# start
#
echo ""
echo "**** INSTALLING KDE Version 3.0 BETA1 on Tru64 Unix ****"
echo ""
#
# find out the distribution file date
#
DT=`ls kdebase*.tar.bz2 | head -1 | (IFS=.; read a b c d e; echo $c)`
if [ "$DT" = "" ]; then
    echo "** ERROR: there are no KDE installation files found in `pwd`"
    exit 1
fi
echo "Distribution version/date is: " $DT
echo ""
if [ ! -r ./gtar -a ! -r ./gtar.gz ]; then
    echo "*** ERROR: There is no `pwd`/gtar or `pwd`/gtar.gz file!!"
    exit 1
fi
if [ ! -r ./bzip2 -a ! -r ./bzip2.gz ]; then
    echo "*** ERROR: There is no `pwd`/bzip2 or `pwd`/bzip2.gz file!!"
    exit 1
fi
if [ -r ./gtar.gz ]; then
    /usr/bin/gzip -d ./gtar
fi
if [ ! -x ./gtar ]; then
    chmod 700 ./gtar
fi
if [ -r ./bzip2.gz ]; then
    /usr/bin/gzip -d ./bzip2
fi
if [ ! -x ./bzip2 ]; then
    chmod 700 ./bzip2
fi
TAR=`pwd`/gtar
ZIP=`pwd`/bzip2
#
# check file checksums
#
if [ ! -e Checksums ]; then
    echo "*** ERROR: There is no `pwd`/Checksums file!!"
    exit 1
fi
echo "** INFO: Checking checksums of all distribution files ......."
cat Checksums | while read cksum l f; do
    if [ -r $f ]; then
        cksum1=`/usr/bin/cksum $f | (read a b c; echo $a)`
        if [ $cksum != $cksum1 ]; then
            echo "** WARNING: Checksum for $f did not match !!"
            exit 1
        fi
    fi
done
if [ $? -ne 0 ]; then
    exit 1;
fi
echo "** INFO: All distribution files seem to be intact."
echo ""
# 
# get installation directory
#
echo "You need 230 MB of free space on the target directory for a full install!!"
echo "An installation with ALL supported languages needs about 360MB of diskspace!"
echo ""
echo "If upgrading from a previous KDE 2.x version in the same directory, you"
echo "temporarily need twice as much free disk space!"
echo ""
while true; do
    printf "Where should KDE 3.0 be installed [$D]: "
    if [ $yes -eq 1 ]; then
        T=$instdir;
        echo $T
    else
        read T
    fi
    if [ "$T" = "" ]; then
        T=$D;
    fi
    if [ ! -d $T ]; then
        echo ""
        printf "%s does not exist, do you want to create it [Y/N]: " "$T"
        if [ $yes -eq 1 ]; then
            a="Y";
            echo $a;
        else
            read a
        fi
        if [ "$a" = "Y" -o "$a" = "y" ]; then
            mkdir -m 755 -p $T
            break;
        fi
    else
        break;
    fi
done
#
# create /usr/local if it does not exist yet
#
if [ ! -d /usr/local ]; then
    mkdir /usr/local
    chmod 755 /usr/local
fi
#
# setup migration symlinks
#
#a="Y";
#if [ "$a" = "Y" -o "$a" = "y" ]; then
#    if [ -e /usr/local/kde2.old ]; then
#        echo "** WARNING: /usr/local/kde2.old already existed. It will be"
#        echo "            renamed to /usr/local/kde2.old.$$"
#        mv /usr/local/kde2.old /usr/local/kde2.old.$$
#    fi
#    if [ -e /usr/local/kde21.old ]; then
#        echo "** WARNING: /usr/local/kde21.old already existed. It will be"
#        echo "            renamed to /usr/local/kde21.old.$$"
#        mv /usr/local/kde21.old /usr/local/kde21.old.$$
#    fi
#    if [ -e /usr/local/kde2 ]; then
#        mv /usr/local/kde2 /usr/local/kde2.old
#    fi
#    if [ -e /usr/local/kde21 ]; then
#        mv /usr/local/kde21 /usr/local/kde21.old
#    fi
#    if [ -e /usr/local/kde22 ]; then
#        mv /usr/local/kde22 /usr/local/kde22.old
#    fi
#    if [ -e /usr/local/kde221 ]; then
#        mv /usr/local/kde221 /usr/local/kde221.old
#    fi
#    if [ -e /usr/local/kde222 ]; then
#        mv /usr/local/kde222 /usr/local/kde222.old
#    fi
#    ln -sf $D /usr/local/kde2
#    ln -sf $D /usr/local/kde21
#    ln -sf $D /usr/local/kde22
#    ln -sf $D /usr/local/kde221
#    ln -sf $D /usr/local/kde222
#    break;
#fi
#
# setup file groups
#
BASE="qt kdesupport kdelibs kdebase kdeutils kdeadmin kdenetwork"
BASE="$BASE kdeaddons kdeartwork"
GAMES="kdetoys kdegames"
GRAPHICS="kdegraphics kdemultimedia"
PIM="kdepim"
OFFICE="koffice"
#DEVELOP="kdebindings kdoc kdesdk kdevelop"
DEVELOP="kdesdk kdevelop"
I18N="kde-i18n"
#
# unpack files
#
PWD=`pwd`
echo ""
if [ $yes -ne 1 ]; then
    printf "Press RETURN to start the installation of the KDE 3.0 BASE files: "
    read a
fi
cd $T;
for i in $BASE; do
    echo Unpacking $i.tru64.$DT.tar.bz2
    $ZIP -dc $PWD/$i.tru64.$DT.tar.bz2 | $TAR xpf -
done
#
# some programs only have /usr/local/lib in their RPATH so make sure that
# there's a libz.so in /usr/local/lib after unpacking the base files
#
if [ ! -d /usr/local/lib ]; then
    mkdir /usr/local/lib
    chmod 755 /usr/local/lib
fi
if [ ! -r /usr/local/lib/libz.so ]; then
    ln -fs $D/lib/libz.so /usr/local/lib/libz.so
fi
#
#
if [ -r $PWD/kdetoys.tru64.$DT.tar.bz2 ]; then
    printf "\nInstall toys and games [Y/N]: "
    if [ $yes -eq 1 ]; then
        a="Y";
        echo $a;
    else
        read a
    fi
    if [ "$a" = "Y" -o "$a" = "y" ]; then
        for i in $GAMES; do
            echo Unpacking $i.tru64.$DT.tar.bz2
            $ZIP -dc $PWD/$i.tru64.$DT.tar.bz2 | $TAR xpf -
        done
    fi
fi
#
#
if [ -r $PWD/kdegraphics.tru64.$DT.tar.bz2 ]; then
    printf "\nInstall graphics and multimedia programs [Y/N]: "
    if [ $yes -eq 1 ]; then
        a="Y";
        echo $a;
    else
        read a
    fi
    if [ "$a" = "Y" -o "$a" = "y" ]; then
        for i in $GRAPHICS; do
            echo Unpacking $i.tru64.$DT.tar.bz2
            $ZIP -dc $PWD/$i.tru64.$DT.tar.bz2 | $TAR xpf -
        done
    fi
fi
#
#
if [ -r $PWD/kdepim.tru64.$DT.tar.bz2 ]; then
    printf "\nInstall KPim (Personal Information Manager) [Y/N]: "
    if [ $yes -eq 1 ]; then
        a="Y";
        echo $a;
    else
        read a
    fi
    if [ "$a" = "Y" -o "$a" = "y" ]; then
        for i in $PIM; do
            echo Unpacking $i.tru64.$DT.tar.bz2
            $ZIP -dc $PWD/$i.tru64.$DT.tar.bz2 | $TAR xpf -
        done
    fi
fi
#
#
if [ -r $PWD/koffice.tru64.$DT.tar.bz2 ]; then
    printf "\nInstall KOffice [Y/N]: "
    if [ $yes -eq 1 ]; then
        a="Y";
        echo $a;
    else
        read a
    fi
    if [ "$a" = "Y" -o "$a" = "y" ]; then
        for i in $OFFICE; do
            echo Unpacking $i.tru64.$DT.tar.bz2
            $ZIP -dc $PWD/$i.tru64.$DT.tar.bz2 | $TAR xpf -
        done
    fi
fi
#
#
if [ -r $PWD/kdesdk.tru64.$DT.tar.bz2 ]; then
    printf "\nInstall Software Development tools, SDK and KDEVELOP [Y/N]: "
    if [ $yes -eq 1 ]; then
        a="Y";
        echo $a;
    else
        read a
    fi
    if [ "$a" = "Y" -o "$a" = "y" ]; then
        for i in $DEVELOP; do
            echo Unpacking $i.tru64.$DT.tar.bz2
            $ZIP -dc $PWD/$i.tru64.$DT.tar.bz2 | $TAR xpf -
        done
    fi
fi
#
w=`ls $PWD/kde-i18n.*.tru64.$DT.tar.bz2 2>/dev/null | wc -l`
if [ $w -gt 0 ]; then
    printf "\nThe following language packs are available: \n"
    n=0;
    for i in $PWD/kde-i18n.*.tru64.$DT.tar.bz2; do
        L=`basename $i | (IFS=.; read a b c d e; echo $b)`
        printf "%s " $L
        if [ $n -gt 15 ]; then
            printf "\n";
            n=0;
	fi
        n=`expr $n + 1`
    done
    printf "\n\nPlease enter the language packs you wish to install, separated\n"
    printf "by blanks. Note that US English is installed by default and does\n"
    printf "not need to be selected here. If you do not want to install any\n"
    printf "additional language pack, just press RETURN: "
    if [ $yes -eq 1 ]; then
        packs="$lang";
        echo "$packs";
    else
        read packs
    fi
    if [ "$packs" != "" ]; then
        for i in $packs; do
            echo Installing language pack kde-i18n.$i.tru64.$DT.tar.bz2
            $ZIP -dc $PWD/kde-i18n.$i.tru64.$DT.tar.bz2 | $TAR xpf -
        done
    fi
fi
#
# move files into place
#
for i in $D1/* ; do
    b=`basename $i`
    if [ -d ./$b ]; then
        echo "Removing old $T/$b .............."
        rm -rf ./$b
    fi
    mv $i .
done
rm -rf $D1
# 
# create symlink if necessary
#
if [ "$T" != "$D" ]; then
    echo ""
    echo "Creating symlink from $T to $D .........."
    if [ ! -d /usr/local ]; then
        mkdir /usr/local
        chmod 755 /usr/local
    fi
    ln -f -s $T $D
fi
# 
# install the proper kcheckpass based on the installed security mode
#
SEC="BASE"
if [ -f /etc/rc.config ]; then
    . /etc/rc.config
    SEC=${SECURITY:=BASE}
fi
echo ""
echo "Installing Password Check Program for $SEC Security!"
echo ""
rm -f $D/bin/kcheckpass
if [ "$SEC" = "BASE" ]; then
    ln -f $D/bin/kcheckpass_base_sec $D/bin/kcheckpass
else
    ln -f $D/bin/kcheckpass_enh_sec $D/bin/kcheckpass
fi
chmod 755 $D/bin/kcheckpass*
chown root:auth $D/bin/kcheckpass_enh_sec
chmod 2755 $D/bin/kcheckpass_enh_sec
V5=0;
uname -r | grep V5 >/dev/null
if [ $? -eq 0 ]; then
    V5=1;
fi
if [ $V5 -eq 1 ]; then
    chmod 4755 $D/bin/kcheckpass_enh_sec
fi
#
#
printf "Search for locally installed applications and include them into the\n"
printf "KDE 3.0 start menu [Y/N]: "
if [ $yes -eq 1 ]; then
    a="Y";
    echo $a;
else
    read a
fi
if [ "$a" = "Y" -o "$a" = "y" ]; then
    $D/bin/kappfinder_install $D/share/applnk
fi
echo
printf "For ejecting removable media by KDE menus, it is necessary to set the\n"
printf "/dev/cam device to mode 666. Do you want to do this: [Y/N]: "
if [ $yes -eq 1 ]; then
    a="Y";
    echo $a;
else
    read a
fi
if [ "$a" = "Y" -o "$a" = "y" ]; then
    chmod 666 /dev/cam
fi
echo ""
#
# install modified Xsession if required. This is only possible under
# v4.0x because the DXSession Session menu entry does not exist anymore in 
# Tru64 v5.0x
#
if [ $V5 -eq 1 ]; then
    XS=/usr/lib/X11/xdm/Xsession
    if [ -r $D/bin/Xsession -a -r $XS ]; then
        grep KDE $XS >/dev/null 2>&1
        if [ $? -ne 0 ]; then
            printf "KDE2 comes with a modified $XS file which allows you\n"
            printf "to start up KDE2 when the DXSession is selected in the CDE Login Session\n"
            printf "menu. Do you want to install this file? [Y/N]: "
            if [ $yes -eq 1 ]; then
                a="Y";
                echo $a;
            else
                read a
            fi
            if [ "$a" = "Y" -o "$a" = "y" ]; then
                cp $XS $XS.old
                cp $D/bin/Xsession $XS
                chmod 755 $XS
                chown bin:bin $XS
                echo New $XS installed, old version saved as $XS.old
            fi
        fi
    fi
fi
#
# EGD support for konqueror SSL connections
# 
if [ "$egd" != "" ]; then
    mv $D/bin/startprngd $D/bin/startprngd.orig
    rm -f /tmp/random
    ln -s $egd /tmp/random
else
printf "\n";
printf "For konqueror SSL support, an EGD (entropy gathering daemon) is required.\n"
printf "KDE 3.0 comes with PRNGD which is started automatically when the first KDE\n"
printf "user logs-in. Alternatively you can use an existing EGD running on your\n"
printf "system, or you can decide not to run PRNGD at all. If you want to use an\n"
printf "existing EGD, you need to know the path to the UNIX socket where the EGD\n"
printf "provides its random data.\n\n"
printf "Use the EGD which comes with KDE 3.0: [Y/N]: "
if [ $yes -eq 1 ]; then
    a="Y";
    echo $a;
else
    read a
fi
if [ "$a" != "Y" -a "$a" != "y" ]; then
    mv $D/bin/startprngd $D/bin/startprngd.orig
    while [ true ]; do
        printf "Use an existing EGD on the system: [Y/N]: "
        read a
        if [ "$a" = "Y" -o "$a" = "y" ]; then
            printf "Enter the path to the UNIX socket of the EGD: "
            read s
            if [ ! -r $s ]; then
                printf "\n** ERROR: $s does not seem to exist!\n\n"
            else
                rm -f /tmp/random
                ln -s $s /tmp/random
                break;
            fi
        else
            break;
        fi
    done
fi
fi
echo ""
echo "Installation finished !!"
echo ""
echo "In order to use KDE 3.0 now under a particular user account, please copy"
echo "the file $D/Tru64.xsession" 'to $HOME/.xsession of the user'
echo 'and make it executable with chmod 700 $HOME/.xsession.'
echo ""
echo "IMPORTANT WARNING: If you are upgrading from KDE 2.x, you still need to copy"
echo "the new $D/Tru64.xsession file to "'$HOME/.xsession'.
echo ""
#
# end of file
