From fafb47fed45dddad4cc0955c9a652f3e3b730bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 15:52:01 +0100 Subject: [PATCH 1/7] rewrite usage function --- package/usr/local/bin/hassbian-config | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index e38a11b7..b67c3478 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -4,17 +4,22 @@ SUITE_INSTALL_DIR=/opt/hassbian/suites SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control function usage { - echo hassbian-config usage: - echo - echo hassbian-config \ \ - echo where \ 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 \ is the name of a software component to operate on. - echo + printf "hassbian-config\\n" + printf "Version: $(hassbian-config -V)\\n" + 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 isntall/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 "%-8s\\t%s\\n" " -V" "Prints the version of hassbian-config" + printf "\\n" + printf "available [options]:\\n" + printf "%-5s\\t%s\\n" " -y" "accept all inputs/defaults" + printf "%-5s\\t%s\\n" " -f" "force" + printf "\\n" return 0 } From 06c338667310e36022d2c17306f0a11be8835e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 15:57:01 +0100 Subject: [PATCH 2/7] Stickler fix --- package/usr/local/bin/hassbian-config | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index b67c3478..a55f84dc 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -5,7 +5,7 @@ SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control function usage { printf "hassbian-config\\n" - printf "Version: $(hassbian-config -V)\\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" @@ -16,9 +16,9 @@ function usage { printf "%-8s\\t%s\\n" " share-log" "Generates an hastebin link of the last operation" printf "%-8s\\t%s\\n" " -V" "Prints the version of hassbian-config" printf "\\n" - printf "available [options]:\\n" - printf "%-5s\\t%s\\n" " -y" "accept all inputs/defaults" - printf "%-5s\\t%s\\n" " -f" "force" + printf "available optional [options]:\\n" + printf "%-5s\\t%s\\n" " -y" "accept defaults on scripts that allow this" + printf "%-5s\\t%s\\n" " -f" "force run an script, this is useful if you need to reinstall a package" printf "\\n" return 0 } From 6b66f11494960860625320c15f661f4c21bb4aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 16:22:08 +0100 Subject: [PATCH 3/7] added stuff --- package/usr/local/bin/hassbian-config | 34 +++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index a55f84dc..95c3716e 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -4,6 +4,11 @@ SUITE_INSTALL_DIR=/opt/hassbian/suites SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control function usage { + printf "usage: hassbian-config [command] [suite] [options]\\n" + return 0 +} + +function help { printf "hassbian-config\\n" printf "%s\\n" "version: $(hassbian-config -V)" printf "\\n" @@ -11,14 +16,17 @@ function usage { 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 isntall/upgrade" + 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 "%-8s\\t%s\\n" " -V" "Prints the version of hassbian-config" printf "\\n" printf "available optional [options]:\\n" - printf "%-5s\\t%s\\n" " -y" "accept defaults on scripts that allow this" - printf "%-5s\\t%s\\n" " -f" "force run an script, this is useful if you need to reinstall a package" + 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 } @@ -88,6 +96,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" @@ -117,6 +129,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..." @@ -164,11 +180,11 @@ SUITE=$2 case $COMMAND in - "-f") + "-f"|"--force") FORCE="true" shift # past argument ;; - "-y") + "-y"|"--accept") ACCEPT="true" shift # past argument ;; @@ -211,7 +227,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 @@ -220,6 +236,10 @@ case $COMMAND in RUN="show-installed-suites" shift # past argument ;; + "-H"|"--help") + RUN="help" + shift # past argument + ;; *) RUN="usage" shift # past argument From af1e7b61342d2ee6f679f870be001fc2fea22dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 16:25:13 +0100 Subject: [PATCH 4/7] added --help to usage --- package/usr/local/bin/hassbian-config | 1 + 1 file changed, 1 insertion(+) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index 95c3716e..ec081bb3 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -5,6 +5,7 @@ SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control function usage { printf "usage: hassbian-config [command] [suite] [options]\\n" + printf "run 'hassbian-config --help' to see all options\\n" return 0 } From 730f1a71bac37ad132c3d686d29421d8b26b779f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 16:31:52 +0100 Subject: [PATCH 5/7] added documentation --- docs/hassbian_config.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/hassbian_config.md b/docs/hassbian_config.md index 7144ba95..cb54bdbd 100644 --- a/docs/hassbian_config.md +++ b/docs/hassbian_config.md @@ -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). From c65e44330668056e5d586401589702ec9656f045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 16:36:34 +0100 Subject: [PATCH 6/7] Stickler fix, and removed sudo check in scripts --- package/opt/hassbian/suites/libcec.sh | 5 ----- package/opt/hassbian/suites/mariadb.sh | 5 ----- package/opt/hassbian/suites/mosquitto.sh | 5 ----- package/opt/hassbian/suites/mssql.sh | 5 ----- package/opt/hassbian/suites/mysql.sh | 5 ----- package/opt/hassbian/suites/postgresql.sh | 5 ----- package/opt/hassbian/suites/samba.sh | 5 ----- package/opt/hassbian/suites/tradfri.sh | 5 ----- package/usr/local/bin/hassbian-config | 4 ++-- 9 files changed, 2 insertions(+), 42 deletions(-) diff --git a/package/opt/hassbian/suites/libcec.sh b/package/opt/hassbian/suites/libcec.sh index 5fa2e308..00f20214 100644 --- a/package/opt/hassbian/suites/libcec.sh +++ b/package/opt/hassbian/suites/libcec.sh @@ -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 diff --git a/package/opt/hassbian/suites/mariadb.sh b/package/opt/hassbian/suites/mariadb.sh index 7612efdb..499851b8 100644 --- a/package/opt/hassbian/suites/mariadb.sh +++ b/package/opt/hassbian/suites/mariadb.sh @@ -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 diff --git a/package/opt/hassbian/suites/mosquitto.sh b/package/opt/hassbian/suites/mosquitto.sh index 31ced68c..98c85086 100644 --- a/package/opt/hassbian/suites/mosquitto.sh +++ b/package/opt/hassbian/suites/mosquitto.sh @@ -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 diff --git a/package/opt/hassbian/suites/mssql.sh b/package/opt/hassbian/suites/mssql.sh index d73a4429..632be0ef 100644 --- a/package/opt/hassbian/suites/mssql.sh +++ b/package/opt/hassbian/suites/mssql.sh @@ -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 diff --git a/package/opt/hassbian/suites/mysql.sh b/package/opt/hassbian/suites/mysql.sh index 0c6d7300..ecdd4eec 100644 --- a/package/opt/hassbian/suites/mysql.sh +++ b/package/opt/hassbian/suites/mysql.sh @@ -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 diff --git a/package/opt/hassbian/suites/postgresql.sh b/package/opt/hassbian/suites/postgresql.sh index 76db0748..688a3aef 100644 --- a/package/opt/hassbian/suites/postgresql.sh +++ b/package/opt/hassbian/suites/postgresql.sh @@ -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 diff --git a/package/opt/hassbian/suites/samba.sh b/package/opt/hassbian/suites/samba.sh index a180773f..da5f4970 100644 --- a/package/opt/hassbian/suites/samba.sh +++ b/package/opt/hassbian/suites/samba.sh @@ -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 diff --git a/package/opt/hassbian/suites/tradfri.sh b/package/opt/hassbian/suites/tradfri.sh index b58cfa06..3a5a6716 100644 --- a/package/opt/hassbian/suites/tradfri.sh +++ b/package/opt/hassbian/suites/tradfri.sh @@ -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 diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index ec081bb3..a60525a6 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -98,7 +98,7 @@ 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 + 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 @@ -131,7 +131,7 @@ 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 + 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) From fdab307c021178e4442fff3e6d35ea934904d428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Sat, 24 Feb 2018 16:38:45 +0100 Subject: [PATCH 7/7] stickler fix --- package/usr/local/bin/hassbian-config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index a60525a6..363a48c8 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -98,7 +98,7 @@ 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 + 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 @@ -131,7 +131,7 @@ 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 + 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)