#!/bin/bash

# wp80in.sh - version 2.3 (2026)
# A script to install WordPerfect 8.0 for Linux on debian-based systems.
# \(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 a debian-based distro current in 2026 or later.
echo " " 
echo It has been tested most recently on Mint 22.3, Ubuntu 26.04, and MX 25.1.
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 ${bold}WordPerfect-8.0-7.i386.rpm${normal} file from your Caldera OpenLinux 2.2 CD,
echo or your ${bold}WordPerfect-8.0-17.i386.rpm${normal} file from your OpenCaldera 2.3 CD,
echo or your ${bold}wordperfect-8.0.3.i386.rpm${normal} file echo 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 that 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 your
echo 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:"  "\"${bold}sh ./wp80in.sh${normal}\"

# ****************************************************
# Carrying out preliminary preparations - mainly tests and downloads.
# Ensuring that the working directory exists.

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

cd ~/Downloads/wp-inst

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

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

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


# *****************************************************************************
# Now ensuring that i386 architecture is available in debian-based distros.

sudo dpkg --add-architecture i386
sudo apt-get update

# *****************************************************************************
# Now installing wget.

echo " "
sudo apt-get -y install wget

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

# Now installing libxaw7:i386.

sudo apt-get -y install libxaw7:i386

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

# Downloading the wp-utils utility, if necessary, and removing 
# earlier conflicting utilities.

echo " "
test -e ./wp-utils_5.1_i386.deb
if ! [ $? = 0 ] 
then 
    wget http://www.xwp8users.com/packages/wp-utils_5.1_i386.deb
fi
  
if ! [ $? = 0 ] 
then 
    echo " "
    echo "Command failed. wp-utils is not available. Exiting script."
    exit
fi

sudo dpkg -r wppmwrap wppmwrap80 wppmwrap81d wppmwrap-80 wppmwrap-81d
sudo dpkg -r xlib6g type1inst type1-64add prewp64 prewp68 wputils80
sudo dpkg -r ldso libc5

# ****************************************************************
# Now installing the supporting packages.
# Now installing wp-utils.

echo " "
sudo dpkg -i wp-utils_5.1_i386.deb

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

sudo cp /lib/libc5/* /lib/

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

cd ~/Downloads/wp-inst

echo " "
# Now installing libc6:i386.

sudo apt-get -y install libc6:i386

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

echo " "
# Now installing binutils.

sudo apt-get -y install binutils

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

echo " "
# Now installing groff.

sudo apt-get -y install groff

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

echo " "
# Now installing perl.

sudo apt-get -y install perl

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

echo " "
# Now installing xbase-clients.

sudo apt-get -y install xbase-clients

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

echo " "
# Now installing rpm package.

sudo apt-get -y install rpm

if ! [ $? = 0 ]
then
    echo " "
    echo "Command failed. Unable to install the \"rpm\" package. Exiting script."
    exit
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 WordPerfect itself, and its print manager.
# Now converting and then installing WordPerfect 8.0.

cd ~/Downloads/wp-inst

test -e ./wp80.rpm
if [ $? = 0 ]
then
    mkdir ./extraction
    cp ./wp80.rpm ./extraction/
    cd extraction
    rpm2cpio wp80.rpm | cpio -idv
    rm wp80.rpm
    sudo cp -r ./* /
    cd ..
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 cp -a /usr/local/wordperfect/. /opt/wp8/
fi

echo " "

sudo apt-get -y install printer-driver-cups-pdf

# Now co-ordinating with a WP 8.1 installation.

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 " "
# 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 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
    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

mkdir ~/.wprc
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\) 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 terminal window, the command:
echo "   "\"${bold}sudo 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,
echo by giving, in a terminal window, the command:
echo "   "\"${bold}xwp80${normal}\"
echo " "
echo Alternatively, you may run WordPerfect 8.0 from an entry thereto in your Linux menu.
echo " "
echo \(5\) To run the WP Print Manager, you can give, in a terminal window, the command:
echo "   "\"${bold}sudo xwppmgr80${normal}\"
echo " "
echo " "
echo Enjoy!
echo " "
exit
