From c7aabc6902af3a6431071f615eb19bde2a0f8b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Mon, 12 Feb 2018 21:41:48 +0100 Subject: [PATCH] Moved user input to the top of the scripts. (#109) * Moved userinput to the top of the scripts. * Changes for review. * Changes for review. --- package/opt/hassbian/suites/appdaemon.sh | 66 ++++++++++--------- package/opt/hassbian/suites/homebridge.sh | 78 +++++++++++------------ package/opt/hassbian/suites/mosquitto.sh | 46 +++++++------ 3 files changed, 97 insertions(+), 93 deletions(-) diff --git a/package/opt/hassbian/suites/appdaemon.sh b/package/opt/hassbian/suites/appdaemon.sh index e385258c..4fbb94c6 100644 --- a/package/opt/hassbian/suites/appdaemon.sh +++ b/package/opt/hassbian/suites/appdaemon.sh @@ -15,6 +15,13 @@ function appdaemon-install-package { appdaemon-show-short-info appdaemon-show-copyright-info +if [ "$ACCEPT" != "true" ]; then + if [ -f "/usr/sbin/samba" ]; then + echo -n "Do you want to add Samba share for AppDaemon configuration? [N/y] : " + read SAMBA + fi +fi + echo "Creating directory for AppDaemon Venv" sudo mkdir /srv/appdaemon sudo chown -R homeassistant:homeassistant /srv/appdaemon @@ -53,34 +60,37 @@ sync echo "Starting AppDaemon service" systemctl start appdaemon@homeassistant.service -if [ "$ACCEPT" != "true" ]; then - if [ -f "/usr/sbin/samba" ]; then - read -p "Do you want to add samba share for AppDaemon configuration? [N/y] : " SAMBA - if [ "$SAMBA" == "y" ] || [ "$SAMBA" == "Y" ]; then - echo "Adding configuration to samba..." - echo "[appdaemon]" | tee -a /etc/samba/smb.conf - echo "path = /home/homeassistant/appdaemon" | tee -a /etc/samba/smb.conf - echo "writeable = yes" | tee -a /etc/samba/smb.conf - echo "guest ok = yes" | tee -a /etc/samba/smb.conf - echo "create mask = 0644" | tee -a /etc/samba/smb.conf - echo "directory mask = 0755" | tee -a /etc/samba/smb.conf - echo "force user = homeassistant" | tee -a /etc/samba/smb.conf - echo "" | tee -a /etc/samba/smb.conf - echo "Restarting Samba service" - sudo systemctl restart smbd.service - fi - fi + +if [ "$SAMBA" == "y" ] || [ "$SAMBA" == "Y" ]; then + echo "Adding configuration to Samba..." + echo "[appdaemon]" | tee -a /etc/samba/smb.conf + echo "path = /home/homeassistant/appdaemon" | tee -a /etc/samba/smb.conf + echo "writeable = yes" | tee -a /etc/samba/smb.conf + echo "guest ok = yes" | tee -a /etc/samba/smb.conf + echo "create mask = 0644" | tee -a /etc/samba/smb.conf + echo "directory mask = 0755" | tee -a /etc/samba/smb.conf + echo "force user = homeassistant" | tee -a /etc/samba/smb.conf + echo "" | tee -a /etc/samba/smb.conf + echo "Restarting Samba service" + sudo systemctl restart smbd.service fi -echo -echo "Installation done." -echo -echo "You may find the appdaemon configuration files in:" -echo "/home/homeassistant/appdaemon" -echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" -echo -echo "If you have issues with this script, please say something in the #devs_hassbian channel on Discord." -echo +validation=$(ps -ef | grep -v grep | grep appdaemon | wc -l) +if [ "$validation" != "0" ]; then + echo + echo -e "\e[32mInstallation done..\e[0m" + echo + echo "You will find the AppDaemon configuration files in:" + echo "/home/homeassistant/appdaemon" + echo + echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" + echo +else + echo -e "\e[31mInstallation failed..." + echo -e "\e[31mAborting..." + echo -e "\e[0mIf you have issues with this script, please say something in the #devs_hassbian channel on Discord." + return 1 +fi return 0 } @@ -117,10 +127,8 @@ if [ "$validation" != "0" ]; then echo echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" echo - echo "If you have issues with this script, please say something in the #devs_hassbian channel on Discord." - echo else - echo -e "\e[31mInstallation failed..." + echo -e "\e[31mUpgrade failed..." echo -e "\e[31mAborting..." echo -e "\e[0mIf you have issues with this script, please say something in the #devs_hassbian channel on Discord." return 1 diff --git a/package/opt/hassbian/suites/homebridge.sh b/package/opt/hassbian/suites/homebridge.sh index e2826a29..6e9945cf 100644 --- a/package/opt/hassbian/suites/homebridge.sh +++ b/package/opt/hassbian/suites/homebridge.sh @@ -1,10 +1,10 @@ #!/bin/bash function homebridge-show-short-info { - echo "Installs and configure homebridge for Home Assistant." + echo "Installs and configure Homebridge for Home Assistant." } function homebridge-show-long-info { - echo "Installs and configure homebridge for Home Assistant" + echo "Installs and configure Homebridge for Home Assistant" echo "This will allow you to use HomeKit enabled devices to control Home Assistant." } @@ -17,28 +17,12 @@ function homebridge-install-package { homebridge-show-long-info homebridge-show-copyright-info -echo "Preparing system, and adding dependencies..." -sudo apt update -sudo apt -y upgrade -sudo apt install -y make git -curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - -sudo apt install -y nodejs -sudo apt install -y libavahi-compat-libdnssd-dev - -echo "Installing homebridge for homeassistant..." -sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp -sudo npm install -g homebridge-homeassistant - -echo "Adding homebridge user, and creating config file..." -sudo useradd --system --create-home homebridge -sudo mkdir /home/homebridge/.homebridge -sudo touch /home/homebridge/.homebridge/config.json - if [ "$ACCEPT" == "true" ]; then HOMEASSISTANT_URL="http://127.0.0.1:8123" HOMEASSISTANT_PASSWORD="" else echo "" + echo "Please take a moment to setup the Homebridge configuration..." echo "" echo "Example: https://home.duckdns.org:8123" echo -n "Enter your Home Assistant URL and port: " @@ -46,7 +30,6 @@ else if [ ! "$HOMEASSISTANT_URL" ]; then HOMEASSISTANT_URL="http://127.0.0.1:8123" fi - echo "" echo "" echo -n "Enter your Home Assistant API password: " @@ -54,6 +37,28 @@ else echo fi +if [ "$ACCEPT" != "true" ]; then + if [ -f "/usr/sbin/samba" ]; then + echo -n "Do you want to add Samba share for Homebridge configuration? [N/y] : " + read SAMBA + fi +fi + +echo "Preparing system, and adding dependencies..." +sudo apt update +sudo apt -y upgrade +curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - +sudo apt install -y nodejs +sudo apt install -y libavahi-compat-libdnssd-dev + +echo "Installing Homebridge for Home Assistant..." +sudo npm install -g --unsafe-perm homebridge hap-nodejs node-gyp +sudo npm install -g homebridge-homeassistant + +echo "Adding homebridge user, and creating config file..." +sudo useradd --system --create-home homebridge +sudo mkdir /home/homebridge/.homebridge +sudo touch /home/homebridge/.homebridge/config.json HOMEBRIDGE_PIN=$(printf "%03d-%02d-%03d" $(($RANDOM % 999)) $(($RANDOM % 99)) $(($RANDOM % 999))) HEX_CHARS=0123456789ABCDEF RANDOM_MAC=$( for i in {1..6} ; do echo -n ${HEX_CHARS:$(( $RANDOM % 16 )):1} ; done | sed -e 's/\(..\)/:\1/g' ) @@ -108,24 +113,19 @@ sudo systemctl daemon-reload sudo systemctl enable homebridge.service sudo systemctl start homebridge.service -if [ "$ACCEPT" != "true" ]; then - if [ -f "/usr/sbin/samba" ]; then - read -p "Do you want to add samba share for homebridge configuration? [N/y] : " SAMBA - if [ "$SAMBA" == "y" ] || [ "$SAMBA" == "Y" ]; then - echo "Adding configuration to samba..." - sudo smbpasswd -a homebridge -n - echo "[homebridge]" | tee -a /etc/samba/smb.conf - echo "path = /home/homebridge/.homebridge" | tee -a /etc/samba/smb.conf - echo "writeable = yes" | tee -a /etc/samba/smb.conf - echo "guest ok = yes" | tee -a /etc/samba/smb.conf - echo "create mask = 0644" | tee -a /etc/samba/smb.conf - echo "directory mask = 0755" | tee -a /etc/samba/smb.conf - echo "force user = homebridge" | tee -a /etc/samba/smb.conf - echo "" | tee -a /etc/samba/smb.conf - echo "Restarting Samba service" - sudo systemctl restart smbd.service - fi - fi +if [ "$SAMBA" == "y" ] || [ "$SAMBA" == "Y" ]; then + echo "Adding configuration to Samba..." + sudo smbpasswd -a homebridge -n + echo "[homebridge]" | tee -a /etc/samba/smb.conf + echo "path = /home/homebridge/.homebridge" | tee -a /etc/samba/smb.conf + echo "writeable = yes" | tee -a /etc/samba/smb.conf + echo "guest ok = yes" | tee -a /etc/samba/smb.conf + echo "create mask = 0644" | tee -a /etc/samba/smb.conf + echo "directory mask = 0755" | tee -a /etc/samba/smb.conf + echo "force user = homebridge" | tee -a /etc/samba/smb.conf + echo "" | tee -a /etc/samba/smb.conf + echo "Restarting Samba service" + sudo systemctl restart smbd.service fi echo "Checking the installation..." @@ -140,8 +140,6 @@ if [ "$validation" != "0" ]; then echo "For more information see this repo:" echo "https://github.com/home-assistant/homebridge-homeassistant#customization" echo - echo "If you have issues with this script, please say something in the #devs_hassbian channel on Discord." - echo else echo -e "\e[31mInstallation failed..." echo -e "\e[31mAborting..." diff --git a/package/opt/hassbian/suites/mosquitto.sh b/package/opt/hassbian/suites/mosquitto.sh index 621e21ef..d09f2c8d 100644 --- a/package/opt/hassbian/suites/mosquitto.sh +++ b/package/opt/hassbian/suites/mosquitto.sh @@ -22,6 +22,28 @@ echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 return 1 fi +if [ "$ACCEPT" == "true" ]; then + mqtt_username=pi + mqtt_password=raspberry +else + echo + echo "Please take a moment to setup your first MQTT user" + echo + + echo -n "Username: " + read mqtt_username + if [ ! "$mqtt_username" ]; then + mqtt_username=pi + fi + + echo -n "Password: " + read -s mqtt_password + echo + if [ ! "$mqtt_password" ]; then + mqtt_password=raspberry + fi +fi + echo "Adding mosquitto user" adduser mosquitto --system --group @@ -62,28 +84,6 @@ touch pwfile chown mosquitto:mosquitto pwfile chmod 0600 pwfile -if [ "$ACCEPT" == "true" ]; then - mqtt_username=pi - mqtt_password=raspberry -else - echo - echo "Please take a moment to setup your first MQTT user" - echo - - echo -n "Username: " - read mqtt_username - if [ ! "$mqtt_username" ]; then - mqtt_username=pi - fi - - echo -n "Password: " - read -s mqtt_password - echo - if [ ! "$mqtt_password" ]; then - mqtt_password=raspberry - fi -fi - echo "Creating password entry for user $mqtt_username" mosquitto_passwd -b pwfile "$mqtt_username" "$mqtt_password" @@ -104,8 +104,6 @@ if [ "$validation" != "0" ]; then echo "For more information see this repo:" echo "https://github.com/home-assistant/homebridge-homeassistant#customization" echo - echo "If you have issues with this script, please say something in the #devs_hassbian channel on Discord." - echo else echo -e "\e[31mInstallation failed..." echo -e "\e[31mAborting..."