#!/bin/bash

# wp81in-fed.sh - version 2.0
# A script to install WordPerfect 8.1 for Linux on rpm/dnf distros such as Fedora.
# \(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 Fedora or Mageia current in 2026 or later.
echo " "
echo It has been tested most recently on Fedora 43 \(Workstation-Gnome and KDE\).
echo It may be expected to run successfully on any rpm-based distro which uses \"dnf\"
echo as its usual package manager.
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 your ${bold}wp8-full${normal} and ${bold}fonts-\[x\]${normal} deb files,
echo or your ${bold}wpx-free${normal} deb file,
echo from your Corel Linux CD to that 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 In the case of Mageia, it may be necessary for the user to be a member
echo of the \"wheel\" group.
echo " "
echo " "
echo After changing to the working directory, this script can be executed
echo with the command:"  "\"${bold}sh ./wp81in-fed.sh${normal}\"
echo " "

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

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

echo " "
cd ~/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 installing wget and binutils.

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

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

# Now installing mkfontscale, if necessary.

sudo dnf -y install mkfontscale

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.

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

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 groff.

sudo dnf -y install groff

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

echo " "

# Now installing perl.

sudo dnf install -y perl

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

# " "

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

# Now installing fonts for wp-full.

cd ~/Downloads/wp-inst

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
        
        sudo 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 
            sudo 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 
            sudo installpkg15 ./fonts-115-1.0.tgz
        fi
    fi
fi    

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

echo " "
cd ~/Downloads/wp-inst

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

    sudo 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.

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

# *************************************************************************
# 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.

    sudo type1inst

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

# Now running mkfontdir.

    sudo mkfontdir

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

# Now running wpfi.

    sudo /usr/lib/wp8/shbin10/wpfi

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

# Now copying fonts to whole system.

    sudo cp -RT /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
fi

cd ~/Downloads/wp-inst

echo " "
# Now installing cups-pdf

sudo dnf -y install cups-pdf


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

# 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
   
cd /usr/lib/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


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

cd ~/Downloads/wp-inst
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 terminal window, the command:
echo "   "\"${bold}sudo 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 run WordPerfect 8.1 as a normal user, by giving,
echo in a terminal window, the command:
echo "   "\"${bold}xwp${normal}\"
echo " "
echo Alternatively, you may run WordPerfect 8.1 from an entry thereto in your Linux menu.
echo " "
echo \(4\) To run the WP Print Manager, you can give, in a terminal window, the command:
echo "   "\"${bold}sudo xwppmgr${normal}\"
echo " "
echo " "
echo Enjoy!
echo " "
exit

