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

Added log functionality and easy hastebin sharing. #78

Merged
merged 7 commits into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ where command is one of:
- `install`
- `upgrade`
- `show`
- `log`
- `share-log`

##### install
The install command takes one argument and will attempt to install the indicated suite of software.
Expand All @@ -29,6 +31,10 @@ Generally, this means that the invocation of `hassbian-config` should be run as
`sudo hassbian-config upgrade *suite*`
##### show
The show command can be run without arguments, and lists all available suites which can be installed or with a *suite* name as argument and shows information about the suite .
##### log
This command shows the log from the last `hassbian-config` operation.
##### share-log
This command creates an easy to share hastebin link of your last `hassbian-config` operation.

## Installer script components
All scripts listed below are helper scripts for the `hassbian-config` command, and shouldn't be run directly. The documentation has been kept for explanatory purposes only.
Expand Down
6 changes: 3 additions & 3 deletions package/etc/bash_completion.d/hassbian-config
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
_hassbian-config()
_hassbian-config()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="install upgrade show"
opts="install upgrade show log share-log"

case "${prev}" in
install)
Expand All @@ -21,7 +21,7 @@ _hassbian-config()
;;
esac

COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
}
complete -F _hassbian-config hassbian-config
33 changes: 27 additions & 6 deletions package/usr/local/bin/hassbian-config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

LOGFILE=/tmp/hassbian.log
SUITE_INSTALL_DIR=/opt/hassbian/suites
SUITE_INSTALL_DB=/srv/homeassistant/hassbian/suite-states
SUITE_INSTALL_DB_LOCK=/srv/homeassistant/hassbian/suite-states.lock
Expand All @@ -9,9 +9,11 @@ function usage {
echo
echo $0 \<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 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
}
Expand Down Expand Up @@ -122,6 +124,19 @@ function check-permission {
fi
}

function share-log {
echo "This will put the output from your last operation on hastebin."
echo "This could include sensitive informastion."
echo "If you are unsure about what it contains, you can rin 'hassbian-config log' to check."
read -p "Do you want to crate an hastebin link? [N/y] : " RESPONCE
if [ "$RESPONCE" == "y" ] || [ "$RESPONCE" == "Y" ]; then
echo ""
a=$(cat $LOGFILE); curl -X POST -s -d "$a" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}'
exit 1
fi
exit 1
}

function install-suite {
# Having got here, the installer script exists; source it, then run the installer function.
check-permission
Expand Down Expand Up @@ -228,7 +243,7 @@ case $COMMAND in
"install")
if verify-suite $SUITE
then
install-suite $SUITE
install-suite $SUITE | tee $LOGFILE
else
echo "suite $SUITE doesn't exist."
fi
Expand All @@ -245,7 +260,7 @@ case $COMMAND in
"upgrade")
if verify-suite $SUITE
then
upgrade-suite $SUITE
upgrade-suite $SUITE | tee $LOGFILE
else
echo "suite $SUITE doesn't exist."
fi
Expand All @@ -254,6 +269,12 @@ case $COMMAND in
"state")
get-suite-state-info $SUITE
;;
"log")
more $LOGFILE
;;
"share-log")
share-log
;;
*)
usage
;;
Expand Down