#!/bin/bash

# wp81in-pclos - version 2.0
# A script to install WordPerfect 8.1 for Linux on PCLinuxOS.
# \(c\) Peter Stone, 2026
# peter@xwp8users.com

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

echo " "
echo This script is designed to install ${bold}WordPerfect 8.1 for Linux${normal}
echo on versions of PCLinuxOS Slackware current in 2026 or later.
echo " "
echo It has been tested on PCLinuxOs 2025.09 KDE.
echo " "
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}/root/Downloads/wp-inst${normal}
echo " "
echo 2. Copy this script file to that directory.
echo " "
echo 3. Copy your ${bold}wp8-full${normal} and ${bold}fonts-\[x\]${normal} deb files, or your ${bold}wpx-free${normal} deb file,
echo from your Corel Linux CD to that directory.
echo " "
echo " "
echo On PCLinuxOS the script must be run in a root terminal.
echo " "
echo After changing to the working directory, the script can be executed with 
echo the command:"   "\"${bold}sh ./wp81in-pclos.sh${normal}\"

echo " "
echo Ensuring that the working directory exists.
test -e /root/Downloads/wp-inst
if ! [ $? = 0 ] 
then 
     mkdir /root/Downloads/wp-inst
fi

echo " "

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

cd /root/Downloads/wp-inst

# Testing for the WordPerfect 8.1 deb.

test -e ./wp-full_8.1-12_i386.deb 
if [ $? = 0 ] 
then 
     test -e ./fonts-16_1.0-5.deb
     if ! [ $? = 0 ] 
     then 
        echo " "
        echo "Command failed. fonts-16 is not available. Exiting script."
        exit
     fi

     cp ./wp-full_8.1-12_i386.deb ./wp81.deb

else
     test -e ./wpx-free_8.0-78_i386.deb
     if [ $? = 0 ] 
     then 
         cp ./wpx-free_8.0-78_i386.deb ./wp81.deb
     else
         echo " "
         echo "Command failed. No version of WordPerfect 8.1 is available. Exiting script."
         exit
     fi
fi

echo " "
# Now downloading various utilities, 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.

cp ./wp-utils-4.5.tgz /wp-utils-4.5.tgz
cd /
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

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

echo " "

# Now running ldconfig.

ldconfig -c old

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

cd ~/Downloads/wp-inst

echo " "

# *********************************************************************************
# Now proceeding with the main installation.

# Now installing fonts for wp-full.

test -e ./wp-full_8.1-12_i386.deb 
if [ $? = 0 ] 
then 
    test -e ./fonts-16_1.0-5.deb
    if [ $? = 0 ] 
    then 
        ar -vx ./fonts-16_1.0-5.deb
        mv ./data.tar.gz ./fonts-16-1.0.tgz

        if ! [ $? = 0 ] 
        then 
            echo " "
            echo "Command failed. fonts-16 cannot be converted. Exiting script."
            exit
        fi
        
        installpkg15 ./fonts-16-1.0.tgz

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

test -e ./wp-full_8.1-12_i386.deb 
if [ $? = 0 ] 
then 
    echo " "
    test -e ./fonts-69_1.0-4.deb
    if [ $? = 0 ] 
    then 
        ar -vx ./fonts-69_1.0-4.deb
        mv ./data.tar.gz ./fonts-69-1.0.tgz

        if [ $? = 0 ] 
        then 
            installpkg15 ./fonts-69-1.0.tgz
        fi             
    fi
fi

test -e ./wp-full_8.1-12_i386.deb 
if [ $? = 0 ] 
then 
    test -e fonts-115_1.0-4.deb
    if [ $? = 0 ] 
    then 
        ar -vx ./fonts-115_1.0-4.deb
        mv ./data.tar.gz ./fonts-115-1.0.tgz
            
        if [ $? = 0 ] 
        then 
            installpkg15 ./fonts-115-1.0.tgz
        fi
    fi
fi    

cd ~/Downloads/wp-inst

echo " "

# ***************************************************************************
# Now converting and then installing the core WordPerfect package.

test -e ./wp81.deb
if [ $? = 0 ] 
then
    ar -vx ./wp81.deb
    mv ./data.tar.gz ./wp81.tgz

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

    installpkg15 ./wp81.tgz

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

# Now co-ordinating with 8.0, if necessary.

cp /usr/bin/xwp81 /usr/bin/xwp

echo " "

cd /root/Downloads/wp-inst

# ***********************************************************************************
# Now setting up the fonts for wp-full.

test -e /usr/lib/wp8/shbin10/xwpfi
if [ $? = 0 ] 
then
    cd /usr/X11R6/lib/X11/fonts/Type1

# Now running type1inst.

    type1inst

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

# Now running mkfontdir.

    mkfontdir

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

# Now running wpfi.

    /usr/lib/wp8/shbin10/wpfi

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

echo " "

# Now copying fonts to whole system.

cp -r /usr/X11R6/lib/X11/fonts/Type1/ /usr/share/fonts/type1/

if ! [ $? = 0 ] 
then 
    echo " "
    echo "Command failed. Unable to copy fonts to the whole system."
    echo "Exiting script."
    exit
fi

cd ~/Downloads/wp-inst

echo " "

# ************************************************************************
# Now dealing with printing.

dnf install cups-pdf

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

test -e /etc/printcap
if ! [ $? = 0 ] 
then 
    ln -s /run/cups/printcap /etc/printcap
fi
   
cd /usr/lib/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

cd /root/Downloads/wp-inst

echo " "

# ******************************************************************************
# Now providing the final messages.

echo " "
echo \(1\) ${bold}WordPerfect 8.1${normal} has been successfully installed,
echo along with an updated version of the WP Print Manager.
echo " "
echo \(2\) ${bold}Next${normal}, you should run WordPerfect 8.1 ${bold}once${normal} as a superuser,
echo by giving, in a root terminal window, the command:
echo "   "\"${bold}xwp -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 \(3\) ${bold}Thereafter${normal}, you should WordPerfect 8.1 as a normal user, by giving,
echo in a normal terminal window, the command:
echo "   "\"${bold}xwp${normal}\"
echo " "
echo Alternatively, you may run WordPerfect 8.1 from an entry thereto in the Office folder
echo in your Linux menu.
echo " "
echo \(4\) To run the WP Print Manager, you can give, in a root terminal window, the command:
echo "   "\"${bold}xwppmgr${normal}\"
echo " "
echo " "
echo Enjoy!
echo " "
exit
