2020-12-31 01:39:32 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# set -x # Uncomment to Debug
|
|
|
|
|
2021-10-08 01:00:49 +00:00
|
|
|
cd "$(dirname "$0")"
|
2020-12-31 01:39:32 +00:00
|
|
|
# verify packages installed
|
|
|
|
ERROR=0
|
|
|
|
if ! command -v genisoimage &> /dev/null ; then
|
|
|
|
echo "genisoimage could not be found"
|
|
|
|
echo "Run 'sudo apt install genisoimage' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
if ! command -v python3 &> /dev/null ; then
|
|
|
|
echo "python3 could not be found"
|
|
|
|
echo "Run 'sudo apt install python3' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
if ! python3 -m venv --help &> /dev/null ; then
|
|
|
|
echo "venv could not be found"
|
|
|
|
echo "Run 'sudo apt install python3-venv' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
if ! command -v unzip &> /dev/null ; then
|
|
|
|
echo "unzip could not be found"
|
|
|
|
echo "Run 'sudo apt install unzip' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
2022-08-12 03:19:02 +00:00
|
|
|
if ! command -v unar &> /dev/null ; then
|
|
|
|
echo "unar could not be found"
|
|
|
|
echo "Run 'sudo apt install unar' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
2020-12-31 01:39:32 +00:00
|
|
|
if [ $ERROR = 1 ] ; then
|
2021-11-07 00:25:02 +00:00
|
|
|
echo
|
|
|
|
echo "Fix errors and re-run ./start.sh"
|
|
|
|
exit 1
|
2020-12-31 01:39:32 +00:00
|
|
|
fi
|
|
|
|
|
2023-11-13 22:52:05 +00:00
|
|
|
# Force rebuild the venv if RESET_VENV is set to any non-empty value
|
|
|
|
if [[ "$RESET_VENV" ]]; then
|
|
|
|
echo "Force-removing old venv"
|
|
|
|
sudo rm -rf venv
|
|
|
|
fi
|
|
|
|
|
2021-12-07 02:38:41 +00:00
|
|
|
# Test for two known broken venv states
|
|
|
|
if test -e venv; then
|
|
|
|
GOOD_VENV=true
|
2022-01-01 17:38:10 +00:00
|
|
|
if ! test -e venv/bin/activate; then
|
|
|
|
GOOD_VENV=false
|
|
|
|
else
|
|
|
|
source venv/bin/activate
|
|
|
|
pip3 list 1> /dev/null
|
|
|
|
test $? -eq 1 && GOOD_VENV=false
|
|
|
|
fi
|
2021-12-07 02:38:41 +00:00
|
|
|
if ! "$GOOD_VENV"; then
|
|
|
|
echo "Deleting bad python venv"
|
|
|
|
sudo rm -rf venv
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the venv if it doesn't exist
|
2020-12-31 01:39:32 +00:00
|
|
|
if ! test -e venv; then
|
2021-11-07 00:25:02 +00:00
|
|
|
echo "Creating python venv for web server"
|
|
|
|
python3 -m venv venv
|
|
|
|
echo "Activating venv"
|
|
|
|
source venv/bin/activate
|
|
|
|
echo "Installing requirements.txt"
|
2021-12-10 01:45:54 +00:00
|
|
|
pip3 install wheel
|
|
|
|
pip3 install -r requirements.txt
|
2022-01-09 14:26:28 +00:00
|
|
|
|
2022-09-20 00:56:22 +00:00
|
|
|
if git rev-parse --is-inside-work-tree &> /dev/null; then
|
2022-01-09 14:26:28 +00:00
|
|
|
git rev-parse HEAD > current
|
|
|
|
fi
|
2020-12-31 01:39:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
source venv/bin/activate
|
|
|
|
|
2021-12-23 17:08:50 +00:00
|
|
|
# Detect if someone updates the git repo - we need to re-run pip3 install.
|
|
|
|
set +e
|
2022-01-09 14:26:28 +00:00
|
|
|
|
2021-12-23 17:08:50 +00:00
|
|
|
git rev-parse --is-inside-work-tree &> /dev/null
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
set -e
|
|
|
|
if ! test -e current; then
|
|
|
|
git rev-parse > current
|
|
|
|
elif [ "$(cat current)" != "$(git rev-parse HEAD)" ]; then
|
|
|
|
echo "New version detected, updating libraries from requirements.txt"
|
2021-12-10 01:45:54 +00:00
|
|
|
pip3 install -r requirements.txt
|
2021-11-07 00:25:02 +00:00
|
|
|
git rev-parse HEAD > current
|
|
|
|
fi
|
2021-12-23 17:08:50 +00:00
|
|
|
else
|
|
|
|
echo "Warning: Not running from a valid git repository. Will not be able to update the code."
|
2020-12-31 01:39:32 +00:00
|
|
|
fi
|
2021-12-23 17:08:50 +00:00
|
|
|
set -e
|
2020-12-31 01:39:32 +00:00
|
|
|
|
2022-01-09 14:26:28 +00:00
|
|
|
pybabel compile -d src/translations
|
2021-12-26 21:36:12 +00:00
|
|
|
|
2021-11-15 19:00:32 +00:00
|
|
|
# parse arguments
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
PARAM=$(echo "$1" | awk -F= '{print $1}')
|
|
|
|
VALUE=$(echo "$1" | awk -F= '{print $2}')
|
|
|
|
case $PARAM in
|
2022-07-26 04:47:11 +00:00
|
|
|
-p | --web-port)
|
|
|
|
ARG_PORT="--port $VALUE"
|
|
|
|
;;
|
|
|
|
-P | --password)
|
|
|
|
ARG_PASSWORD="--password $VALUE"
|
|
|
|
;;
|
2022-12-05 17:58:23 +00:00
|
|
|
-h | --backend-host)
|
|
|
|
ARG_BACKEND_HOST="--backend-host $VALUE"
|
2022-07-26 04:47:11 +00:00
|
|
|
;;
|
2022-12-05 17:58:23 +00:00
|
|
|
-o | --backend-port)
|
|
|
|
ARG_BACKEND_PORT="--backend-port $VALUE"
|
2022-07-26 04:47:11 +00:00
|
|
|
;;
|
2022-08-01 00:02:14 +00:00
|
|
|
-l | --log-level)
|
|
|
|
ARG_LOG_LEVEL="--log-level $VALUE"
|
|
|
|
;;
|
2022-08-28 13:51:31 +00:00
|
|
|
-d | --dev-mode)
|
|
|
|
ARG_DEV_MODE="--dev-mode"
|
|
|
|
;;
|
2022-07-26 04:47:11 +00:00
|
|
|
*)
|
|
|
|
echo "ERROR: unknown parameter \"$PARAM\""
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-11-15 19:00:32 +00:00
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2022-01-21 23:08:29 +00:00
|
|
|
PYTHON_COMMON_PATH=$(dirname $PWD)/common/src
|
|
|
|
export PYTHONPATH=$PWD/src:${PYTHON_COMMON_PATH}
|
2022-12-05 17:58:23 +00:00
|
|
|
cd src || exit 1
|
2022-08-28 13:51:31 +00:00
|
|
|
|
|
|
|
if [[ $ARG_DEV_MODE ]]; then
|
2022-12-05 17:58:23 +00:00
|
|
|
echo "Starting PiSCSI Web UI (dev mode) ..."
|
2022-08-28 13:51:31 +00:00
|
|
|
watchmedo auto-restart --directory=../../ --pattern=*.py --recursive -- \
|
2022-12-05 17:58:23 +00:00
|
|
|
python3 web.py ${ARG_PORT} ${ARG_PASSWORD} ${ARG_BACKEND_HOST} ${ARG_BACKEND_PORT} ${ARG_LOG_LEVEL} ${ARG_DEV_MODE}
|
2022-08-28 13:51:31 +00:00
|
|
|
else
|
2022-12-05 17:58:23 +00:00
|
|
|
echo "Starting PiSCSI Web UI ..."
|
|
|
|
python3 web.py ${ARG_PORT} ${ARG_PASSWORD} ${ARG_BACKEND_HOST} ${ARG_BACKEND_PORT} ${ARG_LOG_LEVEL} ${ARG_DEV_MODE}
|
|
|
|
fi
|