From 92d88b680ae0854c39651f85120f82fde582a069 Mon Sep 17 00:00:00 2001 From: JLFN Date: Fri, 15 Feb 2019 23:08:35 +0100 Subject: [PATCH] All in one install (#1098) * All in one install Need to have user Pi added * move to folder scripts --- scripts/install.sh | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 scripts/install.sh diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100644 index 000000000..b159a6981 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,73 @@ +#!/bin/bash +function zigbee2mqtt-show-short-info { + echo "Setup for Zigbee2mqtt bridge." +} + +function zigbee2mqtt-show-long-info { + echo "This script installs the Zigbee2mqtt bridge" +} + +function zigbee2mqtt-show-copyright-info { + echo "Original concept by Landrash ." +} + +function zigbee2mqtt-install-package { +echo -n "Installing dependencies : " +node=$(which npm) +if [ -z "${node}" ]; then #Installing NodeJS if not already installed. + printf "Downloading and installing NodeJS...\\n" + curl -sL https://deb.nodesource.com/setup_10.x | bash - + apt install -y nodejs +fi + +echo "Cloning Zigbee2mqtt git repository" +git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt +chown -R pi:pi /opt/zigbee2mqtt + +echo "Running install. This might take a while and can produce som expected errors" +cd /opt/zigbee2mqtt || exit +su pi -c "npm install" + +echo "Creating service file zigbee2mqtt.service" +service_path="/etc/systemd/system/zigbee2mqtt.service" + +echo "[Unit] +Description=zigbee2mqtt +After=network.target + +[Service] +ExecStart=/usr/bin/npm start +WorkingDirectory=/opt/zigbee2mqtt +StandardOutput=inherit +StandardError=inherit +Restart=always +User=pi + +[Install] +WantedBy=multi-user.target" > $service_path + +echo "Checking the installation..." +if [ ! -f /opt/zigbee2mqtt/data/configuration.yaml ]; then + validation="" +else + validation="ok" +fi + +if [ ! -z "${validation}" ]; then + echo + echo -e "\\e[32mInstallation done..\\e[0m" + echo -e "Update of configuration.yaml is required found at /opt/zigbee2mqtt/data/" + echo -e "Some further configuration is required and details can be found here https://www.zigbee2mqtt.io" + echo + echo -e "Service can be started after configuration but running sudo systemctl start zigbee2mqtt" + echo +else + echo + echo -e "\\e[31mInstallation failed..." + echo + return 1 +fi +return 0 +} + +[[ "$_" == "$0" ]] && zigbee2mqtt-install-package