mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2025-12-10 12:51:16 +08:00
Merge pull request #218 from lhartmann/python3
Maintenance: Use Python 3 and venv
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#!/bin/bash
|
||||
OPENPLC_DIR="$PWD"
|
||||
SWAP_FILE="$OPENPLC_DIR/swapfile"
|
||||
WIRINGPI_VERSION="2.61-1"
|
||||
VENV_DIR="$OPENPLC_DIR/.venv"
|
||||
|
||||
function print_help_and_exit {
|
||||
echo ""
|
||||
@@ -35,27 +37,38 @@ function linux_install_deps {
|
||||
if [ -x /bin/yum ]; then
|
||||
yum clean expire-cache
|
||||
yum check-update
|
||||
$1 yum -q -y install curl make automake gcc gcc-c++ kernel-devel pkg-config bison flex autoconf libtool openssl-devel cmake python3 python3-pip
|
||||
$1 yum -q -y install python2.7 python2-devel
|
||||
$1 yum -q -y install curl make automake gcc gcc-c++ kernel-devel pkg-config bison flex autoconf libtool openssl-devel cmake python3
|
||||
#Installing dependencies for Ubuntu/Mint/Debian
|
||||
elif [ -x /usr/bin/apt-get ]; then
|
||||
$1 apt-get update
|
||||
$1 apt-get install -y build-essential pkg-config bison flex autoconf \
|
||||
automake libtool make git python2.7 \
|
||||
sqlite3 cmake git curl python3 python3-pip libmodbus-dev
|
||||
automake libtool make git \
|
||||
sqlite3 cmake curl python3 python3-venv libmodbus-dev
|
||||
else
|
||||
fail "Unsupported linux distro."
|
||||
fi
|
||||
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
|
||||
$1 python2.7 get-pip.py
|
||||
}
|
||||
|
||||
function install_wiringpi {
|
||||
echo "[WIRINGPI]"
|
||||
echo "Trying distribution package..."
|
||||
sudo apt-get install -y wiringpi && return 0
|
||||
|
||||
echo "Falling back to direct download..."
|
||||
local FILE="wiringpi-$WIRINGPI_VERSION-arm64.deb"
|
||||
local URL="https://github.com/WiringPi/WiringPi/releases/download/$WIRINGPI_VERSION/$FILE"
|
||||
(
|
||||
set -e
|
||||
wget -c -O "$OPENPLC_DIR/$FILE" "$URL"
|
||||
sudo dpkg -i "$OPENPLC_DIR/$FILE"
|
||||
sudo apt install -f
|
||||
rm -f "$OPENPLC_DIR/$FILE"
|
||||
) || fail "Failed to install wiringpi."
|
||||
}
|
||||
|
||||
function install_py_deps {
|
||||
$1 pip2 install flask
|
||||
$1 pip2 install flask-login
|
||||
$1 pip2 install pyserial
|
||||
$1 pip2 install pymodbus
|
||||
$1 pip3 install pymodbus==2.5.3
|
||||
python3 -m venv "$VENV_DIR"
|
||||
"$VENV_DIR/bin/python3" -m pip install flask flask-login pyserial pymodbus==2.5.3
|
||||
}
|
||||
|
||||
function swap_on {
|
||||
@@ -199,7 +212,18 @@ function finalize_install {
|
||||
./change_hardware_layer.sh blank_linux
|
||||
fi
|
||||
./compile_program.sh blank_program.st
|
||||
cp "start_openplc.sh" "$OPENPLC_DIR"
|
||||
cat > "$OPENPLC_DIR/start_openplc.sh" <<EOF
|
||||
#!/bin/bash
|
||||
mkdir -p /persistent/st_files
|
||||
cp -n /workdir/webserver/dnp3_default.cfg /persistent/dnp3.cfg
|
||||
cp -n /workdir/webserver/openplc_default.db /persistent/openplc.db
|
||||
cp -n /workdir/webserver/st_files_default/* /persistent/st_files/
|
||||
cp -n /dev/null /persistent/persistent.file
|
||||
cp -n /dev/null /persistent/mbconfig.cfg
|
||||
cd "$OPENPLC_DIR/webserver"
|
||||
"$OPENPLC_DIR/.venv/bin/python3" webserver.py
|
||||
EOF
|
||||
chmod a+x "$OPENPLC_DIR/start_openplc.sh"
|
||||
cd "$OPENPLC_DIR"
|
||||
}
|
||||
|
||||
@@ -250,10 +274,7 @@ elif [ "$1" == "linux" ]; then
|
||||
|
||||
echo "Installing OpenPLC on Linux"
|
||||
linux_install_deps sudo
|
||||
|
||||
install_py_deps
|
||||
install_py_deps "sudo -H"
|
||||
|
||||
install_all_libs sudo
|
||||
[ "$2" == "ethercat" ] && install_ethercat
|
||||
install_systemd_service sudo
|
||||
@@ -268,13 +289,9 @@ elif [ "$1" == "docker" ]; then
|
||||
|
||||
elif [ "$1" == "rpi" ]; then
|
||||
echo "Installing OpenPLC on Raspberry Pi"
|
||||
|
||||
linux_install_deps sudo
|
||||
sudo apt-get install -y wiringpi
|
||||
|
||||
install_wiringpi
|
||||
install_py_deps
|
||||
install_py_deps "sudo -H"
|
||||
|
||||
install_all_libs sudo
|
||||
install_systemd_service sudo
|
||||
finalize_install linux
|
||||
@@ -292,10 +309,7 @@ elif [ "$1" == "neuron" ]; then
|
||||
sudo systemctl disable evok.service
|
||||
|
||||
linux_install_deps sudo
|
||||
|
||||
install_py_deps
|
||||
install_py_deps "sudo -H"
|
||||
|
||||
install_all_libs sudo
|
||||
install_systemd_service sudo
|
||||
finalize_install linux
|
||||
|
||||
Reference in New Issue
Block a user