Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Moved user input to the top of the scripts. (#109)
Browse files Browse the repository at this point in the history
* Moved userinput to the top of the scripts.

* Changes for review.

* Changes for review.
  • Loading branch information
ludeeus authored and Landrash committed Feb 12, 2018
1 parent 82f25d7 commit c7aabc6
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 93 deletions.
66 changes: 37 additions & 29 deletions package/opt/hassbian/suites/appdaemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
78 changes: 38 additions & 40 deletions package/opt/hassbian/suites/homebridge.sh
Original file line number Diff line number Diff line change
@@ -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."
}

Expand All @@ -17,43 +17,48 @@ 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: "
read HOMEASSISTANT_URL
if [ ! "$HOMEASSISTANT_URL" ]; then
HOMEASSISTANT_URL="http://127.0.0.1:8123"
fi

echo ""
echo ""
echo -n "Enter your Home Assistant API password: "
read -s HOMEASSISTANT_PASSWORD
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' )
Expand Down Expand Up @@ -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..."
Expand All @@ -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..."
Expand Down
46 changes: 22 additions & 24 deletions package/opt/hassbian/suites/mosquitto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"

Expand All @@ -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..."
Expand Down

0 comments on commit c7aabc6

Please sign in to comment.