2022-10-06 07:05:46 -05:00
|
|
|
#!/bin/bash
|
|
|
|
# 2022-09-14 Hyperling
|
|
|
|
# Ensure dependencies are met and start the webserver.
|
|
|
|
|
2024-01-24 11:02:23 +00:00
|
|
|
## Setup ##
|
|
|
|
|
|
|
|
DIR=`dirname $0`
|
|
|
|
PROG=`basename $0`
|
|
|
|
|
|
|
|
## Functions ##
|
|
|
|
|
|
|
|
function usage {
|
|
|
|
cat <<- EOF
|
|
|
|
$PROG calls the main Node.js program after ensuring the project can run.
|
|
|
|
(PORTS)
|
|
|
|
-p : Pass the port numbers that the API/website should listen at.
|
|
|
|
Example: $PROG -p 80 -p 443 -p 8080
|
|
|
|
(HELP)
|
|
|
|
-h : Show this usage output and exit successfully.
|
|
|
|
EOF
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
|
|
|
## Parameters ##
|
|
|
|
|
|
|
|
while getopts ':p:h' opt; do
|
|
|
|
case "$opt" in
|
|
|
|
p) (( OPTARG < 1024 )) && [[ $LOGNAME != "root" ]] && {
|
|
|
|
echo "WARNING: Port $OPTARG is privileged. Will need to be root."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
ports="$ports $OPTARG" ;;
|
|
|
|
h) usage 0 ;;
|
|
|
|
*) echo "ERROR: Option $OPTARG not recognized." >&2
|
|
|
|
usage 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
## Build Environment ##
|
|
|
|
|
2022-10-08 09:19:40 -05:00
|
|
|
# Ensure we are executing from this file's directory.
|
2024-01-24 11:02:23 +00:00
|
|
|
cd $DIR
|
2022-10-08 09:19:40 -05:00
|
|
|
|
2024-01-30 05:59:40 -07:00
|
|
|
echo "`date` - Check if any dependencies need installed."
|
2022-10-06 07:12:28 -05:00
|
|
|
if [[ ! `which php` || ! `which node`|| ! `which npm` ]]; then
|
|
|
|
sudo apt install -y php-fpm nodejs npm
|
2022-10-06 07:05:46 -05:00
|
|
|
fi
|
|
|
|
|
2022-10-08 09:19:40 -05:00
|
|
|
# Directories and allowed page types are executable, others are not.
|
2024-01-30 05:59:40 -07:00
|
|
|
echo "`date` - Fix any strange file permissions."
|
2022-10-08 09:19:40 -05:00
|
|
|
find ./pages/ | while read file; do
|
|
|
|
if [[ $file == *".php" || $file == *".sh" || -d $file ]]; then
|
|
|
|
mode=755
|
|
|
|
else
|
|
|
|
mode=644
|
|
|
|
fi
|
|
|
|
chmod -c $mode $file
|
|
|
|
done
|
|
|
|
|
2024-01-30 05:59:40 -07:00
|
|
|
echo "`date` - Check if any modules need updated/installed."
|
2022-10-06 07:05:46 -05:00
|
|
|
npm install
|
|
|
|
|
2024-01-24 11:02:23 +00:00
|
|
|
## Main ##
|
|
|
|
|
2024-01-30 05:59:40 -07:00
|
|
|
echo "`date` - Start website API."
|
2024-01-24 11:02:23 +00:00
|
|
|
./main.js $ports
|
2024-01-30 05:59:40 -07:00
|
|
|
status=$?
|
2024-01-24 11:02:23 +00:00
|
|
|
|
|
|
|
## Finish ##
|
2022-10-06 07:05:46 -05:00
|
|
|
|
2024-01-30 05:59:40 -07:00
|
|
|
echo "`date` - Exiting with status '$status'."
|
|
|
|
exit $status
|