From 12424bba83c763b1d0bcd0fe94fbb58c84f4a69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 13 Feb 2018 19:43:43 +0100 Subject: [PATCH 1/9] Preparations --- package/opt/hassbian/suites/appdaemon.sh | 82 +++++++++---------- package/opt/hassbian/suites/duckdns.sh | 40 ++++----- .../hassbian/suites/hassbian-script-dev.sh | 16 ++-- .../opt/hassbian/suites/hassbian-script.sh | 10 +-- package/opt/hassbian/suites/hassbian.sh | 10 +-- .../opt/hassbian/suites/homeassistant-dev.sh | 8 +- package/opt/hassbian/suites/homeassistant.sh | 14 ++-- package/opt/hassbian/suites/homebridge.sh | 18 ++-- package/opt/hassbian/suites/hue.sh | 26 +++--- package/opt/hassbian/suites/libcec.sh | 18 ++-- package/opt/hassbian/suites/mariadb.sh | 12 +-- package/opt/hassbian/suites/mosquitto.sh | 54 ++++++------ package/opt/hassbian/suites/mssql.sh | 12 +-- package/opt/hassbian/suites/mysql.sh | 12 +-- package/opt/hassbian/suites/postgresql.sh | 12 +-- package/opt/hassbian/suites/razberry.sh | 30 +++---- package/opt/hassbian/suites/samba.sh | 16 ++-- package/opt/hassbian/suites/tradfri.sh | 2 +- package/opt/hassbian/suites/webterminal.sh | 6 +- 19 files changed, 199 insertions(+), 199 deletions(-) diff --git a/package/opt/hassbian/suites/appdaemon.sh b/package/opt/hassbian/suites/appdaemon.sh index 4fbb94c6..eabff7eb 100644 --- a/package/opt/hassbian/suites/appdaemon.sh +++ b/package/opt/hassbian/suites/appdaemon.sh @@ -1,14 +1,14 @@ #!/bin/bash function appdaemon-show-short-info { - echo "AppDaemon install script for Hassbian" + echo "AppDaemon install script for Hassbian." } function appdaemon-show-long-info { - echo "Installs AppDaemon in a separate Venv onto this system." + echo "Installs AppDaemon in a separate Venv onto this system." } function appdaemon-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function appdaemon-install-package { @@ -18,7 +18,7 @@ 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 + read -r SAMBA fi fi @@ -62,34 +62,34 @@ echo "Starting AppDaemon service" systemctl start appdaemon@homeassistant.service 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 + 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 -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 +validation=$(pgrep -f appdaemon) +if [ "$validation" == NULL ]; 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 + 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 } @@ -120,19 +120,19 @@ echo "Starting AppDaemon service..." systemctl start appdaemon@homeassistant.service echo "Checking the installation..." -validation=$(ps -ef | grep -v grep | grep appdaemon | wc -l) -if [ "$validation" != "0" ]; then - echo - echo -e "\e[32mUppgrade done..\e[0m" - echo - echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" - echo +validation=$(pgrep -f appdaemon) +if [ "$validation" == NULL ]; then + echo + echo -e "\e[32mUppgrade done..\e[0m" + echo + echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" + echo else - 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 + 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 fi return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/duckdns.sh b/package/opt/hassbian/suites/duckdns.sh index 66ed25ff..d793bd7a 100644 --- a/package/opt/hassbian/suites/duckdns.sh +++ b/package/opt/hassbian/suites/duckdns.sh @@ -1,15 +1,15 @@ #!/bin/bash function duckdns-show-short-info { -echo -e "Setup for Duck DNS auto renewal, and generates SSL certificate." + echo "Setup for Duck DNS auto renewal, and generates SSL certificate." } function duckdns-show-long-info { -echo -e "This script adds an cron job to auto uppdate you the WAN IP address for the defined domain." -echo -e "This script could also generate SSL certificate for https with Let’s Encrypt." + echo "This script adds an cron job to auto uppdate you the WAN IP address for the defined domain." + echo "This script can also generate SSL certificate for https with Let’s Encrypt." } function duckdns-show-copyright-info { - echo "Original concept by Ludeeus " + echo "Original concept by Ludeeus ." } function duckdns-install-package { @@ -22,7 +22,7 @@ echo "If no choice is made the installation will exit." echo echo "(if your domain is 'example.duckdns.org' type example)" echo -n "Domain: " -read domain +read -r domain if [ ! "$domain" ]; then exit fi @@ -30,34 +30,34 @@ if [[ $domain = *"duckdns"* ]]; then domain=$(echo "$domain" | cut -d\. -f1) fi if [[ $domain = *"//"* ]]; then - domain=$(echo "$domain" | cut -d\/ -f3) + domain=$(echo "$domain" | cut -d/ -f3) fi echo -n "Token: " -read token +read -r token echo if [ ! "$token" ]; then exit fi -read -p "Do you want to generate certificates to use SSL(https)? [N/y] : " SSL_RESPONSE +read -p -r "Do you want to generate certificates to use SSL(https)? [N/y] : " SSL_RESPONSE echo "Changing to homeassistant user..." sudo -u homeassistant -H /bin/bash << EOF cd if [ "$SSL_RESPONSE" == "y" ] || [ "$SSL_RESPONSE" == "Y" ]; then - git clone https://github.com/lukas2511/dehydrated.git - cd dehydrated - echo $domain".duckdns.org" | tee domains.txt - echo "CHALLENGETYPE='dns-01'" | tee -a config - echo "HOOK='./hook.sh'" | tee -a config - curl -o ./hook.sh https://raw.githubusercontent.com/home-assistant/hassbian-scripts/dev/package/opt/hassbian/suites/files/ssl_hook.sh - sed -i 's/myhome/'$domain'/g' ./hook.sh - sed -i 's/your-duckdns-token/'$token'/g' ./hook.sh - chmod 755 hook.sh - ./dehydrated --register --accept-terms - ./dehydrated -c + git clone https://github.com/lukas2511/dehydrated.git + cd dehydrated + echo $domain".duckdns.org" | tee domains.txt + echo "CHALLENGETYPE='dns-01'" | tee -a config + echo "HOOK='./hook.sh'" | tee -a config + curl -o ./hook.sh https://raw.githubusercontent.com/home-assistant/hassbian-scripts/dev/package/opt/hassbian/suites/files/ssl_hook.sh + sed -i 's/myhome/'$domain'/g' ./hook.sh + sed -i 's/your-duckdns-token/'$token'/g' ./hook.sh + chmod 755 hook.sh + ./dehydrated --register --accept-terms + ./dehydrated -c fi echo "Creating duckdns folder..." @@ -95,4 +95,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/hassbian-script-dev.sh b/package/opt/hassbian/suites/hassbian-script-dev.sh index e7ccf1b8..f27c8fb3 100644 --- a/package/opt/hassbian/suites/hassbian-script-dev.sh +++ b/package/opt/hassbian/suites/hassbian-script-dev.sh @@ -1,12 +1,12 @@ #!/bin/bash function hassbian-script-dev-show-short-info { - echo "Uppdates scripts from the dev branch." + echo "Uppdates scripts from the dev branch." } function hassbian-script-dev-show-long-info { - echo "This scripts downloads new scripts directly from the dev branch on github." - echo "you can use this to be on the 'bleeding edge of the development of Hassbian.'" - echo "This is not recomended for daily use." + echo "This scripts downloads new scripts directly from the dev branch on github." + echo "you can use this to be on the 'bleeding edge of the development of Hassbian.'" + echo "This is not recomended for daily use." } function hassbian-script-dev-show-copyright-info { @@ -18,9 +18,9 @@ hassbian-script-dev-show-short-info hassbian-script-dev-show-copyright-info echo "Creation and changing in to temporary folder." -cd +cd || exit sudo mkdir /tmp/hassbian_config_update -cd /tmp/hassbian_config_update +cd /tmp/hassbian_config_update || exit echo "Downloading new scripts from github." curl -L https://api.github.com/repos/home-assistant/hassbian-scripts/tarball| sudo tar xz --strip=1 @@ -30,7 +30,7 @@ yes | sudo cp -rf /tmp/hassbian_config_update/package/usr/local/bin/hassbian-con yes | sudo cp -rf /tmp/hassbian_config_update/package/opt/hassbian/suites/* /opt/hassbian/suites/ echo "Removing the temporary folder." -cd +cd || exit sudo rm -r /tmp/hassbian_config_update echo @@ -41,4 +41,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/hassbian-script.sh b/package/opt/hassbian/suites/hassbian-script.sh index 9ac374cf..a9c5453b 100644 --- a/package/opt/hassbian/suites/hassbian-script.sh +++ b/package/opt/hassbian/suites/hassbian-script.sh @@ -16,19 +16,19 @@ hassbian-script-show-short-info hassbian-script-show-copyright-info echo "Changing to temporary folder" -cd /tmp +cd /tmp || exit echo "Downloading newest release" curl https://api.github.com/repos/home-assistant/hassbian-scripts/releases/latest | grep "browser_download_url.*deb" | cut -d : -f 2,3 | tr -d \" | wget -qi - # Setting package name -HASSBIAN_PACKAGE=$(ls | grep 'hassbian*') +HASSBIAN_PACKAGE=$(echo hassbian*.deb) echo "Installing newest release" -sudo apt install -y /tmp/$HASSBIAN_PACKAGE +sudo apt install -y /tmp/"$HASSBIAN_PACKAGE" echo "Cleanup" -rm $HASSBIAN_PACKAGE +rm "$HASSBIAN_PACKAGE" echo echo "Uppgrade is now done." @@ -39,4 +39,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/hassbian.sh b/package/opt/hassbian/suites/hassbian.sh index c5b2b8b4..8487ec88 100644 --- a/package/opt/hassbian/suites/hassbian.sh +++ b/package/opt/hassbian/suites/hassbian.sh @@ -1,15 +1,15 @@ #!/bin/bash function hassbian-show-short-info { - echo "Upgrade the base OS installation on this system" + echo "Upgrade the base OS installation on this system." } function hassbian-show-long-info { - echo "Upgrade the base OS installation on this system" + echo "Upgrade the base OS installation on this system." } function hassbian-show-copyright-info { - echo "Original concept by Ludeeus " - echo "Modyfied by Landrash " + echo "Original concept by Ludeeus ." + echo "Modyfied by Landrash ." } function hassbian-upgrade-package { @@ -32,4 +32,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/homeassistant-dev.sh b/package/opt/hassbian/suites/homeassistant-dev.sh index 80d1cc7c..923a6ac8 100644 --- a/package/opt/hassbian/suites/homeassistant-dev.sh +++ b/package/opt/hassbian/suites/homeassistant-dev.sh @@ -1,14 +1,14 @@ #!/bin/bash function homeassistant-dev-show-short-info { - echo "Home Assistant developement branch install script for Hassbian" + echo "Home Assistant developement branch install script for Hassbian." } function homeassistant-dev-show-long-info { - echo "Installs Home Assistant from the developement branch from github onto this system." + echo "Installs Home Assistant from the developement branch from github onto this system." } function homeassistant-dev-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function homeassistant-dev-install-package { @@ -52,4 +52,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/homeassistant.sh b/package/opt/hassbian/suites/homeassistant.sh index 4b5e3e60..87d31646 100644 --- a/package/opt/hassbian/suites/homeassistant.sh +++ b/package/opt/hassbian/suites/homeassistant.sh @@ -1,14 +1,14 @@ #!/bin/bash function homeassistant-show-short-info { - echo "Home Assistant install script for Hassbian" + echo "Home Assistant install script for Hassbian." } function homeassistant-show-long-info { - echo "Installs the base homeassistant package onto this system." + echo "Installs the base homeassistant package onto this system." } function homeassistant-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function homeassistant-install-package { @@ -65,14 +65,14 @@ homeassistant-show-copyright-info echo "Checking current version" pypiversion=$(curl -s https://pypi.python.org/pypi/homeassistant/json | grep '"version":' | awk -F'"' '{print $4}') -sudo -u homeassistant -H /bin/bash << EOF | grep Version|awk '{print $2'}|while read version; do if [[ ${pypiversion} == ${version} ]]; then echo "You already have the latest version: $version";exit 1;fi;done +sudo -u homeassistant -H /bin/bash << EOF | grep Version | awk '{print $2}'|while read -r version; do if [[ "${pypiversion}" == "${version}" ]]; then echo "You already have the latest version: $version";exit 1;fi;done source /srv/homeassistant/bin/activate pip3 show homeassistant EOF if [[ $? == 1 ]]; then - echo "Stopping upgrade" - exit 1 + echo "Stopping upgrade" + exit 1 fi echo "Stopping Home Assistant" @@ -105,4 +105,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/homebridge.sh b/package/opt/hassbian/suites/homebridge.sh index 6e9945cf..729e645f 100644 --- a/package/opt/hassbian/suites/homebridge.sh +++ b/package/opt/hassbian/suites/homebridge.sh @@ -26,21 +26,21 @@ else echo "" echo "Example: https://home.duckdns.org:8123" echo -n "Enter your Home Assistant URL and port: " - read HOMEASSISTANT_URL + read -r 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 + read -s -r 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 + read -r SAMBA fi fi @@ -59,11 +59,11 @@ 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))) +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' ) +RANDOM_MAC=$( for i in {1..6} ; do echo -n ${HEX_CHARS:$((RANDOM % 16)):1} ; done | sed -e 's/\(..\)/:\1/g' ) HOMEBRIDGE_USERNAME=CC:22:3D$RANDOM_MAC -HOMEBRIDGE_PORT=$( printf "57%03d" $(($RANDOM % 999))) +HOMEBRIDGE_PORT=$( printf "57%03d" $((RANDOM % 999))) cat > /home/homebridge/.homebridge/config.json <" + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function hue-install-package { hue-show-short-info hue-show-copyright-info -echo "Setting permissions for Python" +echo "Setting permissions for Python." if [ -d "/usr/lib/python3.5" ]; then - echo "Setting permissions for Python 3.5" - sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.5 - else - echo "Setting permissions for Python 3.4" - sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.4 + echo "Setting permissions for Python 3.5" + sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.5 + else + echo "Setting permissions for Python 3.4" + sudo setcap 'cap_net_bind_service=+ep' /usr/bin/python3.4 fi if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo @@ -41,4 +41,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/libcec.sh b/package/opt/hassbian/suites/libcec.sh index 026c9333..a2422252 100644 --- a/package/opt/hassbian/suites/libcec.sh +++ b/package/opt/hassbian/suites/libcec.sh @@ -1,15 +1,15 @@ #!/bin/bash function libcec-show-short-info { - echo "libcec install script for Hassbian" + echo "libcec install script for Hassbian." } function libcec-show-long-info { - echo "Installs the libcec package for controlling CEC devices from this Pi" + echo "Installs the libcec package for controlling CEC devices from this Pi." } function libcec-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function libcec-install-package { @@ -17,8 +17,8 @@ libcec-show-short-info libcec-show-copyright-info if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo "Running apt-get preparation" @@ -45,7 +45,7 @@ make EOF echo "Installing Pulse-Eight platform" -cd /srv/homeassistant/src/platform/build +cd /srv/homeassistant/src/platform/build || exit sudo make install sudo ldconfig @@ -65,12 +65,12 @@ make -j4 EOF echo "Installing Pulse-Eight libcec" -cd /srv/homeassistant/src/libcec/build +cd /srv/homeassistant/src/libcec/build || exit sudo make install sudo ldconfig echo "Linking libcec to venv site packages" -PYTHONVER=$(ls /usr/local/lib/ | grep python | tail -1) +PYTHONVER=$(echo /usr/local/lib/*python* | awk -F/ '{print $NF}') sudo -u homeassistant -H /bin/bash <" + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function mariadb-install-package { @@ -17,8 +17,8 @@ mariadb-show-short-info mariadb-show-copyright-info if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo "Running apt-get preparation" @@ -49,4 +49,4 @@ echo "If you have issues with this script, please say something in the #devs_has return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/mosquitto.sh b/package/opt/hassbian/suites/mosquitto.sh index d09f2c8d..99c5f81c 100644 --- a/package/opt/hassbian/suites/mosquitto.sh +++ b/package/opt/hassbian/suites/mosquitto.sh @@ -1,16 +1,16 @@ #!/bin/bash function mosquitto-show-short-info { - echo "Mosquitto Installer for Hassbian" + echo "Mosquitto Installer for Hassbian." } function mosquitto-show-long-info { - echo "Installs the Mosquitto package for setting up a local MQTT server" + echo "Installs the Mosquitto package for setting up a local MQTT server." } function mosquitto-show-copyright-info { - echo "Copyright(c) 2016 Dale Higgs " - echo "Modified by Landrash for use with Hassbian." + echo "Copyright(c) 2016 Dale Higgs ." + echo "Modified by Landrash for use with Hassbian." } function mosquitto-install-package { @@ -31,13 +31,13 @@ else echo echo -n "Username: " - read mqtt_username + read -r mqtt_username if [ ! "$mqtt_username" ]; then mqtt_username=pi fi echo -n "Password: " - read -s mqtt_password + read -s -r mqtt_password echo if [ ! "$mqtt_password" ]; then mqtt_password=raspberry @@ -59,12 +59,12 @@ echo "Installing repository key" wget -O - http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key | apt-key add - echo "Adding repository" -OS_VERSION=$(cat /etc/os-release | grep VERSION= | awk -F'(' '{print $2}' | awk -F')' '{print $1}') -if [ ! -f /etc/apt/sources.list.d/mosquitto-$OS_VERSION.list ] +OS_VERSION=$(lsb_release -cs) +if [ ! -f /etc/apt/sources.list.d/mosquitto-"$OS_VERSION".list ] then - sudo curl -o /etc/apt/sources.list.d/mosquitto-$OS_VERSION.list http://repo.mosquitto.org/debian/mosquitto-$OS_VERSION.list + sudo curl -o /etc/apt/sources.list.d/mosquitto-"$OS_VERSION".list http://repo.mosquitto.org/debian/mosquitto-"$OS_VERSION".list else - echo "Already present, skipping..." + echo "Already present, skipping..." fi @@ -74,7 +74,7 @@ apt-cache search mosquitto apt-get install -y mosquitto mosquitto-clients echo "Writing default configuration" -cd /etc/mosquitto +cd /etc/mosquitto || exit mv mosquitto.conf mosquitto.conf.backup cp /opt/hassbian/suites/files/mosquitto.conf /etc/mosquitto/mosquitto.conf chown mosquitto:mosquitto mosquitto.conf @@ -93,24 +93,24 @@ systemctl restart mosquitto.service ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') echo "Checking the installation..." -validation=$(ps -ef | grep -v grep | grep mosquitto | wc -l) -if [ "$validation" != "0" ]; then - echo - echo -e "\e[32mInstallation done.\e[0m" - echo - echo "Your MQTT broker is running at $ip_address:1883 or if prefered hassbian.local:1883" - echo "" - echo "To continue have a look at https://home-assistant.io/docs/mqtt/" - echo "For more information see this repo:" - echo "https://github.com/home-assistant/homebridge-homeassistant#customization" - echo +validation=$(pgrep -f mosquitto) +if [ "$validation" == NULL ]; then + echo + echo -e "\e[32mInstallation done.\e[0m" + echo + echo "Your MQTT broker is running at $ip_address:1883 or if prefered hassbian.local:1883" + echo "" + echo "To continue have a look at https://home-assistant.io/docs/mqtt/" + echo "For more information see this repo:" + echo "https://github.com/home-assistant/homebridge-homeassistant#customization" + 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 + 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 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/mssql.sh b/package/opt/hassbian/suites/mssql.sh index baa42efe..6b4dab7a 100644 --- a/package/opt/hassbian/suites/mssql.sh +++ b/package/opt/hassbian/suites/mssql.sh @@ -1,15 +1,15 @@ #!/bin/bash function mssql-show-short-info { - echo "MS SQL install script for Hassbian" + echo "MS SQL install script for Hassbian." } function mssql-show-long-info { - echo "Installs the MS SQL database engine and dependecies for use with the recorder in Home Assistant" + echo "Installs the MS SQL database engine and dependecies for use with the recorder in Home Assistant." } function mssql-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function mssql-install-package { @@ -17,8 +17,8 @@ mssql-show-short-info mssql-show-copyright-info if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo "Running apt-get preparation" @@ -51,4 +51,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/mysql.sh b/package/opt/hassbian/suites/mysql.sh index 1feb89d6..e7eb629e 100644 --- a/package/opt/hassbian/suites/mysql.sh +++ b/package/opt/hassbian/suites/mysql.sh @@ -1,15 +1,15 @@ #!/bin/bash function mysql-show-short-info { - echo "MySQL install script for Hassbian" + echo "MySQL install script for Hassbian." } function mysql-show-long-info { - echo "Installs the MySQL database engine and dependecies for use with the recorder in Home Assistant" + echo "Installs the MySQL database engine and dependecies for use with the recorder in Home Assistant." } function mysql-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function mysql-install-package { @@ -17,8 +17,8 @@ mysql-show-short-info mysql-show-copyright-info if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo "Running apt-get preparation" @@ -50,4 +50,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/postgresql.sh b/package/opt/hassbian/suites/postgresql.sh index 3d202260..7cb0cad7 100644 --- a/package/opt/hassbian/suites/postgresql.sh +++ b/package/opt/hassbian/suites/postgresql.sh @@ -1,15 +1,15 @@ #!/bin/bash function postgresql-show-short-info { - echo "PostgreSQL install script for Hassbian" + echo "PostgreSQL install script for Hassbian." } function postgresql-show-long-info { - echo "Installs the PostgreSQL database engine and dependecies for use with the recorder in Home Assistant" + echo "Installs the PostgreSQL database engine and dependecies for use with the recorder in Home Assistant." } function postgresql-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function postgresql-install-package { @@ -17,8 +17,8 @@ postgresql-show-short-info postgresql-show-copyright-info if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo "Running apt-get preparation" @@ -51,4 +51,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/razberry.sh b/package/opt/hassbian/suites/razberry.sh index 67fc922b..ca8806ed 100644 --- a/package/opt/hassbian/suites/razberry.sh +++ b/package/opt/hassbian/suites/razberry.sh @@ -1,18 +1,18 @@ #!/bin/bash function razberry-show-short-info { - echo "Disables Bluetooth for the use of a RaZberry with Hassbian." + echo "Disables Bluetooth for the use of a RaZberry with Hassbian." } function razberry-show-long-info { - echo "Disables Bluetooth for the use of a RaZberry with Hassbian." - echo "This will disable the use of Bluetooth and BLE devices." - echo " " - echo "Original script from http://razberry.z-wave.me/install" + echo "Disables Bluetooth for the use of a RaZberry with Hassbian." + echo "This will disable the use of Bluetooth and BLE devices." + echo " " + echo "Original script from http://razberry.z-wave.me/install" } function razberry-show-copyright-info { - echo "Original script from http://razberry.z-wave.me/install" + echo "Original script from http://razberry.z-wave.me/install" } function razberry-install-package { @@ -20,16 +20,16 @@ razberry-show-short-info razberry-show-copyright-info echo "Checking for version of Raspberry Pi" -RPI_BOARD_REVISION=`grep Revision /proc/cpuinfo | cut -d: -f2 | tr -d " "` +RPI_BOARD_REVISION=$(grep Revision /proc/cpuinfo | cut -d: -f2 | tr -d " ") if [[ $RPI_BOARD_REVISION == "a02082" || $RPI_BOARD_REVISION == "a22082" ]] then - echo "Raspberry Pi 3 Detected. Disabling Bluetooth" - systemctl disable hciuart - if [[ ! `grep "dtoverlay=pi3-miniuart-bt" /boot/config.txt` ]] - then - echo "Adding 'dtoverlay=pi3-miniuart-bt' to /boot/config.txt" - echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt - fi + echo "Raspberry Pi 3 Detected. Disabling Bluetooth" + systemctl disable hciuart + if grep -q "dtoverlay=pi3-miniuart-bt" /boot/config.txt + then + echo "Adding 'dtoverlay=pi3-miniuart-bt' to /boot/config.txt" + echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt + fi fi echo @@ -42,4 +42,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/samba.sh b/package/opt/hassbian/suites/samba.sh index fd82d0ed..c059282c 100644 --- a/package/opt/hassbian/suites/samba.sh +++ b/package/opt/hassbian/suites/samba.sh @@ -1,16 +1,16 @@ #!/bin/bash function samba-show-short-info { - echo "Samba install script for Hassbian" + echo "Samba install script for Hassbian." } function samba-show-long-info { - echo "Installs the samba package for sharing the hassbian configuration files" - echo "over the network." + echo "Installs the samba package for sharing the hassbian configuration files." + echo "over the network." } function samba-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " + echo "Copyright(c) 2017 Fredrik Lindqvist ." } function samba-install-package { @@ -18,8 +18,8 @@ samba-show-short-info samba-show-copyright-info if [ "$(id -u)" != "0" ]; then - echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 - return 1 + echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 + return 1 fi echo "Running apt-get preparation" @@ -30,7 +30,7 @@ echo "Adding homeassistant Samba user" sudo smbpasswd -a homeassistant -n echo "Adding shared folder for Home Assistant configuration directory" -cd /etc/samba/ +cd /etc/samba/ || exit sudo patch <<'EOF' --- smb.conf 2017-02-02 20:29:42.383603738 +0000 +++ smb_ha.conf 2017-02-02 20:37:12.418960977 +0000 @@ -64,4 +64,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/tradfri.sh b/package/opt/hassbian/suites/tradfri.sh index 5d9e011d..116ab3d0 100644 --- a/package/opt/hassbian/suites/tradfri.sh +++ b/package/opt/hassbian/suites/tradfri.sh @@ -50,4 +50,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/webterminal.sh b/package/opt/hassbian/suites/webterminal.sh index 3e9019a6..dfb16ec3 100644 --- a/package/opt/hassbian/suites/webterminal.sh +++ b/package/opt/hassbian/suites/webterminal.sh @@ -1,10 +1,10 @@ #!/bin/bash function webterminal-show-short-info { - echo "Installs an websevice terminal." + echo "Installs an websevice terminal." } function webterminal-show-long-info { - echo "Installs an websevice terminal to controll your installation." + echo "Installs an websevice terminal to controll your installation." } function webterminal-show-copyright-info { @@ -35,4 +35,4 @@ echo return 0 } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" +[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" From b332ef319fd1874743e838bcefcecc59fa1b60c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Wed, 14 Feb 2018 21:00:15 +0100 Subject: [PATCH 2/9] homebridge fix --- package/opt/hassbian/suites/homebridge.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package/opt/hassbian/suites/homebridge.sh b/package/opt/hassbian/suites/homebridge.sh index 729e645f..57fc571d 100644 --- a/package/opt/hassbian/suites/homebridge.sh +++ b/package/opt/hassbian/suites/homebridge.sh @@ -60,9 +60,7 @@ 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' ) -HOMEBRIDGE_USERNAME=CC:22:3D$RANDOM_MAC +HOMEBRIDGE_USERNAME=$(hexdump -n3 -e'/3 "00:60:2F" 3/1 ":%02X"' /dev/random) HOMEBRIDGE_PORT=$( printf "57%03d" $((RANDOM % 999))) cat > /home/homebridge/.homebridge/config.json < Date: Thu, 15 Feb 2018 21:50:14 +0100 Subject: [PATCH 3/9] hassbian-connfig compliant --- package/usr/local/bin/hassbian-config | 227 +++++++++++++------------- 1 file changed, 115 insertions(+), 112 deletions(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index b174980a..564cadd0 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -4,135 +4,142 @@ SUITE_INSTALL_DIR=/opt/hassbian/suites SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control function usage { - echo hassbian-config usage: - echo - echo hassbian-config \ \ - echo where \ is one of: - echo install - installs a software suite - echo upgrade - upgrades a software suite - echo show - shows software suites available - echo log - displays an log of the last operation - echo share-log - generates an hastebin link of the last operation - echo and \ is the name of a software component to operate on. - echo + echo hassbian-config usage: + echo + echo hassbian-config \ \ + echo where \ is one of: + echo install - installs a software suite + echo upgrade - upgrades a software suite + echo show - shows software suites available + echo log - displays an log of the last operation + echo share-log - generates an hastebin link of the last operation + echo and \ is the name of a software component to operate on. + echo + return 0 } function show-suite-info { - source $SUITE_INSTALL_DIR/$1.sh - $1-show-short-info + source $SUITE_INSTALL_DIR/"$1".sh + "$1"-show-short-info + return 0 } function get-all-suite-installers { - echo $(find $SUITE_INSTALL_DIR/ -maxdepth 1 -type f | sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') + ALLSUITES=$(find $SUITE_INSTALL_DIR/ -maxdepth 1 -type f | sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') + echo $ALLSUITES + return 0 } function show-suites { - echo -e "Install scripts: (Usage 'sudo hassbian-config install \e[32msuite-name\e[0m')" - installers=$(get-all-suite-installers) - for i in $installers - do - if [ ! -f $SUITE_CONTROL_DIR/$i ]; then + echo -e "Install scripts: (Usage 'sudo hassbian-config install \e[32msuite-name\e[0m')" + installers=$(get-all-suite-installers) + for i in $installers + do + if [ ! -f $SUITE_CONTROL_DIR/"$i" ]; then SUITESTATE="" else - SUITESTATE=$(cat $SUITE_CONTROL_DIR/$i | grep SCRIPTSTATE | awk -F'=' '{printf $2}') + SUITESTATE=$(grep SCRIPTSTATE $SUITE_CONTROL_DIR/"$i" | awk -F'=' '{printf $2}') SUITESTATE=$(printf "\e[34m $SUITESTATE%-7s") fi - printf "\e[32m%-20s\e[0m %s\n" "$i$SUITESTATE" "$(show-suite-info $i)" - done - echo -e "To view more info about a suite type: 'hassbian-config show \e[32msuite-name\e[0m'" + printf "\e[32m%-20s\e[0m %s\n" "$i$SUITESTATE" "$(show-suite-info "$i")" + done + echo -e "To view more info about a suite type: 'hassbian-config show \e[32msuite-name\e[0m'" + return 0 } function show-suite-long-info { - # Shows long info for the suite. - source $SUITE_INSTALL_DIR/$1.sh - $1-show-short-info - $1-show-long-info - $1-show-copyright-info + source $SUITE_INSTALL_DIR/"$1".sh + "$1"-show-short-info + "$1"-show-long-info + "$1"-show-copyright-info + return 0 } function check-permission { - if (( $EUID != 0 )) - then - echo "Error: hassbian-config must be run as root (with sudo) for this to be possible" - exit 1 - fi + if (( EUID != 0 )) + then + echo "Error: hassbian-config must be run as root (with sudo) for this to be possible" + exit 1 + fi + return 0 } function share-log { - echo "This will put the output from your last operation on hastebin." - echo "This could include sensitive informastion." - echo "If you are unsure about what it contains, you can rin 'hassbian-config log' to check." - read -p "Do you want to crate an hastebin link? [N/y] : " RESPONCE - if [ "$RESPONCE" == "y" ] || [ "$RESPONCE" == "Y" ]; then - echo "" + if [ "$ACCEPT" == "true" ]; then + a=$(cat $LOGFILE); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' + else + echo "This will put the output from your last operation on hastebin." + echo "This could include sensitive informastion." + echo "If you are unsure about what it contains, you can rin 'hassbian-config log' to check." + read -p -r "Do you want to crate an hastebin link? [N/y] : " RESPONSE + if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then + echo "" a=$(cat $LOGFILE); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' - exit 1 fi - exit 1 + fi + return 0 } function install-suite { - if [ ! -f $SUITE_CONTROL_DIR/$1 ]; then - touch $SUITE_CONTROL_DIR/$1 - echo "SCRIPTSTATE=uninstalled" > $SUITE_CONTROL_DIR/$1 + if [ ! -f $SUITE_CONTROL_DIR/"$1" ]; then + touch $SUITE_CONTROL_DIR/"$1" + echo "SCRIPTSTATE=uninstalled" > $SUITE_CONTROL_DIR/"$1" fi - SUITESTATE=$(cat $SUITE_CONTROL_DIR/$1 | grep SCRIPTSTATE | awk -F'=' '{print $2}') - source $SUITE_INSTALL_DIR/$1.sh + SUITESTATE=$(grep "SCRIPTSTATE" $SUITE_CONTROL_DIR/"$1" | awk -F'=' '{print $2}') + source $SUITE_INSTALL_DIR/"$1".sh if [ "$FORCE" == "true" ]; then - $1-install-package | tee $LOGFILE - sed -i -- 's/SCRIPTSTATE='$SUITESTATE'/SCRIPTSTATE=installed/g' $SUITE_CONTROL_DIR/$1 + "$1"-install-package | tee $LOGFILE + sed -i -- 's/SCRIPTSTATE='"$SUITESTATE"'/SCRIPTSTATE=installed/g' $SUITE_CONTROL_DIR/"$1" elif [ "$SUITESTATE" == "installed" ]; then echo "$1 is already installed, trying upgrade script..." - UPGRADE=$(cat $SUITE_INSTALL_DIR/$1.sh | grep $1-upgrade-package) - if [ "$UPGRADE" == "" ]; then - echo "Upgrade script is not available..." - echo "You can force run the install script like this:" - echo "sudo hassbian-config -f install $1" - exit - fi - $1-upgrade-package | tee $LOGFILE - sed -i -- 's/SCRIPTSTATE='$SUITESTATE'/SCRIPTSTATE=installed/g' $SUITE_CONTROL_DIR/$1 + UPGRADE=$(grep "$1"-upgrade-package $SUITE_INSTALL_DIR/"$1".sh) + if [ "$UPGRADE" == "" ]; then + echo "Upgrade script is not available..." + echo "You can force run the install script like this:" + echo "sudo hassbian-config -f install $1" + exit + fi + "$1"-upgrade-package | tee $LOGFILE + sed -i -- 's/SCRIPTSTATE='"$SUITESTATE"'/SCRIPTSTATE=installed/g' $SUITE_CONTROL_DIR/"$1" else - source $SUITE_INSTALL_DIR/$1.sh - $1-install-package | tee $LOGFILE - sed -i -- 's/SCRIPTSTATE='$SUITESTATE'/SCRIPTSTATE=installed/g' $SUITE_CONTROL_DIR/$1 + source $SUITE_INSTALL_DIR/"$1".sh + "$1"-install-package | tee $LOGFILE + sed -i -- 's/SCRIPTSTATE='"$SUITESTATE"'/SCRIPTSTATE=installed/g' $SUITE_CONTROL_DIR/"$1" fi return 0 } function upgrade-suite { - # Having got here, the installer script exists; source it, then run the installer function. - UPGRADE=$(cat $SUITE_INSTALL_DIR/$1.sh | grep $1-upgrade-package) - if [ "$UPGRADE" == "" ]; then - echo "Upgrade script is not available..." - echo "You can force run the install script like this:" - echo "sudo hassbian-config -f install $1" - exit - fi - check-permission - source $SUITE_INSTALL_DIR/$1.sh - $1-upgrade-package + UPGRADE=$(grep "$1"-upgrade-package $SUITE_INSTALL_DIR/"$1".sh) + if [ "$UPGRADE" == "" ]; then + echo "Upgrade script is not available..." + echo "You can force run the install script like this:" + echo "sudo hassbian-config -f install $1" + fi + check-permission + source $SUITE_INSTALL_DIR/"$1".sh + "$1"-upgrade-package + return 0 } function verify-suite { - # Check that the suite specified actually exists - if [ -f "$SUITE_INSTALL_DIR/$1.sh" ] - then - retval=0 # beware - 0 is true in bash. - else - retval=1 - fi - return $retval + if [ -f "$SUITE_INSTALL_DIR/$1.sh" ] + then + retval=0 # beware - 0 is true in bash. + else + retval=1 + fi + return $retval } function show-installed-suites { INSTALLERS=$(find $SUITE_CONTROL_DIR/ -maxdepth 1 -type f | awk -F'/|_' ' {print $NF}' | grep -v 'homeassistant' | awk -F. '{print $1}') for i in $INSTALLERS do - STATE=$(cat $SUITE_CONTROL_DIR/$i | grep SCRIPTSTATE=installed | awk -F'=' '{print $2}') + STATE=$(grep "SCRIPTSTATE=installed" $SUITE_CONTROL_DIR/"$i" | awk -F'=' '{print $2}') if [ "$STATE" != "" ]; then - echo "$i:" $STATE + echo "$i:" "$STATE" fi done return 0 @@ -140,8 +147,8 @@ function show-installed-suites { if [ $# -lt 1 ] then - usage - exit + usage + return 0 fi while [[ $# -gt 0 ]] @@ -160,14 +167,12 @@ case $COMMAND in shift # past argument ;; "show") - if [ "$SUITE" != "" ] - then - if verify-suite $SUITE - then + if [ "$SUITE" != "" ]; then + if verify-suite "$SUITE"; then RUN="show-suite-long-info $SUITE" else RUN="echo suite $SUITE doesn't exist." - fi + fi else RUN="show-suites" fi @@ -175,18 +180,16 @@ case $COMMAND in shift # past value ;; "install") - if verify-suite $SUITE - then + if verify-suite "$SUITE"; then RUN="install-suite $SUITE" else RUN="echo suite $SUITE doesn't exist." fi shift # past argument shift # past value - ;; + ;; "info") - if verify-suite $SUITE - then + if verify-suite "$SUITE"; then RUN="info-suite $SUITE" else RUN="echo suite $SUITE doesn't exist." @@ -195,39 +198,39 @@ case $COMMAND in shift # past value ;; "upgrade") - if verify-suite $SUITE - then + if verify-suite "$SUITE"; then RUN="upgrade-suite $SUITE" else RUN="echo suite $SUITE doesn't exist." fi shift # past argument shift # past value - ;; + ;; "log") - RUN="more $LOGFILE" - shift # past argument - ;; + RUN="more $LOGFILE" + shift # past argument + ;; "share-log") - RUN="share-log" - shift # past argument - ;; + RUN="share-log" + shift # past argument + ;; "-V") - VERSION=$(dpkg -s hassbian-scripts | grep 'Version:' | awk '{print $2}') - RUN="echo $VERSION" - shift # past argument + VERSION=$(dpkg -s hassbian-scripts | grep 'Version:' | awk '{print $2}') + RUN="echo $VERSION" + shift # past argument ;; "show-installed") - RUN="show-installed-suites" - shift # past argument - ;; + RUN="show-installed-suites" + shift # past argument + ;; *) - RUN="usage" - shift # past argument - ;; + RUN="usage" + shift # past argument + ;; esac done if [ "$RUN" != "" ]; then $RUN - exit + exit fi +exit 0 From b3f9a3d4dab4da092b3e443d2bf3f20f3be2f618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 15 Feb 2018 21:52:50 +0100 Subject: [PATCH 4/9] shellcheck --- package/usr/local/bin/hassbian-config | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index 564cadd0..98585f3a 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -1,4 +1,5 @@ #!/bin/bash +# shellcheck source=src/lib.sh LOGFILE=/tmp/hassbian.log SUITE_INSTALL_DIR=/opt/hassbian/suites SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control @@ -26,7 +27,7 @@ function show-suite-info { function get-all-suite-installers { ALLSUITES=$(find $SUITE_INSTALL_DIR/ -maxdepth 1 -type f | sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') - echo $ALLSUITES + echo "$ALLSUITES" return 0 } From 1454dfc89b376e729b38f6023977d2cc77f2db2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 15 Feb 2018 21:55:09 +0100 Subject: [PATCH 5/9] shellcheck --- package/usr/local/bin/hassbian-config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index 98585f3a..5fd96168 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -1,5 +1,5 @@ #!/bin/bash -# shellcheck source=src/lib.sh +# shellcheck source=/opt/hassbian/suites LOGFILE=/tmp/hassbian.log SUITE_INSTALL_DIR=/opt/hassbian/suites SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control From 0364904751687a8f0661a1196c2325f63c35014d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Thu, 15 Feb 2018 22:01:36 +0100 Subject: [PATCH 6/9] stickler.yml --- package/.stickler.yml | 4 ++++ package/usr/local/bin/hassbian-config | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 package/.stickler.yml diff --git a/package/.stickler.yml b/package/.stickler.yml new file mode 100644 index 00000000..7dbe3db2 --- /dev/null +++ b/package/.stickler.yml @@ -0,0 +1,4 @@ +linters: + shellcheck: + shell: sh + exclude: 'SC1090' diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index 5fd96168..6aaccf48 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -1,5 +1,4 @@ #!/bin/bash -# shellcheck source=/opt/hassbian/suites LOGFILE=/tmp/hassbian.log SUITE_INSTALL_DIR=/opt/hassbian/suites SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control From f1de5b4a358307510a88a2c7b3480f11302d2bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 16 Feb 2018 11:34:06 +0100 Subject: [PATCH 7/9] minor fixes --- package/opt/hassbian/suites/appdaemon.sh | 4 +-- package/opt/hassbian/suites/homebridge.sh | 2 +- package/opt/hassbian/suites/mosquitto.sh | 2 +- package/usr/local/bin/hassbian-config | 36 +++++++++-------------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/package/opt/hassbian/suites/appdaemon.sh b/package/opt/hassbian/suites/appdaemon.sh index eabff7eb..db4cdfef 100644 --- a/package/opt/hassbian/suites/appdaemon.sh +++ b/package/opt/hassbian/suites/appdaemon.sh @@ -76,7 +76,7 @@ if [ "$SAMBA" == "y" ] || [ "$SAMBA" == "Y" ]; then fi validation=$(pgrep -f appdaemon) -if [ "$validation" == NULL ]; then +if [ "$validation" != NULL ]; then echo echo -e "\e[32mInstallation done..\e[0m" echo @@ -121,7 +121,7 @@ systemctl start appdaemon@homeassistant.service echo "Checking the installation..." validation=$(pgrep -f appdaemon) -if [ "$validation" == NULL ]; then +if [ "$validation" != NULL ]; then echo echo -e "\e[32mUppgrade done..\e[0m" echo diff --git a/package/opt/hassbian/suites/homebridge.sh b/package/opt/hassbian/suites/homebridge.sh index 57fc571d..44bdf49b 100644 --- a/package/opt/hassbian/suites/homebridge.sh +++ b/package/opt/hassbian/suites/homebridge.sh @@ -128,7 +128,7 @@ fi echo "Checking the installation..." validation=$(pgrep -f homebridge) -if [ "$validation" == NULL ]; then +if [ "$validation" != NULL ]; then echo echo -e "\e[32mInstallation done.\e[0m" echo diff --git a/package/opt/hassbian/suites/mosquitto.sh b/package/opt/hassbian/suites/mosquitto.sh index 99c5f81c..affcfb7b 100644 --- a/package/opt/hassbian/suites/mosquitto.sh +++ b/package/opt/hassbian/suites/mosquitto.sh @@ -94,7 +94,7 @@ ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $ echo "Checking the installation..." validation=$(pgrep -f mosquitto) -if [ "$validation" == NULL ]; then +if [ "$validation" != NULL ]; then echo echo -e "\e[32mInstallation done.\e[0m" echo diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index 6aaccf48..3a003eeb 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -68,11 +68,12 @@ function check-permission { function share-log { if [ "$ACCEPT" == "true" ]; then a=$(cat $LOGFILE); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' - else - echo "This will put the output from your last operation on hastebin." - echo "This could include sensitive informastion." - echo "If you are unsure about what it contains, you can rin 'hassbian-config log' to check." - read -p -r "Do you want to crate an hastebin link? [N/y] : " RESPONSE + else + echo "This will put the output from your last operation on hastebin." + echo "This could include sensitive informastion." + echo "If you are unsure about what it contains, you can rin 'hassbian-config log' to check." + echo -n "Do you want to crate an hastebin link? [N/y] : " + read -r RESPONSE if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then echo "" a=$(cat $LOGFILE); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}' @@ -124,8 +125,7 @@ function upgrade-suite { } function verify-suite { - if [ -f "$SUITE_INSTALL_DIR/$1.sh" ] - then + if [ -f "$SUITE_INSTALL_DIR/$1.sh" ]; then retval=0 # beware - 0 is true in bash. else retval=1 @@ -134,21 +134,22 @@ function verify-suite { } function show-installed-suites { - INSTALLERS=$(find $SUITE_CONTROL_DIR/ -maxdepth 1 -type f | awk -F'/|_' ' {print $NF}' | grep -v 'homeassistant' | awk -F. '{print $1}') + INSTALLERS=$(find $SUITE_INSTALL_DIR/ -maxdepth 1 -type f | sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') for i in $INSTALLERS do + if [ -f "$SUITE_CONTROL_DIR/$i" ]; then STATE=$(grep "SCRIPTSTATE=installed" $SUITE_CONTROL_DIR/"$i" | awk -F'=' '{print $2}') - if [ "$STATE" != "" ]; then - echo "$i:" "$STATE" + if [ "$STATE" != "" ]; then + echo "$i:" "$STATE" + fi fi done return 0 } -if [ $# -lt 1 ] -then +if [ $# -lt 1 ]; then usage - return 0 + exit 0 fi while [[ $# -gt 0 ]] @@ -188,15 +189,6 @@ case $COMMAND in shift # past argument shift # past value ;; - "info") - if verify-suite "$SUITE"; then - RUN="info-suite $SUITE" - else - RUN="echo suite $SUITE doesn't exist." - fi - shift # past argument - shift # past value - ;; "upgrade") if verify-suite "$SUITE"; then RUN="upgrade-suite $SUITE" From c66f27600d80240c8a9412d9e967b311cf0772e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 16 Feb 2018 11:39:42 +0100 Subject: [PATCH 8/9] update duckdns --- package/opt/hassbian/suites/duckdns.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package/opt/hassbian/suites/duckdns.sh b/package/opt/hassbian/suites/duckdns.sh index d793bd7a..d7b85774 100644 --- a/package/opt/hassbian/suites/duckdns.sh +++ b/package/opt/hassbian/suites/duckdns.sh @@ -40,7 +40,8 @@ echo if [ ! "$token" ]; then exit fi -read -p -r "Do you want to generate certificates to use SSL(https)? [N/y] : " SSL_RESPONSE +echo -n "Do you want to generate certificates to use SSL(https)? [N/y] : " +read -r SSL_RESPONSE echo "Changing to homeassistant user..." sudo -u homeassistant -H /bin/bash << EOF From 9064996496f01fdfd22a16ee573a176c590c133c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 16 Feb 2018 13:26:17 +0100 Subject: [PATCH 9/9] minor fix --- package/etc/bash_completion.d/hassbian-config | 2 +- package/opt/hassbian/suites/mssql.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package/etc/bash_completion.d/hassbian-config b/package/etc/bash_completion.d/hassbian-config index 55f4918d..02e6586e 100644 --- a/package/etc/bash_completion.d/hassbian-config +++ b/package/etc/bash_completion.d/hassbian-config @@ -7,7 +7,7 @@ _hassbian-config() opts="install upgrade show log share-log" case "${prev}" in - install|upgrade) + install|upgrade|show) local inst=$(find /opt/hassbian/suites/ -maxdepth 1 -type f | awk -F'/|_' ' {print $NF}' | awk -F. '{print $1}') COMPREPLY=( $(compgen -W "${inst}" -- ${cur}) ) return 0 diff --git a/package/opt/hassbian/suites/mssql.sh b/package/opt/hassbian/suites/mssql.sh index 6b4dab7a..62908c3d 100644 --- a/package/opt/hassbian/suites/mssql.sh +++ b/package/opt/hassbian/suites/mssql.sh @@ -33,6 +33,7 @@ echo "Changing to Home Assistant venv" source /srv/homeassistant/bin/activate echo "Installing dependencies for MS SQL" +pip3 install --upgrade setuptools wheel pip3 install pymssql echo "Deactivating virtualenv"