#!/bin/bash

# wp80in-suse.sh - version 2.0
# A script to install WordPerfect 8.0 for Linux on OpenSUSE Leap 15.
# \(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,
echo on OpenSUSE Leap 15.
echo " " 
echo It has been tested on OpenSUSE Leap 15.6 \(KDE and Gnome\).
echo " " 
echo It is not designed to work on OpenSUSE Leap 16.
echo " "
echo Before running this script, you should have taken the following preliminary steps:
echo " "
echo 1. Create the following directory, which will serve as the working directory
echo for the script:"   "${bold}~/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 a normal user \(not as root\). It will call for
echo your sudo password on the first occasion that \"sudo\" is called.
echo " "
echo You must be a user enabled to use \"sudo\" in order to run the script.
echo " "
echo After changing to the working directory, the script can be executed
echo with the command: 
echo "   "\"${bold}sh ./wp80in-suse.sh${normal}\"
echo " "

# ***************************************************************************
# Carrying out preliminary steps

# Ensuring that the working directory exists.

test -e ~/Downloads/wp-inst
if ! [ $? = 0 ] 
then 
   mkdir ~/Downloads/wp-inst
fi

cd ~/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

echo " "

# Now installing wget.

sudo zypper install wget

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

echo " "
echo Downloading the wp-utils utility, if necessary.
echo " "

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.

sudo cp ./wp-utils-4.5.tgz /wp-utils-4.5.tgz
cd /
sudo tar -xvzf wp-utils-4.5.tgz --keep-directory-symlink

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

sudo rm /wp-utils-4.5.tgz
cd ~/Downloads/wp-inst

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

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

echo " "

# Now running ldconfig.

sudo ldconfig -c old

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

echo " "

# ****************************************************************************
# Now installing some official support packages.

echo " "
# Now installing glibc-32bit. 

sudo zypper install glibc-32bit

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

echo " "
# Now installing groff.

sudo zypper install groff

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

echo " "
# Now installing perl.

sudo zypper install perl

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

echo " "

# ****************************************************************************
# Now proceeding with the main installation.
# Now converting and then installing the core WordPerfect 8.0 package.

cd ~/Downloads/wp-inst

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

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

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

# Now co-ordinating with a 8.1 installation, if necessary.

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

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

echo " "

sudo zypper install cups-pdf

# ***************************************************************************
# Now installing the WP Print Manager

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

test -e /etc/printcap
if ! [ $? = 0 ] 
then 
    sudo 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 
    sudo 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

sudo cp /usr/bin/xwppmgr80d /usr/bin/xwppmgr80

sudo ldconfig -c old

echo " "

# *********************************************************************************
# Testing whether WordPerfect 8.1 \(light or deluxe 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.

cd ~/Downloads/wp-inst

test -e /usr/lib/wp8/shbin10/xwpfi
if [ $? = 0 ] 
then 
    cd /opt/wp8/shlib10
    sudo cp -RT /usr/X11R6/lib/X11/fonts/Type1 /opt/wp8/shlib10 
    sudo 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
        sudo mkdir /usr/X11R6/lib/X11/fonts
        sudo cp -RT ~/Downloads/wp-inst/fonts /opt/wp8/shlib10
        sudo cp -RT ~/Downloads/wp-inst/fonts /usr/X11R6/lib/X11/fonts/Type1
        sudo cp -RT ~/Downloads/wp-inst/fonts /usr/share/fonts/Type1
        
        sudo cp /opt/extras/bibfonts/Fontmap /usr/X11R6/lib/X11/fonts/Type1
        sudo cp /opt/extras/bibfonts/fonts.scale /usr/X11R6/lib/X11/fonts/Type1
        sudo cp /opt/extras/bibfonts/TRANS.TBL /usr/X11R6/lib/X11/fonts/Type1

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

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

sudo ldconfig -c old

cd ~/Downloads/wp-inst

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\) 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
        echo have 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 To enter a root terminal window on OpenSUSE, you can open a normal terminal window,
echo and give the command: \"su\". As an alternative, on KDE only, you can use the superuser
echo terminal entry in the System sub-folder in the KDE menu.
echo " "
echo \(4\) ${bold}Thereafter${normal}, you should run WordPerfect 8.0 as a normal user, by giving,
echo in a normal terminal window, the command:
echo "   "\"${bold}xwp80${normal}\"
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 As a further alternative, on KDE only, you can give, in a normal terminal window,
echo the command:
echo "   "\"${bold}kdesu xwppmgr80${normal}\"
echo " "
echo Enjoy!
echo " "
exit
