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. diff --git a/hassbian-config b/hassbian-config new file mode 100755 index 00000000..a23a2fb2 --- /dev/null +++ b/hassbian-config @@ -0,0 +1,87 @@ +#!/bin/bash + +SUITE_INSTALL_DIR=/home/pi/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: + # 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 +} + +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 diff --git a/install_homeassistant.sh b/install_homeassistant.sh index 65492081..69c38dec 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 +#!/bin/bash +function homeassistant-show-short-info { + echo "Home Assistant install script for Hassbian" +} + +function homeassistant-show-long-info { + echo "Installs the base homeassistant package onto this system." +} + +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,7 @@ 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 +} - +# Make this script function as it always has if run standalone, rather than issue a warning and do nothing. +[[ $_ == $0 ]] && homeassistant-install-package diff --git a/install_libcec.sh b/install_libcec.sh index 2a559d12..b2437b64 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,6 @@ 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 +} + +[[ $_ == $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 a11e89ec..b8cccf80 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,6 @@ echo 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 da9daaf5..24b7f061 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,6 @@ echo 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 f8d63312..487d8970 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"