diff --git a/package/DEBIAN/control b/package/DEBIAN/control index efcfc116..9d9bb8b6 100644 --- a/package/DEBIAN/control +++ b/package/DEBIAN/control @@ -2,7 +2,7 @@ Package: hassbian-scripts Version: 0.12.0 Priority: optional Architecture: all -Depends: bash, wget, git, python3, python3-venv, python3-pip, python3-dev, bluetooth, libbluetooth-dev, avahi-daemon, build-essential, libssl-dev, libffi-dev, python-dev,libudev-dev, zip, apt-transport-https, bluez-hcidump, bc, figlet +Depends: bash, wget, git, python3, python3-venv, python3-pip, python3-dev, bluetooth, libbluetooth-dev, avahi-daemon, build-essential, libssl-dev, libffi-dev, python-dev,libudev-dev, zip, apt-transport-https, bluez-hcidump, bc, figlet, jq Maintainer: Fredrik Lindqvist Homepage: www.home-assistant.io Description: Hassbian scripts diff --git a/package/etc/bash_completion.d/hassbian-config b/package/etc/bash_completion.d/hassbian-config index 1a5d4078..b3e61287 100644 --- a/package/etc/bash_completion.d/hassbian-config +++ b/package/etc/bash_completion.d/hassbian-config @@ -4,9 +4,9 @@ _hassbian-config() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="developer-test-pr install upgrade remove show log share-log --version --help systeminfo" + opts="developer-test-pr developer-test-package install upgrade remove show log share-log --version --help systeminfo" altopts="--accept --force --debug --version --help --dev --beta" - inst=$(find /opt/hassbian/suites/ -maxdepth 1 -type f | awk -F'/|_' ' {print $NF}' | awk -F. '{print $1}') + inst=$(find /opt/hassbian/suites/ -maxdepth 1 -type d | awk -F'/|_' ' {print $NF}' | awk -F. '{print $1}') if [[ ${cur} == -* ]] ; then COMPREPLY=( $(compgen -W "${altopts}" -- ${cur}) ) diff --git a/package/opt/hassbian/helpers/cli b/package/opt/hassbian/helpers/cli new file mode 100644 index 00000000..272c7c8b --- /dev/null +++ b/package/opt/hassbian/helpers/cli @@ -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" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/developer b/package/opt/hassbian/helpers/developer new file mode 100644 index 00000000..22e4866c --- /dev/null +++ b/package/opt/hassbian/helpers/developer @@ -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" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/info/general b/package/opt/hassbian/helpers/info/general new file mode 100644 index 00000000..1457a218 --- /dev/null +++ b/package/opt/hassbian/helpers/info/general @@ -0,0 +1,123 @@ +#!bin/bash +# Helper script for hassbian-config. + +function hassbian.info.general.rootcheck { + # Check if the current user is root. + if (( EUID != 0 )); then + echo "Error: hassbian-config must be run as root (with sudo) for this to be possible." + return 1 + fi +} + +function hassbian.info.general.usage { + # Show usage in the console. + echo " + usage: hassbian-config [command] [suite] [options] + run 'hassbian-config --help' to see all options" +} + +function hassbian.info.general.ipaddress { + # Retrun the IP Address of the host. + local ipaddress + ipaddress=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') + printf "%s" "$ipaddress" +} + +function hassbian.info.general.help { + # Show this help section in the console. + local hassbian_config_version + hassbian_config_version=$(hassbian.info.version.hassbian_config.installed) + echo " + hassbian-config + version: $hassbian_config_version + + usage: + hassbian-config [command] [suite] [options] + where [command] is one of: + install Installs a software [suite]. + upgrade Upgrades software [suite]. + remove Remove software [suite]. + show To see available [suite] for install/upgrade. + log Displays an log of the last operation. + share-log Generates an hastebin link of the last operation. + show-installed Generates a list of installed suites. + + available optional [options]: + -Y | --accept Accept defaults on scripts that allows this. + -F | --force Force run an script, this is useful if you need to reinstall a package. + -D | --debug This will output every comand to the console. + -B | --beta This will install the current beta version if implemented. + --dev This will install the current development version if implemented. + + other [command] available: + -V | --version Prints the version of hassbian-config + -H | --help Shows this help + " +} + +function hassbian.info.general.systeminfo { + # Prints system information to the console. + # Usefull to call before scripts and as a standalone. + local haversion + local hapyversion + local hcversion + local hcversionremote + + # Root check. + hassbian.info.general.rootcheck + + echo "Generating system information..." + haversion=$(hassbian.info.version.homeassistant.installed) + hapyversion=$(hassbian.info.version.homeassistant.python) + hcversion=$(hassbian.info.version.hassbian_config.installed) + hcversionremote=$(hassbian.info.version.hassbian_config.remote) + + echo " + Home Assistant: $haversion + Home Assistant Python: $hapyversion + hassbian-config: $hcversion + + $(uname -a) + " + + if [ "$hcversion" != "$hcversionremote" ]; then + printf "\\e[31m%s\\n" " + There is an update pending for 'hassbian-config' + You can upgrade by running this: + sudo hassbian-config upgrade hassbian-script + " + fi +} + +function hassbian.info.general.all_suites { + # Return a list of all suites. + local allsuites + allsuites=$(find "$HASSBIAN_SUITE_DIR"/ -maxdepth 1 -type d | \ + sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') + echo "$allsuites" +} + +function hassbian.info.general.isntalled_suites { + # Return a list of all installed suites. + local allsuites + local installed + + allsuites=$(hassbian.info.general.all_suites) + echo "These suites are installed:" + for suite in $allsuites; do + installed=$(hassbian.suite.info.installed "$suite") + if [ "$installed" ]; then + echo "$suite" + fi + done +} + +function hassbian.info.general.python.location { + # Return the full path of the newest python version. + local location + location=$(command -v "python$(hassbian.info.version.python)") + + printf "%s" "$location" +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/info/version b/package/opt/hassbian/helpers/info/version new file mode 100644 index 00000000..734b98df --- /dev/null +++ b/package/opt/hassbian/helpers/info/version @@ -0,0 +1,93 @@ +#!bin/bash +# Helper script for hassbian-config. + + +function hassbian.info.version.hassbian_config.installed { + # Return the installed version of hassbian-config. + local version + version=$(dpkg -s hassbian-scripts | grep 'Version:' | awk '{print $2}') + printf "%s" "$version" +} + +function hassbian.info.version.hassbian_config.remote { + # Return the remote version of hassbian-config. + local version + version=$(curl -sSL https://raw.githubusercontent.com/home-assistant/hassbian-scripts/dev/package/DEBIAN/control | \ + grep Version | awk -F' ' '{print $NF}') + printf "%s" "$version" +} + +function hassbian.info.version.homeassistant.installed { + # Return the installed version of homeassistant. + local version + + if [ -f "/srv/homeassistant/bin/activate" ]; then + version=$(sudo -u homeassistant -H /bin/bash << EOF | \ + awk -F ' ' '{print $NF}' + source /srv/homeassistant/bin/activate + hass --version +EOF + ) + printf "%s" "$version" + fi +} + +function hassbian.info.version.homeassistant.github { + # Return the latest version of homeassistant from github. + local version + + version=$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases | \ + grep tag_name | head -1 | awk -F'"' '{print $4}') + + printf "%s" "$version" +} + +function hassbian.info.version.homeassistant.pypi { + # Return the latest version of homeassistant from pypi. + local version + + version=$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases/latest | \ + grep tag_name | awk -F'"' '{print $4}') + + printf "%s" "$version" +} + +function hassbian.info.version.homeassistant.python { + # Return the version of python that homeassistant uses. + local version + + if [ -f "/srv/homeassistant/bin/activate" ]; then + version=$(sudo -u homeassistant -H /bin/bash << EOF | \ + awk -F ' ' '{print $NF}' + source /srv/homeassistant/bin/activate + python -V +EOF + ) + printf "%s" "${version:0:5}" + fi +} + +function hassbian.info.version.python { + # Get the MAJOR.MINOR version of the newest installed python version. + local potentialversions + local isntalledversion + + potentialversions="3.5 3.6 3.7" + + for version in $potentialversions; do + if [[ -n "$(command -v python"$version")" ]]; then + isntalledversion="$version" + fi + done + printf "%s" "${version}" +} + +function hassbian.info.version.osreleasename { + # Get name of the OS release. + local name + + name=$(lsb_release -cs) + printf "%s" "${name}" +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/input b/package/opt/hassbian/helpers/input new file mode 100644 index 00000000..f6e1a6af --- /dev/null +++ b/package/opt/hassbian/helpers/input @@ -0,0 +1,36 @@ +#!bin/bash +# Helper script for hassbian-config. + +declare message + +function hassbian.input.bool { + # Present a pretty GUI for your question. + # Usage example: + # hassbian.input.bool "Do you want to generate SSL certificates?" + + message="$1" + + whiptail --title "hassbian-config" --yesno "$message" 0 0 3>&1 1>&2 2>&3 + printf "%s" "$?" +} + +function hassbian.input.info { + # Present a pretty GUI for your info. + # Usage example: + # hassbian.input.info "Please take the time to setup your account" + + message="$1" + + whiptail --title "hassbian-config" --msgbox "$message" 0 0 3>&1 1>&2 2>&3 +} + +function hassbian.input.text { + # Present a pretty GUI for your question. + # Usage example: + # hassbian.input.text "Define a username:" + + message="$1" + whiptail --title "hassbian-config" --inputbox "$message" 0 0 3>&1 1>&2 2>&3 + printf "%s" "$?" +} +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" diff --git a/package/opt/hassbian/helpers/log b/package/opt/hassbian/helpers/log new file mode 100644 index 00000000..84135f9a --- /dev/null +++ b/package/opt/hassbian/helpers/log @@ -0,0 +1,47 @@ +#!bin/bash +# Helper script for hassbian-config. + +function hassbian.log.show { + # Show the logfile in the console. + more "$HASSBIAN_LOG_FILE" +} + + +function hassbian.log.share { + # Upload the logfile to hastebin. + local loglink + local response + + if [ ! -f "$HASSBIAN_LOG_FILE" ];then + echo "No logfile exists, exiting..." + fi + + if [ "$HASSBIAN_RUNTIME_ACCEPT" = false ]; then + local message=" + This will put the output from your last operation on hastebin. + This could include sensitive information. + If you are unsure about what it contains, you can run 'hassbian-config log' to check. + + Do you want to create an hastebin link?: " + + response=$(hassbian.input.bool "$message") + + if [ "$response" == "1" ]; then + return + fi + fi + echo "Publishing logfile to hastebin..." + loglink=$(curl -X POST -s -d "$(cat "$HASSBIAN_LOG_FILE")" \ + https://hastebin.com/documents | \ + awk -F '"' '{print "https://hastebin.com/"$4}') + + if [[ $loglink != *"initial"* ]]; then + echo "$loglink" + else + echo " + There is an issue with your network connection, or with the Hastebin API. + Try again later." + fi +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/suite/action b/package/opt/hassbian/helpers/suite/action new file mode 100644 index 00000000..b4453f26 --- /dev/null +++ b/package/opt/hassbian/helpers/suite/action @@ -0,0 +1,107 @@ +#!bin/bash +# Helper script for hassbian-config. + +# shellcheck disable=SC1090,SC2034 + +declare suitename +declare suitestate +declare suiteaction +declare -i returnvalue + +function hassbian.suite.action { + suiteaction="$1" + suitename="$2" + + # Split suitename if needed. + if [[ "$suitename" = *"="* ]]; then + suitename=$(echo "$suitename" | awk -F'=' '{print $1}') + HASSBIAN_RUNTIME_TARGET_VERSION=$(echo "$suitename" | awk -F'=' '{print $2}') + fi + + # Root check. + hassbian.info.general.rootcheck + + # Verify that the suite exist. + hassbian.suite.helper.exist "$suitename" + + # Show info + if [ "$suiteaction" == "show" ]; then + hassbian.suite.info.print "$suitename" + exit + fi + + # Do checks to see if the suite can be run. + hassbian.suite.helper.blockcheck "$suitename" + hassbian.suite.helper.pizerocheck "$suitename" + + # Run the suite action. + if [[ "$suiteaction" =~ ^(install|upgrade|remove)$ ]]; then + # Generate systeminfo + hassbian.info.general.systeminfo + + # Echo metadata + hassbian.suite.info.print "$suitename" + + # check if suiteaction is 'installed' and that the suite is not allready installed. + if [ "$suiteaction" == "install" ]; then + installed=$(hassbian.suite.info.installed "$suitename") + if [ "$installed" == "true" ] && [ "$HASSBIAN_RUNTIME_FORCE" = false ]; then + echo "Suite $suitename, is allready installed." + echo "You can force a reinstallation by running:" + echo "sudo hassbian-config install $suitename --force" + + # Check if upgrade is available. + if [ -f "$HASSBIAN_SUITE_DIR/$suitename/upgrade" ]; then + printf "\\n\\n" + echo "Or run the upgrdade script by running:" + echo "sudo hassbian-config upgrade $suitename" + fi + return 0 + fi + fi + + # Run the suite action. + hassbian.suite.action.execute "$suiteaction" "$suitename" 2>&1 | tee "$HASSBIAN_LOG_FILE" + else + echo "$suiteaction is not a valid suite action." + return 1 + fi +} + +function hassbian.suite.action.execute { + # We need this extra function to keep logging and be able to use the return value. + suiteaction="$1" + suitename="$2" + returnvalue=0 + + # Activate debug + if [ "$HASSBIAN_RUNTIME_DEBUG" = true ]; then set -x; fi + + if [ -f "$HASSBIAN_SUITE_DIR/$suitename/$suiteaction" ]; then + source "$HASSBIAN_SUITE_DIR/$suitename/$suiteaction" + "$suiteaction" + returnvalue="$?" + else + echo "$suiteaction script does not exist for this suite." + fi + + # Post action + if [ "$returnvalue" == "0" ]; then + suitestate="installed" + else + echo "$ECHO_ACTION_ERROR" + suitestate="failed" + fi + + if [ "$suiteaction" == "remove" ]; then + rm "$HASSBIAN_CONTROL_DIR/$suitename" + else + echo "SCRIPTSTATE=$suitestate" > "$HASSBIAN_CONTROL_DIR/$suitename" + fi + + # Deactivate debug + if [ "$HASSBIAN_RUNTIME_DEBUG" == true ]; then set +x; fi + + return "$returnvalue" +} +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING"s \ No newline at end of file diff --git a/package/opt/hassbian/helpers/suite/helper b/package/opt/hassbian/helpers/suite/helper new file mode 100644 index 00000000..7827049a --- /dev/null +++ b/package/opt/hassbian/helpers/suite/helper @@ -0,0 +1,162 @@ +#!bin/bash +# Helper script for hassbian-config. + +declare packages +declare suitename +declare manifestkey + +function hassbian.suite.helper.install.pip { + # Purpose: Install python packages in the homeassistant venv. + # Usage: + # hassbian.suite.helper.install.pip sampleclient + # hassbian.suite.helper.install.pip sampleclient someotherpackage + local logcheck + packages=$@ + + echo "Changing to homeassistant user..." + sudo -u homeassistant -H /bin/bash << EOF + + echo "Changing to Home Assistant venv..." + source /srv/homeassistant/bin/activate + + echo "Updating Python dependencies..." + python -m pip install --upgrade pip --no-cache-dir + python -m pip install --upgrade setuptools --no-cache-dir + python -m pip install --upgrade wheel --no-cache-dir + + echo "Installing Python packages..." + python -m pip install --upgrade $packages + + source "$HASSBIAN_HELPERS_DIR"/workaround + hassbian.workaround.check $packages + + echo "Deactivating virtualenv..." + deactivate +EOF +} + +function hassbian.suite.helper.install.apt { + # Purpose: Install apt packages. + # Usage: + # hassbian.suite.helper.install.apt sampleclient + # hassbian.suite.helper.install.apt sampleclient someotherpackage + packages=$@ + + echo "Updating apt..." + apt update + + echo "Installing packages..." + apt install -y $packages +} + +function hassbian.suite.helper.install.node { + # Purpose: Install node. + # Usage: + # hassbian.suite.helper.install.node sampleclient + local node + local nodeversion + + nodeversion='11' + node=$(command -v npm) + + if [ -z "${node}" ]; then + echo "Downloading and installing NodeJS..." + curl -sL https://deb.nodesource.com/setup_"$nodeversion".x | bash - + hassbian.suite.helper.install.apt nodejs + else + echo "NodeJS is installed." + fi +} + +function hassbian.suite.helper.manifest { + # Purpose: retrun info from the suite manifest. + # Usage: + # hassbian.suite.helper.manifest [suite] [key] + # hassbian.suite.helper.manifest duckdns author + local manifestvalue + + suitename="$1" + manifestkey="$2" + + manifestvalue=$(jq ."$manifestkey" -r "$HASSBIAN_SUITE_DIR"/"$suitename"/manifest) + printf "%s" "$manifestvalue" +} + +function hassbian.suite.helper.blockcheck { + # Check the manifest if the suite is blocked. + # If blocked, print the message and exit. + # Usage: + # hassbian.suite.helper.blockcheck [suite] + # hassbian.suite.helper.blockcheck duckdns + local blocked + local blocked_releasename + local blocked_message + local osrelease + + suitename="$1" + + blocked=$(hassbian.suite.helper.manifest "$suitename" blocked) + + if [ "$blocked" = true ]; then + osrelease=$(hassbian.info.version.osreleasename) + blocked_releasename=$(hassbian.suite.helper.manifest "$suitename" blocked_releasename) + if [ "$blocked_releasename" == "ALL" ] || [ "$blocked_releasename" == "$osrelease" ]; then + blocked_message=$(hassbian.suite.helper.manifest "$suitename" blocked_message) + echo -e "$blocked_message" + exit + fi + fi +} + + +function hassbian.suite.helper.exist { + # Purpose: Check if a suite exist. + # Usage: + # hassbian.suite.helper.exist [suite] + # hassbian.suite.helper.exist duckdns + + suitename="$1" + + # Check if suite directory exist. + if [ ! -d "$HASSBIAN_SUITE_DIR/$suitename" ]; then + echo "$suitename does not exist." + exit 1 + fi + + # Check if suite manifest file exist. + if [ ! -f "$HASSBIAN_SUITE_DIR/$suitename/manifest" ]; then + echo "$suitename are missing manifest file." + exit 1 + fi +} + +function hassbian.suite.helper.pizerocheck { + # Check for suites not able to install on a Raspberry Pi Zero. + local REVCODE + + suitename="$1" + + REVCODE=$(cat /proc/cpuinfo | grep 'Revision' | \ + awk '{print $3}' | sed 's/^ *//g' | sed 's/ *$//g') + if [ "$REVCODE" = "90092" ] || \ + [ "$REVCODE" = "90093" ] || \ + [ "$REVCODE" = "0x9000C1" ] || \ + [ "$REVCODE" = "9000c1" ]; then + if [[ "$suitename" =~ ^(mosquitto|cloud9|zigbee2mqtt)$ ]]; then + echo "This suite can't be installed on Raspberry Pi Zero..." + return 0 + fi + fi +} + +function hassbian.suite.helper.action.success { + # Print message to the console on success action. + printf "\\n\\e[32mOperation completed...\\e[0m\\n\\n" +} + +function hassbian.suite.helper.action.failed { + # Print message to the console on failed action. + printf "\\n\\e[31mOperation failed...\\e[0m\\n\\n" +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/suite/info b/package/opt/hassbian/helpers/suite/info new file mode 100644 index 00000000..afa0fc5c --- /dev/null +++ b/package/opt/hassbian/helpers/suite/info @@ -0,0 +1,53 @@ +#!bin/bash +# Helper script for hassbian-config. + +declare suitename + +function hassbian.suite.info.print { + # Show information about a suite. + # Usage example: + # hassbian.suite.info.print [suite] + # hassbian.suite.info.print duckdns + local author + local name + local long_description + local installed + + suitename="$1" + + author=$(hassbian.suite.helper.manifest "$suitename" author) + name=$(hassbian.suite.helper.manifest "$suitename" name) + long_description=$(hassbian.suite.helper.manifest "$suitename" long_description) + installed=$(hassbian.suite.info.installed "$suitename") + + + echo -e " +Suite: $name +Installed: $installed +Contributed to the project by $author +$long_description +" +} + +function hassbian.suite.info.installed { + # Return true if installed, else false. + # Usage example: + # hassbian.suite.info.installed [suite] + # hassbian.suite.info.installed duckdns + local installed + local suitestate + + suitename="$1" + installed='false' + + if [ -f "$HASSBIAN_CONTROL_DIR"/"$suitename" ]; then + suitestate=$(grep "SCRIPTSTATE" "$HASSBIAN_CONTROL_DIR"/"$suitename" | \ + awk -F'=' '{print $2}') + if [ "$suitestate" == "installed" ]; then + installed='true' + fi + fi + printf "%s" "$installed" +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/suite/verify b/package/opt/hassbian/helpers/suite/verify new file mode 100644 index 00000000..39aa2f10 --- /dev/null +++ b/package/opt/hassbian/helpers/suite/verify @@ -0,0 +1,43 @@ +#!bin/bash +# Helper script for hassbian-config. + +# shellcheck disable=SC2034 + +function hassbian.suite.verify.service { + # Example usage: + # hassbian.suite.verify.service home-assistant@homeassistant.service + local servicename + local retrunvalue + + servicename="$1" + retrunvalue=1 + + for i in {1..5}; do + if [ "$(systemctl is-active "$servicename")" == "active" ]; then + retrunvalue=0 + break + fi + sleep 1s + done + printf "%s" "$retrunvalue" +} + +function hassbian.suite.verify.pgrep { + # Example usage: + # hassbian.suite.verify.pgrep pihole + local prosessename + local retrunvalue + + prosessename="$1" + retrunvalue=1 + + for i in {1..5}; do + if [ ! -z "$(pgrep -f "$prosessename")" ]; then + retrunvalue=0 + break + fi + sleep 1s + done + printf "%s" "$retrunvalue" +} +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/helpers/workaround b/package/opt/hassbian/helpers/workaround new file mode 100644 index 00000000..fea3bf9c --- /dev/null +++ b/package/opt/hassbian/helpers/workaround @@ -0,0 +1,44 @@ +#!bin/bash +# Helper script for hassbian-config. +# This particular helper is here to give us some flexibility. + +# shellcheck disable=SC2086,SC2124 + +# Loggfile for 'hassbian-config' operations. +readonly HASSBIAN_LOG_FILE='/tmp/hassbian.log' + +function hassbian.workaround.check { + # Check the logfile for known issues. + local logcontent + local packages + + packages=$@ + + logcontent=$(cat "$HASSBIAN_LOG_FILE") + + if [[ "$logcontent" == *"unsupported operand type(s) for -=: 'Retry' and 'int'"* ]]; then + hassbian.workaround.pip.typeerror $packages + fi +} + + + +function hassbian.workaround.pip.typeerror { + # Workaround for known debian issue. + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=880472 + local packages + + packages=$@ + + echo "Found known issue about the TypeError above... applying fix..." + wget -O /tmp/get-pypi.py https://bootstrap.pypa.io/get-pip.py + python /tmp/get-pypi.py + + echo "Fix have been applied to the system, trying to run the previous command again..." + + echo "Installing Python packages..." + python -m pip install --upgrade $packages + +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/appdaemon.sh b/package/opt/hassbian/suites/appdaemon.sh deleted file mode 100644 index 5b650403..00000000 --- a/package/opt/hassbian/suites/appdaemon.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash -function appdaemon-show-short-info { - echo "AppDaemon install script for Hassbian." -} - -function appdaemon-show-long-info { - echo "Installs AppDaemon in a separate Venv onto this system." -} - -function appdaemon-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function appdaemon-install-package { -if [ "$ACCEPT" != "true" ]; then - if [ -f "/usr/sbin/samba" ]; then - echo -n "Do you want to add Samba share for AppDaemon configuration? [N/y] : " - read -r SAMBA - fi - echo -n "Enter your Home Assistant API password: " - read -s -r HOMEASSISTANT_PASSWORD - printf "\\n" -else - HOMEASSISTANT_PASSWORD="" -fi - -echo "Checking python version to use..." -PYTHONVER=$(echo /usr/local/lib/*python* | awk -F/ '{print $NF}') -echo "Using $PYTHONVER..." - -echo "Creating directory for AppDaemon Venv" -mkdir /srv/appdaemon -chown -R homeassistant:homeassistant /srv/appdaemon - -echo "Changing to the homeassistant user" -sudo -u homeassistant -H /bin/bash << EOF - -echo "Creating AppDaemon venv" -$PYTHONVER -m venv /srv/appdaemon - -echo "Changing to AppDaemon venv" -source /srv/appdaemon/bin/activate - -echo "Creating directory for AppDaemon configuration file" -mkdir /home/homeassistant/appdaemon -mkdir /home/homeassistant/appdaemon/apps - -echo "Installing latest version of AppDaemon" -pip3 install wheel -pip3 install appdaemon - -echo "Copying AppDaemon config file" -cp /opt/hassbian/suites/files/appdaemon.conf /home/homeassistant/appdaemon/appdaemon.yaml -if [ ! -z "${HOMEASSISTANT_PASSWORD}" ]; then - sed -i 's/#ha_key:/ha_key: $HOMEASSISTANT_PASSWORD/g' /home/homeassistant/appdaemon/appdaemon.yaml -fi - -echo "Deactivating virtualenv" -deactivate -EOF - -echo "Copying AppDaemon service file" -cp /opt/hassbian/suites/files/appdaemon.service /etc/systemd/system/appdaemon@homeassistant.service - -echo "Enabling AppDaemon service" -systemctl enable appdaemon@homeassistant.service -sync - -echo "Starting AppDaemon service" -systemctl start appdaemon@homeassistant.service - -if [ "$SAMBA" == "y" ] || [ "$SAMBA" == "Y" ]; then - echo "Adding configuration to Samba..." - echo "[appdaemon]" | tee -a /etc/samba/smb.conf - echo "path = /home/homeassistant/appdaemon" | tee -a /etc/samba/smb.conf - echo "writeable = yes" | tee -a /etc/samba/smb.conf - echo "guest ok = yes" | tee -a /etc/samba/smb.conf - echo "create mask = 0644" | tee -a /etc/samba/smb.conf - echo "directory mask = 0755" | tee -a /etc/samba/smb.conf - echo "force user = homeassistant" | tee -a /etc/samba/smb.conf - echo "" | tee -a /etc/samba/smb.conf - echo "Restarting Samba service" - systemctl restart smbd.service -fi - -echo "Checking the installation..." -validation=$(pgrep -f appdaemon) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo - echo "You will find the AppDaemon configuration files in:" - echo "/home/homeassistant/appdaemon" - echo - echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -function appdaemon-upgrade-package { -echo "Stopping AppDaemon service..." -systemctl stop appdaemon@homeassistant.service - -echo "Changing to the homeassistant user..." -sudo -u homeassistant -H /bin/bash << EOF - -echo "Changing to AppDaemon venv..." -source /srv/appdaemon/bin/activate - -echo "Installing latest version of AppDaemon..." -pip3 install wheel -pip3 install --upgrade appdaemon - - -echo "Deactivating virtualenv..." -deactivate -EOF - -echo "Starting AppDaemon service..." -systemctl start appdaemon@homeassistant.service - -echo "Checking the installation..." -validation=$(pgrep -f appdaemon) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mUpgrade done..\\e[0m" - echo - echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" - echo -else - echo - echo -e "\\e[31mUpgrade failed..." - echo - return 1 -fi -return 0 -} -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/files/appdaemon.conf b/package/opt/hassbian/suites/appdaemon/files/appdaemon.conf similarity index 100% rename from package/opt/hassbian/suites/files/appdaemon.conf rename to package/opt/hassbian/suites/appdaemon/files/appdaemon.conf diff --git a/package/opt/hassbian/suites/files/appdaemon.service b/package/opt/hassbian/suites/appdaemon/files/appdaemon.service similarity index 100% rename from package/opt/hassbian/suites/files/appdaemon.service rename to package/opt/hassbian/suites/appdaemon/files/appdaemon.service diff --git a/package/opt/hassbian/suites/appdaemon/files/samba.conf b/package/opt/hassbian/suites/appdaemon/files/samba.conf new file mode 100644 index 00000000..4baa1e27 --- /dev/null +++ b/package/opt/hassbian/suites/appdaemon/files/samba.conf @@ -0,0 +1,7 @@ +[appdaemon] +path = /home/homeassistant/appdaemon +writeable = yes +guest ok = yes +create mask = 0644 +directory mask = 0755 +force user = homeassistant \ No newline at end of file diff --git a/package/opt/hassbian/suites/appdaemon/install b/package/opt/hassbian/suites/appdaemon/install new file mode 100644 index 00000000..fa5dc186 --- /dev/null +++ b/package/opt/hassbian/suites/appdaemon/install @@ -0,0 +1,89 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: AppDaemon +# + +function install { + local activatesamba + local homeassistant_password + local python_version + + if [ "$HASSBIAN_RUNTIME_ACCEPT" = false ]; then + if [ -f "/usr/sbin/samba" ]; then + activatesamba=$(hassbian.input.bool "Do you want to add Samba share for AppDaemon configuration?") + fi + homeassistant_password=$(hassbian.input.text "Enter your Home Assistant API password:") + else + homeassistant_password="" + fi + + echo "Checking python version to use..." + python_version=$(hassbian.info.version.python) + echo "Using python$python_version..." + + echo "Creating directory for AppDaemon Venv" + mkdir /srv/appdaemon + chown -R homeassistant:homeassistant /srv/appdaemon + + echo "Changing to the homeassistant user..." + sudo -u homeassistant -H /bin/bash << EOF + echo "Creating AppDaemon venv..." + python"$python_version" -m venv /srv/appdaemon + + echo "Changing to AppDaemon venv..." + source /srv/appdaemon/bin/activate + + echo "Creating directory for AppDaemon configuration file..." + mkdir /home/homeassistant/appdaemon + mkdir /home/homeassistant/appdaemon/apps + + echo "Installing latest version of AppDaemon..." + python -m pip install setuptools wheel + python -m pip install appdaemon + + hassbian.workaround.check appdaemon + + echo "Copying AppDaemon config file..." + cp $HASSBIAN_SUITE_DIR/appdaemon/files/appdaemon.conf /home/homeassistant/appdaemon/appdaemon.yaml + if [ ! -z "${HOMEASSISTANT_PASSWORD}" ]; then + sed -i 's/#ha_key:/ha_key: $HOMEASSISTANT_PASSWORD/g' /home/homeassistant/appdaemon/appdaemon.yaml + fi + + echo "Deactivating virtualenv..." + deactivate +EOF + + echo "Copying AppDaemon service file" + cp "$HASSBIAN_SUITE_DIR"/appdaemon/files/appdaemon.service /etc/systemd/system/appdaemon@homeassistant.service + + echo "Enabling AppDaemon service" + systemctl enable appdaemon@homeassistant.service + sync + + echo "Starting AppDaemon service" + systemctl start appdaemon@homeassistant.service + + if [ "$activatesamba" == "0" ]; then + echo "Adding configuration to Samba..." + tee -a /etc/samba/smb.conf < "$HASSBIAN_SUITE_DIR"/appdaemon/files/samba.conf + + echo "Restarting Samba service" + systemctl restart smbd.service + fi + + validation=$(hassbian.suite.verify.service appdaemon@homeassistant.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + + echo "You will find the AppDaemon configuration files in: + /home/homeassistant/appdaemon + + To continue have a look at http://appdaemon.readthedocs.io/en/latest/" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/appdaemon/manifest b/package/opt/hassbian/suites/appdaemon/manifest new file mode 100644 index 00000000..1fa22c4b --- /dev/null +++ b/package/opt/hassbian/suites/appdaemon/manifest @@ -0,0 +1,9 @@ +{ + "name": "AppDaemon", + "author": "Username ", + "short_description": "AppDaemon install script for Hassbian.", + "long_description": "Installs AppDaemon in a separate Venv onto this system.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/appdaemon/upgrade b/package/opt/hassbian/suites/appdaemon/upgrade new file mode 100644 index 00000000..ad3c9f50 --- /dev/null +++ b/package/opt/hassbian/suites/appdaemon/upgrade @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: AppDaemon +# + +function upgrade { + local validation + + echo "Stopping AppDaemon service..." + systemctl stop appdaemon@homeassistant.service + + echo "Changing to the homeassistant user..." + sudo -u homeassistant -H /bin/bash << EOF + echo "Changing to AppDaemon venv..." + source /srv/appdaemon/bin/activate + + echo "Installing latest version of AppDaemon..." + python -m pip install --upgrade setuptools wheel + python -m pip install --upgrade appdaemon + + hassbian.workaround.check appdaemon + + echo "Deactivating virtualenv..." + deactivate +EOF + + echo "Starting AppDaemon service..." + systemctl start appdaemon@homeassistant.service + + validation=$(hassbian.suite.verify.service appdaemon@homeassistant.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + echo "To continue have a look at http://appdaemon.readthedocs.io/en/latest/" + + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/cloud9.sh b/package/opt/hassbian/suites/cloud9.sh deleted file mode 100644 index d0dfb051..00000000 --- a/package/opt/hassbian/suites/cloud9.sh +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash -function cloud9-show-short-info { - printf "Cloud9 script for Hassbian.\\n" -} - -function cloud9-show-long-info { - printf "Cloud9 script for Hassbian.\\n" - printf "Cloud9 SDK is an webservice IDE that makes it easy to manage your configuration files.\\n" -} - -function cloud9-show-copyright-info { - printf "This script was originally contributed by Ludeeus .\\n" -} - -function cloud9-install-package { - -if [ "$ACCEPT" == "true" ]; then - username=pi - password=raspberry -else - echo - echo "Please take a moment to setup your the user account" - echo - - echo -n "Username: " - read -r username - if [ ! "$username" ]; then - username=pi - fi - - echo -n "Password: " - read -s -r password - echo - if [ ! "$password" ]; then - password=raspberry - fi -fi - -node=$(which node) -if [ -z "${node}" ]; then #Installing NodeJS if not already installed. - printf "Downloading and installing NodeJS...\\n" - curl -sL https://deb.nodesource.com/setup_10.x | bash - - apt install -y nodejs -fi - -echo "Creating installation directory..." -mkdir /opt/c9sdk -chown homeassistant:homeassistant /opt/c9sdk - -echo "Changing to the homeassistant user" -sudo -u homeassistant -H /bin/bash << EOF - printf "Downloading and installing Cloud9 SDK...\\n" - git clone git://github.com/c9/core.git /opt/c9sdk - bash /opt/c9sdk/scripts/install-sdk.sh - echo "Creating workspace for Cloud9." - mkdir -p /home/homeassistant/c9workspace/.c9 - echo "Create default config." - echo '{"projecttree": {"@showhidden": false,"@hiddenFilePattern": ".*,.n*,*c9*,.b*,.p*,.w*,*.db"}}' | tee /home/homeassistant/c9workspace/.c9/user.settings - echo "Symlinking /home/homeassistant/.homeassistant to the workspace." - ln -s /home/homeassistant/.homeassistant/ /home/homeassistant/c9workspace/homeassistant -EOF - -echo "Copying Cloud9 service file..." -cp /opt/hassbian/suites/files/cloud9.service /etc/systemd/system/cloud9@homeassistant.service - -sed -i "s,%%USERNAME%%,${username},g" /etc/systemd/system/cloud9@homeassistant.service -sed -i "s,%%PASSWORD%%,${password},g" /etc/systemd/system/cloud9@homeassistant.service - -echo "Enabling Cloud9 service..." -systemctl enable cloud9@homeassistant.service -sync - -echo "Starting Cloud9 service..." -systemctl start cloud9@homeassistant.service - -echo "Checking the installation..." -sleep 15 -validation=$(pgrep -f cloud9) -if [ ! -z "${validation}" ]; then - echo "Using fallback installation." - echo "Installing npm" - apt install -y npm - - cd /opt/c9sdk || exit 1 - npm install - - echo "Checking the installation..." - sleep 15 -fi - -validation=$(pgrep -f cloud9) -if [ -z "${validation}" ]; then - ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - echo - echo -e "\\e[32mInstallation done.\\e[0m" - echo "Your Cloud9 IDE is now avaiable at http://$ip_address:8181" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -function cloud9-upgrade-package { -printf "Stopping Cloud9 service...\\n" -systemctl stop cloud9@homeassistant.service -sudo -u homeassistant -H /bin/bash << EOF - printf "Downloading and installing newest version of Cloud9 SDK...\\n" - git clone git://github.com/c9/core.git /opt/c9sdk - bash /opt/c9sdk/scripts/install-sdk.sh -EOF - -printf "Starting Cloud9 service...\\n" -systemctl start cloud9@homeassistant.service - -echo "Checking the installation..." -sleep 15 -validation=$(pgrep -f cloud9) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mUpgrade done.\\e[0m" - echo -else - echo - echo -e "\\e[31mUpgrade failed..." - echo - return 1 -fi -return 0 -} - -function cloud9-remove-package { -printf "Removing Cloud9 IDE...\\n" -systemctl stop cloud9@homeassistant.service -systemctl disable cloud9@homeassistant.service -rm /etc/systemd/system/cloud9@homeassistant.service -sync -bash /opt/c9sdk/scripts/uninstall-c9.sh -rm -R /opt/c9sdk -rm -R /home/homeassistant/c9workspace - -printf "\\e[32mRemoval done..\\e[0m\\n" -} -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/files/cloud9.service b/package/opt/hassbian/suites/cloud9/files/cloud9.service similarity index 100% rename from package/opt/hassbian/suites/files/cloud9.service rename to package/opt/hassbian/suites/cloud9/files/cloud9.service diff --git a/package/opt/hassbian/suites/cloud9/install b/package/opt/hassbian/suites/cloud9/install new file mode 100644 index 00000000..52a74966 --- /dev/null +++ b/package/opt/hassbian/suites/cloud9/install @@ -0,0 +1,82 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Cloud9 IDE +# + +function install { + local ipaddress + local validation + local username + local password + + if [ "$HASSBIAN_RUNTIME_ACCEPT" = true ]; then + username=pi + password=raspberry + else + hassbian.input.info "Please take the time to setup your account" + username=$(hassbian.input.text "Username:") + password=$(hassbian.input.text "Password:") + if [ "$username" == "0" ]; then + username=pi + fi + if [ "$password" == "0" ]; then + password=raspberry + fi + fi + + #Installing NodeJS if not already installed. + hassbian.suite.helper.install.node + + echo "Creating installation directory..." + mkdir /opt/c9sdk + chown homeassistant:homeassistant /opt/c9sdk + + echo "Changing to the homeassistant user" + sudo -u homeassistant -H /bin/bash << EOF + echo "Downloading and installing Cloud9 SDK..." + git clone git://github.com/c9/core.git /opt/c9sdk + bash /opt/c9sdk/scripts/install-sdk.sh + echo "Creating workspace for Cloud9." + mkdir -p /home/homeassistant/c9workspace/.c9 + echo "Create default config." + echo '{"projecttree": {"@showhidden": false,"@hiddenFilePattern": ".*,.n*,*c9*,.b*,.p*,.w*,*.db"}}' | tee /home/homeassistant/c9workspace/.c9/user.settings + echo "Symlinking /home/homeassistant/.homeassistant to the workspace." + ln -s /home/homeassistant/.homeassistant/ /home/homeassistant/c9workspace/homeassistant +EOF + + echo "Copying Cloud9 service file..." + cp "$HASSBIAN_SUITE_DIR"/cloud9/files/cloud9.service /etc/systemd/system/cloud9@homeassistant.service + + sed -i "s,%%USERNAME%%,${username},g" /etc/systemd/system/cloud9@homeassistant.service + sed -i "s,%%PASSWORD%%,${password},g" /etc/systemd/system/cloud9@homeassistant.service + + echo "Enabling Cloud9 service..." + systemctl enable cloud9@homeassistant.service + sync + + echo "Starting Cloud9 service..." + systemctl start cloud9@homeassistant.service + + validation=$(hassbian.suite.verify.service cloud9@homeassistant.service) + if [ "$validation" == "1" ]; then + echo "Using fallback installation." + echo "Installing npm" + apt install -y npm + + cd /opt/c9sdk || return 1 + npm install + fi + + validation=$(hassbian.suite.verify.service cloud9@homeassistant.service) + if [ "$validation" == "0" ]; then + ipaddress=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Your Cloud9 IDE is now avaiable at http://$ipaddress:8181" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/cloud9/manifest b/package/opt/hassbian/suites/cloud9/manifest new file mode 100644 index 00000000..a9244ca4 --- /dev/null +++ b/package/opt/hassbian/suites/cloud9/manifest @@ -0,0 +1,9 @@ +{ + "name": "Cloud9 IDE", + "author": "Ludeeus ", + "short_description": "Cloud9 script for Hassbian.", + "long_description": "Cloud9 SDK is an webservice IDE that makes it easy to manage your configuration files.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/cloud9/remove b/package/opt/hassbian/suites/cloud9/remove new file mode 100644 index 00000000..a4177d7d --- /dev/null +++ b/package/opt/hassbian/suites/cloud9/remove @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Uninstallation script for Hassbian suite: Cloud9 IDE +# + +function remove { + echo "Removing Cloud9 IDE..." + systemctl stop cloud9@homeassistant.service + systemctl disable cloud9@homeassistant.service + rm /etc/systemd/system/cloud9@homeassistant.service + sync + bash /opt/c9sdk/scripts/uninstall-c9.sh + rm -R /opt/c9sdk + rm -R /home/homeassistant/c9workspace + + hassbian.suite.helper.action.success +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/cloud9/upgrade b/package/opt/hassbian/suites/cloud9/upgrade new file mode 100644 index 00000000..9b4c92a6 --- /dev/null +++ b/package/opt/hassbian/suites/cloud9/upgrade @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Cloud9 IDE +# + +function upgrade { + local validation + + echo "Stopping Cloud9 service..." + systemctl stop cloud9@homeassistant.service + + sudo -u homeassistant -H /bin/bash << EOF + enho "Downloading and installing newest version of Cloud9 SDK..." + git clone git://github.com/c9/core.git /opt/c9sdk + bash /opt/c9sdk/scripts/install-sdk.sh +EOF + + echo "Starting Cloud9 service..." + systemctl start cloud9@homeassistant.service + + validation=$(hassbian.suite.verify.service cloud9@homeassistant.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/custom-component-store.sh b/package/opt/hassbian/suites/custom-component-store.sh deleted file mode 100644 index f64b94d7..00000000 --- a/package/opt/hassbian/suites/custom-component-store.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/bash -function custom-component-store-show-short-info { - echo "Custom component store script." -} - -function custom-component-store-show-long-info { - echo "Custom component store is a web UI tool that can help you manage your custom components." -} - -function custom-component-store-show-copyright-info { - echo "Original concept by Ludeeus ." -} - -function custom-component-store-install-package { - -if [ "$ACCEPT" == "true" ]; then - username=pi - password=raspberry -else - echo - echo "Please take a moment to setup your the user account" - echo - - echo -n "Username: " - read -r username - if [ ! "$username" ]; then - username=pi - fi - - echo -n "Password: " - read -s -r password - echo - if [ ! "$password" ]; then - password=raspberry - fi -fi - -echo "Installing latest version of Custom component store" -python3 -m pip install componentstore - -echo "Enabling Custom component store service" -cp /opt/hassbian/suites/files/custom-component-store@homeassistant.service /etc/systemd/system/custom-component-store@homeassistant.service - -sed -i "s,%%USERNAME%%,${username},g" /etc/systemd/system/custom-component-store@homeassistant.service -sed -i "s,%%PASSWORD%%,${password},g" /etc/systemd/system/custom-component-store@homeassistant.service - -systemctl enable custom-component-store@homeassistant.service -sync - -echo "Starting Custom component storer" -systemctl start custom-component-store@homeassistant.service - -echo "Starting cleanup" -cd || exit 1 -rm -R /tmp/custom-component-store - -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -echo "Checking the installation..." -validation=$(pgrep -x componentstore) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo "Custom component store installation is running at $ip_address:8120 or if preferred http://hassbian.local:8120" - echo - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -function custom-component-store-upgrade-package { -echo "Upgrading Custom component store" -python3 -m pip install --upgrade componentstore - -echo "Restarting Custom component store" -systemctl start custom-component-store@homeassistant.service - -echo "Checking the installation..." -validation=$(pgrep -x componentstore) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mUpgrade script completed..\\e[0m" - echo -else - echo - echo -e "\\e[31mUpgrade failed..." - echo - return 1 -fi -return 0 -} - -function custom-component-store-remove-package { -printf "Removing Custom component store...\\n" -systemctl stop custom-component-store@homeassistant.service -systemctl disable custom-component-store@homeassistant.service -rm /etc/systemd/system/custom-component-store@homeassistant.service -sync - - -python3 -m pip uninstall --yes componentstore - - -printf "\\e[32mRemoval done..\\e[0m\\n" -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" \ No newline at end of file diff --git a/package/opt/hassbian/suites/files/custom-component-store@homeassistant.service b/package/opt/hassbian/suites/custom-component-store/files/custom-component-store@homeassistant.service similarity index 100% rename from package/opt/hassbian/suites/files/custom-component-store@homeassistant.service rename to package/opt/hassbian/suites/custom-component-store/files/custom-component-store@homeassistant.service diff --git a/package/opt/hassbian/suites/custom-component-store/install b/package/opt/hassbian/suites/custom-component-store/install new file mode 100644 index 00000000..0d29c10b --- /dev/null +++ b/package/opt/hassbian/suites/custom-component-store/install @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Custom component store +# + +function install { + local ipaddress + local validation + local username + local password + + if [ "$HASSBIAN_RUNTIME_ACCEPT" = true ]; then + username='pi' + password='raspberry' + else + hassbian.input.info "Please take the time to setup your account" + username=$(hassbian.input.text "Username:") + password=$(hassbian.input.text "Password:") + if [ "$username" == "0" ]; then + username='pi' + fi + if [ "$password" == "0" ]; then + password='raspberry' + fi + fi + + echo "Installing latest version of Custom component store..." + hassbian.suite.helper.install.pip componentstore + + echo "Enabling Custom component store service..." + cp "$HASSBIAN_SUITE_DIR"/custom-component-store/files/custom-component-store@homeassistant.service /etc/systemd/system/custom-component-store@homeassistant.service + + sed -i "s,%%USERNAME%%,${username},g" /etc/systemd/system/custom-component-store@homeassistant.service + sed -i "s,%%PASSWORD%%,${password},g" /etc/systemd/system/custom-component-store@homeassistant.service + + systemctl enable custom-component-store@homeassistant.service + sync + + echo "Starting Custom component store..." + systemctl start custom-component-store@homeassistant.service + + validation=$(hassbian.suite.verify.service custom-component-store@homeassistant.service) + if [ "$validation" == "0" ]; then + ipaddress=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Custom component store installation is running at $ipaddress:8120 or if preferred http://hassbian.local:8120" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/custom-component-store/manifest b/package/opt/hassbian/suites/custom-component-store/manifest new file mode 100644 index 00000000..ffdf4308 --- /dev/null +++ b/package/opt/hassbian/suites/custom-component-store/manifest @@ -0,0 +1,9 @@ +{ + "name": "Custom component store", + "author": "Ludeeus ", + "short_description": "Custom component store script.", + "long_description": "Custom component store is a web UI tool that can help you manage your custom components.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/custom-component-store/remove b/package/opt/hassbian/suites/custom-component-store/remove new file mode 100644 index 00000000..b39356b7 --- /dev/null +++ b/package/opt/hassbian/suites/custom-component-store/remove @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Uninstallation script for Hassbian suite: Custom component store +# + +function remove { + echo "Removing Custom component store..." + systemctl stop custom-component-store@homeassistant.service + systemctl disable custom-component-store@homeassistant.service + rm /etc/systemd/system/custom-component-store@homeassistant.service + sync + + python3 -m pip uninstall --yes componentstore + + hassbian.suite.helper.action.success +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/custom-component-store/upgrade b/package/opt/hassbian/suites/custom-component-store/upgrade new file mode 100644 index 00000000..427d4464 --- /dev/null +++ b/package/opt/hassbian/suites/custom-component-store/upgrade @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Custom component store +# + +function upgrade { + echo "Upgrading Custom component store" + hassbian.suite.helper.install.pip componentstore + + echo "Restarting Custom component store" + systemctl restart custom-component-store@homeassistant.service + + validation=$(hassbian.suite.verify.service custom-component-store@homeassistant.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/duckdns.sh b/package/opt/hassbian/suites/duckdns.sh deleted file mode 100644 index 8f3b63e8..00000000 --- a/package/opt/hassbian/suites/duckdns.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash -function duckdns-show-short-info { - echo "Setup for Duck DNS auto renewal, and generates SSL certificate." -} - -function duckdns-show-long-info { - echo "This script adds an cron job to auto update you the WAN IP address for the defined domain." - echo "This script can also generate SSL certificate for https with Let’s Encrypt." -} - -function duckdns-show-copyright-info { - echo "Original concept by Ludeeus ." -} - -function duckdns-install-package { -echo "Please take a moment to setup autorenewal of duckdns." -echo "If no choice is made the installation will exit." -echo -echo "(if your domain is 'example.duckdns.org' type example)" -echo -n "Domain: " -read -r domain -if [ ! "$domain" ]; then - exit -fi -if [[ $domain = *"duckdns"* ]]; then - domain=$(echo "$domain" | cut -d\. -f1) -fi -if [[ $domain = *"//"* ]]; then - domain=$(echo "$domain" | cut -d/ -f3) -fi - - -echo -n "Token: " -read -r token -echo -if [ ! "$token" ]; then - exit -fi -echo -n "Do you want to generate certificates to use SSL(https)? [N/y] : " -read -r SSL_RESPONSE - -echo "Changing to homeassistant user..." -sudo -u homeassistant -H /bin/bash << EOF -cd - -if [ "$SSL_RESPONSE" == "y" ] || [ "$SSL_RESPONSE" == "Y" ]; then - git clone https://github.com/lukas2511/dehydrated.git - cd dehydrated || exit - echo $domain".duckdns.org" | tee domains.txt - echo "CHALLENGETYPE='dns-01'" | tee -a config - echo "HOOK='./hook.sh'" | tee -a config - curl -so ./hook.sh https://raw.githubusercontent.com/home-assistant/hassbian-scripts/dev/package/opt/hassbian/suites/files/ssl_hook.sh - sed -i 's/myhome/'$domain'/g' ./hook.sh - sed -i 's/your-duckdns-token/'$token'/g' ./hook.sh - chmod 755 hook.sh - ./dehydrated --register --accept-terms - ./dehydrated -c -fi - -echo "Creating duckdns folder..." -cd /home/homeassistant || exit -mkdir duckdns -cd duckdns || exit - -echo "Creating a script file to be used by cron." -echo "echo url='https://www.duckdns.org/update?domains=$domain&token=$token&ip=' | curl -k -o ~/duckdns/duck.log -K -" > duck.sh - -echo "Setting permissions..." -chmod 700 duck.sh - -echo "Creating cron job..." -(crontab -l ; echo "*/5 * * * * /home/homeassistant/duckdns/duck.sh >/dev/null 2>&1")| crontab - - -EOF - -if [ "$SSL_RESPONSE" == "y" ] || [ "$SSL_RESPONSE" == "Y" ]; then - cp /opt/hassbian/suites/files/dehydrated_cron /etc/cron.daily/dehydrated - chmod +x /etc/cron.daily/dehydrated -fi - -echo "Restarting cron service..." -systemctl restart cron.service - -echo "Checking the installation..." -if [ "$SSL_RESPONSE" == "y" ] || [ "$SSL_RESPONSE" == "Y" ]; then - certvalidation=$(find /home/homeassistant/dehydrated/certs/"$domain".duckdns.org/ -maxdepth 1 -type f | sort | grep privkey) -else - certvalidation="ok" -fi -if [ ! -f /home/homeassistant/duckdns/duck.sh ]; then - dnsvalidation="" -else - dnsvalidation="ok" -fi - -if [ ! -z "${certvalidation}" ] && [ ! -z "${dnsvalidation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo - if [ "$SSL_RESPONSE" == "y" ] || [ "$SSL_RESPONSE" == "Y" ]; then - echo "Remember to update your configuration.yaml to take advantage of SSL!" - echo "Documentation for this can be found here ." - echo - fi -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -function duckdns-remove-package { - echo "Removing certificates if installed." - rm -R /home/homeassistant/dehydrated >/dev/null 2>&1 - - echo "Removing cron jobs" - rm /etc/cron.daily/dehydrated >/dev/null 2>&1 - crontab -u homeassistant -l | grep -v 'duck.sh' | crontab -u homeassistant - - - echo - echo -e "\\e[32mRemoval done..\\e[0m" - echo - return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/files/dehydrated_cron b/package/opt/hassbian/suites/duckdns/files/cron/dehydrated similarity index 84% rename from package/opt/hassbian/suites/files/dehydrated_cron rename to package/opt/hassbian/suites/duckdns/files/cron/dehydrated index 46610974..30f51d4a 100644 --- a/package/opt/hassbian/suites/files/dehydrated_cron +++ b/package/opt/hassbian/suites/duckdns/files/cron/dehydrated @@ -1,7 +1,6 @@ #!/bin/bash # Run the dehydrated script to renew certificates -echo "Changing to homeassistant user..." sudo -u homeassistant -H /bin/bash << EOF cd /home/homeassistant/dehydrated || exit ./dehydrated -c diff --git a/package/opt/hassbian/suites/duckdns/files/cron/duckdns b/package/opt/hassbian/suites/duckdns/files/cron/duckdns new file mode 100644 index 00000000..daea2475 --- /dev/null +++ b/package/opt/hassbian/suites/duckdns/files/cron/duckdns @@ -0,0 +1,8 @@ +#!/bin/bash +# Run the DuckDNS curl command to update the A record. + +readonly DOMAIN=%%DOMAIN%% +readonly TOKEN=%%TOKEN%% + +echo "Updating DuckDNS A record." +curl -sSL "https://www.duckdns.org/update?domains=$DOMAIN&token=$TOKEN&ip=" diff --git a/package/opt/hassbian/suites/files/ssl_hook.sh b/package/opt/hassbian/suites/duckdns/files/hook.sh similarity index 100% rename from package/opt/hassbian/suites/files/ssl_hook.sh rename to package/opt/hassbian/suites/duckdns/files/hook.sh diff --git a/package/opt/hassbian/suites/duckdns/install b/package/opt/hassbian/suites/duckdns/install new file mode 100644 index 00000000..a26da1fd --- /dev/null +++ b/package/opt/hassbian/suites/duckdns/install @@ -0,0 +1,93 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: DuckDNS +# + +function install { + local DUCKDNS_DOMAIN + local DUCKDNS_TOKEN + local SSL_RESPONSE + local certvalidation + local dnsvalidation + + hassbian.input.info "Please take a moment to setup autorenewal of duckdns, "\ + "if no choice is made the installation will exit." + + DUCKDNS_DOMAIN=$(hassbian.input.text "What is your DuckDNS subdomain?") + if [ ! "$DUCKDNS_DOMAIN" ]; then + exit + fi + if [[ $DUCKDNS_DOMAIN = *"duckdns"* ]]; then + DUCKDNS_DOMAIN=$(echo "$DUCKDNS_DOMAIN" | cut -d\. -f1) + fi + if [[ $DUCKDNS_DOMAIN = *"//"* ]]; then + DUCKDNS_DOMAIN=$(echo "$DUCKDNS_DOMAIN" | cut -d/ -f3) + fi + + DUCKDNS_TOKEN=$(hassbian.input.text "What is your DuckDNS token?") + if [ ! "$token" ]; then + exit + fi + + SSL_RESPONSE=$(hassbian.input.bool "Do you want to generate certificates to use SSL(https)?") + + echo "Changing to homeassistant user..." + sudo -u homeassistant -H /bin/bash << EOF + cd + if [ "$SSL_RESPONSE" == "y" ] || [ "$SSL_RESPONSE" == "Y" ]; then + git clone https://github.com/lukas2511/dehydrated.git + cd dehydrated || exit + echo $DUCKDNS_DOMAIN".duckdns.org" | tee domains.txt + echo "CHALLENGETYPE='dns-01'" | tee -a config + echo "HOOK='./hook.sh'" | tee -a config + cp $HASSBIAN_SUITE_DIR/duckdns/files/hook.sh ./hook.sh + sed -i 's/myhome/'$DUCKDNS_DOMAIN'/g' ./hook.sh + sed -i 's/your-duckdns-token/'$DUCKDNS_TOKEN'/g' ./hook.sh + chmod 755 hook.sh + ./dehydrated --register --accept-terms + ./dehydrated -c + fi + + echo "Creating duckdns folder..." + cd /home/homeassistant || exit + mkdir duckdns + cd duckdns || exit +EOF + + echo "Creating cron jobs..." + cp /"$HASSBIAN_SUITE_DIR"/duckdns/files/cron/duckdns /etc/cron.hourly/duckdns + sed -i "s,%%DOMAIN%%,${DUCKDNS_DOMAIN},g" /etc/cron.hourly/duckdns + sed -i "s,%%TOKEN%%,${DUCKDNS_TOKEN},g" /etc/cron.hourly/duckdns + chmod +x /etc/cron.hourly/duckdns + + if [ "$SSL_RESPONSE" == "0" ]; then + cp "$HASSBIAN_SUITE_DIR"/duckdns/files/cron/dehydrated /etc/cron.daily/dehydrated + chmod +x /etc/cron.daily/dehydrated + fi + + echo "Restarting cron service..." + systemctl restart cron.service + + echo "Checking the installation..." + if [ "$SSL_RESPONSE" == "0" ]; then + certvalidation=$(find /home/homeassistant/dehydrated/certs/"$DUCKDNS_DOMAIN".duckdns.org/ -maxdepth 1 -type f | sort | grep privkey) + fi + if [ -f /home/homeassistant/duckdns/duck.sh ]; then + dnsvalidation="ok" + fi + + if [ ! -z "${certvalidation}" ] && [ ! -z "${dnsvalidation}" ]; then + hassbian.hassbian.suite.helper.action.success + if [ "$SSL_RESPONSE" == "0" ]; then + echo "Remember to update your configuration.yaml to take advantage of SSL!" + echo "Documentation for this can be found here ." + echo + fi + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" diff --git a/package/opt/hassbian/suites/duckdns/manifest b/package/opt/hassbian/suites/duckdns/manifest new file mode 100644 index 00000000..3beda770 --- /dev/null +++ b/package/opt/hassbian/suites/duckdns/manifest @@ -0,0 +1,9 @@ +{ + "name": "DuckDNS", + "author": "Ludeeus ", + "short_description": "Setup for Duck DNS auto renewal, and generates SSL certificate.", + "long_description": "This script adds an cron job to auto update you the WAN IP address for the defined domain.\\nThis script can also generate SSL certificate for https with Let’s Encrypt.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/duckdns/remove b/package/opt/hassbian/suites/duckdns/remove new file mode 100644 index 00000000..12491afb --- /dev/null +++ b/package/opt/hassbian/suites/duckdns/remove @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Uninstallation script for Hassbian suite: DuckDNS +# + +function remove { + echo "Removing certificates if installed." + rm -R /home/homeassistant/dehydrated >/dev/null 2>&1 + + echo "Removing cron jobs." + rm /etc/cron.daily/dehydrated >/dev/null 2>&1 + rm /etc/cron.hourly/duckdns >/dev/null 2>&1 + + hassbian.suite.helper.action.success + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/fail2ban.sh b/package/opt/hassbian/suites/fail2ban.sh deleted file mode 100644 index 6a0b35c0..00000000 --- a/package/opt/hassbian/suites/fail2ban.sh +++ /dev/null @@ -1,81 +0,0 @@ -#!/bin/bash -function fail2ban-show-short-info { - echo "Setup for fail2ban service." -} - -function fail2ban-show-long-info { - echo "This script installs the fail2ban service." - echo "Some further configuration is required after installation." -} - -function fail2ban-show-copyright-info { - echo "Original concept by Landrash ." -} - -function fail2ban-install-package { -echo "Installing fail2ban package" -apt install -y fail2ban - -FAIL2BANFILTER="/etc/fail2ban/filter.d/ha.conf" -FAIL2BANJAIL="/etc/fail2ban/jail.d/ha.conf" - -echo "Creating configuration files" -if [ -f $FAIL2BANFILTER ] ; then - echo "Configuration file exists. Skipping.." -else - -echo "[INCLUDES] -before = common.conf - -[Definition] -failregex = ^%(__prefix_line)s.*Login attempt or request with invalid authentication from .*$ -ignoreregex =" > "$FAIL2BANFILTER" - -fi - -if [ -f $FAIL2BANJAIL ] ; then - echo "Configuration file exists. Skipping.." -else - -echo "[DEFAULT] -# Email config -sender = email@address.com -destemail = email@address.com - -# Action %(action_mwl)s will ban the IP and send an email notification including whois data and log entries. -action = %(action_mwl)s - -[ha] -enabled = true -filter = ha -logpath = /home/homeassistant/.homeassistant/home-assistant.log - -# 3600 seconds = 1 hour -bantime = 3600 -#bantime = 30 # during testing it is useful to have a short ban interval, comment out this line later - -# Maximum amount of login attempts before IP is blocked -maxretry = 3" > "$FAIL2BANJAIL" -fi - -echo "Restarting fail2ban service" -systemctl restart fail2ban - -echo "Checking the installation..." -validation=$(which fail2ban-client) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done.\\e[0m" - echo - echo "To continue have a look at https://www.home-assistant.io/cookbook/fail2ban/" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/fail2ban/files/filter b/package/opt/hassbian/suites/fail2ban/files/filter new file mode 100644 index 00000000..0bd71b9f --- /dev/null +++ b/package/opt/hassbian/suites/fail2ban/files/filter @@ -0,0 +1,6 @@ +[INCLUDES] +before = common.conf + +[Definition] +failregex = ^%(__prefix_line)s.*Login attempt or request with invalid authentication from .*$ +ignoreregex = \ No newline at end of file diff --git a/package/opt/hassbian/suites/fail2ban/files/jail b/package/opt/hassbian/suites/fail2ban/files/jail new file mode 100644 index 00000000..c620bb3c --- /dev/null +++ b/package/opt/hassbian/suites/fail2ban/files/jail @@ -0,0 +1,19 @@ +[DEFAULT] +# Email config +sender = email@address.com +destemail = email@address.com + +# Action %(action_mwl)s will ban the IP and send an email notification including whois data and log entries. +action = %(action_mwl)s + +[ha] +enabled = true +filter = ha +logpath = /home/homeassistant/.homeassistant/home-assistant.log + +# 3600 seconds = 1 hour +bantime = 3600 +#bantime = 30 # during testing it is useful to have a short ban interval, comment out this line later + +# Maximum amount of login attempts before IP is blocked +maxretry = 3" \ No newline at end of file diff --git a/package/opt/hassbian/suites/fail2ban/install b/package/opt/hassbian/suites/fail2ban/install new file mode 100644 index 00000000..e838efd1 --- /dev/null +++ b/package/opt/hassbian/suites/fail2ban/install @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: DuckDNS +# + +function install { + local FAIL2BANFILTER + local FAIL2BANJAIL + + hassbian.suite.helper.install.apt fail2ban + + FAIL2BANFILTER="/etc/fail2ban/filter.d/ha.conf" + FAIL2BANJAIL="/etc/fail2ban/jail.d/ha.conf" + + echo "Creating configuration files..." + if [ -f $FAIL2BANFILTER ] ; then + echo "Configuration file exists. Skipping..." + else + cat "$HASSBIAN_SUITE_DIR/fail2ban/files/filter" > "$FAIL2BANFILTER" + fi + + if [ -f $FAIL2BANJAIL ] ; then + echo "Configuration file exists. Skipping.." + else + cat "$HASSBIAN_SUITE_DIR/fail2ban/files/jail" > "$FAIL2BANJAIL" + fi + + echo "Restarting fail2ban service" + systemctl restart fail2ban + + echo "Checking the installation..." + validation=$(command -v fail2ban-client) + if [ ! -z "${validation}" ]; then + hassbian.suite.helper.action.success + echo "To continue have a look at https://www.home-assistant.io/cookbook/fail2ban/" + echo + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/fail2ban/manifest b/package/opt/hassbian/suites/fail2ban/manifest new file mode 100644 index 00000000..49ea62c1 --- /dev/null +++ b/package/opt/hassbian/suites/fail2ban/manifest @@ -0,0 +1,9 @@ +{ + "name": "fail2ban", + "author": "Landrash ", + "short_description": "Setup for fail2ban service.", + "long_description": "This script installs the fail2ban service.\\nSome further configuration is required after installation.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/files/webterminalsslhelper.sh b/package/opt/hassbian/suites/files/webterminalsslhelper.sh deleted file mode 100644 index 6bec5d1f..00000000 --- a/package/opt/hassbian/suites/files/webterminalsslhelper.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -# Helper script for using LE certificates with Webterminal (shellinabox) -if [ -d "/etc/letsencrypt/live" ]; then - CERTDIR="/etc/letsencrypt/live/" -elif [ -d "/home/homeassistant/dehydrated/certs" ]; then - CERTDIR="/home/homeassistant/dehydrated/certs/" -else - CERTDIR="" -fi -DOMAIN=$(ls "$CERTDIR") -cat "$CERTDIR$DOMAIN/fullchain.pem" "$CERTDIR$DOMAIN/privkey.pem" > /var/lib/shellinabox/certificate-"$DOMAIN".pem -chown shellinabox:shellinabox -R /var/lib/shellinabox/ -service shellinabox reload -service shellinabox stop -service shellinabox start -exit 0 diff --git a/package/opt/hassbian/suites/hassbian-script.sh b/package/opt/hassbian/suites/hassbian-script.sh deleted file mode 100644 index 01cba55d..00000000 --- a/package/opt/hassbian/suites/hassbian-script.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -function hassbian-script-show-short-info { - echo "Hassbian-script upgrade script for Hassbian" -} - -function hassbian-script-show-long-info { - echo "Upgrade hassbian-scripts" -} - -function hassbian-script-show-copyright-info { - echo "Original concept by Ludeeus " -} - -function hassbian-script-upgrade-package { -if [ "$DEV" == "true" ]; then - echo "This script downloads new scripts directly from the dev branch on Github." - echo "you can use this to be on the 'bleeding edge of the development of Hassbian.'" - echo "This is not recommended for daily use." - echo -n "Are you really sure you want to continue? [N/y] : " - read -r RESPONSE - if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then - devbranch="-dev" - else - echo "Exiting..." - return 0 - fi -fi - -OSRELEASE=$(lsb_release -cs) - -echo "Updating apt information..." -echo "deb [trusted=yes] https://gitlab.com/hassbian/repository$devbranch/raw/master $OSRELEASE main" | tee /etc/apt/sources.list.d/hassbian.list -apt update - -echo "Checking installed version..." -current_version=$(apt list hassbian-scripts | tail -1 | awk -F'[' '{print $NF}' | awk -F']' '{print $1}') -if [ "$current_version" != "installed" ]; then - echo "Removing old version of hassbian-scripts..." - apt purge -y hassbian-scripts - apt clean - - echo "Installing newest version of hassbian-scripts..." - echo "deb [trusted=yes] https://gitlab.com/hassbian/repository$devbranch/raw/master $OSRELEASE main" | tee /etc/apt/sources.list.d/hassbian.list - apt update - apt install -y hassbian-scripts -else - echo "Installed version is up to date, exiting..." - return 0 -fi -systemctl daemon-reload - -echo -echo "Upgrade is now done." -echo -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/hassbian-script/files/dev b/package/opt/hassbian/suites/hassbian-script/files/dev new file mode 100644 index 00000000..bdfc1158 --- /dev/null +++ b/package/opt/hassbian/suites/hassbian-script/files/dev @@ -0,0 +1 @@ +[trusted=yes] https://gitlab.com/hassbian/repository-dev/raw/master %%OSRELEASE%% main \ No newline at end of file diff --git a/package/opt/hassbian/suites/hassbian-script/files/stable b/package/opt/hassbian/suites/hassbian-script/files/stable new file mode 100644 index 00000000..aa728503 --- /dev/null +++ b/package/opt/hassbian/suites/hassbian-script/files/stable @@ -0,0 +1 @@ +[trusted=yes] https://gitlab.com/hassbian/repository/raw/master %%OSRELEASE%% main \ No newline at end of file diff --git a/package/opt/hassbian/suites/hassbian-script/manifest b/package/opt/hassbian/suites/hassbian-script/manifest new file mode 100644 index 00000000..d654c9ac --- /dev/null +++ b/package/opt/hassbian/suites/hassbian-script/manifest @@ -0,0 +1,9 @@ +{ + "name": "Hassbian scripts", + "author": "Ludeeus ", + "short_description": "Hassbian-script upgrade script for Hassbian.", + "long_description": "Hassbian-script upgrade script for Hassbian", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/hassbian-script/upgrade b/package/opt/hassbian/suites/hassbian-script/upgrade new file mode 100644 index 00000000..cdbd763f --- /dev/null +++ b/package/opt/hassbian/suites/hassbian-script/upgrade @@ -0,0 +1,57 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Hassbian scripts +# + +function upgrade { + local branch + local infomsg + local response + local osrelease + + if [ "$HASSBIAN_RUNTIME_DEV" = true ]; then + infomsg="This script downloads new scripts directly from the dev branch on Github. + you can use this to be on the 'bleeding edge of the development of Hassbian.' + This is not recommended for daily use. + + Are you really sure you want to continue?" + response=$(hassbian.input.bool "$infomsg") + if [ "$response" == "0" ]; then + branch="dev" + else + echo "Exiting..." + return 0 + fi + else + branch='stable' + fi + + osrelease=$(hassbian.info.version.osreleasename) + + echo "Updating apt information..." + cat "$HASSBIAN_SUITE_DIR"/hassbian-script/files/"$branch" > /etc/apt/sources.list.d/hassbian.list + sed -i "s,%%OSRELEASE%%,${osrelease},g" /etc/apt/sources.list.d/hassbian.list + apt update + + echo "Checking installed version..." + current_version=$(apt list hassbian-scripts | tail -1 | awk -F'[' '{print $NF}' | awk -F']' '{print $1}') + if [ "$current_version" != "installed" ]; then + echo "Removing old version of hassbian-scripts..." + apt purge -y hassbian-scripts + apt clean + + echo "Installing newest version of hassbian-scripts..." + cat "$HASSBIAN_SUITE_DIR"/hassbian-script/files/"$branch" > /etc/apt/sources.list.d/hassbian.list + sed -i "s,%%OSRELEASE%%,${osrelease},g" /etc/apt/sources.list.d/hassbian.list + hassbian.suite.helper.install.apt hassbian-scripts + else + echo "Installed version is up to date, exiting..." + return 0 + fi + systemctl daemon-reload + + hassbian.suite.helper.action.success + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/hassbian.sh b/package/opt/hassbian/suites/hassbian.sh deleted file mode 100644 index d9f77a1a..00000000 --- a/package/opt/hassbian/suites/hassbian.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -function hassbian-show-short-info { - echo "Upgrade the base OS installation on this system." -} - -function hassbian-show-long-info { - echo "Upgrade the base OS installation on this system." -} - -function hassbian-show-copyright-info { - echo "Original concept by Ludeeus ." - echo "Modified by Landrash ." -} - -function hassbian-upgrade-package { -echo "Updating package list" -apt update - -echo "Upgrading base operating system" -apt upgrade -y - -echo -echo "Upgrade complete." -echo -echo "Note that you may need to reboot the raspberry Pi for some updates to take effect." -echo -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/hassbian/manifest b/package/opt/hassbian/suites/hassbian/manifest new file mode 100644 index 00000000..c62a4a09 --- /dev/null +++ b/package/opt/hassbian/suites/hassbian/manifest @@ -0,0 +1,10 @@ +{ + "name": "Hassbian", + "author": "Ludeeus ", + "short_description": "Upgrade the base OS installation on this system.", + "long_description": "Upgrade the base OS installation on this system.", + "unattended": true, + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/hassbian/upgrade b/package/opt/hassbian/suites/hassbian/upgrade new file mode 100644 index 00000000..f1c816ec --- /dev/null +++ b/package/opt/hassbian/suites/hassbian/upgrade @@ -0,0 +1,18 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Hassbian +# + +function upgrade { + echo "Updating package list" + apt update + + echo "Upgrading base operating system" + apt upgrade -y + + hassbian.suite.helper.action.success + echo "Note that you may need to reboot the raspberry Pi for some updates to take effect." + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/homeassistant.sh b/package/opt/hassbian/suites/homeassistant.sh deleted file mode 100644 index 458f83c0..00000000 --- a/package/opt/hassbian/suites/homeassistant.sh +++ /dev/null @@ -1,251 +0,0 @@ -#!/bin/bash -function homeassistant-show-short-info { - echo "Home Assistant install script for Hassbian." -} - -function homeassistant-show-long-info { - echo "Installs the base homeassistant package onto this system." -} - -function homeassistant-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function python-migration { - # Implemented to cope with the announced D-Day of Python 3.5 - # To track if this allready have been run, we create a file to hold that "state" - # /srv/homeassistant/hassbian/pythonmigration with HAVENV=pythonversion as the content. - - force="$1" - readonly pythonmigrationfile='/srv/homeassistant/hassbian/pythonmigration' - readonly targetpythonversion='3.7' - - # Get the current python version HA is running under. - CURRENTHAPYVERSION=$(currenthapyversion) - - # Check if the file exist - if [ ! -f "$pythonmigrationfile" ]; then - # file does not exist, let's create it (if we can). - echo "HAVENV=$CURRENTHAPYVERSION" > "$pythonmigrationfile" - fi - - # Checks to see if migration is needed. - pyversion=$(grep "HAVENV" $pythonmigrationfile | awk -F'=' '{print $2}') - if [[ "${pyversion:0:3}" == "$targetpythonversion" ]]; then - # Migration not needed. - return 0 - fi - - if [[ "${CURRENTHAPYVERSION:0:3}" == "$targetpythonversion" ]]; then - # Migration not needed. - if [ -n "${CURRENTHAPYVERSION}" ]; then - echo "HAVENV=$CURRENTHAPYVERSION" > "$pythonmigrationfile" - fi - return 0 - fi - - # We got here, a migration is needed. - echo "HAVENV=$CURRENTHAPYVERSION" > "$pythonmigrationfile" - echo - echo "A migration of your python virtual enviorment for Home Assistant will be needed." - echo "This will take about 1 hour on a raspberry pi 3." - echo - if [ "$force" != "true" ]; then - echo -n "Do you want to start this migration now? [N/y] : " - read -r RESPONSE - if [ "$RESPONSE" != "y" ] || [ "$RESPONSE" != "Y" ]; then - return 0 - fi - fi - echo " - - MIGRATION IN PROGRESS - THIS WILL TAKE A LONG TIME, IT IS IMPORTANT THAT YOU DO NOT INTERRUPT THIS - - - AFTER THIS MIGRATION YOUR HOME ASSISTANT INSTANCE WILL BE RUNNING UNDER PYTHON $targetpythonversion - - " - sleep 20 - # shellcheck disable=SC1091 - source /opt/hassbian/suites/python.sh - python-upgrade-package - echo "HAVENV=$(currenthapyversion)" > "$pythonmigrationfile" - # Quit when execution is done. - exit 0 - -} - -function homeassistant-install-package { -# Check if migration is needed. -python-migration true - -echo "Checking generation of local certificates " -c_rehash - -echo "Setting correct premissions" -chown homeassistant:homeassistant -R /srv/homeassistant - -echo "Changing to the homeassistant user" -sudo -u homeassistant -H /bin/bash << EOF - - echo "Creating Home Assistant venv" - python"${INSTALLEDPYTHON::-2}" -m venv /srv/homeassistant - - echo "Changing to Home Assistant venv" - source /srv/homeassistant/bin/activate - - echo "Installing latest version of Home Assistant" - python -m pip install setuptools wheel - python -m pip install homeassistant - - echo "Deactivating virtualenv" - deactivate -EOF - -echo "Enabling Home Assistant service" -systemctl enable home-assistant@homeassistant.service -sync - -echo "Disabling the Home Assistant install script" -systemctl disable install_homeassistant -systemctl daemon-reload - -echo "Starting Home Assistant" -systemctl start home-assistant@homeassistant.service - -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -echo "Checking the installation..." -validation=$(pgrep -x hass) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo "Your Home Assistant installation is running at $ip_address:8123 or if preferred http://hassbian.local:8123" - echo "To continue have a look at https://home-assistant.io/getting-started/configuration/" - echo - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -function homeassistant-upgrade-package { -# Check if migration is needed. -python-migration - -if [ "$DEV" == "true" ]; then - echo "This script downloads Home Assistant directly from the dev branch on Github." - echo "you can use this to be on the 'bleeding edge of the development of Home Assistant.'" - echo "This is not recommended for daily use." - echo -n "Are you really sure you want to continue? [N/y] : " - read -r RESPONSE - if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then - RESPONSE="Y" - else - echo "Exiting..." - return 0 - fi -else - echo "Checking current version" - if [ "$BETA" == "true" ]; then - newversion=$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases | grep tag_name | head -1 | awk -F'"' '{print $4}') - elif [ ! -z "${VERSIONNUMBER}" ]; then - verify=$(curl -s https://pypi.org/pypi/homeassistant/"$VERSIONNUMBER"/json) - if [[ "$verify" = *"Not Found"* ]]; then - echo "Version $VERSIONNUMBER not found..." - echo "Exiting..." - return 0 - else - newversion="$VERSIONNUMBER" - fi - else - newversion=$(curl -s https://api.github.com/repos/home-assistant/home-assistant/releases/latest | grep tag_name | awk -F'"' '{print $4}') - fi - sudo -u homeassistant -H /bin/bash << EOF | grep Version | awk '{print $2}'|while read -r version; do if [[ "${newversion}" == "${version}" ]]; then echo "You already have version: $version";exit 1;fi;done - source /srv/homeassistant/bin/activate - python3 -m pip show homeassistant -EOF - - if [[ $? == 1 ]]; then - echo "Stopping upgrade" - exit 1 - fi -fi - -echo "Setting correct premissions" -chown homeassistant:homeassistant -R /srv/homeassistant - -echo "Changing to the homeassistant user" -sudo -u homeassistant -H /bin/bash << EOF - -echo "Changing to Home Assistant venv" -source /srv/homeassistant/bin/activate - -echo "Upgrading Home Assistant" -python -m pip install --upgrade setuptools wheel -if [ "$DEV" == "true" ]; then - python -m pip install git+https://github.com/home-assistant/home-assistant@dev -elif [ "$BETA" == "true" ]; then - python -m pip install --upgrade --pre homeassistant -else - python -m pip install --upgrade homeassistant=="$newversion" -fi - -echo "Deactivating virtualenv" -deactivate -EOF - -if [ "$FORCE" != "true" ]; then - current_version=$(cat /home/homeassistant/.homeassistant/.HA_VERSION) - config_check=$(sudo -u homeassistant -H /bin/bash << EOF - source /srv/homeassistant/bin/activate - hass --script check_config -c /home/homeassistant/.homeassistant/ -EOF - ) - config_check_lines=$(echo "$config_check" | wc -l) - if (( config_check_lines > 2 ));then - if [ "$ACCEPT" != "true" ]; then - echo "$config_check" - echo -n "Config check failed for new version, do you want to revert? [Y/n] : " - read -r RESPONSE - if [ ! "$RESPONSE" ]; then - RESPONSE="Y" - fi - else - RESPONSE="Y" - fi - if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then - sudo -u homeassistant -H /bin/bash << EOF - source /srv/homeassistant/bin/activate - python -m pip install --upgrade homeassistant=="$current_version" - deactivate -EOF - fi - fi -fi - -echo "Restarting Home Assistant" -systemctl restart home-assistant@homeassistant.service - -echo "Checking the installation..." -validation=$(pgrep -x hass) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mUpgrade script completed..\\e[0m" - echo "Note that it may take some time to start up after an upgrade." - echo -else - echo - echo -e "\\e[31mUpgrade failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/homeassistant/install b/package/opt/hassbian/suites/homeassistant/install new file mode 100644 index 00000000..e52df2f2 --- /dev/null +++ b/package/opt/hassbian/suites/homeassistant/install @@ -0,0 +1,55 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Home Assistant +# + +function install { + local ip_address + local validation + local pythonversion + + # Check if migration is needed. + source "$HASSBIAN_SUITE_DIR/homeassistant/python-migration" + python-migration true # 'true' forces the migration to run. + + echo "Checking generation of local certificates " + c_rehash + + echo "Setting correct premissions" + chown homeassistant:homeassistant -R "$HOME_ASSISTANT_VENV" + + pythonversion=$(hassbian.info.version.python) + + echo "Creating Home Assistant venv" + sudo -u homeassistant -H /bin/bash << EOF + python"$pythonversion" -m venv $HOME_ASSISTANT_VENV +EOF + + hassbian.suite.helper.install.pip homeassistant + + echo "Enabling Home Assistant service" + systemctl enable home-assistant@homeassistant.service + sync + + echo "Disabling the Home Assistant install script" + systemctl disable install_homeassistant + systemctl daemon-reload + + echo "Starting Home Assistant" + systemctl start home-assistant@homeassistant.service + + echo "Checking the installation..." + validation=$(hassbian.suite.verify.service home-assistant@homeassistant.service) + if [ "$validation" == "0" ]; then + ip_address=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Your Home Assistant installation is running at $ip_address:8123 or if preferred http://hassbian.local:8123" + echo "To continue have a look at https://home-assistant.io/getting-started/configuration/" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/homeassistant/manifest b/package/opt/hassbian/suites/homeassistant/manifest new file mode 100644 index 00000000..a43d835f --- /dev/null +++ b/package/opt/hassbian/suites/homeassistant/manifest @@ -0,0 +1,9 @@ +{ + "name": "Home Assistant", + "author": "Lindqvist ", + "short_description": "Home Assistant install script for Hassbian.", + "long_description": "Installs the base homeassistant package onto this system.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/homeassistant/python-migration b/package/opt/hassbian/suites/homeassistant/python-migration new file mode 100644 index 00000000..96bf039c --- /dev/null +++ b/package/opt/hassbian/suites/homeassistant/python-migration @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Python migration check script for Hassbian suite: Home Assistant +# + +# shellcheck disable=SC1090 + +function python-migration { + # Implemented to cope with the announced D-Day of Python 3.5 + # To track if this allready have been run, we create a file to hold that "state" + # /srv/homeassistant/hassbian/pythonmigration with HAVENV=pythonversion as the content. + readonly pythonmigrationfile="$HOME_ASSISTANT_VENV/hassbian/pythonmigration" + readonly targetpythonversion="3.7" + local force + local pyversion + local currenthapyversion + local infomsg + local response + + force="$1" + + # Get the current python version HA is running under. + currenthapyversion=$(hassbian.info.version.homeassistant.python) + + # Check if the file exist + if [ ! -f "$pythonmigrationfile" ]; then + # file does not exist, let's create it (if we can). + echo "HAVENV=$currenthapyversion" > "$pythonmigrationfile" + fi + + # Checks to see if migration is needed. + pyversion=$(grep "HAVENV" "$pythonmigrationfile" | awk -F'=' '{print $2}') + if [[ "${pyversion:0:3}" == "$targetpythonversion" ]]; then + # Migration not needed. + return 0 + fi + + if [[ "${currenthapyversion:0:3}" == "$targetpythonversion" ]]; then + # Migration not needed. + echo "HAVENV=$currenthapyversion" > "$pythonmigrationfile" + return 0 + fi + + # We got here, a migration is needed. + echo "HAVENV=$currenthapyversion" > "$pythonmigrationfile" + if [ "$force" != "true" ]; then + infomsg="A migration of your python virtual enviorment for Home Assistant will be needed. + This will take about 1 hour on a raspberry pi 3. + + Do you want to start this migration now?" + response=$(hassbian.input.bool "$infomsg") + if [ "$response" != "0" ]; then + return 0 + fi + fi + echo " + + MIGRATION IN PROGRESS + THIS WILL TAKE A LONG TIME, IT IS IMPORTANT THAT YOU DO NOT INTERRUPT THIS + + + AFTER THIS MIGRATION YOUR HOME ASSISTANT INSTANCE WILL BE RUNNING UNDER PYTHON $targetpythonversion + + " + sleep 20 # To give the user the option to panic and abort thr progress. + source "$HASSBIAN_SUITE_DIR/python/install" + install + echo "HAVENV=$currenthapyversion" > "$pythonmigrationfile" + exit +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/homeassistant/upgrade b/package/opt/hassbian/suites/homeassistant/upgrade new file mode 100644 index 00000000..fc8aed2c --- /dev/null +++ b/package/opt/hassbian/suites/homeassistant/upgrade @@ -0,0 +1,106 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Template +# + +function upgrade { + local ip_address + local validation + local pythonversion + local infomsg + local response + local newversion + local current_version + local config_check_lines + + # Check if migration is needed. + source "$HASSBIAN_SUITE_DIR/homeassistant/python-migration" + python-migration + + if [ "$HASSBIAN_RUNTIME_DEV" = true ]; then + infomsg="This script downloads Home Assistant directly from the dev branch on Github. + you can use this to be on the 'bleeding edge of the development of Home Assistant.' + This is not recommended for daily use. + + Are you really sure you want to continue?" + response=$(hassbian.input.bool "$infomsg") + if [ "$response" != "0" ]; then + hassbian.suite.helper.action.failed + exit + fi + fi + + echo "Checking current version" + if [ "$HASSBIAN_RUNTIME_BETA" = true ]; then + newversion=$(hassbian.info.version.homeassistant.github) + + elif [ ! -z "${HASSBIAN_RUNTIME_TARGET_VERSION}" ]; then + verify=$(curl -s https://pypi.org/pypi/homeassistant/"$HASSBIAN_RUNTIME_TARGET_VERSION"/json) + if [[ "$verify" = *"Not Found"* ]]; then + echo "Version $HASSBIAN_RUNTIME_TARGET_VERSION not found..." + hassbian.suite.helper.action.failed + exit + else + newversion="$HASSBIAN_RUNTIME_TARGET_VERSION" + fi + + else + newversion=$(hassbian.info.version.homeassistant.pypi) + fi + + # Check if we need an update. + if [[ "$newversion" == "$(hassbian.info.version.homeassistant.installed)" ]]; then + echo "You already have version: $newversion" + hassbian.suite.helper.action.success + exit + fi + + echo "Setting correct premissions" + chown homeassistant:homeassistant -R /srv/homeassistant + + echo "Upgrading Home Assistant" + if [ "$HASSBIAN_RUNTIME_DEV" = true ]; then + hassbian.suite.helper.install.pip git+https://github.com/home-assistant/home-assistant@dev + elif [ "$HASSBIAN_RUNTIME_BETA" = true ]; then + hassbian.suite.helper.install.pip --pre homeassistant + else + hassbian.suite.helper.install.pip homeassistant=="$newversion" + fi + + if [ "$HASSBIAN_RUNTIME_FORCE" = false ]; then + current_version=$(cat /home/homeassistant/.homeassistant/.HA_VERSION) + config_check=$(sudo -u homeassistant -H /bin/bash << EOF + source $HOME_ASSISTANT_VENV/bin/activate + hass --script check_config -c /home/homeassistant/.homeassistant/ +EOF + ) + config_check_lines=$(echo "$config_check" | wc -l) + if (( config_check_lines > 2 ));then + if [ "$HASSBIAN_RUNTIME_ACCEPT" = false ]; then + echo "$config_check" + hassbian.input.info "$config_check" + infomsg="Config check failed for new version, do you want to revert?" + response=$(hassbian.input.bool "$infomsg") + if [ "$response" == "0" ]; then + hassbian.suite.helper.install.pip homeassistant=="$current_version" + fi + fi + fi + fi + + echo "Restarting Home Assistant" + systemctl restart home-assistant@homeassistant.service + + echo "Checking the installation..." + validation=$(hassbian.suite.verify.service home-assistant@homeassistant.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + echo "Note that it may take some time to start up after an upgrade." + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/hue.sh b/package/opt/hassbian/suites/hue.sh deleted file mode 100644 index 0f737d7f..00000000 --- a/package/opt/hassbian/suites/hue.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -function hue-show-short-info { - echo "Echo/Mycroft Emulated Hue install script for Hassbian." -} - -function hue-show-long-info { - echo "Configures the Python executable to allow usage of low numbered" - echo "ports for use with Amazon Echo or Mycroft.ai." -} - -function hue-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function hue-install-package { -echo "Setting permissions for Python." -PYTHONVER=$(echo /usr/lib/*python* | awk -F/ '{print $NF}') -setcap 'cap_net_bind_service=+ep' /usr/bin/"$PYTHONVER" - -echo "Checking the installation..." -validation=$(getcap /usr/bin/"$PYTHONVER" | awk -F'= ' '{print $NF}') -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo - echo "To continue have a look at https://home-assistant.io/components/emulated_hue/" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/hue/install b/package/opt/hassbian/suites/hue/install new file mode 100644 index 00000000..d526a2f3 --- /dev/null +++ b/package/opt/hassbian/suites/hue/install @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Hue +# + +function install { + local pythonlocation + + echo "Setting permissions for Python..." + pythonlocation=$(hassbian.info.general.python.location) + setcap 'cap_net_bind_service=+ep' "$pythonlocation" + + echo "Checking the installation..." + validation=$(getcap "$pythonlocation" | awk -F'= ' '{print $NF}') + if [ ! -z "${validation}" ]; then + hassbian.suite.helper.action.success + echo "To continue have a look at https://home-assistant.io/components/emulated_hue/" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/hue/manifest b/package/opt/hassbian/suites/hue/manifest new file mode 100644 index 00000000..31cf3a4b --- /dev/null +++ b/package/opt/hassbian/suites/hue/manifest @@ -0,0 +1,9 @@ +{ + "name": "Hue", + "author": "Landrash ", + "short_description": "Echo/Mycroft Emulated Hue install script for Hassbian.", + "long_description": "Configures the Python executable to allow usage of low numbered\\nports for use with Amazon Echo or Mycroft.ai.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/libcec.sh b/package/opt/hassbian/suites/libcec.sh deleted file mode 100644 index c2139bee..00000000 --- a/package/opt/hassbian/suites/libcec.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash - -function libcec-show-short-info { - echo "libcec install script for Hassbian." -} - -function libcec-show-long-info { - echo "Installs the libcec package for controlling CEC devices from this Pi." -} - -function libcec-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function libcec-install-package { -echo "Running apt-get preparation" -apt-get update -apt-get install -y cmake libudev-dev libxrandr-dev swig - -echo "Changing to homeassistant user" -sudo -u homeassistant -H /bin/bash <", + "short_description": "libcec install script for Hassbian.", + "long_description": "Installs the libcec package for controlling CEC devices from this Pi.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/manager.sh b/package/opt/hassbian/suites/manager.sh deleted file mode 100644 index b3912d59..00000000 --- a/package/opt/hassbian/suites/manager.sh +++ /dev/null @@ -1,109 +0,0 @@ -#!/bin/bash -function manager-show-short-info { - echo "Hassbian manager script." -} - -function manager-show-long-info { - echo "Hassbian manager is a web UI tool that can help you manage your suites." -} - -function manager-show-copyright-info { - echo "Original concept by Ludeeus ." -} - -function manager-install-package { - -if [ "$ACCEPT" == "true" ]; then - username=pi - password=raspberry -else - echo - echo "Please take a moment to setup your the user account" - echo - - echo -n "Username: " - read -r username - if [ ! "$username" ]; then - username=pi - fi - - echo -n "Password: " - read -s -r password - echo - if [ ! "$password" ]; then - password=raspberry - fi -fi - -echo "Installing latest version of Hassbian manager" -python3 -m pip install setuptools wheel -python3 -m pip install pyhassbian - - -echo "Enabling Hassbian manager service" -cp /opt/hassbian/suites/files/hassbian-manager@homeassistant.service /etc/systemd/system/hassbian-manager@homeassistant.service - -sed -i "s,%%USERNAME%%,${username},g" /etc/systemd/system/hassbian-manager@homeassistant.service -sed -i "s,%%PASSWORD%%,${password},g" /etc/systemd/system/hassbian-manager@homeassistant.service - -systemctl enable hassbian-manager@homeassistant.service -sync - -echo "Starting Hassbian manager" -systemctl start hassbian-manager@homeassistant.service - -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -echo "Checking the installation..." -validation=$(pgrep -x pyhassbian) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo "Hassbian manager installation is running at $ip_address:9999 or if preferred http://hassbian.local:9999" - echo - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -function manager-upgrade-package { -echo "Upgrading Hassbian manager" -python3 -m pip install --upgrade pyhassbian - -echo "Restarting Hassbian manager" -systemctl start hassbian-manager@homeassistant.service - -echo "Checking the installation..." -validation=$(pgrep -x pyhassbian) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mUpgrade script completed..\\e[0m" - echo -else - echo - echo -e "\\e[31mUpgrade failed..." - echo - return 1 -fi -return 0 -} - -function manager-remove-package { -printf "Removing Hassbian manager...\\n" -systemctl stop hassbian-manager@homeassistant.service -systemctl disable hassbian-manager@homeassistant.service -rm /etc/systemd/system/hassbian-manager@homeassistant.service -sync - -echo "Removing Hassbian manager" -python3 -m pip uninstall --yes pyhassbian - -printf "\\e[32mRemoval done..\\e[0m\\n" -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/files/hassbian-manager@homeassistant.service b/package/opt/hassbian/suites/manager/files/hassbian-manager@homeassistant.service similarity index 100% rename from package/opt/hassbian/suites/files/hassbian-manager@homeassistant.service rename to package/opt/hassbian/suites/manager/files/hassbian-manager@homeassistant.service diff --git a/package/opt/hassbian/suites/manager/install b/package/opt/hassbian/suites/manager/install new file mode 100644 index 00000000..0abcbf7d --- /dev/null +++ b/package/opt/hassbian/suites/manager/install @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Hassbian manager +# + +function install { + local ipaddress + local validation + local username + local password + + if [ "$HASSBIAN_RUNTIME_ACCEPT" = true ]; then + username='pi' + password='raspberry' + else + hassbian.input.info "Please take the time to setup your account" + username=$(hassbian.input.text "Username:") + password=$(hassbian.input.text "Password:") + if [ "$username" == "0" ]; then + username='pi' + fi + if [ "$password" == "0" ]; then + password='raspberry' + fi + fi + + echo "Installing latest version of Hassbian manager..." + hassbian.suite.helper.install.pip pyhassbian + + echo "Enabling Hassbian manager service..." + cp /opt/hassbian/suites/manager/files/hassbian-manager@homeassistant.service /etc/systemd/system/hassbian-manager@homeassistant.service + + sed -i "s,%%USERNAME%%,${username},g" /etc/systemd/system/hassbian-manager@homeassistant.service + sed -i "s,%%PASSWORD%%,${password},g" /etc/systemd/system/hassbian-manager@homeassistant.service + + systemctl enable hassbian-manager@homeassistant.service + sync + + echo "Starting Hassbian manager..." + systemctl start hassbian-manager@homeassistant.service + + validation=$(hassbian.suite.verify.service hassbian-manager@homeassistant.service) + if [ "$validation" == "0" ]; then + ipaddress=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Hassbian manager installation is running at http://$ipaddress:9999 or if preferred http://hassbian.local:9999" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/manager/manifest b/package/opt/hassbian/suites/manager/manifest new file mode 100644 index 00000000..146d4ed2 --- /dev/null +++ b/package/opt/hassbian/suites/manager/manifest @@ -0,0 +1,9 @@ +{ + "name": "Hassbian manager", + "author": "Ludeeus ", + "short_description": "Hassbian manager script.", + "long_description": "Hassbian manager is a web UI tool that can help you manage your suites.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/manager/remove b/package/opt/hassbian/suites/manager/remove new file mode 100644 index 00000000..c37364b1 --- /dev/null +++ b/package/opt/hassbian/suites/manager/remove @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Uninstallation script for Hassbian suite: Hassbian manager +# + +function remove { + echo "Removing Hassbian manager..." + systemctl stop hassbian-manager@homeassistant.service + systemctl disable hassbian-manager@homeassistant.service + rm /etc/systemd/system/hassbian-manager@homeassistant.service + sync + + echo "Removing Hassbian manager" + python3 -m pip uninstall --yes pyhassbian + + hassbian.suite.helper.action.success +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/manager/upgrade b/package/opt/hassbian/suites/manager/upgrade new file mode 100644 index 00000000..c3b11b59 --- /dev/null +++ b/package/opt/hassbian/suites/manager/upgrade @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Hassbian manager +# + +function upgrade { + echo "UpgradingHassbian manager" + hassbian.suite.helper.install.pip pyhassbian + + echo "Restarting Hassbian manager" + systemctl restart hassbian-manager@homeassistant.service + + validation=$(hassbian.suite.verify.service hassbian-manager@homeassistant.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/mariadb.sh b/package/opt/hassbian/suites/mariadb.sh deleted file mode 100644 index 589e278f..00000000 --- a/package/opt/hassbian/suites/mariadb.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash - -function mariadb-show-short-info { - echo "MariaDB install script for Hassbian." -} - -function mariadb-show-long-info { - echo "Installs the MariaDB database engine and dependecies for use with the recorder component in Home Assistant." -} - -function mariadb-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function mariadb-install-package { -echo "Running apt-get preparation" -apt-get update -apt-get install -y mariadb-server libmariadbclient-dev default-libmysqlclient-dev - -echo "Changing to homeassistant user" -sudo -u homeassistant -H /bin/bash <", + "short_description": "MariaDB install script for Hassbian.", + "long_description": "Installs the MariaDB database engine and dependecies for use with the recorder component in Home Assistant.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/monitor.sh b/package/opt/hassbian/suites/monitor.sh deleted file mode 100644 index 690ccf14..00000000 --- a/package/opt/hassbian/suites/monitor.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/bin/bash -function monitor-show-short-info { - echo "Setup for Monitor. Bluetooth-based passive presence detection." -} - -function monitor-show-long-info { - echo "This script installs Monitor a script for Bluetooth-based passive presence detection." - echo "The Mosquitto suite will also be installed since it's a dependency for Monitor." - echo "This script also optionaly installs a service that can be enabled to run Monitor." -} - -function monitor-show-copyright-info { - echo "Original concept by Landrash ." -} - -function monitor-install-package { -echo -n "Installing Mosquitto package: " - -echo "Checking the installation..." -validation=$(pgrep -f mosquitto) -if [ ! -z "${validation}" ]; then - echo "Existing Mosquitto install detected. Skipping install of Mosquitto." -else - echo "Installing Mosquitto" -hassbian-config install mosquitto --accept -fi - -echo "Creating Monitor folder..." -mkdir /opt/monitor || exit -cd /opt || exit - -echo "Cloning Monitor git repository" -git clone git://github.com/andrewjfreyer/monitor - -echo "Running interactive setup" -cd /opt/monitor || exit -chmod +x /opt/monitor/monitor.sh || exit -bash /opt/monitor/monitor.sh - -echo "Checking the installation..." -if [ ! -f /opt/monitor/monitor.sh ]; then - validation="" -else - validation="ok" -fi - -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo -e "Update of mqtt_preferences is required found at /opt/monitor/mqtt_prefences" - echo -e "Some further configuration is required and details can be found here https://github.com/andrewjfreyer/monitor#getting-started " - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/monitor/install b/package/opt/hassbian/suites/monitor/install new file mode 100644 index 00000000..8c068c09 --- /dev/null +++ b/package/opt/hassbian/suites/monitor/install @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Monitor +# + +function install { + local validation + + echo "Installing Mosquitto package: " + + echo "Checking the installation..." + validation=$(pgrep -f mosquitto) + if [ ! -z "${validation}" ]; then + echo "Existing Mosquitto install detected. Skipping install of Mosquitto." + else + echo "Installing Mosquitto" + hassbian-config install mosquitto --accept + fi + + echo "Creating Monitor folder..." + mkdir /opt/monitor || exit + cd /opt || exit + + echo "Cloning Monitor git repository" + git clone git://github.com/andrewjfreyer/monitor + + echo "Running interactive setup" + cd /opt/monitor || exit + chmod +x /opt/monitor/monitor.sh || exit + bash /opt/monitor/monitor.sh + + echo "Checking the installation..." + if [ -f /opt/monitor/monitor.sh ]; then + validation="ok" + fi + + if [ ! -z "${validation}" ]; then + hassbian.suite.helper.action.success + echo "Update of mqtt_preferences is required found at /opt/monitor/mqtt_prefences" + echo "Some further configuration is required and details can be found here https://github.com/andrewjfreyer/monitor#getting-started " + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/monitor/manifest b/package/opt/hassbian/suites/monitor/manifest new file mode 100644 index 00000000..d9a10a8f --- /dev/null +++ b/package/opt/hassbian/suites/monitor/manifest @@ -0,0 +1,9 @@ +{ + "name": "Monitor", + "author": "Landrash ", + "short_description": "Setup for Monitor. Bluetooth-based passive presence detection.", + "long_description": "This script installs Monitor a script for Bluetooth-based passive presence detection.\\nThe Mosquitto suite will also be installed since it's a dependency for Monitor.\\nThis script also optionaly installs a service that can be enabled to run Monitor.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/mosquitto.sh b/package/opt/hassbian/suites/mosquitto.sh deleted file mode 100644 index e22a814c..00000000 --- a/package/opt/hassbian/suites/mosquitto.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash - -function mosquitto-show-short-info { - echo "Mosquitto Installer for Hassbian." -} - -function mosquitto-show-long-info { - echo "Installs the Mosquitto package for setting up a local MQTT server." -} - -function mosquitto-show-copyright-info { - echo "Copyright(c) 2016 Dale Higgs ." - echo "Modified by Landrash for use with Hassbian." -} - -function mosquitto-install-package { -if [ "$ACCEPT" == "true" ]; then - mqtt_username=pi - mqtt_password=raspberry -else - echo - echo "Please take a moment to setup your first MQTT user" - echo - - echo -n "Username: " - read -r mqtt_username - if [ ! "$mqtt_username" ]; then - mqtt_username=pi - fi - - echo -n "Password: " - read -s -r mqtt_password - echo - if [ ! "$mqtt_password" ]; then - mqtt_password=raspberry - fi -fi - -echo "Adding mosquitto user" -adduser mosquitto --system --group - -echo "Creating pid file" -touch /var/run/mosquitto.pid -chown mosquitto:mosquitto /var/run/mosquitto.pid - -echo "Creating data directory" -mkdir -p /var/lib/mosquitto -chown mosquitto:mosquitto /var/lib/mosquitto - -echo "Installing repository key" -wget -O - http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key | apt-key add - - -echo "Adding repository" -if [ ! -f /etc/apt/sources.list.d/mosquitto-stretch.list ] -then - curl -o /etc/apt/sources.list.d/mosquitto-stretch.list http://repo.mosquitto.org/debian/mosquitto-stretch.list -else - echo "Already present, skipping..." -fi - - -echo "Installing mosquitto" -apt-get update -apt-cache search mosquitto -apt-get install -y mosquitto mosquitto-clients - -echo "Writing default configuration" -cd /etc/mosquitto || exit -mv mosquitto.conf mosquitto.conf.backup -cp /opt/hassbian/suites/files/mosquitto.conf /etc/mosquitto/mosquitto.conf -chown mosquitto:mosquitto mosquitto.conf - -echo "Initializing password file" -touch pwfile -chown mosquitto:mosquitto pwfile -chmod 0600 pwfile - -echo "Creating password entry for user $mqtt_username" -mosquitto_passwd -b pwfile "$mqtt_username" "$mqtt_password" - -echo "Restarting Mosquitto service" -systemctl restart mosquitto.service - -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -echo "Checking the installation..." -validation=$(pgrep -f mosquitto) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done.\\e[0m" - echo - echo "Your MQTT broker is running at $ip_address:1883 or if preferred hassbian.local:1883" - echo "" - echo "To continue have a look at https://home-assistant.io/docs/mqtt/" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/files/mosquitto.conf b/package/opt/hassbian/suites/mosquitto/files/mosquitto.conf similarity index 100% rename from package/opt/hassbian/suites/files/mosquitto.conf rename to package/opt/hassbian/suites/mosquitto/files/mosquitto.conf diff --git a/package/opt/hassbian/suites/mosquitto/install b/package/opt/hassbian/suites/mosquitto/install new file mode 100644 index 00000000..772ade8a --- /dev/null +++ b/package/opt/hassbian/suites/mosquitto/install @@ -0,0 +1,81 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Mosquitto +# + +function install { + local mqtt_username + local mqtt_password + local validation + local ip_address + + if [ "$HASSBIAN_RUNTIME_ACCEPT" = true ]; then + mqtt_username='pi' + mqtt_password='raspberry' + else + hassbian.input.info "Please take a moment to setup your first MQTT user" + mqtt_username=$(hassbian.input.text "Username:") + mqtt_password=$(hassbian.input.text "Password:") + if [ "$mqtt_username" == "0" ]; then + mqtt_username='pi' + fi + if [ "$mqtt_password" == "0" ]; then + mqtt_password='raspberry' + fi + fi + echo "Adding mosquitto user" + adduser mosquitto --system --group + + echo "Creating pid file" + touch /var/run/mosquitto.pid + chown mosquitto:mosquitto /var/run/mosquitto.pid + + echo "Creating data directory" + mkdir -p /var/lib/mosquitto + chown mosquitto:mosquitto /var/lib/mosquitto + + echo "Installing repository key" + wget -O - http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key | apt-key add - + + echo "Adding repository" + if [ ! -f /etc/apt/sources.list.d/mosquitto-stretch.list ] + then + curl -o /etc/apt/sources.list.d/mosquitto-stretch.list http://repo.mosquitto.org/debian/mosquitto-stretch.list + else + echo "Already present, skipping..." + fi + + hassbian.suite.helper.install.apt mosquitto mosquitto-clients + + echo "Writing default configuration" + cd /etc/mosquitto || exit + mv mosquitto.conf mosquitto.conf.backup + cp /opt/hassbian/suites/mosquitto/files/mosquitto.conf /etc/mosquitto/mosquitto.conf + chown mosquitto:mosquitto mosquitto.conf + + echo "Initializing password file" + touch pwfile + chown mosquitto:mosquitto pwfile + chmod 0600 pwfile + + echo "Creating password entry for user $mqtt_username" + mosquitto_passwd -b pwfile "$mqtt_username" "$mqtt_password" + + echo "Restarting Mosquitto service" + systemctl restart mosquitto.service + + validation=$(hassbian.suite.verify.pgrep mosquitto) + if [ "$validation" == "0" ]; then + ip_address=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Your MQTT broker is running at $ip_address:1883 or if preferred hassbian.local:1883" + echo + echo "To continue have a look at https://home-assistant.io/docs/mqtt/" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/mosquitto/manifest b/package/opt/hassbian/suites/mosquitto/manifest new file mode 100644 index 00000000..0cae50a8 --- /dev/null +++ b/package/opt/hassbian/suites/mosquitto/manifest @@ -0,0 +1,9 @@ +{ + "name": "Mosquitto", + "author": "Landrash ", + "short_description": "Mosquitto Installer for Hassbian.", + "long_description": "Installs the Mosquitto package for setting up a local MQTT server.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/mssql.sh b/package/opt/hassbian/suites/mssql.sh deleted file mode 100644 index 36845e8f..00000000 --- a/package/opt/hassbian/suites/mssql.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -function mssql-show-short-info { - echo "MS SQL install script for Hassbian." -} - -function mssql-show-long-info { - echo "Installs the MS SQL database engine and dependencies for use with the recorder component in Home Assistant." -} - -function mssql-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function mssql-install-package { -echo "Running apt-get preparation" -apt-get update -apt-get install -y freetds-dev - - -echo "Changing to homeassistant user" -sudo -u homeassistant -H /bin/bash <", + "short_description": "MS SQL install script for Hassbian.", + "long_description": "Installs the MS SQL database engine and dependencies for use with the recorder component in Home Assistant.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/mysql.sh b/package/opt/hassbian/suites/mysql.sh deleted file mode 100644 index 844aa51f..00000000 --- a/package/opt/hassbian/suites/mysql.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -function mysql-show-short-info { - echo "MySQL install script for Hassbian." -} - -function mysql-show-long-info { - echo "Installs the MySQL database engine and dependecies for use with the recorder component in Home Assistant." -} - -function mysql-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function mysql-install-package { -echo "Running apt-get preparation" -apt-get update -apt-get install -y default-libmysqlclient-dev libssl-dev - -echo "Changing to homeassistant user" -sudo -u homeassistant -H /bin/bash <", + "short_description": "MySQL install script for Hassbian.", + "long_description": "Installs the MySQL database engine and dependecies for use with the recorder component in Home Assistant.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/pihole.sh b/package/opt/hassbian/suites/pihole.sh deleted file mode 100644 index e5e9adb9..00000000 --- a/package/opt/hassbian/suites/pihole.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -function pihole-show-short-info { - echo "Downloads and runs the Pi-hole install script." -} - -function pihole-show-long-info { - echo "This script downloads and runs the Pi-hole install script" - echo "All credit for the install script goes to the Pi-hole authors." -} - -function pihole-show-copyright-info { - echo "Original concept by Landrash ." -} - -function pihole-install-package { -echo -n "Downloading Pi-hole install script: " -mkdir /tmp/pihole || exit -cd /tmp/pihole || exit -wget -O basic-install.sh https://install.pi-hole.net - -echo "Running interactive setup" -cd /tmp/pihole || exit -chmod +x /tmp/pihole/basic-install.sh || exit -bash /tmp/pihole/basic-install.sh - -echo "Checking the installation..." -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -echo "Checking the installation..." -validation=$(pgrep -f pihole) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done.\\e[0m" - echo - echo "Your Pi-Hole instance is running at $ip_address or if preferred hassbian.local" - echo - else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/pihole/install b/package/opt/hassbian/suites/pihole/install new file mode 100644 index 00000000..378455db --- /dev/null +++ b/package/opt/hassbian/suites/pihole/install @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Pi-Hole +# + +function install { + local ipaddress + local validation + + echo "Downloading Pi-hole install script..." + mkdir /tmp/pihole || exit + cd /tmp/pihole || exit + wget -O basic-install.sh https://install.pi-hole.net + + echo "Running interactive setup..." + cd /tmp/pihole || exit + chmod +x /tmp/pihole/basic-install.sh || exit + bash /tmp/pihole/basic-install.sh + + echo "Checking the installation..." + validation=$(hassbian.suite.verify.pgrep pihole) + + if [ "${validation}" ]; then + ipaddress=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Your Pi-Hole instance is running at $ipaddress or if preferred hassbian.local" + else + hassbian.suite.helper.action.failed + return 1 + fi + + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/pihole/manifest b/package/opt/hassbian/suites/pihole/manifest new file mode 100644 index 00000000..3c739eab --- /dev/null +++ b/package/opt/hassbian/suites/pihole/manifest @@ -0,0 +1,9 @@ +{ + "name": "Pi-Hole", + "author": "Landrash ", + "short_description": "Downloads and runs the Pi-hole install script.", + "long_description": "This script downloads and runs the Pi-hole install script.\\nAll credit for the install script goes to the Pi-hole authors.", + "blocked": true, + "blocked_releasename": "buster", + "blocked_message": "Due to an upstream issue with pihole we can not install this suite at this time.\\nFor more information about this, see https://github.com/home-assistant/hassbian-scripts/issues/XXX" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/postgresql.sh b/package/opt/hassbian/suites/postgresql.sh deleted file mode 100644 index 2e93b66b..00000000 --- a/package/opt/hassbian/suites/postgresql.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -function postgresql-show-short-info { - echo "PostgreSQL install script for Hassbian." -} - -function postgresql-show-long-info { - echo "Installs the PostgreSQL database engine and dependencies for use with the recorder component in Home Assistant." -} - -function postgresql-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function postgresql-install-package { -echo "Running apt-get preparation" -apt-get update - -if [ "$(lsb_release -cs)" == "stretch" ]; then - apt-get install -y postgresql-server-dev-9.6 postgresql-9.6 -else - apt-get install -y postgresql-server-dev-11 postgresql-11 -fi - -echo "Changing to homeassistant user" -sudo -u homeassistant -H /bin/bash <", + "short_description": "PostgreSQL install script for Hassbian.", + "long_description": "Installs the PostgreSQL database engine and dependencies for use with the recorder component in Home Assistant.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/python.sh b/package/opt/hassbian/suites/python.sh deleted file mode 100644 index 8bf754d6..00000000 --- a/package/opt/hassbian/suites/python.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash -function python-show-short-info { - echo "Upgrades python3 and virtual environment to the newest stable version." -} - -function python-show-long-info { - echo "Upgrades python3 and virtual environment to the newest stable version." -} - -function python-show-copyright-info { - echo "This script was originally contributed by Ludeeus ." -} - -function python-upgrade-package { - -PYTHONVERSION=$(curl -s https://www.python.org/downloads/source/ | grep "Latest Python 3 Release" | cut -d "<" -f 3 | awk -F ' ' '{print $NF}') - -echo "Checking current version..." -hapyversion=$(currenthapyversion) - -if [ "$hapyversion" == "$PYTHONVERSION" ]; then - echo "Python is already the highest stable version.." - return 0 -fi - -isinstalled="$(command -v python"${PYTHONVERSION:0:3}")" -if [ -z "${isinstalled}" ]; then - echo "Upgrading to Python $PYTHONVERSION" - apt-get -y update - apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev - apt-get install libtcmalloc-minimal4 - export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4" - cd /tmp || return 1 - wget https://www.python.org/ftp/python/"$PYTHONVERSION"/Python-"$PYTHONVERSION".tar.xz - tar xf Python-"$PYTHONVERSION".tar.xz - cd Python-"$PYTHONVERSION" || return 1 - ./configure - make altinstall - apt -y autoremove - cd || return 1 - rm -r /tmp/Python-"$PYTHONVERSION" - rm /tmp/Python-"$PYTHONVERSION".tar.xz - echo "Done" -fi -echo "Stopping Home Assistant." -systemctl stop home-assistant@homeassistant.service - -echo "Backing up previous virutal enviorment." -mv /srv/homeassistant /srv/homeassistant_"$hapyversion" - -echo "Creating new virutal environment using Python $PYTHONVERSION" -python"${PYTHONVERSION:: -2}" -m venv /srv/homeassistant -mv /srv/homeassistant_"$hapyversion"/hassbian /srv/homeassistant/hassbian -chown homeassistant:homeassistant -R /srv/homeassistant -apt install python3-pip python3-dev -pip"${PYTHONVERSION:: -2}" install --upgrade virtualenv -sudo -u homeassistant -H /bin/bash << EOF -source /srv/homeassistant/bin/activate -pip3 install --upgrade setuptools wheel -pip3 install --upgrade homeassistant -deactivate -EOF - -mv /home/homeassistant/.homeassistant/deps /home/homeassistant/.homeassistant/deps_"$hapyversion" - -echo "Starting Home Assistant." -systemctl start home-assistant@homeassistant.service - -echo "Checking the installation..." -validation=$(sudo -u homeassistant -H /bin/bash << EOF | awk -F ' ' '{print $NF}' -source /srv/homeassistant/bin/activate -python -V -EOF -) -if [ "$validation" == "$PYTHONVERSION" ]; then - echo - echo -e "\\e[32mUpgrade done..\\e[0m" - echo "First time Home Assistant starts it will take a long time. This is normal." - echo "You can run 'sudo journalctl -u home-assistant@homeassistant.service -f' to see the live service log." - echo -else - echo - echo -e "\\e[31mUpgrade failed..." - echo -e "\\e[31mReverting..." - systemctl stop home-assistant@homeassistant.service - rm -R /srv/homeassistant - mv /srv/homeassistant_"$hapyversion" /srv/homeassistant - systemctl start home-assistant@homeassistant.service - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/python/manifest b/package/opt/hassbian/suites/python/manifest new file mode 100644 index 00000000..b495e13b --- /dev/null +++ b/package/opt/hassbian/suites/python/manifest @@ -0,0 +1,9 @@ +{ + "name": "Python", + "author": "Ludeeus ", + "short_description": "Upgrades python3 and virtual environment to the newest stable version.", + "long_description": "Upgrades python3 and virtual environment to the newest stable version.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/python/upgrade b/package/opt/hassbian/suites/python/upgrade new file mode 100644 index 00000000..b9bb225b --- /dev/null +++ b/package/opt/hassbian/suites/python/upgrade @@ -0,0 +1,99 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Python +# + +function upgrade { + local remotepyversion + local hapyversion + local isinstalled + local validation + + remotepyversion=$(curl -s https://www.python.org/downloads/source/ | \ + grep "Latest Python 3 Release" | cut -d "<" -f 3 | awk -F ' ' '{print $NF}') + + echo "Checking current pythin version..." + hapyversion=$(hassbian.info.version.homeassistant.python) + + if [ "$hapyversion" == "$remotepyversion" ]; then + echo "Python is already the highest stable version." + hassbian.suite.helper.action.success + return 0 + fi + + isinstalled=$(command -v python"${remotepyversion:0:3}") + if [ -z "${isinstalled}" ]; then + echo "Upgrading to Python $remotepyversion..." + hassbian.suite.helper.install.apt build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev + hassbian.suite.helper.install.apt libtcmalloc-minimal4 + + echo "Setting build options..." + export LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4" + + echo "Downloading Python $remotepyversion..." + wget -O /tmp/Python-"$remotepyversion".tar.xz \ + https://www.python.org/ftp/python/"$remotepyversion"/Python-"$remotepyversion".tar.xz + + echo "Unpacking Python $remotepyversion..." + cd /tmp || return 1 + tar xf Python-"$remotepyversion".tar.xz + + echo "Running altinstall for Python $remotepyversion..." + cd Python-"$remotepyversion" || return 1 + ./configure + make altinstall + apt -y autoremove + + echo "Cleanup" + cd || return 1 + rm -r /tmp/Python-"$remotepyversion" + rm /tmp/Python-"$remotepyversion".tar.xz + echo "Done" + fi + + echo "Stopping Home Assistant...." + systemctl stop home-assistant@homeassistant.service + + echo "Backing up previous virutal enviorment...." + mv "$HOME_ASSISTANT_VENV" "$HOME_ASSISTANT_VENV_$hapyversion" + + echo "Creating new virutal environment using Python $remotepyversion..." + python"${remotepyversion:: -2}" -m venv "$HOME_ASSISTANT_VENV" + + echo "Copying hassbian from the old venv to the new..." + cp "$HOME_ASSISTANT_VENV"_"$hapyversion"/hassbian "$HOME_ASSISTANT_VENV"/hassbian + + echo "Setting premissions..." + chown homeassistant:homeassistant -R "$HOME_ASSISTANT_VENV" + + echo "Reinstalling Home Assistant..." + hassbian.suite.helper.install.apt python3-pip python3-dev + + pip"${remotepyversion:: -2}" install --upgrade virtualenv + hassbian.suite.helper.install.pip homeassistant + + mv /home/homeassistant/.homeassistant/deps /home/homeassistant/.homeassistant/deps_"$hapyversion" + + echo "Starting Home Assistant." + systemctl start home-assistant@homeassistant.service + + echo "Checking the installation..." + validation=$(hassbian.info.version.homeassistant.installed) + + if [ "$validation" == "$remotepyversion" ]; then + hassbian.suite.helper.action.success + echo "First time Home Assistant starts it will take a long time. This is normal." + echo "You can run the command 'halog' to see the live service log." + else + hassbian.suite.helper.action.failed + echo -e "\\e[31mReverting..." + systemctl stop home-assistant@homeassistant.service + rm -R "$HOME_ASSISTANT_VENV" + mv "$HOME_ASSISTANT_VENV"_"$hapyversion" "$HOME_ASSISTANT_VENV" + systemctl start home-assistant@homeassistant.service + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/razberry.sh b/package/opt/hassbian/suites/razberry.sh deleted file mode 100644 index b6879671..00000000 --- a/package/opt/hassbian/suites/razberry.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -function razberry-show-short-info { - echo "Disables Bluetooth for the use of a RaZberry with Hassbian." -} - -function razberry-show-long-info { - echo "Disables Bluetooth for the use of a RaZberry with Hassbian." - echo "This will disable the use of Bluetooth and BLE devices." - echo " " - echo "Original script from http://razberry.z-wave.me/install" -} - -function razberry-show-copyright-info { - echo "Original script from http://razberry.z-wave.me/install" -} - -function razberry-install-package { -echo "Checking for version of Raspberry Pi" -RPI_BOARD_REVISION=$(grep Revision /proc/cpuinfo | cut -d: -f2 | tr -d " ") -if [[ $RPI_BOARD_REVISION == "a02082" || $RPI_BOARD_REVISION == "a22082" ]] -then - echo "Raspberry Pi 3 Detected. Disabling Bluetooth" - systemctl disable hciuart - if ! grep -q "dtoverlay=pi3-miniuart-bt" /boot/config.txt - then - echo "Adding 'dtoverlay=pi3-miniuart-bt' to /boot/config.txt" - echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt - fi -fi - -validation=$(grep "dtoverlay=pi3-miniuart-bt" /boot/config.txt) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/razberry/install b/package/opt/hassbian/suites/razberry/install new file mode 100644 index 00000000..5113ffec --- /dev/null +++ b/package/opt/hassbian/suites/razberry/install @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: RaZberry +# + +function install { + local validation + + echo "Checking for version of Raspberry Pi" + RPI_BOARD_REVISION=$(grep Revision /proc/cpuinfo | cut -d: -f2 | tr -d " ") + if [[ $RPI_BOARD_REVISION == "a02082" || $RPI_BOARD_REVISION == "a22082" ]] + then + echo "Raspberry Pi 3 Detected. Disabling Bluetooth" + systemctl disable hciuart + if ! grep -q "dtoverlay=pi3-miniuart-bt" /boot/config.txt; then + echo "Adding 'dtoverlay=pi3-miniuart-bt' to /boot/config.txt" + echo "dtoverlay=pi3-miniuart-bt" >> /boot/config.txt + fi + fi + + validation=$(grep "dtoverlay=pi3-miniuart-bt" /boot/config.txt) + if [ ! -z "${validation}" ]; then + hassbian.suite.helper.action.success + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/razberry/manifest b/package/opt/hassbian/suites/razberry/manifest new file mode 100644 index 00000000..e5d8ff89 --- /dev/null +++ b/package/opt/hassbian/suites/razberry/manifest @@ -0,0 +1,9 @@ +{ + "name": "RaZberry", + "author": "Landrash, based from http://razberry.z-wave.me/install", + "short_description": "Disables Bluetooth for the use of a RaZberry with Hassbian.", + "long_description": "This will disable the use of Bluetooth and BLE devices.\\n\\nOriginal script from http://razberry.z-wave.me/install", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/samba.sh b/package/opt/hassbian/suites/samba.sh deleted file mode 100644 index 569c8e08..00000000 --- a/package/opt/hassbian/suites/samba.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash - -function samba-show-short-info { - echo "Samba install script for Hassbian." -} - -function samba-show-long-info { - echo "Installs the samba package for sharing the Hassbian configuration files." - echo "over the network." -} - -function samba-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist ." -} - -function samba-install-package { -echo "Running apt-get preparation" -apt-get update -apt-get install -y samba - -echo "Adding homeassistant Samba user" -smbpasswd -a homeassistant -n - -echo "Adding shared folder for Home Assistant configuration directory" -cd /etc/samba/ || exit -patch <<'EOF' ---- smb.conf 2017-02-02 20:29:42.383603738 +0000 -+++ smb_ha.conf 2017-02-02 20:37:12.418960977 +0000 -@@ -252,3 +252,11 @@ - # to the drivers directory for these users to have write rights in it - ; write list = root, @lpadmin - -+[homeassistant] -+path = /home/homeassistant/.homeassistant -+writeable = yes -+guest ok = yes -+create mask = 0644 -+directory mask = 0755 -+force user = homeassistant -+ -EOF - - -echo "Restarting Samba service" -systemctl restart smbd.service - -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -echo "Checking the installation..." -validation=$(pgrep -x smbd) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo - echo "Configuration is now available as a Samba share at \\\\$ip_address\\homeassistant" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/samba/files/samba.conf b/package/opt/hassbian/suites/samba/files/samba.conf new file mode 100644 index 00000000..5b7d2ffa --- /dev/null +++ b/package/opt/hassbian/suites/samba/files/samba.conf @@ -0,0 +1,7 @@ +[homeassistant] +path = /home/homeassistant/.homeassistant +writeable = yes +guest ok = yes +create mask = 0644 +directory mask = 0755 +force user = homeassistant \ No newline at end of file diff --git a/package/opt/hassbian/suites/samba/install b/package/opt/hassbian/suites/samba/install new file mode 100644 index 00000000..89cbddc6 --- /dev/null +++ b/package/opt/hassbian/suites/samba/install @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Samba +# + +function install { + local validation + local ip_address + + echo "Running apt-get preparation" + hassbian.suite.helper.install.apt samba + + echo "Adding homeassistant Samba user" + smbpasswd -a homeassistant -n + + echo "Adding shared folder for Home Assistant configuration directory" + tee -a /etc/samba/smb.conf < "$HASSBIAN_SUITE_DIR"/samba/files/samba.conf + + echo "Restarting Samba service" + systemctl restart smbd.service + + echo "Checking the installation..." + validation=$(hassbian.suite.verify.pgrep smbd) + if [ "$validation" == "0" ]; then + ip_address=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "Configuration is now available as a Samba share at \\\\$ip_address\\homeassistant" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/samba/manifest b/package/opt/hassbian/suites/samba/manifest new file mode 100644 index 00000000..8a792169 --- /dev/null +++ b/package/opt/hassbian/suites/samba/manifest @@ -0,0 +1,9 @@ +{ + "name": "Samba", + "author": "Landrash ", + "short_description": "Samba install script for Hassbian.", + "long_description": "Installs the samba package for sharing the Hassbian configuration files, over the network.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/template/files/template.service b/package/opt/hassbian/suites/template/files/template.service new file mode 100644 index 00000000..ce08163b --- /dev/null +++ b/package/opt/hassbian/suites/template/files/template.service @@ -0,0 +1,15 @@ +# +# Template service file for Hassbian suites. +# + +[Unit] +Description=Template description +After=network.target + +[Service] +Type=simple +ExecStart=sleep 3600 +SendSIGKILL=no + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/package/opt/hassbian/suites/template/install b/package/opt/hassbian/suites/template/install new file mode 100644 index 00000000..60d68379 --- /dev/null +++ b/package/opt/hassbian/suites/template/install @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Template +# + +function install { + echo "Installing Suite Template..." + + echo "Enabling Template service..." + cp "$HASSBIAN_SUITE_DIR"/template/files/template.service /etc/systemd/system/template.service + systemctl enable template.service + sync + + echo "Starting Template service..." + systemctl start template.service + + validation=$(hassbian.suite.verify.service template.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/template/manifest b/package/opt/hassbian/suites/template/manifest new file mode 100644 index 00000000..6b9e79b0 --- /dev/null +++ b/package/opt/hassbian/suites/template/manifest @@ -0,0 +1,10 @@ +{ + "name": "Suite Template", + "author": "Username ", + "short_description": "Suite Template.", + "long_description": "Can be used to test 'hassbian-config' or as a template to build new suites from.", + "unattended": true, + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/template/remove b/package/opt/hassbian/suites/template/remove new file mode 100644 index 00000000..38167437 --- /dev/null +++ b/package/opt/hassbian/suites/template/remove @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Uninstallation script for Hassbian suite: Template +# + +function remove { + echo "Removing Template..." + systemctl stop template.service + systemctl disable template.service + rm /etc/systemd/system/template.service + sync + + hassbian.suite.helper.action.success +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/template/upgrade b/package/opt/hassbian/suites/template/upgrade new file mode 100644 index 00000000..7ef26e1f --- /dev/null +++ b/package/opt/hassbian/suites/template/upgrade @@ -0,0 +1,22 @@ +#!/bin/bash +# +# Upgrade script for Hassbian suite: Template +# + +function upgrade { + echo "Upgrading Suite Template..." + + echo "Restarting Template service..." + systemctl restart custom-component-store@homeassistant.service + + validation=$(hassbian.suite.verify.service template.service) + if [ "$validation" == "0" ]; then + hassbian.suite.helper.action.success + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/tradfri.sh b/package/opt/hassbian/suites/tradfri.sh deleted file mode 100644 index 78dfcb59..00000000 --- a/package/opt/hassbian/suites/tradfri.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -function tradfri-show-short-info { - echo "Tradfri install script for Hassbian" -} - -function tradfri-show-long-info { - echo "Installs the libraries needed to control IKEA Tradfri devices from this Pi." -} - -function tradfri-show-copyright-info { - echo "Copyright(c) 2017 Fredrik Lindqvist " -} - -function tradfri-install-package { -echo "Running apt-get preparation" -apt-get update -apt-get install -y dh-autoreconf - -echo "Changing to homeassistant user" -sudo -u homeassistant -H /bin/bash <", + "short_description": "Tradfri install script for Hassbian", + "long_description": "Installs the libraries needed to control IKEA Tradfri devices from this Pi.", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/webterminal.sh b/package/opt/hassbian/suites/webterminal.sh deleted file mode 100644 index 86c792b3..00000000 --- a/package/opt/hassbian/suites/webterminal.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -function webterminal-show-short-info { - echo "Installs an webservice terminal." -} - -function webterminal-show-long-info { - echo "Installs an webservice terminal to control your installation." -} - -function webterminal-show-copyright-info { - echo "Original concept by Ludeeus " -} - -function webterminal-install-package { -if [ "$ACCEPT" == "true" ]; then # True if `-y` flag is used. - if [ -d "/etc/letsencrypt/live" ] || [ -d "/home/homeassistant/dehydrated/certs" ]; then - SSL="Y" - else - SSL="N" - fi -else - echo "" - echo -n "Do you use SSL (https) with Home Assistant? [N/y] : " - read -r SSL - if [ ! "$SSL" ]; then - SSL="N" - fi -fi - -echo "Installing packages." -apt-get install -y openssl shellinabox -echo "Changing config." -if [ "$SSL" == "y" ] || [ "$SSL" == "Y" ]; then - echo "No need to change default configuration, skipping this step..." - echo "Checking cert directory..." - if [ -d "/etc/letsencrypt/live" ]; then - CERTDIR="/etc/letsencrypt/live/" - elif [ -d "/home/homeassistant/dehydrated/certs" ]; then - CERTDIR="/home/homeassistant/dehydrated/certs/" - else - CERTDIR="" - fi - echo "Merging files and adding to correct dir..." - DOMAIN=$(ls "$CERTDIR") - cat "$CERTDIR$DOMAIN/fullchain.pem" "$CERTDIR$DOMAIN/privkey.pem" > /var/lib/shellinabox/certificate-"$DOMAIN".pem - chown shellinabox:shellinabox -R /var/lib/shellinabox/ - echo "Adding crong job to copy certs..." - (crontab -l ; echo "5 1 1 * * bash /opt/hassbian/suites/files/webterminalsslhelper.sh >/dev/null 2>&1")| crontab - -else - sed -i 's/--no-beep/--no-beep --disable-ssl/g' /etc/default/shellinabox -fi - -echo "Reloading and starting the service." -service shellinabox reload -service shellinabox stop -service shellinabox start - -ip_address=$(ifconfig | grep "inet.*broadcast" | grep -v 0.0.0.0 | awk '{print $2}') - -if [ "$SSL" == "y" ] || [ "$SSL" == "Y" ]; then - PROTOCOL="https" -else - PROTOCOL="http" -fi - -echo "Checking the installation..." -validation=$(pgrep -f shellinaboxd) -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo - echo "You can now access the web terminal here: $PROTOCOL://$ip_address:4200" - echo "You can also add this to your Home-Assistant config in an 'panel_iframe'" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/webterminal/files/cron b/package/opt/hassbian/suites/webterminal/files/cron new file mode 100644 index 00000000..7f1494dd --- /dev/null +++ b/package/opt/hassbian/suites/webterminal/files/cron @@ -0,0 +1,22 @@ +#!/bin/bash +# Helper script for using LE certificates with Webterminal (shellinabox) +declare certdir +declare domain + +if [ -d "/etc/letsencrypt/live" ]; then + certdir="/etc/letsencrypt/live/" +elif [ -d "/home/homeassistant/dehydrated/certs" ]; then + certdir="/home/homeassistant/dehydrated/certs/" +else + echo "Could not find a valid cerification directory..." + return 1 +fi +domain=$(ls "$certdir") +cat "$certdir$domain/fullchain.pem" "$certdir$domain/privkey.pem" > /var/lib/shellinabox/certificate-"$domain".pem + +chown shellinabox:shellinabox -R /var/lib/shellinabox/ + +service shellinabox reload +service shellinabox stop +service shellinabox start +exit 0 \ No newline at end of file diff --git a/package/opt/hassbian/suites/webterminal/install b/package/opt/hassbian/suites/webterminal/install new file mode 100644 index 00000000..91c19e67 --- /dev/null +++ b/package/opt/hassbian/suites/webterminal/install @@ -0,0 +1,73 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Web Terminal +# + +function install { + local certdir + local domain + local protocol + local usingssl + local validation + local ipaddress + + if [ "$ACCEPT" == "true" ]; then # True if `-y` flag is used. + if [ -d "/etc/letsencrypt/live" ] || [ -d "/home/homeassistant/dehydrated/certs" ]; then + usingssl="0" + fi + else + usingssl=$(hassbian.input.bool "Do you use SSL (https) with Home Assistant?") + fi + + echo "Installing packages." + hassbian.suite.helper.install.apt shellinabox + + echo "Changing config." + if [ "$usingssl" == "0" ]; then + echo "No need to change default configuration, skipping this step..." + echo "Checking certificate directories..." + if [ -d "/etc/letsencrypt/live" ]; then + certdir="/etc/letsencrypt/live/" + elif [ -d "/home/homeassistant/dehydrated/certs" ]; then + certdir="/home/homeassistant/dehydrated/certs/" + else + echo "Could not find a valid cerification directory..." + hassbian.suite.helper.action.failed + return 1 + fi + echo "Merging files and adding to correct dir..." + domain=$(ls "$certdir") + cat "$certdir$domain/fullchain.pem" "$certdir$domain/privkey.pem" > /var/lib/shellinabox/certificate-"$domain".pem + chown shellinabox:shellinabox -R /var/lib/shellinabox/ + echo "Adding crong job to copy certs..." + cp HASSBIAN_SUITE_DIR/webterminal/files/cron /etc/cron.daily/shellinabox + else + sed -i 's/--no-beep/--no-beep --disable-ssl/g' /etc/default/shellinabox + fi + + echo "Reloading and starting the service." + service shellinabox reload + service shellinabox stop + service shellinabox start + + if [ "$usingssl" == "0" ]; then + protocol="https" + else + protocol="http" + fi + + echo "Checking the installation..." + validation=$(hassbian.suite.verify.pgrep shellinaboxd) + if [ "$validation" == "0" ]; then + ipaddress=$(hassbian.info.general.ipaddress) + hassbian.suite.helper.action.success + echo "You can now access the web terminal here: $protocol://$ipaddress:4200" + echo "You can also add this to your Home-Assistant config in an 'panel_iframe'" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/webterminal/manifest b/package/opt/hassbian/suites/webterminal/manifest new file mode 100644 index 00000000..425c01e4 --- /dev/null +++ b/package/opt/hassbian/suites/webterminal/manifest @@ -0,0 +1,9 @@ +{ + "name": "Web Terminal", + "author": "Ludeeus ", + "short_description": "Installs an webservice terminal.", + "long_description": "Installs an webservice terminal to control your installation", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/opt/hassbian/suites/zigbee2mqtt.sh b/package/opt/hassbian/suites/zigbee2mqtt.sh deleted file mode 100644 index 0638ffa6..00000000 --- a/package/opt/hassbian/suites/zigbee2mqtt.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash -function zigbee2mqtt-show-short-info { - echo "Setup for Zigbee2mqtt bridge." -} - -function zigbee2mqtt-show-long-info { - echo "This script installs the Zigbee2mqtt bridge" -} - -function zigbee2mqtt-show-copyright-info { - echo "Original concept by Landrash ." -} - -function zigbee2mqtt-install-package { -echo -n "Installing dependencies : " -node=$(which npm) -if [ -z "${node}" ]; then #Installing NodeJS if not already installed. - printf "Downloading and installing NodeJS...\\n" - curl -sL https://deb.nodesource.com/setup_10.x | bash - - apt install -y nodejs -fi - -echo "Cloning Zigbee2mqtt git repository" -git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt -chown -R pi:pi /opt/zigbee2mqtt - -echo "Running install. This might take a while and can produce som expected errors" -cd /opt/zigbee2mqtt || exit -su pi -c "npm install" - -echo "Creating service file zigbee2mqtt.service" -service_path="/etc/systemd/system/zigbee2mqtt.service" - -echo "[Unit] -Description=zigbee2mqtt -After=network.target - -[Service] -ExecStart=/usr/bin/npm start -WorkingDirectory=/opt/zigbee2mqtt -StandardOutput=inherit -StandardError=inherit -Restart=always -User=pi - -[Install] -WantedBy=multi-user.target" > $service_path - -echo "Checking the installation..." -if [ ! -f /opt/zigbee2mqtt/data/configuration.yaml ]; then - validation="" -else - validation="ok" -fi - -if [ ! -z "${validation}" ]; then - echo - echo -e "\\e[32mInstallation done..\\e[0m" - echo -e "Update of configuration.yaml is required found at /opt/zigbee2mqtt/data/" - echo -e "Some further configuration is required and details can be found here https://github.com/Koenkk/zigbee2mqtt/wiki/Running-the-bridge " - echo - echo -e "Service can be started after configuration but running sudo systemctl start zigbee2mqtt" - echo -else - echo - echo -e "\\e[31mInstallation failed..." - echo - return 1 -fi -return 0 -} - -[[ "$_" == "$0" ]] && echo "hassbian-config helper script; do not run directly, use hassbian-config instead" diff --git a/package/opt/hassbian/suites/zigbee2mqtt/files/zigbee2mqtt.service b/package/opt/hassbian/suites/zigbee2mqtt/files/zigbee2mqtt.service new file mode 100644 index 00000000..5f0f3101 --- /dev/null +++ b/package/opt/hassbian/suites/zigbee2mqtt/files/zigbee2mqtt.service @@ -0,0 +1,14 @@ +[Unit] +Description=zigbee2mqtt +After=network.target + +[Service] +ExecStart=/usr/bin/npm start +WorkingDirectory=/opt/zigbee2mqtt +StandardOutput=inherit +StandardError=inherit +Restart=always +User=pi + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/package/opt/hassbian/suites/zigbee2mqtt/install b/package/opt/hassbian/suites/zigbee2mqtt/install new file mode 100644 index 00000000..1b85575d --- /dev/null +++ b/package/opt/hassbian/suites/zigbee2mqtt/install @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Installation script for Hassbian suite: Zigbee2mqtt +# + +function install { + local validation + + hassbian.suite.helper.install.node + + echo "Cloning Zigbee2mqtt git repository" + git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/zigbee2mqtt + chown -R pi:pi /opt/zigbee2mqtt + + echo "Running install. This might take a while and can produce som expected errors" + cd /opt/zigbee2mqtt || exit + su pi -c "npm install" + + echo "Creating service file zigbee2mqtt.service" + cp "$HASSBIAN_SUITE_DIR"/zigbee2mqtt/files/zigbee2mqtt.service /etc/systemd/system/zigbee2mqtt.service + + + echo "Checking the installation..." + if [ -f /opt/zigbee2mqtt/data/configuration.yaml ]; then + validation="ok" + fi + + if [ ! -z "${validation}" ]; then + hassbian.suite.helper.action.success + echo "Update of configuration.yaml is required found at /opt/zigbee2mqtt/data/" + echo "Some further configuration is required and details can be found here https://github.com/Koenkk/zigbee2mqtt/wiki/Running-the-bridge " + echo "Service can be started after configuration but running sudo systemctl start zigbee2mqtt" + else + hassbian.suite.helper.action.failed + return 1 + fi + return 0 +} + +[[ "$_" == "$0" ]] && echo "$ECHO_HELPER_WARNING" \ No newline at end of file diff --git a/package/opt/hassbian/suites/zigbee2mqtt/manifest b/package/opt/hassbian/suites/zigbee2mqtt/manifest new file mode 100644 index 00000000..c47b9f32 --- /dev/null +++ b/package/opt/hassbian/suites/zigbee2mqtt/manifest @@ -0,0 +1,9 @@ +{ + "name": "Zigbee2mqtt", + "author": "Landrash ", + "short_description": "Setup for Zigbee2mqtt bridge.", + "long_description": "Original concept by Landrash .", + "blocked": false, + "blocked_releasename": "", + "blocked_messages": "" +} \ No newline at end of file diff --git a/package/usr/local/bin/hassbian-config b/package/usr/local/bin/hassbian-config index 374a80e4..f3f9dc0b 100755 --- a/package/usr/local/bin/hassbian-config +++ b/package/usr/local/bin/hassbian-config @@ -1,451 +1,71 @@ #!/bin/bash -LOGFILE=/tmp/hassbian.log -SUITE_INSTALL_DIR=/opt/hassbian/suites -SUITE_CONTROL_DIR=/srv/homeassistant/hassbian/control +# The base of hassbian-config, this should only contain source links to the helper scripts and global variables. +# shellcheck disable=SC1090,SC1091,SC2034 -function usage { - printf "usage: hassbian-config [command] [suite] [options]\\n" - printf "run 'hassbian-config --help' to see all options\\n" - return 0 -} +##################################### +# Locations +##################################### -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 software [suite]." - printf "%-8s\\t%s\\n" " remove" "Remove 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 "%-8s\\t%s\\n" " show-installed" "Generates a list of installed suites." - printf "%-8s\\t%s\\n" " systeminfo" "Generates information about the system." - printf "\\n" - printf "available optional [options]:\\n" - printf "%-10s\\t%s\\n" " -Y | --accept" "Accept defaults on scripts that allows this." - printf "%-10s\\t%s\\n" " -F | --force" "Force run an script, this is useful if you need to reinstall a package." - printf "%-10s\\t%s\\n" " -D | --debug" "This will output every comand to the console." - printf "%-10s\\t%s\\n" " -B | --beta" "This will install the current beta version if implemented." - printf "%-10s\\t%s\\n" " --dev" "This will install the current development version if implemented." - 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 -} +# Loggfile for 'hassbian-config' operations. +readonly HASSBIAN_LOG_FILE='/tmp/hassbian.log' -function show-suite-info { - source $SUITE_INSTALL_DIR/"$1".sh - "$1"-show-short-info - return 0 -} +# Suite directory for 'hassbian-config'. +readonly HASSBIAN_SUITE_DIR='/opt/hassbian/suites' -function get-all-suite-installers { - ALLSUITES=$(find $SUITE_INSTALL_DIR/ -maxdepth 1 -type f | sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') - echo "$ALLSUITES" - return 0 -} +# Helper scripts directory +readonly HASSBIAN_HELPERS_DIR='/opt/hassbian/helpers' -function currenthapyversion { - if [ -f "/srv/homeassistant/bin/activate" ]; then - version=$(sudo -u homeassistant -H /bin/bash << EOF | awk -F ' ' '{print $NF}' - source /srv/homeassistant/bin/activate - python -V -EOF - ) - printf "%s" "${version:0:5}" - fi -} +# Controll directory for 'hassbian-config'. +readonly HASSBIAN_CONTROL_DIR='/srv/homeassistant/hassbian/control' -function currenthaversion { - if [ -f "/srv/homeassistant/bin/activate" ]; then - version=$(sudo -u homeassistant -H /bin/bash << EOF | awk -F ' ' '{print $NF}' - source /srv/homeassistant/bin/activate - hass --version -EOF - ) - printf "%s" "$version" - fi -} +# Home Assistant venv directory. +readonly HOME_ASSISTANT_VENV='/srv/homeassistant' -function hcversion { - printf "%s" "$(dpkg -s hassbian-scripts | grep 'Version:' | awk '{print $2}')" -} +##################################### +# Runtime flags +##################################### -function hcremote { - version=$(curl -sSL https://raw.githubusercontent.com/home-assistant/hassbian-scripts/dev/package/DEBIAN/control | grep Version | awk -F' ' '{print $NF}') - printf "%s" "$version" -} +# Enabled by adding the --accept flag. +declare HASSBIAN_RUNTIME_ACCEPT=false +# Enabled by adding the --debug flag. +declare HASSBIAN_RUNTIME_DEBUG=false -function systeminfo { - # Prints system information to the console. - # Usefull to call before scripts and as a standalone. +# Enabled by adding the --force flag. +declare HASSBIAN_RUNTIME_FORCE=false - check-permission # Must be root +# Enabled by adding the --beta flag. +declare HASSBIAN_RUNTIME_BETA=false - echo "Generating system information..." - local ha=$(currenthaversion) - local hapy=$(currenthapyversion) - local hc=$(hcversion) - local uname=$(uname -a) +# Enabled by adding the --dev flag. +declare HASSBIAN_RUNTIME_DEV=false - echo " - Home Assistant: $ha - Home Assistant Python: $hapy - hassbian-config: $hc +# Enabled by adding the --ci flag. +declare HASSBIAN_RUNTIME_CI=false - $uname - " +# Enabled by adding '=X.X.X' at the end of the suitename. +declare HASSBIAN_RUNTIME_TARGET_VERSION - if [ "$hc" != "$(hcremote)" ]; then - printf "\\e[31m%s\\n" " - There is an update pending for 'hassbian-config' - You can upgrade by running this: - sudo hassbian-config upgrade hassbian-script - " - fi +##################################### +# Echoable messages +##################################### -} +readonly ECHO_HELPER_WARNING="hassbian-config helper script. Do not run directly, use 'hassbian-config' instead." +readonly ECHO_ACTION_ERROR="If you have issues with this script, please say something in the #hassbian channel on Discord." -function newestinstalledpython { - # Assing the version number of the newest installed version of Python to $INSTALLEDPYTHON - POTENTIAL="3.5 3.6 3.7" - for version in $POTENTIAL; do - if [[ -n "$(command -v python"$version")" ]]; then - INSTALLEDPYTHON="$(python"$version" -V | awk -F' ' '{print $2}')" - fi - done -} -function show-suites { - printf "This is a list over all suites in hassbian-config\\n" - printf "If a \\e[1msuite\\e[0m has \\e[32mgreen color\\e[0m in the name, you have already installed it.\\n" - printf "\\n" - printf "Install scripts: (Usage 'sudo hassbian-config install \\e[1msuite\\e[0m')\\n" - installers=$(get-all-suite-installers) - for i in $installers - do - if [ -f $SUITE_CONTROL_DIR/"$i" ]; then - SUITESTATE=$(grep "SCRIPTSTATE" $SUITE_CONTROL_DIR/"$i" | awk -F'=' '{print $2}') - else - SUITESTATE="" - fi - INSTALLER=$(grep "$i"-install-package $SUITE_INSTALL_DIR/"$i".sh) - if [ "$INSTALLER" != "" ]; then - if [ "$SUITESTATE" == "installed" ]; then - printf "\\e[1m\\e[32m%-20s\\e[0m %s\\n" "$i" "$(show-suite-info "$i")" - else - printf "\\e[1m%-20s\\e[0m %s\\n" "$i" "$(show-suite-info "$i")" - fi - fi - done - printf "\\n" - printf "Upgrade scripts: (Usage 'sudo hassbian-config upgrade \\e[1msuite\\e[0m')\\n" - for i in $installers - do - UPGRADE=$(grep "$i"-upgrade-package $SUITE_INSTALL_DIR/"$i".sh) - if [ "$UPGRADE" != "" ]; then - printf "\\e[1m%-20s\\e[0m %s\\n" "$i" "$(show-suite-info "$i")" - fi - done - printf "\\n" - printf "To view more info about a suite type: 'hassbian-config show \\e[1msuite\\e[0m\\n" - return 0 -} +##################################### +# Source links (alphabetical order) +##################################### +source "$HASSBIAN_HELPERS_DIR"/info/general +source "$HASSBIAN_HELPERS_DIR"/info/version +source "$HASSBIAN_HELPERS_DIR"/suite/action +source "$HASSBIAN_HELPERS_DIR"/suite/helper +source "$HASSBIAN_HELPERS_DIR"/suite/info +source "$HASSBIAN_HELPERS_DIR"/suite/verify +source "$HASSBIAN_HELPERS_DIR"/developer +source "$HASSBIAN_HELPERS_DIR"/input +source "$HASSBIAN_HELPERS_DIR"/log +source "$HASSBIAN_HELPERS_DIR"/workaround -function show-suite-long-info { - source $SUITE_INSTALL_DIR/"$1".sh - "$1"-show-short-info - "$1"-show-long-info - "$1"-show-copyright-info - return 0 -} - -function check-permission { - if (( EUID != 0 )) - then - echo "Error: hassbian-config must be run as root (with sudo) for this to be possible" - exit 1 - fi - return 0 -} - -function 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! - check-permission - readonly PRNUMBER="$1" - readonly INSTALLDIR="/tmp/hassbian_config_install_${PRNUMBER}" - if [[ -z "$PRNUMBER" ]]; then - echo "Error: Missing PR argument." - echo "" - echo "Run: bash test_pr.sh PRNUMBER" - return 1 - 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 raspberry_pi_zero_check { -## Start check for Raspberry Pi Zero -if [ "$FORCE" != "true" ]; then - REVCODE=$(cat /proc/cpuinfo | grep 'Revision' | awk '{print $3}' | sed 's/^ *//g' | sed 's/ *$//g') - if [ "$REVCODE" = "90092" ] || [ "$REVCODE" = "90093" ] || [ "$REVCODE" = "0x9000C1" ] || [ "$REVCODE" = "9000c1" ]; then - if [[ "$1" =~ ^(mosquitto|cloud9|zigbee2mqtt)$ ]]; then - echo "This suite can't be installed on Raspberry Pi Zero..." - exit 0 - fi - fi -fi -## End check for Raspberry Pi Zero - -} -function share-log { - if [ ! -f $LOGFILE ];then - echo "No logfile, exiting..." - return 0 - fi - if [ "$ACCEPT" == "true" ]; then - loglink=$(curl -X POST -s -d "$(cat "$LOGFILE")" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}') - if [[ $loglink != *"initial"* ]]; then - echo "$loglink" - else - echo "There is an issue with your network connection, or with the Hastebin API." - echo "Try again later." - return 0 - fi - else - echo "This will put the output from your last operation on hastebin." - echo "This could include sensitive information." - echo "If you are unsure about what it contains, you can run 'hassbian-config log' to check." - echo -n "Do you want to create an hastebin link? [N/y] : " - read -r RESPONSE - if [ "$RESPONSE" == "y" ] || [ "$RESPONSE" == "Y" ]; then - loglink=$(curl -X POST -s -d "$(cat "$LOGFILE")" https://hastebin.com/documents | awk -F '"' '{print "https://hastebin.com/"$4}') - if [[ $loglink != *"initial"* ]]; then - echo "$loglink" - else - echo - echo "There is an issue with your network connection, or with the Hastebin API." - echo "Try again later." - return 0 - fi - fi - fi - return 0 -} - -function run-suite { #This is the function the actually run install/upgrade. - source "$SUITE_INSTALL_DIR/$2".sh #Sourcing the script file. - "$2"-show-short-info && "$2"-show-copyright-info && printf "\\n" #Prints suite-show-short-info & suite-show-copyright-info to console. - if [ "$DEBUG" == "true" ]; then set -x; fi #Activating debug if --debug is used. - "$2"-"$1"-package #Running the script function install/upgrade SUITE. - RETURN=("$?") # Return value after script execution. - if [ "$DEBUG" == "true" ]; then set +x; fi #Deactivating debug if --debug is used. - if [ "$RETURN" == "0" ]; then STATE="installed"; else printf "\\e[0mIf you have issues with this script, please say something in the #hassbian channel on Discord.\\n" && STATE="failed"; fi #Set suite state to installed if 0 is returned, failed otherwise. - if [ "$1" == "remove" ]; then - rm "$SUITE_CONTROL_DIR/$2" - else - echo "SCRIPTSTATE=$STATE" > "$SUITE_CONTROL_DIR/$2" #Setting status in control file. - fi - return 0 -} - -function install-suite { #This function do checks if we can/want to install. - systeminfo - raspberry_pi_zero_check "$1" - INSTALL=$(grep "$1"-install-package "$SUITE_INSTALL_DIR/$1".sh) #Checking if suite has install function. - SUITESTATE=$(if [ -f "$SUITE_CONTROL_DIR/$1" ]; then grep "SCRIPTSTATE" "$SUITE_CONTROL_DIR/$1" | awk -F'=' '{print $2}'; else echo ""; fi) #Checking current suite state. - if [ "$FORCE" == "true" ]; then #Go straight to run-suite if --force is used. - run-suite install "$1" | tee "$LOGFILE" #Run if -F/-f/--force is used. - elif [ "$SUITESTATE" == "installed" ] || [ "$INSTALL" == "" ]; then #Try redirect to upgrade script if already installed. - printf "%s is already installed or install script is not available...\\n" "$1" - UPGRADE=$(grep "$1"-upgrade-package "$SUITE_INSTALL_DIR/$1".sh) - if [ "$UPGRADE" == "" ]; then - printf "Upgrade script is not available...\\n\\nYou can force run the install script like this:\\nsudo hassbian-config install %s --force\\n" "$1" - return 0 - fi - printf "upgrade script for %s found, running that...\\n\\n" "$1" - run-suite upgrade "$1" | tee "$LOGFILE" #Redirects to upgrade script. - else - run-suite install "$1" | tee "$LOGFILE" #This is the default run, if no options is used. - fi - return 0 -} - -function upgrade-suite { #This function do checks if we can upgrade. - systeminfo - UPGRADE=$(grep "$1"-upgrade-package "$SUITE_INSTALL_DIR/$1".sh) #Checking if suite has upgrade function. - if [ "$UPGRADE" == "" ]; then - printf "Upgrade script is not available...\\n\\nYou can force run the install script like this:\\nsudo hassbian-config install %s --force\\n" "$1" - return 0 - fi - run-suite upgrade "$1" | tee "$LOGFILE" #This is the default run. - return 0 -} - -function remove-suite { #This function do checks if we can remove. - systeminfo - REMOVABLE=$(grep "$1"-remove-package "$SUITE_INSTALL_DIR/$1".sh) #Checking if suite has remove function. - if [ "$REMOVABLE" == "" ]; then - printf "Remove function not avaialable for this suite.\\n" - return 0 - fi - run-suite remove "$1" | tee "$LOGFILE" #This is the default run. - return 0 -} - -function verify-suite { - if [ -f "$SUITE_INSTALL_DIR/$1.sh" ]; then - retval=0 # beware - 0 is true in bash. - else - retval=1 - fi - return $retval -} - -function show-installed-suites { - INSTALLERS=$(find $SUITE_INSTALL_DIR/ -maxdepth 1 -type f | sort | awk -F'/' ' {print $NF}' | awk -F. '{print $1}') - echo "These suites are installed:" - for i in $INSTALLERS - do - if [ -f "$SUITE_CONTROL_DIR/$i" ]; then - STATE=$(grep "SCRIPTSTATE=installed" $SUITE_CONTROL_DIR/"$i" | awk -F'=' '{print $2}') - if [ "$STATE" != "" ]; then - echo "$i" - fi - fi - done - return 0 -} - -if [ $# -lt 1 ]; then - usage - exit 0 -fi - -while [[ $# -gt 0 ]] -do -COMMAND=$1 -SUITE=$2 - -case $COMMAND in - "-F"|"-f"|"--force") - FORCE="true" - shift # past argument - ;; - "-Y"|"-y"|"--accept") - ACCEPT="true" - shift # past argument - ;; - "-D"|"--debug") - DEBUG="true" - shift # past argument - ;; - "--dev") - DEV="true" - shift # past argument - ;; - "-B"|"--beta") - BETA="true" - shift # past argument - ;; - "show") - if [ "$SUITE" != "" ]; then - if verify-suite "$SUITE"; then - RUN="show-suite-long-info $SUITE" - else - RUN="echo suite $SUITE doesn't exist." - fi - else - RUN="show-suites" - fi - shift # past argument - shift # past value - ;; - "install") - if verify-suite "$SUITE"; then - RUN="install-suite $SUITE" - else - RUN="echo suite $SUITE doesn't exist." - fi - shift # past argument - shift # past value - ;; - "upgrade") - if [[ "$SUITE" = *"="* ]]; then - VERSIONNUMBER=$(echo "$SUITE" | awk -F'=' '{print $2}') - SUITE=$(echo "$SUITE" | awk -F'=' '{print $1}') - else - VERSIONNUMBER="" - fi - if verify-suite "$SUITE"; then - RUN="upgrade-suite $SUITE" - else - RUN="echo suite $SUITE doesn't exist." - fi - shift # past argument - shift # past value - ;; - "remove") - if verify-suite "$SUITE"; then - RUN="remove-suite $SUITE" - else - RUN="echo suite $SUITE doesn't exist." - fi - shift # past argument - shift # past value - ;; - "developer-test-pr") - RUN="developer-test-pr $2" - shift # past argument - shift # past value - ;; - "log") - RUN="more $LOGFILE" - shift # past argument - ;; - "systeminfo") - RUN="systeminfo" - shift # past argument - ;; - "share-log") - RUN="share-log" - shift # past argument - ;; - "-V"|"--version") - VERSION=$(dpkg -s hassbian-scripts | grep 'Version:' | awk '{print $2}') - RUN="echo $VERSION" - shift # past argument - ;; - "show-installed") - RUN="show-installed-suites" - shift # past argument - ;; - "-H"|"--help") - RUN="help" - shift # past argument - ;; - *) - RUN="usage" - shift # past argument - ;; -esac -done -if [ "$RUN" != "" ]; then - $RUN - exit 0 -fi -exit 0 +# the CLI is dependant on other sources so we load that at the end. +source "$HASSBIAN_HELPERS_DIR"/cli \ No newline at end of file