# Install.sh

# PHP can have a systemProcess pipe set.  If the websocket server needs to communicate with it, it can connect to the read and write named pipes.  If a user needs to have a PHP system set up on their system, named pipes can be included along with Websockets, so that system commands can be executed, which requiring waiting and further input.  The names of the system pipes should be systemProcessIn and systemProcessOut.

# HTTPS would have to be installed for their nginx server on their local system.
# The named pipes could go in $Neolamia/Temporary

# New PHP scripts: CheckInstall, SetInstall


# PHP must be installed to read the configuration file.
sudo apt install php

# -- Check the user's configuration file before writing to .profile.
if($(php $Neolamia/PHP/CheckInstall 1) == "true"); then
  echo "The neolamia.com project has already been installed.  This script will exit.  The current version is $(php $Neolamia/PHP/CheckInstall 2).
  exit;
fi

# Try installing php-fpm and nginx.  Other packages will need to be installed.  Https needs to be activated for localhost.
sudo apt install nginx php-fpm
# /etc/nginx/sites-available/default will need to be configured for localhost.


# Append these strings of text to $HOME/.profile.
# Set and export the $Neolamia variable.  Try to get it so it's usable by all scripts (try by including it in this file, $HOME/.profile, which has been done).
echo "
export Neolamia=\$HOME/Neolamia
" >> $HOME/.profile

# Append to $HOME/.profile (where PATH is set).
echo "
# Run when the user logs in.
if [ ! -d \$Neolamia/Temporary ]; then
  mkdir \$Neolamia/Temporary
fi
mount -F tmpfs $Neolamia/Temporary
" >> $HOME/.profile

# Append to $HOME/.profile (where PATH is set).
echo "
# set PATH so it includes user's Neolamia/Bash folder if it exists.
if [ -d "$HOME/Neolamia/Bash" ] ; then
   PATH="\$HOME/Neolamia/Bash:\$PATH"
fi
" >> $HOME/.profile

Update the user's Neolamia configuration file.  $Neolamia/Configuration.json should be edited.
php $Neolamia/PHP/SetInstall "true" "1.0"


# Pipes must be initiated when the user logs in, in $Neolamia/Temporary/.
# New PHP scripts: StartServerClientPipe.php
php $Neolamia/PHP/StartServerClientPipe.php $Neolamia/Temporary/systemProcessIn $Neolamia/Temporary/systemProcessOut