#!/bin/bash
## <a name="installation-summary"></a><b>INSTALLATION/SETUP SUMMARY</b>
## Installed 21 Dec 2019
## Poplog is location independent. Choose an appropriate location to run this script and install poplog

##A directory poplog_base will be created in the directory in which poplog is installed.
##It will contain the files required at run time. Some of the downloaded files are used
##to build the final usable poplog system.

## Expert users may wish to modify some of the instructions before running
## the script.'

##Get the required poplog-specific tar files used for installation

echo 'Download the latest "core" version of poplog with sources and documentation'
echo 'produced by Waldek Hebisch'
echo ''
echo 'wget http://www.cs.bham.ac.uk/research/projects/poplog/V16/latest_poplog_base.tar.bz2'

wget http://www.cs.bham.ac.uk/research/projects/poplog/V16/latest_poplog_base.tar.bz2

echo ''
echo 'Download the poplog documentation and tutorial files from Birmingham'
echo 'To be added to the poplog system in the $usepop/pop/{doc,help,teach,ref} directories'
echo ''
echo 'wget http://www.cs.bham.ac.uk/research/projects/poplog/V16/docs.tar.bz2'

wget http://www.cs.bham.ac.uk/research/projects/poplog/V16/docs.tar.bz2

## Download the poplog 'packages' system from Birmingham, to be added to the core
## poplog system as the $usepop/pop/packages directory

echo ''
echo 'wget http://www.cs.bham.ac.uk/research/projects/poplog/packages-v16.tgz'
wget http://www.cs.bham.ac.uk/research/projects/poplog/packages-v16.tgz

echo ''
echo 'Download the poplog installation script and make it executable'
echo 'wget https://www.cs.bham.ac.uk/research/projects/poplog/V16/build_all.csh'

### previously build_pop.sh now build_all.csh
wget https://www.cs.bham.ac.uk/research/projects/poplog/V16/build_all.csh

echo ''
echo 'Make it executable'
echo 'chmod u+rwx build_all.csh'
chmod u+rwx build_all.csh

echo ''

## echo 'Setup user environment variables'
## echo 'usepop will be set to `pwd`/poplog_base'
## echo `pwd`'/poplog_base' > poplog_base/USEPOP
## `pwd`'/poplog_base' > poplog_base/USEPOP
## echo 'the value of $usepop needs to be set to `cat poplog_base/USEPOP`'
## echo 'for all users.\n'
## echo 'The variable $usepop will need to be set at the beginning of a session in which'
## echo 'poplog is run. Regular users of poplog often set up $usepop in their login'
## echo 'start-up scripts, e.g. .bashrc or .tcshrc'

##USE THE FETCHED FILES TO INSTALL POPLOG##
echo 'Starting to install poplog in' `pwd`/poplog_base

echo ''

echo 'tar xfj latest_poplog_base.tar.bz2'
    tar xfj latest_poplog_base.tar.bz2

echo 'contents of poplog_base'
ls -l poplog_base

echo ''
echo 'Unpacked files''
ls -l *

echo ''
echo 'Build the new Poplog V16 system, after changing to subdirectory poplog_base'

echo 'cd poplog_base'
cd poplog_base
echo 'Now in directory:'
pwd

## set up value of $usepop
echo 'Create file whose content is the name of this directory'
echo `pwd` > USEPOP

echo "directory name stored"
cat USEPOP

export usepop=`pwd`

echo 'Use the build_all.csh script to build poplog from the contents of the'
echo 'previously downloaded tar file, and the packages sub-tree.\n'

echo "Run the script '../build_all.csh'"
echo 'This may take some time.'

## can't run or source it where it is for some reason
cp -p ../build_all.csh .

    ./build_all.csh

## That should produce these two files recording the installation processes,
## which may be useful for debugging
##     poplog_base/buildout1
##     poplog_base/buildout2


## If all goes well it will print out something like this, [but altered for csh]
## recording its actions and some of their results:
##
##     ./build_pop0 > rapp1 2>&1
##     mv pop/pop/newpop11 pop/pop/corepop
##     ./build_pop2 > rapp2 2>&1
##     ls -l pop/lib/psv
##     total 5500
##     -rw-r--r-- 1 axs axs 2574744 Dec 15 04:11 clisp.psv
##     -rw-r--r-- 1 axs axs 1112472 Dec 15 04:11 pml.psv
##     -rw-r--r-- 1 axs axs  743832 Dec 15 04:11 prolog.psv
##     -rw-r--r-- 1 axs axs  911728 Dec 15 04:11 startup.psv
##     -rw-r--r-- 1 axs axs  280984 Dec 15 04:11 xved.psv

echo ''
echo 'Detailed trace output, for debugging, is in files buildout1 and buildout2'
echo "(Previously rapp1 and rapp2)"

## Install documentation files
echo ''
echo 'Now in directory:'
pwd
echo ''
echo 'Install the documentation files fetched from Birmingham'
echo 'cd pop'
cd pop
echo 'current directory'
pwd
echo ''
echo 'tar xfj ../../docs.tar.bz2'
tar xfj ../../docs.tar.bz2

echo 'Check that contents of $usepop/pop directory now contain doc, help, ref, teach directories'
echo ''
pwd
echo 'ls -l'
ls -l

## Install Poplog packages files
echo 'Untar and install the Poplog packages library also in poplog_base/pop'
echo ''
echo 'pwd'
pwd
echo ''

echo 'tar xfz ../../packages-v16.tgz'

tar xfz ../../packages-v16.tgz

echo ''
echo 'Check that $usepop/pop directory now also contains packages directory'
echo 'Current directory:'
pwd
echo ''
echo 'ls -l'
ls -l

echo ''
echo 'Check $popsavelib contents'
echo 'ls -l lib/psv'

echo 'Create documentation index files'

echo  'com/makeindexes'
echo ''
    com/makeindexes

echo ''
echo 'makeindexes can be run again later if any new documentation and library files
echo 'are added to poplog in standard sub-directories.'
echo ''

echo 'This file should be edited if the editor Ved is to be used for mail:'

echo '$usepop/pop/packages/vedmail/auto/popsitename.p'

echo 'If you expect to use the poplog editor Ved to read and send email message, then'
echo 'after the packages directory has been installed as above, edit the file:'

echo '$usepop/pop/packages/vedmail/auto/popsitename.p'

echo "Replace the line popsitename = '@cs.bham.ac.uk';"
echo 'with the domain of your email address if you intend to use Ved'
echo 'to insert the address automatically, e.g. when composing email messages.'
echo '----------------------------------------------------------------------'

echo "Test that it's all working, using the previously set up value for" '$usepop'
echo 'Try these linux commands, and exit each with CTRL-D:\n  pop11\n  ved\n  prolog\n  clisp\n  pml\n'

echo 'If you have any difficulties try joining the pop-forum mailing list'
echo 'and asking for help'.

echo ''

echo 'Send an email message to: pop-forum-request@cs.bham.ac.uk'

echo 'with one line in the message containing the word "subscribe"'

echo 'You should be sent a confirmation message, with instructions for posting.'

echo ''
