#!/bin/bash

# wp80in-slack - version 2.0
# A script to install WordPerfect 8.0 for Linux on Slackware.
# \(c\) Peter Stone, 2026
# peter@xwp8users.com

bold=$(tput bold)
normal=$(tput sgr0)

echo " "
echo This script is designed to install ${bold}WordPerfect 8.0 for Linux${normal},
echo from the rpm in Caldera OpenLinux 2.2 or 2.3, or TurboLinux 4, on
echo versions of Slackware current in 2026 or later.
echo " "
echo It has been tested on Slackware 15 KDE.
echo " "
echo " "
echo Before running this script, you should have taken the following
echo preliminary steps:
echo " "
echo 1. Create the following directory, which will serve as the working 
echo directory for the script:"   "${bold}/root/Downloads/wp-inst${normal}
echo " "
echo 2. Copy this script file to that directory.
echo
echo 3. Copy to that directory:
echo your WordPerfect-8.0-7.i386.rpm file from your Caldera OpenLinux 2.2 CD,
echo or your WordPerfect-8.0-17.i386.rpm file from your OpenCaldera 2.3 CD,
echo or your wordperfect-8.0.3.i386.rpm file from your TurboLinux 4 CD, .
echo " "
echo 4. If you do not have WordPerfect 8.1 already installed, and wish 
echo to make the fonts from the WordPerfect for Linux Bible CD available 
echo in WordPerfect 8.0, then also copy the /fonts folder on the CD 
echo with its contents into the working directory.
echo " "
echo " "
echo The script should be run as in a root terminal.
echo " "
echo After changing to the working directory, the script can be 
echo executed with the command:"   "\"${bold}sh ./wp80in-slack.sh${normal}\"

# ****************************************************************************
# Carrying out preliminary preparations - mainly tests and downloads.

# Ensuring that the working directory exists.

echo " "
test -e /root/Downloads/wp-inst
if ! [ $? = 0 ] 
then 
    mkdir /root/Downloads/wp-inst
    echo " "
    echo "wp-inst folder was not available, and has now been created. Exiting script."
    exit
fi

cd /root/Downloads/wp-inst

echo " "
test -e ./WordPerfect-8.0-17.i386.rpm
if [ $? = 0 ]
then
    cp ./WordPerfect-8.0-17.i386.rpm ./WordPerfect-8.0.i386.rpm

else
    test -e ./WordPerfect-8.0-7.i386.rpm
    if [ $? = 0 ]
    then
        cp ./WordPerfect-8.0-7.i386.rpm ./WordPerfect-8.0.i386.rpm

    else
        test -e ./wordperfect-8.0-3.i386.rpm
        if ! [ $? = 0 ]
        then
            echo " "
            echo "Command failed. No WordPerfect 8.0 is available. Exiting script."
            exit
        fi
    fi
fi


cd /root/Downloads/wp-inst

echo " "
# Now downloading wp-utils, if necessary.

test -e ./wp-utils-4.5.tgz
if ! [ $? = 0 ] 
then 
    wget http://www.xwp8users.com/packages/wp-utils-4.5.tgz
fi

if ! [ $? = 0 ] 
then 
    echo " "
    echo "Command failed. wp-utils is not available. Exiting script."
    exit
fi

echo " "

# Now installing wp-utils.

cd /root/Downloads/wp-inst

# tar -xvzf wp-utils-4.0.tgz --keep-directory-symlink
installpkg ./wp-utils-4.5.tgz

if ! [ $? = 0 ] 
then 
    echo " "
    echo "Command failed. Unable to install wp-utils. Exiting script."
    exit
fi

cd /root/Downloads/wp-inst

chmod +x /usr/bin/type1inst
chmod +x /usr/bin/xwppmgr81
chmod +x /usr/bin/xwppmgr80
chmod +x /usr/bin/xwppmgr81-mj
chmod +x /usr/bin/xwppmgr80-mj
chmod +x /lib/ld-2.27.so

cp /usr/bin/xwppmgr80 /usr/bin/xwppmgr
rm /usr/bin/installpkg15
rm /usr/bin/installpkg

test -e ./WordPerfect-8.0.i386.rpm
if ! [ $? = 0 ]
then
    mv /opt/wp8 /opt/wp8-org
fi

echo " "

# **********************************************************************
# Now running ldconfig.

ldconfig -c old

if ! [ $? = 0 ] 
then 
    echo " "
    echo "Command failed. Unable to run ldconfig. Exiting script."
    exit
fi

echo " "

# ***********************************************************
# Now installing WordPerfect itself, and its print manager.

# Now converting and then installing WordPerfect 8.0.

# ####

cd /root/Downloads/wp-inst

test -e ./WordPerfect-8.0.i386.rpm
if [ $? = 0 ]
then
    rpm -i --nodeps ./WordPerfect-8.0.i386.rpm
else
    rpm -i --nodeps ./wordperfect-8.0-3.i386.rpm
fi

if ! [ $? = 0 ]
then
    echo " "
    echo "Command failed. Unable to install WordPerfect 8.0. Exiting script."
    exit
fi

test -e /opt/wp8/wpbin/xwp
if ! [ $? = 0 ]
then
    ln -s /usr/local/wordperfect /opt/
    mv /opt/wordperfect /opt/wp8
    mv /opt/wp8-org/shlib10/hpc4600p.prs /opt/wp8/shlib10/hpc4600p.prs
    rm -R /opt/wp8-org
