#!/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 } sed -i 's/user-session=LXDE-pi-wayfire/user-session=LXDE-pi-x/' /etc/lightdm/lightdm.conf sed -i 's/autologin-session=LXDE-pi-wayfire/autologin-session=LXDE-pi-x/' /etc/lightdm/lightdm.conf insert "# GPIO Configuration" /boot/firmware/config.txt insert "gpio=4=pd" /boot/firmware/config.txt insert "gpio=5=pd" /boot/firmware/config.txt insert "gpio=6=pd" /boot/firmware/config.txt insert "gpio=25=ip,pu" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# I2C Configuration" /boot/firmware/config.txt insert "dtparam=i2c_arm=on" /boot/firmware/config.txt update "dtoverlay=i2c-rtc,ds3231" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# SPI Configuration" /boot/firmware/config.txt insert "dtparam=spi=on" /boot/firmware/config.txt insert "dtoverlay=spi0-2cs,cs0_pin=8,cs1_pin=7" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# UART Configuration" /boot/firmware/config.txt insert "enable_uart=1" /boot/firmware/config.txt insert "dtoverlay=miniuart-bt" /boot/firmware/config.txt insert "dtoverlay=uart5" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# HDMI Configuration" /boot/firmware/config.txt insert "hdmi_group=2" /boot/firmware/config.txt insert "hdmi_mode=87" /boot/firmware/config.txt insert "hdmi_drive=1" /boot/firmware/config.txt insert "hdmi_cvt 1980 1080 60 6 0 0 0" /boot/firmware/config.txt insert "max_usb_current=1" /boot/firmware/config.txt insert "ignore_lcd=0" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# Touchscreen Configuration" /boot/firmware/config.txt insert "dtoverlay=ilitek251x,interrupt=1" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# UPS Functionalities" /boot/firmware/config.txt insert "dtoverlay=gpio-poweroff,gpiopin=23,active_low" /boot/firmware/config.txt insert "dtoverlay=gpio-shutdown,gpio_pin=24,gpio_pull=up" /boot/firmware/config.txt insert "" /boot/firmware/config.txt insert "# Splash" /boot/firmware/config.txt insert "disable_splash=1" /boot/firmware/config.txt sed -i 's/console=serial0,115200 //' /boot/firmware/cmdline.txt sed -i 's/$/ logo\.nologo vt\.global_cursor_default=0/' /boot/firmware/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 gateway 10.10.10.1 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 apt install -y libudev-dev RPISHUTDOWN_STATUS=0 mkdir -p /etc/rpishutdown/hooks systemctl status rpishutdown-pre-poweroff [ $? -eq 0 ] && RPISHUTDOWN_STATUS=1 && systemctl stop rpishutdown-pre-poweroff curl -L https://apps.industrialshields.com/main/rpi_experimental/rpiplc/rpishutdown-pre-poweroff.service \ -o /lib/systemd/system/rpishutdown-pre-poweroff.service curl -L https://apps.industrialshields.com/main/rpi_experimental/rpiplc/check-pre-poweroff-hook.sh \ -o /etc/rpishutdown/hooks/check-pre-poweroff chmod ugo+x /etc/rpishutdown/hooks/check-pre-poweroff if [ ${RPISHUTDOWN_STATUS} -eq 1 ]; then systemctl daemon-reload && systemctl start rpishutdown-pre-poweroff fi systemctl enable rpishutdown-pre-poweroff 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 rm /etc/xdg/autostart/pprompt.desktop apt-get -y remove piwiz rm /etc/profile.d/sshpwd.sh # No sleep desktop echo "@xset s noblank" >> /etc/xdg/lxsession/LXDE-pi/autostart echo "@xset s off" >> /etc/xdg/lxsession/LXDE-pi/autostart echo "@xset -dpms" >> /etc/xdg/lxsession/LXDE-pi/autostart # FNo sleep desktop apt-get clean sync ######################################################################### # Calibrar tactil apt install -y libinput-tools echo 'ACTION=="add|change", KERNEL=="event*", ENV{ID_INPUT_TOUCHSCREEN}=="1", ENV{LIBINPUT_CALIBRATION_MATRIX}="1 0 0 0 0.58 0 0 0 1"' | sudo tee "/etc/udev/rules.d/99-touchscreen-calibration.rules" udevadm control --reload-rules udevadm trigger ######################################################################### # Set splash curl -L https://apps.industrialshields.com/main/rpi/touchberry_18_5/splash.png -o /usr/share/plymouth/themes/pix/splash.png update-initramfs -u ######################################################################### # Verificar si el archivo /etc/ssh/sshd_config existe if [ -f "/etc/ssh/sshd_config" ]; then # Verificar si la línea "PubkeyAuthentication" está presente y tiene el valor correcto if ! grep -q "^PubkeyAuthentication yes" /etc/ssh/sshd_config; then # Si no se encuentra la línea, la añadimos o la modificamos sed -i -E 's/^#?(PubkeyAuthentication).*/\1 yes/' /etc/ssh/sshd_config fi # Verificar si la línea "PasswordAuthentication" está presente y tiene el valor correcto if ! grep -q "^PasswordAuthentication yes" /etc/ssh/sshd_config; then # Si no se encuentra la línea, la añadimos o la modificamos sed -i -E 's/^#?(PasswordAuthentication).*/\1 yes/' /etc/ssh/sshd_config fi # Reiniciar el servicio SSH para aplicar los cambios # No cal en virtual encara systemctl restart ssh else echo "El archivo /etc/ssh/sshd_config no existe." fi ######################################################################### apt-get clean sync echo Done ######################################################################### reboot