This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: It's all the same (mostly), just completely different. (#268)
* Idea * manifest update * Valid json * Progress * Idea * manifest update * Valid json * Progress * More progress. * Adds whiptail input * More progress * More progress * more progress * Move * Adds skelleton files * remove template * Cleanup * migrate pihole * uuuups * fix typo * Fix order * Fix log * Fix definitions * remove unused code * fix paths * changed too much * Removed unused check * Style changes * Style update * Add missing source link * typo * More styling. * Styling * Move show * more styling * fix this * Move files * migrate more suites * password -> text * update to show output * More progress * Fail2Ban * Hassbian * more progress * More progress * Done... Mostly... * missed one thing * fix verifications * simplify actions * cleanup * More cleanup * Add post action to new function * Cleanup * rewording * Suite cleanup * Missplaced fi * typos * Fix python version * Use correct pyversion * Initial updates for testing * Add test functions to cli * more testing stuff * Skip log.share * More testing * testing * more for tests * more test updates * Fix tests? * more testing * include error * test update * finish up testing * Add defaults * remove show template * Implement CI suite test * Adds unattended to Template * json lint * Fix flags * Add defaults for error handling * Typo * fix cli * Fix CI logs * cleanup CI logs * Fix for multiple packages * Buypass cahche issue * Adds workaround handling * load wokarounds * Add check to see if suite is installed. * Add force esception * Skip typeerror checks * Fix issue with workaround * Add logfine declaration to workaround
- Loading branch information
Showing
119 changed files
with
3,063 additions
and
2,494 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!bin/bash | ||
# Helper script for hassbian-config. | ||
# The purpose of this is to provide support for commandline arguments. | ||
|
||
# shellcheck disable=SC2034 | ||
|
||
declare argument | ||
declare suites | ||
declare suiteaction | ||
declare runfunction | ||
|
||
# Show usage if no arguments are given. | ||
if [ $# -lt 1 ]; then | ||
hassbian.info.general.usage | ||
exit 0 | ||
fi | ||
|
||
for argument in "$@"; do | ||
## Flags | ||
if [ "$argument" == "--accept" ] || [ "$argument" == "-Y" ]; then | ||
HASSBIAN_RUNTIME_ACCEPT=true | ||
|
||
elif [ "$argument" == "--force" ] || [ "$argument" == "-F" ]; then | ||
HASSBIAN_RUNTIME_FORCE=true | ||
|
||
elif [ "$argument" == "--debug" ] || [ "$argument" == "-D" ]; then | ||
HASSBIAN_RUNTIME_DEBUG=true | ||
|
||
elif [ "$argument" == "--beta" ] || [ "$argument" == "-B" ]; then | ||
HASSBIAN_RUNTIME_BETA=true | ||
|
||
elif [ "$argument" == "--dev" ]; then | ||
HASSBIAN_RUNTIME_DEV=true | ||
|
||
elif [ "$argument" == "--ci" ]; then | ||
HASSBIAN_RUNTIME_CI=true | ||
|
||
# Actions | ||
elif [ "$argument" == "install" ]; then | ||
suiteaction="$argument" | ||
|
||
elif [ "$argument" == "upgrade" ]; then | ||
suiteaction="$argument" | ||
|
||
elif [ "$argument" == "remove" ]; then | ||
suiteaction="$argument" | ||
|
||
elif [ "$argument" == "show" ]; then | ||
suiteaction="$argument" | ||
|
||
elif [ "$argument" == "developer-test-pr" ]; then | ||
runfunction="hassbian.developer.test.pr $2" | ||
|
||
elif [ "$argument" == "developer-test-package" ]; then | ||
runfunction="hassbian.developer.test.package" | ||
|
||
elif [ "$argument" == "log" ]; then | ||
runfunction="hassbian.log.show" | ||
|
||
elif [ "$argument" == "share-log" ]; then | ||
runfunction="hassbian.log.share" | ||
|
||
elif [ "$argument" == "show-installed" ]; then | ||
runfunction="hassbian.info.general.isntalled_suites" | ||
|
||
elif [ "$argument" == "systeminfo" ]; then | ||
runfunction="hassbian.info.general.systeminfo" | ||
|
||
## Spesial arguments. | ||
elif [ "$argument" == "--help" ] || [ "$argument" == "-H" ]; then | ||
runfunction="hassbian.info.general.help" | ||
|
||
elif [ "$argument" == "--version" ] || [ "$argument" == "-V" ]; then | ||
printf "%s\\n" "$(hassbian.info.version.hassbian_config.installed)" | ||
exit 0 | ||
|
||
# If we got here we can assume that the argument is a suite. | ||
else | ||
suites+=" $argument" | ||
fi | ||
done | ||
|
||
if [ -n "$runfunction" ]; then | ||
$runfunction | ||
exit 0 | ||
fi | ||
|
||
if [ -n "$suites" ]; then | ||
|
||
for suite in $suites; do | ||
hassbian.suite.action "$suiteaction" "$suite" | ||
done | ||
|
||
else | ||
hassbian.info.general.usage | ||
fi | ||
exit 0 | ||
[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
#!bin/bash | ||
# Helper script for hassbian-config. | ||
|
||
function hassbian.developer.test.pr { | ||
# This function fetches a active PR and build a installation package from that and install it on the system. | ||
# This should only be used by maintainers to test PR's! | ||
local INSTALLDIR | ||
local PRNUMBER | ||
|
||
# Root check | ||
hassbian.info.general.rootcheck | ||
|
||
PRNUMBER="$1" | ||
INSTALLDIR="/tmp/hassbian_config_install_${PRNUMBER}" | ||
|
||
if [[ -z "$PRNUMBER" ]]; then | ||
echo "Error: Missing PR argument. | ||
Run: hassbian-config developer-test-pr PRNUMBER" | ||
exit | ||
fi | ||
|
||
git clone https://github.com/home-assistant/hassbian-scripts.git "$INSTALLDIR" | ||
|
||
cd "$INSTALLDIR" || return 1 | ||
|
||
git fetch origin +refs/pull/"$PRNUMBER"/merge || return 1 | ||
git checkout FETCH_HEAD | ||
|
||
chmod 755 -R package | ||
dpkg-deb --build package/ | ||
|
||
apt install -y "$INSTALLDIR"/package.deb --reinstall --allow-downgrades | ||
|
||
cd || return 1 | ||
|
||
rm -R "$INSTALLDIR" | ||
} | ||
|
||
function hassbian.developer.test.package { | ||
# Run a test on all functions. | ||
# This should only be used by maintainers! | ||
local -i pass=0 | ||
local -i fail=0 | ||
local function | ||
local -a operations | ||
local -a failedtests | ||
local returncode | ||
local testsuite=template | ||
local test | ||
local unattended | ||
|
||
echo " | ||
------------------------------------------ | ||
TESTING HASSBIAN-CONFIG FUNCTIONS | ||
------------------------------------------ | ||
" | ||
|
||
for function in $(declare -F | grep "hassbian\\."); do | ||
if [[ "$function" = *"."* ]]; then | ||
printf "\\e[36mTesting '%s'..............." "$function" | ||
|
||
# Exclude functions from test: | ||
if [ "$function" == "hassbian.developer.test.package" ] || \ | ||
[ "$function" == "hassbian.developer.test.pr" ] || \ | ||
[ "$function" == "hassbian.input.bool" ] || \ | ||
[ "$function" == "hassbian.input.info" ] || \ | ||
[ "$function" == "hassbian.input.text" ] || \ | ||
[ "$function" == "hassbian.log.share" ] || \ | ||
[ "$function" == "hassbian.suite.action.execute" ] || \ | ||
[ "$function" == "hassbian.suite.action" ] || \ | ||
[ "$function" == "hassbian.suite.helper.exist" ] || \ | ||
[ "$function" == "hassbian.suite.helper.install.node" ] || \ | ||
[ "$function" == "hassbian.suite.info.installed" ] || \ | ||
[ "$function" == "hassbian.workaround.pip.typeerror" ]; then | ||
printf "\\e[33mSKIP\\n" | ||
|
||
# Run tests: | ||
else | ||
"$function" >> /dev/null 2>&1 | ||
returncode="$?" | ||
if [ "$returncode" == "0" ];then | ||
((pass+=1)) | ||
printf "\\e[32mPASS\\n" | ||
else | ||
((fail+=1)) | ||
failedtests+=("$function") | ||
printf "\\e[31mFAIL\\n" | ||
fi | ||
fi | ||
fi | ||
done | ||
printf "\\e[0m\\n" | ||
|
||
echo " | ||
------------------------------------------ | ||
TESTING HASSBIAN-CONFIG SUITE OPERATIONS | ||
------------------------------------------ | ||
" | ||
operations=('install' 'upgrade' 'remove') | ||
for cmd in "${operations[@]}"; do | ||
printf "\\e[36mTesting 'hassbian-config %s %s'............." "$cmd" "$testsuite" | ||
test=$(hassbian-config "$cmd" "$testsuite" | grep "Operation failed...") | ||
if [ -z "${test}" ];then | ||
((pass+=1)) | ||
printf "\\e[32mPASS\\n" | ||
else | ||
((fail+=1)) | ||
failedtests+=("hassbian-config $cmd $testsuite") | ||
printf "\\e[31mFAIL\\n" | ||
fi | ||
done | ||
printf "\\e[0m\\n" | ||
|
||
echo " | ||
------------------------------------------ | ||
TESTING HASSBIAN-CONFIG CLI OPERATIONS | ||
------------------------------------------ | ||
" | ||
operations=() | ||
operations+=('--version' '-V') | ||
operations+=('--help' '-H') | ||
operations+=('show-installed') | ||
operations+=('systeminfo') | ||
operations+=('log') | ||
|
||
for operation in "${operations[@]}"; do | ||
printf "\\e[36mTesting 'hassbian-config %s'.................." "$operation" | ||
hassbian-config "$operation" >> /dev/null 2>&1 | ||
returncode="$?" | ||
if [ "$returncode" == "0" ];then | ||
((pass+=1)) | ||
printf "\\e[32mPASS\\n" | ||
else | ||
((fail+=1)) | ||
failedtests+=("hassbian-config $operation") | ||
printf "\\e[31mFAIL\\n" | ||
fi | ||
done | ||
printf "\\e[0m\\n" | ||
|
||
if [ "$HASSBIAN_RUNTIME_CI" == "true" ];then | ||
# Only try this if running in a CI env. | ||
echo " | ||
------------------------------------------ | ||
TESTING HASSBIAN-CONFIG SUITES | ||
------------------------------------------ | ||
" | ||
for suite in $(hassbian.info.general.all_suites); do | ||
printf "\\e[36mTesting Suite: '%s'.................." "$suite" | ||
unattended=$(hassbian.suite.helper.manifest "$suite" unattended) | ||
if [ "$unattended" == "true" ];then | ||
# Install test... | ||
test=$(hassbian-config install "$suite" --accept | grep "Operation failed...") | ||
if [ -z "${test}" ];then | ||
((pass+=1)) | ||
printf "\\e[32mPASS(install)\\e[36m..." | ||
else | ||
((fail+=1)) | ||
failedtests+=("hassbian-config install $suite --accept") | ||
printf "\\e[31mFAIL(install)\\e[36m..." | ||
fi | ||
|
||
# Upgrade test... | ||
test=$(hassbian-config upgrade "$suite" --accept | grep "Operation failed...") | ||
if [ -z "${test}" ];then | ||
((pass+=1)) | ||
printf "\\e[32mPASS(upgrade)\\e[36m..." | ||
else | ||
((fail+=1)) | ||
failedtests+=("hassbian-config upgrade $suite --accept") | ||
printf "\\e[31mFAIL(upgrade)\\e[36m..." | ||
fi | ||
|
||
# Remove test... | ||
test=$(hassbian-config remove "$suite" --accept | grep "Operation failed...") | ||
if [ -z "${test}" ];then | ||
((pass+=1)) | ||
printf "\\e[32mPASS(remove)\\e[36m" | ||
else | ||
((fail+=1)) | ||
failedtests+=("hassbian-config remove $suite --accept") | ||
printf "\\e[31mFAIL(remove)\\e[36m" | ||
fi | ||
else | ||
printf "\\e[33mSKIP" | ||
fi | ||
printf "\\n" | ||
done | ||
printf "\\e[0m\\n" | ||
fi | ||
|
||
|
||
|
||
# Testing is done. | ||
echo " | ||
Total passed:......$pass | ||
Total failed:......$fail | ||
" | ||
|
||
# Exit the test | ||
if [ "$fail" == "0" ];then | ||
exit 0 | ||
else | ||
printf "\\e[31mFailed tests:\\n" | ||
for test in "${failedtests[@]}"; do | ||
printf "\\e[31m %s\\n" "$test" | ||
done | ||
printf "\\e[0m\\n" | ||
exit 1 | ||
fi | ||
} | ||
[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" |
Oops, something went wrong.