From a66428b77ca5fd948c100091c888c03722dc0d53 Mon Sep 17 00:00:00 2001 From: David Jolley Date: Mon, 6 Feb 2017 11:44:46 +0000 Subject: [PATCH 1/9] Initial commit for hassbian-config script. The hassbian-config script is a framework for configuring the installed packages on the system. It utilises the install scripts with minor modifications for inclusion into the framework. hassbian-config defines three operations: install, show and info install will install the named software package (hassbian-config calls this a "suite") show will show all available installers. info will show information about the suite selected. As of this version, there is no kind of state kept by hassbian-config; this will likely need to be changed. --- hassbian-config | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 hassbian-config diff --git a/hassbian-config b/hassbian-config new file mode 100755 index 00000000..2967f964 --- /dev/null +++ b/hassbian-config @@ -0,0 +1,87 @@ +#!/bin/bash + +SUITE_INSTALL_DIR=/home/pi/hassbian-scripts +SUITE_INSTALL_DIR=/home/dave/Projects/hassbian/hassbian-scripts + +function usage { + echo $0: usage: + echo + echo $0 \ \ + echo where \ is one of: + echo install - installs a software suite + echo show - shows software suites available + echo and \ is the name of a software component to operate on. + echo +} + +function show-suite-info { + source $SUITE_INSTALL_DIR/install_$1.sh + $1-show-long-info +} + +function show-suites { + echo List of suites available for installation: + suites=$(ls $SUITE_INSTALL_DIR/install_*.sh | grep -Po "install_\K(.*)\.sh$" | awk -F. '!/homeassistant/ {print $1}') + + for i in $suites + do + echo $i: $(show-suite-info $i) + done +} + +function show-suite-long-info { + # Shows long info for the suite. + source $SUITE_INSTALL_DIR/install_$1.sh + $1-show-short-info + $1-show-long-info + $1-show-copyright-info +} + +function install-suite { + # Having got here, the installer script exists; source it, then run the installer function. + source $SUITE_INSTALL_DIR/install_$1.sh + $1-install-package +} + +function verify-suite { + # Check that the suite specified actually exists + if [ ! -f "$SUITE_INSTALL_DIR/install_$1.sh" ] + then + echo "Cannot find suite $1." + echo "Try running the show command to see all available suites" + exit + fi +} + +if [ $# -lt 1 ] +then + usage + exit +fi +COMMAND=$1 +SUITE=$2 + + +case $COMMAND in +"show") + if [ "$SUITE" != "" ] + then + verify-suite $SUITE + show-suite-long-info $SUITE + else + show-suites + fi + ;; +"install") + verify-suite $SUITE + install-suite $SUITE + exit + ;; +"info") + verify-suite $SUITE + info-suite $SUITE + ;; +*) + usage + ;; +esac From 06b16c17b48d31bbcee59947555491eba77d79a7 Mon Sep 17 00:00:00 2001 From: David Jolley Date: Mon, 6 Feb 2017 12:12:04 +0000 Subject: [PATCH 2/9] Add documentation for hassbian-config. --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 2a06ba09..713ccbf3 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,29 @@ git pull ## The included scripts The following scripts are currently included. You can view the documentation below for usage and instructions. +### hassbian-config (hassbian-config) +This script is a package handler for the hassbian scripts; all interactions for installing software should be handled through this script; running the individual scripts to install software will no longer work as expected. +#### Usage +The hassbian-config script is invoked with: +./hassbian-scripts/hassbian-config *command* *suite* + +where command is one of: +- install +- show +- info + +##### install +The install command takes one argument and will attempt to install the indicated suite of software. +Generally, this means that the invocation of the hassbian-config script should be run as root, with: +sudo ./hassbian-scripts/hassbian-config install *suite* +##### show +The show command takes no arguments, and lists all available suites which can be (re-)installed. +##### info +The info command takes the name of a suite, and shows information about the suite. + +## Installer script components +All scripts listed below are helper scripts for the hassbian-config script, and shouldn't be run directly. The documentation has been kept for explanatory purposes only. + ### Install Home Assistant *(install_homeassistant.sh)* This is a copy of the installation script run during first boot of your Raspberry Pi. This script is downloaded when the HASSbian image is built and is shipped on the Hassbian image. From c99336a2a136cd2a308d7dac7f41d6a2028eec0d Mon Sep 17 00:00:00 2001 From: David Jolley Date: Mon, 6 Feb 2017 12:14:45 +0000 Subject: [PATCH 3/9] Added comment as to why the homeassistant suite is not in the list of available suites. --- hassbian-config | 1 - 1 file changed, 1 deletion(-) diff --git a/hassbian-config b/hassbian-config index 2967f964..92e2d329 100755 --- a/hassbian-config +++ b/hassbian-config @@ -1,7 +1,6 @@ #!/bin/bash SUITE_INSTALL_DIR=/home/pi/hassbian-scripts -SUITE_INSTALL_DIR=/home/dave/Projects/hassbian/hassbian-scripts function usage { echo $0: usage: From 58c0dddb3ac5817bfceaaf48d0bb1edc668e0f0a Mon Sep 17 00:00:00 2001 From: David Jolley Date: Mon, 6 Feb 2017 12:19:17 +0000 Subject: [PATCH 4/9] Attempt to commit all local changes (I'm not familiar with git, sorry). --- hassbian-config | 1 + install_libcec.sh | 20 ++++++++++++++++---- install_mosquitto.sh | 22 +++++++++++++++++----- install_openzwave.sh | 23 ++++++++++++++++++----- install_samba.sh | 23 +++++++++++++++++++---- 5 files changed, 71 insertions(+), 18 deletions(-) diff --git a/hassbian-config b/hassbian-config index 92e2d329..6acda551 100755 --- a/hassbian-config +++ b/hassbian-config @@ -20,6 +20,7 @@ function show-suite-info { function show-suites { echo List of suites available for installation: + # inhibit the homeassistant suite from being displayed, to discourage its (re-)installation. suites=$(ls $SUITE_INSTALL_DIR/install_*.sh | grep -Po "install_\K(.*)\.sh$" | awk -F. '!/homeassistant/ {print $1}') for i in $suites diff --git a/install_libcec.sh b/install_libcec.sh index 2a559d12..ca38a728 100755 --- a/install_libcec.sh +++ b/install_libcec.sh @@ -1,9 +1,20 @@ #!/bin/bash -echo -echo "libcec install script for Hassbian" -echo "Copyright(c) 2017 Fredrik Lindqvist " -echo +function libcec-show-short-info { + echo "libcec install script for Hassbian" +} + +function libcec-show-long-info { + echo "Installs the libcec package for controlling CEC devices from this Pi" +} + +function libcec-show-copyright-info { + echo "Copyright(c) 2017 Fredrik Lindqvist " +} + +function libcec-install-package { +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 @@ -68,3 +79,4 @@ echo echo "To continue have a look at https://home-assistant.io/components/hdmi_cec/" echo "It's recomended that you restart your Pi before continuing with testing libcec." echo +} diff --git a/install_mosquitto.sh b/install_mosquitto.sh index a11e89ec..812cdbc3 100755 --- a/install_mosquitto.sh +++ b/install_mosquitto.sh @@ -1,10 +1,21 @@ #!/bin/bash -echo -echo "Mosquitto Installer for Hassbian" -echo "Modified by Landrash for use with Hassbian." -echo "Copyright(c) 2016 Dale Higgs " -echo +function mosquitto-show-short-info { + echo "Mosquitto Installer for Hassbian" +} + +function mosquitto-show-long-info { + 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." +} + +function mosquitto-install-package { +mosquitto-show-short-info +mosquitto-show-copyright-info if [ "$(id -u)" != "0" ]; then echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2 @@ -81,3 +92,4 @@ echo echo "If you have issues with this script, please contact @Landrash on gitter.im" echo "Original script by @dale3h on gitter.im" echo +} diff --git a/install_openzwave.sh b/install_openzwave.sh index da9daaf5..95227d7e 100755 --- a/install_openzwave.sh +++ b/install_openzwave.sh @@ -1,9 +1,23 @@ #!/bin/bash +function openzwave-show-short-info { + echo "Open Z-Wave Installer for Hassbian" +} + +function openzwave-show-long-info { + echo "Installs the Open Z-wave package for setting up your zwave network" +} + +function openzwave-show-copyright-info { + echo "Copyright(c) 2016 Dale Higgs " + echo "Modified by Landrash for use with Hassbian." +} + +function openzwave-install-package { +openzwave-show-short-info +openzwave-show-copyright-info + echo -echo "Open Z-Wave Installer for Hassbian" -echo "Modified by Landrash for use with Hassbian." -echo "Copyright(c) 2016 Dale Higgs " echo if [ "$(id -u)" != "0" ]; then @@ -90,5 +104,4 @@ echo echo "If you have issues with this script, please contact @Landrash on gitter.im" echo "Original script by @dale3h on gitter.im" echo - - +} diff --git a/install_samba.sh b/install_samba.sh index f8d63312..d3eeb081 100755 --- a/install_samba.sh +++ b/install_samba.sh @@ -1,9 +1,21 @@ #!/bin/bash -echo -echo "Samba install script for Hassbian" -echo "Copyright(c) 2017 Fredrik Lindqvist " -echo +function samba-show-short-info { + 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 Pi's network." +} + +function samba-show-copyright-info { + echo "Copyright(c) 2017 Fredrik Lindqvist " +} + +function samba-install-package { +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 @@ -49,3 +61,6 @@ echo "If you have issues with this script, please contact @Landrash on gitter.im echo echo "Configuration is now available as a Samba share at \\\\$ip_address\homeassistant" echo +} + +[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" \ No newline at end of file From 1c653b684122888a5c5b324978b2a1c15c09024e Mon Sep 17 00:00:00 2001 From: David Jolley Date: Mon, 6 Feb 2017 12:26:14 +0000 Subject: [PATCH 5/9] Added stanzas to all suite installers; updated install_homeassistant.sh to be "just" another suite. --- install_homeassistant.sh | 22 +++++++++++++++++----- install_libcec.sh | 2 ++ install_mosquitto.sh | 2 ++ install_openzwave.sh | 2 ++ install_samba.sh | 2 +- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/install_homeassistant.sh b/install_homeassistant.sh index 65492081..0dcb07ec 100755 --- a/install_homeassistant.sh +++ b/install_homeassistant.sh @@ -1,8 +1,19 @@ #!/bin/sh -echo -echo "Home Assistant install script for Hassbian" -echo "Copyright(c) 2017 Fredrik Lindqvist " -echo +function homeassistant-show-short-info { + echo "Home Assistant install script for Hassbian" +} + +function homeassistant-show-long-info { + echo "Installs the libcec package for controlling CEC devices from this Pi" +} + +function homeassistant-show-copyright-info { + echo "Copyright(c) 2017 Fredrik Lindqvist " +} + +function homeassistant-install-package { +homeassistant-show-short-info +homeassistant-show-copyright-info echo "Changing to the homeassistant user" sudo -u homeassistant -H /bin/bash << EOF @@ -53,5 +64,6 @@ echo echo "If this script failed then this Raspberry Pi most likely did not have a fully functioning internet connection." echo "If you still have issues with this script, please contact @Landrash on gitter.im" echo +} - +[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" diff --git a/install_libcec.sh b/install_libcec.sh index ca38a728..b2437b64 100755 --- a/install_libcec.sh +++ b/install_libcec.sh @@ -80,3 +80,5 @@ echo "To continue have a look at https://home-assistant.io/components/hdmi_cec/" echo "It's recomended that you restart your Pi before continuing with testing libcec." echo } + +[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" diff --git a/install_mosquitto.sh b/install_mosquitto.sh index 812cdbc3..b8cccf80 100755 --- a/install_mosquitto.sh +++ b/install_mosquitto.sh @@ -93,3 +93,5 @@ echo "If you have issues with this script, please contact @Landrash on gitter.im echo "Original script by @dale3h on gitter.im" echo } + +[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" diff --git a/install_openzwave.sh b/install_openzwave.sh index 95227d7e..24b7f061 100755 --- a/install_openzwave.sh +++ b/install_openzwave.sh @@ -105,3 +105,5 @@ echo "If you have issues with this script, please contact @Landrash on gitter.im echo "Original script by @dale3h on gitter.im" echo } + +[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" diff --git a/install_samba.sh b/install_samba.sh index d3eeb081..487d8970 100755 --- a/install_samba.sh +++ b/install_samba.sh @@ -63,4 +63,4 @@ echo "Configuration is now available as a Samba share at \\\\$ip_address\homeass echo } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" \ No newline at end of file +[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" From bdb93c0eed83cabb13eb506d5c1182fde59214c8 Mon Sep 17 00:00:00 2001 From: David Jolley Date: Mon, 6 Feb 2017 21:23:52 +0000 Subject: [PATCH 6/9] Untab file - somehow tabs had crept in, not spaces. --- hassbian-config | 99 +++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/hassbian-config b/hassbian-config index 6acda551..f87b5a2b 100755 --- a/hassbian-config +++ b/hassbian-config @@ -1,62 +1,63 @@ #!/bin/bash SUITE_INSTALL_DIR=/home/pi/hassbian-scripts +SUITE_INSTALL_DIR=/home/dave/Projects/hassbian/hassbian-scripts function usage { - echo $0: usage: - echo - echo $0 \ \ - echo where \ is one of: - echo install - installs a software suite - echo show - shows software suites available - echo and \ is the name of a software component to operate on. - echo + echo $0: usage: + echo + echo $0 \ \ + echo where \ is one of: + echo install - installs a software suite + echo show - shows software suites available + echo and \ is the name of a software component to operate on. + echo } function show-suite-info { - source $SUITE_INSTALL_DIR/install_$1.sh - $1-show-long-info + source $SUITE_INSTALL_DIR/install_$1.sh + $1-show-long-info } function show-suites { - echo List of suites available for installation: - # inhibit the homeassistant suite from being displayed, to discourage its (re-)installation. - suites=$(ls $SUITE_INSTALL_DIR/install_*.sh | grep -Po "install_\K(.*)\.sh$" | awk -F. '!/homeassistant/ {print $1}') + echo List of suites available for installation: + # inhibit the homeassistant suite from being displayed, to discourage its (re-)installation. + suites=$(ls $SUITE_INSTALL_DIR/install_*.sh | grep -Po "install_\K(.*)\.sh$" | awk -F. '!/homeassistant/ {print $1}') - for i in $suites - do - echo $i: $(show-suite-info $i) - done + for i in $suites + do + echo $i: $(show-suite-info $i) + done } function show-suite-long-info { - # Shows long info for the suite. - source $SUITE_INSTALL_DIR/install_$1.sh - $1-show-short-info - $1-show-long-info - $1-show-copyright-info + # Shows long info for the suite. + source $SUITE_INSTALL_DIR/install_$1.sh + $1-show-short-info + $1-show-long-info + $1-show-copyright-info } function install-suite { - # Having got here, the installer script exists; source it, then run the installer function. - source $SUITE_INSTALL_DIR/install_$1.sh - $1-install-package + # Having got here, the installer script exists; source it, then run the installer function. + source $SUITE_INSTALL_DIR/install_$1.sh + $1-install-package } function verify-suite { - # Check that the suite specified actually exists - if [ ! -f "$SUITE_INSTALL_DIR/install_$1.sh" ] - then - echo "Cannot find suite $1." - echo "Try running the show command to see all available suites" - exit - fi + # Check that the suite specified actually exists + if [ ! -f "$SUITE_INSTALL_DIR/install_$1.sh" ] + then + echo "Cannot find suite $1." + echo "Try running the show command to see all available suites" + exit + fi } if [ $# -lt 1 ] then - usage - exit + usage + exit fi COMMAND=$1 SUITE=$2 @@ -64,24 +65,24 @@ SUITE=$2 case $COMMAND in "show") - if [ "$SUITE" != "" ] - then - verify-suite $SUITE - show-suite-long-info $SUITE - else - show-suites - fi - ;; + if [ "$SUITE" != "" ] + then + verify-suite $SUITE + show-suite-long-info $SUITE + else + show-suites + fi + ;; "install") - verify-suite $SUITE - install-suite $SUITE - exit - ;; + verify-suite $SUITE + install-suite $SUITE + exit + ;; "info") - verify-suite $SUITE + verify-suite $SUITE info-suite $SUITE ;; *) - usage - ;; + usage + ;; esac From d16bbf83db5a3505b94b15a0975a7d1824731b1e Mon Sep 17 00:00:00 2001 From: David Jolley Date: Tue, 7 Feb 2017 08:58:23 +0000 Subject: [PATCH 7/9] Fixup tabs Correct /bin/sh stanza which precludes the "function" keyword Restore old functionality if installer is run standalone. --- install_homeassistant.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/install_homeassistant.sh b/install_homeassistant.sh index 0dcb07ec..c1882449 100755 --- a/install_homeassistant.sh +++ b/install_homeassistant.sh @@ -1,10 +1,10 @@ -#!/bin/sh +#!/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 libcec package for controlling CEC devices from this Pi" + echo "Installs the libcec package for controlling CEC devices from this Pi" } function homeassistant-show-copyright-info { @@ -66,4 +66,5 @@ echo "If you still have issues with this script, please contact @Landrash on git echo } -[[ $_ == $0 ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config install instead" +# Make this script function as it always has if run standalone, rather than issue a warning and do nothing. +[[ $_ == $0 ]] && homeassistant-install-package From 21dd16445f85acdf2c2347c9092782ab235e1a71 Mon Sep 17 00:00:00 2001 From: David Jolley Date: Tue, 7 Feb 2017 12:24:56 +0000 Subject: [PATCH 8/9] Change package long info text to reflect reality. --- install_homeassistant.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install_homeassistant.sh b/install_homeassistant.sh index c1882449..69c38dec 100755 --- a/install_homeassistant.sh +++ b/install_homeassistant.sh @@ -4,7 +4,7 @@ function homeassistant-show-short-info { } function homeassistant-show-long-info { - echo "Installs the libcec package for controlling CEC devices from this Pi" + echo "Installs the base homeassistant package onto this system." } function homeassistant-show-copyright-info { From 37a636eb197ebf99b75ee40501d60c586b1af538 Mon Sep 17 00:00:00 2001 From: David Jolley Date: Wed, 8 Feb 2017 09:29:19 +0000 Subject: [PATCH 9/9] Remove local testing variable. --- hassbian-config | 1 - 1 file changed, 1 deletion(-) diff --git a/hassbian-config b/hassbian-config index f87b5a2b..a23a2fb2 100755 --- a/hassbian-config +++ b/hassbian-config @@ -1,7 +1,6 @@ #!/bin/bash SUITE_INSTALL_DIR=/home/pi/hassbian-scripts -SUITE_INSTALL_DIR=/home/dave/Projects/hassbian/hassbian-scripts function usage { echo $0: usage: