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

Implement unified interface to install scripts #11

Merged
merged 9 commits into from
Feb 8, 2017
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
88 changes: 88 additions & 0 deletions hassbian-config
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/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 \<command\> \<suite\>
echo where \<command\> is one of:
echo install - installs a software suite
echo show - shows software suites available
echo and \<suite\> 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
22 changes: 17 additions & 5 deletions install_homeassistant.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/bin/sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't need to be any change to this script since it's the one ran when we create the image. It's not run after the image is created so the tool shouldn't need to care about this script. Might move this script into the files folder but no change you need to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this too - it's a breaking change for first installation, which I'm not happy with. I'm sorta thinking that having it available isn't a bad idea, as it allows for reinstalls of homeassistant to happen from the hassbian-config script; otherwise users have to find out how to perform this one install themselves. I did inhibit it from being viewed as a "suite" though, because it shouldn't ordinarily be run...
With a little more effort, it may be possible to detect that install_homeassistant.sh is being run at first-run time, and make it work as it has previously. It's a case of changing the very last line of the script.
If you're interested, I could look into making this change; but I'm at work and so it won't be a speedily forthcoming one :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it's not as difficult as I first thought. I've just pushed a new change in so that the install_homeassistant.sh script when run standalone acts as if it were the old installer. Bonus: it still fits in the hassbian-config mechanism so it can be used from there too.
This also fixes the install_homeassistant.sh script's hashbang which somehow hadn't been edited to use bash, but /bin/sh - which precluded the whole lot working.

echo
echo "Home Assistant install script for Hassbian"
echo "Copyright(c) 2017 Fredrik Lindqvist <https://github.im/Landrash>"
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 <https://github.im/Landrash>"
}

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
Expand Down Expand Up @@ -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"
22 changes: 18 additions & 4 deletions install_libcec.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
#!/bin/bash

echo
echo "libcec install script for Hassbian"
echo "Copyright(c) 2017 Fredrik Lindqvist <https://github.im/Landrash>"
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 <https://github.im/Landrash>"
}

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
Expand Down Expand Up @@ -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"
24 changes: 19 additions & 5 deletions install_mosquitto.sh
Original file line number Diff line number Diff line change
@@ -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 <https://gitter.im/dale3h>"
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 <https://gitter.im/dale3h>"
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
Expand Down Expand Up @@ -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"
23 changes: 19 additions & 4 deletions install_openzwave.sh
Original file line number Diff line number Diff line change
@@ -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 <https://gitter.im/dale3h>"
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 <https://gitter.im/dale3h>"
echo

if [ "$(id -u)" != "0" ]; then
Expand Down Expand Up @@ -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"
23 changes: 19 additions & 4 deletions install_samba.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#!/bin/bash

echo
echo "Samba install script for Hassbian"
echo "Copyright(c) 2017 Fredrik Lindqvist <https://github.im/Landrash>"
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 <https://github.im/Landrash>"
}

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