#/bin/bash #test for root privilege if [ $(id -u) -ne 0 ] then echo "Please run this script using sudo!" exit fi echo echo "#################################################################" echo "#### Welcome! ####" echo "#### zeroPLC Installer v1.0 ####" echo "#################################################################" echo echo sleep 1 echo "#################################################################" echo "#### Downloading files ####" echo "#################################################################" sleep 1 cd /home/$SUDO_USER wget https://git.sqegmbh.de/zeroPLC/zeroPLC-installer/archive/master.zip #check wget exit code if [ $? -ne 0 ] then echo "Error downloading files, exiting" exit fi unzip -q master.zip cd zeroplc-installer sleep 1 echo echo echo "#################################################################" echo "#### Activating device tree overlays ####" echo "#################################################################" sleep 1 echo "Copying overlay files" cp ./dtoverlay/mcp23017_0x20_zeroplc.dtbo /boot/overlays/ cp ./dtoverlay/mcp23017_0x21_zeroplc.dtbo /boot/overlays/ echo "Activating overlays in /boot/firmware/config.txt" cat <> /boot/firmware/config.txt dtparam=i2c_arm=on dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24 dtoverlay=w1-gpio enable_uart=1 dtparam=spi=on dtoverlay=spi0-0cs dtoverlay=mcp23017_0x20_zeroplc,noints=1 dtoverlay=mcp23017_0x21_zeroplc,addr=0x21,noints=1 dtoverlay=i2c-rtc,pcf8523 dtoverlay=ads1015,addr=0x4b dtparam=cha_enable=true,cha_cfg=4,cha_gain=0 dtparam=chb_enable=true,chb_cfg=5,chb_gain=0 dtparam=chc_enable=true,chc_cfg=6,chc_gain=0 dtparam=chd_enable=true,chd_cfg=7,chd_gain=0 dtoverlay=ads1015,addr=0x49 dtparam=cha_enable=true,cha_cfg=4,cha_gain=0 dtparam=chb_enable=true,chb_cfg=5,chb_gain=0 dtparam=chc_enable=true,chc_cfg=6,chc_gain=0 dtparam=chd_enable=true,chd_cfg=7,chd_gain=0 EOF #load i2c-dev module, done by raspi-config when enabling i2c there echo i2c-dev >> /etc/modules #disable console on serial (will change /boot/firmware/cmdline.txt) echo "Disabling console on serial" raspi-config nonint do_serial_cons 1 echo "Done!" sleep 1 echo echo echo "#################################################################" echo "#### Activating RTC ####" echo "#################################################################" sleep 1 apt -y remove fake-hwclock update-rc.d -f fake-hwclock remove systemctl disable fake-hwclock #GUI echo echo echo "#################################################################" echo "#### zeroPLC testing gui ####" echo "#################################################################" sleep 1 while true; do read -p "Do you want to intall the zeroPLCgui for simple testing of hardware functions? (yes/no) " yn case $yn in yes ) echo Starting zeroPLCgui installation to zeroPLCgui folder in home directory; break;; no ) cd ..; rm -r /home/$SUDO_USER/zeroplc-installer; echo Exiting installer, please reboot the system; exit;; * ) echo invalid response;; esac done apt update apt -y install python3-pip python3-picamera2 mv /home/$SUDO_USER/zeroplc-installer/zeroPLCgui /home/$SUDO_USER/ cd /home/$SUDO_USER/zeroPLCgui chmod +x gui.py echo "Creating python venv" sleep 1 python3 -m venv --system-site-packages .venv . /home/$SUDO_USER/zeroPLCgui/.venv/bin/activate echo "Installing python packages" sleep 1 pip3 install nicegui adafruit-circuitpython-tmp117 adafruit-circuitpython-sht4x adafruit-extended-bus deactivate chown -R $SUDO_USER:$SUDO_USER /home/$SUDO_USER/zeroPLCgui rm -r /home/$SUDO_USER/zeroplc-installer echo echo "Installation finished, start gui with ./gui.py" sleep 1 echo "Exiting installer"