Update Installer.sh

Added OS and Version check.
Fixed oopsie
This commit is contained in:
Beeranco 2023-08-12 02:12:42 +02:00 committed by GitHub
parent bc0e00b8e0
commit cf8a145990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,7 @@
#!/bin/bash
##---------------##
# Static-Vars #
# Static Vars #
##---------------##
sed -i -e 's/magenta/blue/g' /etc/newt/palette
@ -8,7 +10,33 @@ OUTPUT='>/dev/null 2>&1'
APTMODE="debconf-apt-progress -- apt"
REPO=PiAutomation
GIT=https://raw.githubusercontent.com/Beeranco
BRANCHE=main
BRANCH=main
##-----------##
# Check OS #
##-----------##
dist=$(grep --color=never -Po "^ID=\K.*" "/etc/os-release")
dist_ver=$(grep --color=never -Po "^VERSION_ID=\K.*" "/etc/os-release")
dist_ver="${dist_ver//\"}"
if [[ $dist != debian ]]; then
whiptail --title "Error" --msgbox "Only Debian is supported!" 8 78
clear
exit
fi
if [[ $dist != 11 ]]; then
if (whiptail --title "Warning" --yesno "This script is tested on Debian 11, use it on your own risk. \nYou're currently running Debian $dist_ver! \n\nContinue anyway?" 10 78); then
echo ""
else
clear
exit
fi
fi
##---------##
# Menu #
@ -17,23 +45,16 @@ BRANCHE=main
if (whiptail --title "Pi Automation" --yesno "This installer will turn your Raspberry Pi into a hub for home automation." 8 78); then
INSTALL=yes
else
INSTALL=no
INSTALL=no
fi
if [[ $INSTALL = no ]]; then
if [[ $INSTALL == no ]]; then
whiptail --title "Pi Automation" --msgbox "Installation canceled!" 8 78
clear
exit
fi
##--------------------------##
# Debian LXC Requirement #
##--------------------------##
apt install whiptail curl -y -qq 2>/dev/null >/dev/null
##-------------##
# Pre-Check #
##-------------##
@ -42,7 +63,7 @@ TERM=ansi whiptail --title "Pre-Check" --infobox "Please wait..." 8 78
sleep 3
ping -c 1 192.168.1.102 > /dev/null && HOSTUP=yes || HOSTUP=no
if [[ $HOSTUP = yes ]]; then
if [[ $HOSTUP == yes ]]; then
echo > /dev/tcp/192.168.1.102/80 && echo 'Acquire::http::Proxy "http://192.168.1.102:80";'> /etc/apt/apt.conf.d/01prox || TERM=ansi whiptail --title "Pre-Check" --infobox "Not using an APT-Cache server" 8 78
sleep 3
fi
@ -57,8 +78,8 @@ OPTIONS=$(whiptail --title "Configure Options" --checklist \
"Domoticz" "Is a Home Automation System." ON \
"Node-RED" "Is a programming tool wiring hardware devices together." OFF \
"Zigbee2MQTT" "Supports various Zigbee adapters and a big bunch of devices." OFF \
"MQTT Broker" "Is a intermediary entity that enables MQTT clients to communicate." ON \
"Unattended Upgrades" "Is a system package that automaticly downloads security updates." ON 3>&1 1>&2 2>&3)
"MQTT-Broker" "Is a intermediary entity that enables MQTT clients to communicate." ON \
"Unattended-Upgrades" "Is a system package that automaticly downloads security updates." ON 3>&1 1>&2 2>&3)
##---------------##
@ -101,10 +122,10 @@ fi
if [[ $OPTIONS == *"Zigbee2MQTT"* ]]; then
echo "git make g++ gcc" >> /tmp/install.list
fi
if [[ $OPTIONS == *"MQTT Broker"* ]]; then
if [[ $OPTIONS == *"MQTT-Broker"* ]]; then
echo "mosquitto mosquitto-clients" >> /tmp/install.list
fi
if [[ $OPTIONS == *"Unattended Upgrades"* ]]; then
if [[ $OPTIONS == *"Unattended-Upgrades"* ]]; then
echo "unattended-upgrades apt-listchanges" >> /tmp/install.list
fi
@ -126,12 +147,12 @@ apt autoremove -y
if [[ $OPTIONS == *"Domoticz"* ]]; then
mkdir -p /etc/domoticz/
wget $GIT/$REPO/$BRANCHE/Domoticz/DomoSetup.conf -O /etc/domoticz/setupVars.conf
wget $GIT/$REPO/$BRANCH/Domoticz/DomoSetup.conf -O /etc/domoticz/setupVars.conf
mkdir -p /opt/domoticz/
bash -c "$(curl -sSfL https://install.domoticz.com)"
wget $GIT/$REPO/$BRANCHE/Domoticz/DomoService.conf -O /etc/init.d/domoticz.sh
wget $GIT/$REPO/$BRANCH/Domoticz/DomoService.conf -O /etc/init.d/domoticz.sh
chmod +x /etc/init.d/domoticz.sh
update-rc.d domoticz.sh defaults
systemctl start domoticz
@ -146,26 +167,35 @@ if [[ $OPTIONS == *"Node-RED"* ]]; then
cd /root/.node-red/
npm install @node-red-contrib-themes/midnight-red
cd ~
wget $GIT/$REPO/$BRANCHE/Node-RED/NodeRED.conf -O /root/.node-red/settings.js
wget $GIT/$REPO/$BRANCH/Node-RED/NodeRED.conf -O /root/.node-red/settings.js
fi
if [[ $OPTIONS == *"Zigbee2MQTT"* ]]; then
mkdir -p /opt/zigbee2mqtt/
git clone --depth 1 https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt
wget $GIT/$REPO/$BRANCHE/Zigbee/zb2mqtt.config -O /opt/zigbee2mqtt/data/configuration.yaml
wget $GIT/$REPO/$BRANCH/Zigbee/zb2mqtt.config -O /opt/zigbee2mqtt/data/configuration.yaml
cd /opt/zigbee2mqtt/
npm ci /opt/zigbee2mqtt/
npm audit fix
npm start /opt/zigbee2mqtt/
cd ~
wget $GIT/$REPO/$BRANCHE/Zigbee/z2mqtt.service -O /etc/systemd/system/zigbee2mqtt.service
wget $GIT/$REPO/$BRANCH/Zigbee/z2mqtt.service -O /etc/systemd/system/zigbee2mqtt.service
systemctl daemon-reload
systemctl enable zigbee2mqtt
fi
if [[ $OPTIONS == *"Unattended Upgrades"* ]]; then
if [[ $OPTIONS == *"Unattended-Upgrades"* ]]; then
systemctl stop unattended-upgrades
wget $GIT/$REPO/$BRANCHE/Unattended-Security-Updates/20auto-upgrades -O /etc/apt/apt.conf.d/20auto-upgrades
wget $GIT/$REPO/$BRANCHE/Unattended-Security-Updates/50debian-unattended-upgrades -O /etc/apt/apt.conf.d/50unattended-upgrades
wget $GIT/$REPO/$BRANCH/Unattended-Security-Updates/20auto-upgrades -O /etc/apt/apt.conf.d/20auto-upgrades
wget $GIT/$REPO/$BRANCH/Unattended-Security-Updates/50debian-unattended-upgrades -O /etc/apt/apt.conf.d/50unattended-upgrades
fi
##--------------##
# Store Vars #
##--------------##
echo $OPTIONS > /etc/installedmodules
sed -i 's/\s\+/\n/g' /etc/installedmodules
sed -i 's/\"//g' /etc/installedmodules