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

hassbian-config: Usage cleanup, added new help and command options. #125

Merged
merged 7 commits into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/hassbian_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ where command is one of:
- `show` This will show you all available suites.
- `log` This will show you the log of last hassbian-config operation.
- `share-log` This will generate an hastebin link of the last hassbian-config operation.
- `-V` This will show you the installed version of `hassbian-config`.

Optional flags:
- `-y` This will accept defaults on scripts that allow this.
- `-f` This will force run an script. This is useful if you need to reinstall a package.
- `-y | --accept` This will accept defaults on scripts that allow this.
- `-f | --force` This will force run an script. This is useful if you need to reinstall a package.

Other available comands:
- `-V | --version` This will show you the installed version of `hassbian-config`.
- `-H | --help` Shows help for the tool, with all available commands.

## Installation
This package is pre-installed on the [Hassbian image](https://github.com/home-assistant/pi-gen/releases).
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/libcec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ 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
return 1
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y cmake libudev-dev libxrandr-dev swig
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/mariadb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function mariadb-install-package {
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
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y mariadb-server libmariadbclient-dev
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/mosquitto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ 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
return 1
fi

if [ "$ACCEPT" == "true" ]; then
mqtt_username=pi
mqtt_password=raspberry
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/mssql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function mssql-install-package {
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
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y freetds-dev
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function mysql-install-package {
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
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y default-libmysqlclient-dev libssl-dev
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/postgresql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function postgresql-install-package {
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
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y postgresql-server-dev-9.6 postgresql-9.6
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/samba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ 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
return 1
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y samba
Expand Down
5 changes: 0 additions & 5 deletions package/opt/hassbian/suites/tradfri.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ function tradfri-install-package {
tradfri-show-short-info
tradfri-show-copyright-info

if [ "$(id -u)" != "0" ]; then
echo "This script must be run with sudo. Use \"sudo ${0} ${*}\"" 1>&2
return 1
fi

echo "Running apt-get preparation"
apt-get update
apt-get install -y dh-autoreconf
Expand Down
54 changes: 40 additions & 14 deletions package/usr/local/bin/hassbian-config
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@ SUITE_INSTALL_DIR=/opt/hassbian/suites
SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control

function usage {
echo hassbian-config usage:
echo
echo hassbian-config \<command\> \<suite\>
echo where \<command\> 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 \<suite\> is the name of a software component to operate on.
echo
printf "usage: hassbian-config [command] [suite] [options]\\n"
printf "run 'hassbian-config --help' to see all options\\n"
return 0
}

function help {
printf "hassbian-config\\n"
printf "%s\\n" "version: $(hassbian-config -V)"
printf "\\n"
printf "usage: hassbian-config [command] [suite] [options]\\n"
printf "where [command] is one of:\\n"
printf "%-8s\\t%s\\n" " install" "Installs a software [suite]"
printf "%-8s\\t%s\\n" " upgrade" "Upgrades a software [suite]"
printf "%-8s\\t%s\\n" " show" "To see available [suite] for install/upgrade"
printf "%-8s\\t%s\\n" " log" "Displays an log of the last operation"
printf "%-8s\\t%s\\n" " share-log" "Generates an hastebin link of the last operation"
printf "\\n"
printf "available optional [options]:\\n"
printf "%-10s\\t%s\\n" " -y | --accept" "Accept defaults on scripts that allow this"
printf "%-10s\\t%s\\n" " -f | --force" "Force run an script, this is useful if you need to reinstall a package"
printf "\\n"
printf "other [command] available:\\n"
printf "%-10s\\t%s\\n" " -V | --version" "Prints the version of hassbian-config"
printf "%-10s\\t%s\\n" " -H | --help" "Shows this help"
printf "\\n"
return 0
}

Expand Down Expand Up @@ -83,6 +97,10 @@ function share-log {
}

function install-suite {
if [ "$(id -u)" != "0" ]; then
echo "This script must be run with sudo. Use 'sudo hassbian-config install $1'" 1>&2
return 1
fi
if [ ! -f $SUITE_CONTROL_DIR/"$1" ]; then
touch $SUITE_CONTROL_DIR/"$1"
echo "SCRIPTSTATE=uninstalled" > $SUITE_CONTROL_DIR/"$1"
Expand Down Expand Up @@ -112,6 +130,10 @@ function install-suite {
}

function upgrade-suite {
if [ "$(id -u)" != "0" ]; then
echo "This script must be run with sudo. Use 'sudo hassbian-config upgrade $1'" 1>&2
return 1
fi
UPGRADE=$(grep "$1"-upgrade-package $SUITE_INSTALL_DIR/"$1".sh)
if [ "$UPGRADE" == "" ]; then
echo "Upgrade script is not available..."
Expand Down Expand Up @@ -159,11 +181,11 @@ SUITE=$2


case $COMMAND in
"-f")
"-f"|"--force")
FORCE="true"
shift # past argument
;;
"-y")
"-y"|"--accept")
ACCEPT="true"
shift # past argument
;;
Expand Down Expand Up @@ -206,7 +228,7 @@ case $COMMAND in
RUN="share-log"
shift # past argument
;;
"-V")
"-V"|"--version")
VERSION=$(dpkg -s hassbian-scripts | grep 'Version:' | awk '{print $2}')
RUN="echo $VERSION"
shift # past argument
Expand All @@ -215,6 +237,10 @@ case $COMMAND in
RUN="show-installed-suites"
shift # past argument
;;
"-H"|"--help")
RUN="help"
shift # past argument
;;
*)
RUN="usage"
shift # past argument
Expand Down