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 5 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
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

Choose a reason for hiding this comment

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

The surrounding quotes actually unquote this. Remove or escape them.
Double quote to prevent globbing and word splitting.

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

Choose a reason for hiding this comment

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

The surrounding quotes actually unquote this. Remove or escape them.
Double quote to prevent globbing and word splitting.

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