2021-03-06 22:50:59 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
# set -x # Uncomment to Debug
|
|
|
|
|
2021-10-20 01:01:32 +00:00
|
|
|
cd "$(dirname "$0")"
|
2021-03-06 22:50:59 +00:00
|
|
|
# verify packages installed
|
|
|
|
ERROR=0
|
|
|
|
if ! command -v dpkg -l i2c-tools &> /dev/null ; then
|
|
|
|
echo "i2c-tools could not be found"
|
|
|
|
echo "Run 'sudo apt install i2c-tools' 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
|
2021-10-25 02:13:32 +00:00
|
|
|
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
|
2021-03-06 22:50:59 +00:00
|
|
|
# Dep to build Pillow
|
|
|
|
if ! dpkg -l python3-dev &> /dev/null; then
|
|
|
|
echo "python3-dev could not be found"
|
|
|
|
echo "Run 'sudo apt install python3-dev' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
if ! dpkg -l libjpeg-dev &> /dev/null; then
|
|
|
|
echo "libjpeg-dev could not be found"
|
|
|
|
echo "Run 'sudo apt install libjpeg-dev' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
if ! dpkg -l libpng-dev &> /dev/null; then
|
|
|
|
echo "libpng-dev could not be found"
|
|
|
|
echo "Run 'sudo apt install libpng-dev' to fix."
|
|
|
|
ERROR=1
|
|
|
|
fi
|
2021-10-25 02:13:32 +00:00
|
|
|
if ! dpkg -l libopenjp2-7-dev &> /dev/null; then
|
|
|
|
echo "libopenjp2-7-dev could not be found"
|
|
|
|
echo "Run 'sudo apt install libopenjp2-7-dev' to fix."
|
2021-03-06 22:50:59 +00:00
|
|
|
ERROR=1
|
|
|
|
fi
|
|
|
|
if [ $ERROR = 1 ] ; then
|
|
|
|
echo
|
|
|
|
echo "Fix errors and re-run ./start.sh"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
if pgrep -f "python3 src/piscsi_oled_monitor.py" &> /dev/null; then
|
|
|
|
echo "Detected active piscsi_oled_monitor.py process"
|
2021-10-27 01:21:39 +00:00
|
|
|
echo "Terminating before launching a new one."
|
2022-12-05 17:58:23 +00:00
|
|
|
sudo pkill -f "python3 src/piscsi_oled_monitor.py"
|
2021-10-27 01:21:39 +00:00
|
|
|
fi
|
|
|
|
|
2021-03-06 22:50:59 +00:00
|
|
|
if ! i2cdetect -y 1 &> /dev/null ; then
|
|
|
|
echo "i2cdetect -y 1 did not find a screen."
|
|
|
|
exit 2
|
|
|
|
fi
|
2021-11-15 01:48:46 +00:00
|
|
|
|
|
|
|
# Compiler flags needed for gcc v10 and up
|
|
|
|
if [[ `gcc --version | awk '/gcc/' | awk -F ' ' '{print $3}' | awk -F '.' '{print $1}'` -ge 10 ]]; then
|
|
|
|
COMPILER_FLAGS="-fcommon"
|
|
|
|
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
|
2021-03-06 22:50:59 +00:00
|
|
|
if ! test -e venv; then
|
2021-12-23 17:08:50 +00:00
|
|
|
echo "Creating python venv for OLED Screen"
|
|
|
|
python3 -m venv venv
|
|
|
|
echo "Activating venv"
|
|
|
|
source venv/bin/activate
|
|
|
|
echo "Installing requirements.txt"
|
|
|
|
pip3 install wheel
|
|
|
|
CFLAGS="$COMPILER_FLAGS" pip3 install -r requirements.txt
|
2022-01-09 14:26:28 +00:00
|
|
|
|
|
|
|
set +e
|
|
|
|
git rev-parse --is-inside-work-tree &> /dev/null
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
git rev-parse HEAD > current
|
|
|
|
fi
|
|
|
|
set -e
|
2021-03-06 22:50:59 +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
|
|
|
|
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"
|
|
|
|
CFLAGS="$COMPILER_FLAGS" pip3 install -r requirements.txt
|
|
|
|
git rev-parse HEAD > current
|
|
|
|
fi
|
2021-03-06 22:50:59 +00:00
|
|
|
else
|
2021-12-23 17:08:50 +00:00
|
|
|
echo "Warning: Not running from a valid git repository. Will not be able to update the code."
|
2021-03-06 22:50:59 +00:00
|
|
|
fi
|
2021-12-23 17:08:50 +00:00
|
|
|
set -e
|
2021-03-06 22:50:59 +00:00
|
|
|
|
2021-10-21 02:33:06 +00:00
|
|
|
# parse arguments
|
|
|
|
while [ "$1" != "" ]; do
|
|
|
|
PARAM=$(echo "$1" | awk -F= '{print $1}')
|
|
|
|
VALUE=$(echo "$1" | awk -F= '{print $2}')
|
|
|
|
case $PARAM in
|
|
|
|
-r | --rotation)
|
2021-12-23 17:12:16 +00:00
|
|
|
ROTATION="--rotation $VALUE"
|
2021-10-21 02:33:06 +00:00
|
|
|
;;
|
2021-11-14 01:40:49 +00:00
|
|
|
-h | --height)
|
2021-12-23 17:12:16 +00:00
|
|
|
HEIGHT="--height $VALUE"
|
|
|
|
;;
|
2022-11-24 06:27:10 +00:00
|
|
|
-i | --refresh_interval)
|
|
|
|
INTERVAL="--refresh_interval $VALUE"
|
|
|
|
;;
|
2021-12-23 17:12:16 +00:00
|
|
|
-P | --password)
|
|
|
|
PASSWORD="--password $VALUE"
|
2021-11-14 01:40:49 +00:00
|
|
|
;;
|
2021-10-21 02:33:06 +00:00
|
|
|
*)
|
|
|
|
echo "ERROR: unknown parameter \"$PARAM\""
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-11-07 00:23:53 +00:00
|
|
|
echo "Starting OLED Screen..."
|
|
|
|
if [ -z ${ROTATION+x} ]; then
|
|
|
|
echo "No screen rotation parameter given; falling back to the default."
|
|
|
|
else
|
2021-12-23 17:12:16 +00:00
|
|
|
echo "Starting with parameter $ROTATION"
|
2021-11-07 00:23:53 +00:00
|
|
|
fi
|
2021-11-14 01:40:49 +00:00
|
|
|
if [ -z ${HEIGHT+x} ]; then
|
|
|
|
echo "No screen height parameter given; falling back to the default."
|
|
|
|
else
|
2021-12-23 17:12:16 +00:00
|
|
|
echo "Starting with parameter $HEIGHT"
|
2021-11-14 01:40:49 +00:00
|
|
|
fi
|
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
|
|
|
python3 src/piscsi_oled_monitor.py ${ROTATION} ${HEIGHT} ${INTERVAL} ${PASSWORD}
|