fi

# Now co-ordinating with a WP 8.1 installation.

cp /usr/bin/xwp80 /usr/bin/xwp
cp /usr/bin/xwppmgr80 /usr/bin/xwppmgr

test -e /usr/lib/wp8/wpbin/xwp
if [ $? = 0 ] 
then 
    cp /usr/bin/xwp81 /usr/bin/xwp
    cp /usr/bin/xwppmgr81 /usr/bin/xwppmgr
fi

# Now extending user accesss to shlib10.

# chmod -R 777 /opt/wp8/shlib10

echo " "
# Now creating a link to /etc/printcap, if necessary.

test -e /etc/printcap
if ! [ $? = 0 ] 
then 
    ln -s /run/cups/printcap /etc/printcap
fi
   
echo " "
# Now copying the WP Print Manager executable."

cd /opt/wp8/shbin10

test -e ./xwppmgr.bin
if ! [ $? = 0 ] 
then 
    cp ./xwppmgr ./xwppmgr.bin
fi

test -e ./xwppmgr.bin
if ! [ $? = 0 ] 
then 
    echo " "
    echo "Command failed. Unable to create xwppmgr.bin."
    echo "Exiting script."
    exit
fi

ldconfig -c old

# ***********************************************************************
# Testing whether WordPerfect 8.1, in the light or full version, has been 
# installed, and, if so, making the WP 8.1 fonts also available in WP 8.0.
# If not, installing the WP Bible fonts, if available.

echo " "
cd ~/Downloads/wp-inst

test -e /usr/lib/wp8/shbin10/xwpfi
if [ $? = 0 ] 
then 
    cd /opt/wp8/shlib10
    cp -RT /usr/X11R6/lib/X11/fonts/Type1 /opt/wp8/shlib10 
    cp /usr/lib/wp8/shlib10/wp.drs ./wp.drs
    cd ~/Downloads/wp-inst
fi

test -e /usr/lib/wp8/shbin10/xwpfi
if ! [ $? = 0 ] 
then 
    test -e ./fonts
    if [ $? = 0 ] 
    then
        mkdir /usr/X11R6/lib/X11/fonts
        cp -RT ~/Downloads/wp-inst/fonts /opt/wp8/shlib10
        cp -RT ~/Downloads/wp-inst/fonts /usr/X11R6/lib/X11/fonts/Type1
        cp -RT ~/Downloads/wp-inst/fonts /usr/share/fonts/Type1
        
        cp /opt/extras/bibfonts/Fontmap /usr/X11R6/lib/X11/fonts/Type1
        cp /opt/extras/bibfonts/fonts.scale /usr/X11R6/lib/X11/fonts/Type1
        cp /opt/extras/bibfonts/TRANS.TBL /usr/X11R6/lib/X11/fonts/Type1

        cp /opt/wp8/shlib10/wp.drs /opt/wp8/shlib10/wp.drs.org 
        cp /opt/extras/bibfonts/wp.drs.bib /opt/wp8/shlib10
        cp /opt/wp8/shlib10/wp.drs.bib /opt/wp8/shlib10/wp.drs

        chmod -R 755 /opt/wp8/shlib10
        chmod -R 755 /usr/X11R6/lib/X11/fonts
        chmod -R 755 /usr/share/fonts/type1
    fi
fi

ldconfig -c old

mkdir ~/.wprc
cd ~/
echo " "

# *******************************************************************************
# Final messages

echo \(1\) ${bold}WordPerfect 8.0${normal} has been successfully installed,
echo along with an updated version of the WP Print Manager.
echo " "

test -e /usr/lib/wp8/shbin10/xwpfi
if [ $? = 0 ] 
then
    echo \(2\) In addition, the fonts from an installation of WP 8.1 already present
    echo on the partition have been made available also in WP 8.0.
    echo " "
fi

test -e /usr/lib/wp8/shbin10/xwpfi
if ! [ $? = 0 ] 
then 
    cd ~/Downloads/wp-inst
    test -e ./fonts
    if [ $? = 0 ] 
    then
        echo \(2\) In addition, the fonts from the WordPerfect for Linux Bible CD have
        echo been made available in WP 8.0.
        echo " "
    else
        echo \(2\) Only the basic fonts are available.
        echo " "
    fi
fi

echo \(3\) ${bold}Next${normal}, you should run WordPerfect 8.0 ${bold}once${normal} as a superuser,
echo by giving, in a root terminal window, the command:
echo "   "\"${bold}xwp80 -adm${normal}\"
echo " "
echo Then, within WordPerfect, you should select Preferences, and then File Locking,
echo and then ensure that the option to \“Disable Unix File locking\" is switched on.
echo
echo This should ensure that error messages referring to \"too many processes\", or
echo to locked files, are not received.
echo " "
echo \(4\) ${bold}Thereafter${normal}, you should run WordPerfect 8.0 as a normal user, by giving,
echo in a user terminal window, the command:
echo "   "\"${bold}xwp80${normal}\"
echo " "
echo Alternatively, you may run WordPerfect 8.0 from an entry thereto in the Office folder
echo in your Linux menu.
echo " "
echo \(5\) To run the WP Print Manager, you can give, in a root terminal window, the command:
echo "   "\"${bold}xwppmgr80${normal}\"
echo " "
echo " "
echo Enjoy!
echo " "
exit
