#!/bin/bash function update() { # if commented or exists -> do nothing -> return false (1) # if doesn't exist -> add it -> return true (0) grep "^#.*$1" $2 2>&1 >/dev/null if [ $? -ne 0 ]; then grep "^$1" $2 2>&1 >/dev/null if [ $? -ne 0 ]; then echo "$1" >> $2 return 0 fi fi return 1 } function insert() { # if commented -> add it # if doesn't exist -> add it # if exists -> do nothing grep "^$1" $2 2>&1 >/dev/null if [ $? -ne 0 ]; then echo "$1" >> $2 fi } insert "dtparam=spi=on" /boot/config.txt update "dtoverlay=w5500,cs=1,int_pin=6" /boot/config.txt insert "dtparam=i2c_arm=on" /boot/config.txt update "dtoverlay=i2c-rtc,ds3231" /boot/config.txt update "dtoverlay=mcp2515-can0,interrupt=5,oscillator=20000000" /boot/config.txt update "dtoverlay=sc16is752-spi1,int_pin=22,xtal=14745600" /boot/config.txt update "enable_uart=1" /boot/config.txt update "dtoverlay=mcp23017,noints,mcp23008,addr=0x20" /boot/config.txt update "dtoverlay=mcp23017,noints,mcp23008,addr=0x21" /boot/config.txt update "dtoverlay=i2c-pwm-pca9685a,addr=0x40" /boot/config.txt update "dtoverlay=i2c-pwm-pca9685a,addr=0x41" /boot/config.txt if $(update "dtoverlay=ads1015,addr=0x48" /boot/config.txt); then echo "dtparam=cha_enable=true,cha_gain=1" >> /boot/config.txt echo "dtparam=chb_enable=true,chb_gain=1" >> /boot/config.txt echo "dtparam=chc_enable=true,chc_gain=1" >> /boot/config.txt echo "dtparam=chd_enable=true,chd_gain=1" >> /boot/config.txt fi if $(update "dtoverlay=ads1015,addr=0x49" /boot/config.txt); then echo "dtparam=cha_enable=true,cha_gain=1" >> /boot/config.txt echo "dtparam=chb_enable=true,chb_gain=1" >> /boot/config.txt echo "dtparam=chc_enable=true,chc_gain=1" >> /boot/config.txt echo "dtparam=chd_enable=true,chd_gain=1" >> /boot/config.txt fi if $(update "dtoverlay=ads1015,addr=0x4a" /boot/config.txt); then echo "dtparam=cha_enable=true,cha_gain=1" >> /boot/config.txt echo "dtparam=chb_enable=true,chb_gain=1" >> /boot/config.txt echo "dtparam=chc_enable=true,chc_gain=1" >> /boot/config.txt echo "dtparam=chd_enable=true,chd_gain=1" >> /boot/config.txt fi if $(update "dtoverlay=ads1015,addr=0x4b" /boot/config.txt); then echo "dtparam=cha_enable=true,cha_gain=1" >> /boot/config.txt echo "dtparam=chb_enable=true,chb_gain=1" >> /boot/config.txt echo "dtparam=chc_enable=true,chc_gain=1" >> /boot/config.txt echo "dtparam=chd_enable=true,chd_gain=1" >> /boot/config.txt fi sed -i 's/console=serial0,115200 //' /boot/cmdline.txt insert "i2c-dev" /etc/modules if [ ! -f /etc/network/interfaces.d/eth0_1 ]; then cat > /etc/network/interfaces.d/eth0_1 << EOT auto eth0:1 allow-hotplug eth0:1 iface eth0:1 inet static address 10.10.10.20 netmask 255.255.255.0 EOT fi if [ ! -f /etc/network/interfaces.d/eth1_1 ]; then cat > /etc/network/interfaces.d/eth1_1 << EOT auto eth1:1 allow-hotplug eth1:1 iface eth1:1 inet static address 10.10.11.20 netmask 255.255.255.0 EOT fi if [ ! -f /etc/network/interfaces.d/can0 ]; then cat > /etc/network/interfaces.d/can0 << EOT auto can0 iface can0 inet manual pre-up /sbin/ip link set can0 type can bitrate 500000 triple-sampling on restart-ms 100 up /sbin/ifconfig can0 up down /sbin/ifconfig can0 down EOT fi [ ! -d /home/pi/.ssh ] && mkdir /home/pi/.ssh && chown pi:pi /home/pi/.ssh [ ! -f /home/pi/.ssh/authorized_keys ] && touch /home/pi/.ssh/authorized_keys && chown pi:pi /home/pi/.ssh/authorized_keys && chmod 600 /home/pi/.ssh/authorized_keys update "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCmUlYcl2AIROXD6US8s6D+IFU/Mau3TLuoPIhv5t6V0O+u0zoDEvAurC2xP1xf0mLabaIkFxGgixeSvaGrIqy1oPP30ly8f+zMKe0P9k41D+Lq8ZR9ohdTivlZm5MfW4l6xV6jojWPZNafMn+WW7trfRP/XRxKzcz2mjU9GMLHQmxHqBCsqlnUYkIH0Hq+3xwj9U/IJqYiQD5cm9mtXNLhwK7fYS81GPJhE9bNrJ7B/gmvVw0/3JMCK08DcbUOfHoCvJVbYCdZOM3xPIBtnmtLVD9YWn49yXXDg7Ndipq+tYIpg78HLJkhl31wvXiuKZKne/+sCtWArWZkrLdtLhn pi@raspberrypi" /home/pi/.ssh/authorized_keys systemctl enable ssh apt-get update RPISHUTDOWN_STATUS=0 systemctl status rpishutdown [ $? -eq 0 ] && RPISHUTDOWN_STATUS=1 && systemctl stop rpishutdown curl -L https://apps.industrialshields.com/main/rpi/ups/rpishutdown.service -o /lib/systemd/system/rpishutdown.service curl -L https://apps.industrialshields.com/main/rpi/ups/rpishutdown -o /usr/local/bin/rpishutdown chmod ugo+x /usr/local/bin/rpishutdown if [ ${RPISHUTDOWN_STATUS} -eq 1 ]; then systemctl daemon-reload && systemctl start rpishutdown fi systemctl enable rpishutdown.service HWCONFIG_STATUS=0 systemctl status hw-config [ $? -eq 0 ] && HWCONFIG_STATUS=1 && systemctl stop hw-config curl -L https://apps.industrialshields.com/main/rpi/rpiplc/hw-config.service -o /lib/systemd/system/hw-config.service curl -L https://apps.industrialshields.com/main/rpi/rpiplc/hw-config -o /usr/local/bin/hw-config chmod ugo+x /usr/local/bin/hw-config if [ ${HWCONFIG_STATUS} -eq 1 ]; then systemctl daemon-reload && systemctl start hw-config fi systemctl enable hw-config.service CHECKDTBO_STATUS=0 systemctl status check_dtbo [ $? -eq 0 ] && CHECKDTBO_STATUS=1 && systemctl stop check_dtbo curl -L https://apps.industrialshields.com/main/rpi/rpiplc/check_dtbo.service -o /lib/systemd/system/check_dtbo.service curl -L https://apps.industrialshields.com/main/rpi/rpiplc/check_dtbo -o /usr/local/bin/check_dtbo chmod ugo+x /usr/local/bin/check_dtbo if [ ${CHECKDTBO_STATUS} -eq 1 ]; then systemctl daemon-reload && systemctl start check_dtbo fi systemctl enable check_dtbo.service mkdir -p /usr/local/share/industrialshields/overlays/ curl -L https://apps.industrialshields.com/main/rpi/rpiplc/ads1015.dtbo -o /boot/overlays/ads1015.dtbo cp /boot/overlays/ads1015.dtbo /usr/local/share/industrialshields/overlays curl -L https://apps.industrialshields.com/main/rpi/rpiplc/test.tgz -o - | tar zxvf - -C /home/pi/ chown -R pi:pi /home/pi/test curl -L https://apps.industrialshields.com/main/rpi/rpiplc/librpiplc.tar.bz2 | tar jxvf - -C /usr/local sed -i -e "/^if \[ -e \/run\/systemd\/system \].*/,+2 s/^/# /" /lib/udev/hwclock-set LINE=$(echo "127.0.0.1 $(hostname)") sed -i "1i${LINE}" /etc/hosts bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered) << EOT y y y EOT sed -i "/${LINE}/d" /etc/hosts npm install --prefix ~/.node-red node-red-dashboard systemctl enable nodered.service apt -f install can-utils apt-get clean sync reboot