diff --git a/README.md b/README.md index 6e03706..865b5ce 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,18 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in ## Overview -Home automation platform +Awaken your home +Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. + +### Features + +- Works with over 1000 brands ; +- Powerful automations ; +- Extend your system with add-ons ; +- All your smart home data stays local ; +- Companion Mobile Apps ; +- Home Energy Management." + **Shipped version:** 2023.2.3~ynh1 @@ -26,16 +37,6 @@ Home automation platform ![Screenshot of Home Assistant](./doc/screenshots/screenshot1.png) -## Disclaimers / important information - -* Known limitations: - * Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No - * Can the app be used by multiple users? Yes - - -* Additional informations: - * As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achive that (15 to 60 minutes) - ## Documentation and resources * Official app website: diff --git a/README_fr.md b/README_fr.md index 430480f..41c8d1a 100644 --- a/README_fr.md +++ b/README_fr.md @@ -16,7 +16,18 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po ## Vue d’ensemble -Plateforme domotique +Awaken your home +Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. + +### Features + +- Works with over 1000 brands ; +- Powerful automations ; +- Extend your system with add-ons ; +- All your smart home data stays local ; +- Companion Mobile Apps ; +- Home Energy Management." + **Version incluse :** 2023.2.3~ynh1 @@ -26,16 +37,6 @@ Plateforme domotique ![Capture d’écran de Home Assistant](./doc/screenshots/screenshot1.png) -## Avertissements / informations importantes - -* Known limitations: - * Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No - * Can the app be used by multiple users? Yes - - -* Additional informations: - * As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achive that (15 to 60 minutes) - ## Documentations et ressources * Site officiel de l’app : diff --git a/check_process b/check_process deleted file mode 100644 index 4ca3bbf..0000000 --- a/check_process +++ /dev/null @@ -1,27 +0,0 @@ -;; Test complet - ; Manifest - domain="domain.tld" - is_public=1 - home="Home" - latitude="32.87336" - longitude="117.22743" - elevation="430" - unit_system="metric" - currency="USD" - country="US" - time_zone="America/Los_Angeles" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=0 - port_already_use=1 - change_url=1 -;;; Options - Notification=all -;;; Upgrade options diff --git a/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh b/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh index a696206..230871a 100755 --- a/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh +++ b/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh @@ -8,8 +8,8 @@ # define usefull variables app="homeassistant" -final_path="/var/www/$app" -data_path="/home/yunohost.app/$app" +install_dir="/var/www/$app" +data_dir="/home/yunohost.app/$app" ########## END OF CONFIGURATION ########## @@ -28,36 +28,32 @@ if [ ! -z "$DEBUG" ]; then fi # upgrade the virtual environment -MY_PYTHON=$(readlink -e "$final_path/bin/python") +MY_PYTHON=$(readlink -e "$install_dir/bin/python") [ ! -z "$DEBUG" ] && log "Using pyhton '$MY_PYTHON'." -$MY_PYTHON -m venv --upgrade "$final_path" +$MY_PYTHON -m venv --upgrade "$install_dir" # Run source in a 'sub shell' ( # activate the virtual environment set +o nounset [ ! -z "$DEBUG" ] && log "Activate the virtual environment" - source "$final_path/bin/activate" + source "$install_dir/bin/activate" set -o nounset # add pip [ ! -z "$DEBUG" ] && log "Upgrade pip" - "$final_path/bin/python3" -m ensurepip --upgrade + "$install_dir/bin/python3" -m ensurepip --upgrade local VERBOSE [ ! -z "$DEBUG" ] && VERBOSE="--log $LOG_FILE" - # install last version of wheel - [ ! -z "$DEBUG" ] && log "Install latest pip version of wheel" - "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade wheel $VERBOSE - - # install last version of mysqlclient - [ ! -z "$DEBUG" ] && log "Install latest pip version of mysqlclient" - "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade mysqlclient $VERBOSE + # install last version of wheel, pip & mysqlclient + [ ! -z "$DEBUG" ] && log "Install latest pip version of wheel, pip & mysqlclient" + "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel pip mysqlclient $VERBOSE # upgrade homeassistant python package [ ! -z "$DEBUG" ] && log "Install latest pip version of $app" - "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade $app $VERBOSE + "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade $app $VERBOSE ) # restart homeassistant systemd service diff --git a/conf/homeassistant_conf_files/configuration.yaml b/conf/homeassistant_conf_files/configuration.yaml index 6cc3b5a..0d66f50 100644 --- a/conf/homeassistant_conf_files/configuration.yaml +++ b/conf/homeassistant_conf_files/configuration.yaml @@ -10,7 +10,7 @@ homeassistant: external_url: "https://__DOMAIN__" auth_providers: - type: command_line - command: __DATA_PATH__/bin/ynh_ldap-auth.sh + command: __DATA_DIR__/bin/ynh_ldap-auth.sh meta: true http: @@ -36,5 +36,5 @@ switch: - platform: command_line switches: upgrade_homeassistant: - command_on: "nohup bash -c __DATA_PATH__/bin/upgrade_homeassistant.sh $1 > /dev/null 2>&1 &" + command_on: "nohup bash -c __DATA_DIR__/bin/upgrade_homeassistant.sh $1 > /dev/null 2>&1 &" friendly_name: Upgrade Home Assistant diff --git a/conf/systemd.service b/conf/systemd.service index eba5b4a..64fd060 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -5,8 +5,8 @@ After=network.target mysql.service [Service] Type=simple User=__APP__ -WorkingDirectory=__DATA_PATH__ -ExecStart=__FINALPATH__/bin/hass --config "__DATA_PATH__" --log-file "__LOG_FILE__" --verbose +WorkingDirectory=__DATA_DIR__ +ExecStart=__INSTALL_DIR__/bin/hass --config "__DATA_DIR__" --log-file "__LOG_FILE__" --verbose RestartForceExitStatus=100 Restart=on-failure RestartSec=5s diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..53a10f2 --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,11 @@ +Awaken your home +Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. + +### Features + +- Works with over 1000 brands ; +- Powerful automations ; +- Extend your system with add-ons ; +- All your smart home data stays local ; +- Companion Mobile Apps ; +- Home Energy Management." diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md deleted file mode 100644 index 7ddb739..0000000 --- a/doc/DISCLAIMER.md +++ /dev/null @@ -1,7 +0,0 @@ -* Known limitations: - * Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No - * Can the app be used by multiple users? Yes - - -* Additional informations: - * As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achive that (15 to 60 minutes) diff --git a/doc/notifications/pre_install.md b/doc/notifications/pre_install.md new file mode 100644 index 0000000..29e9b5c --- /dev/null +++ b/doc/notifications/pre_install.md @@ -0,0 +1 @@ +As the pyhton version shipped in Debian stable is not always supported, a recent version could be built during the installation process. It may take a while to achieve that (15 to 60 minutes). diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 1dd6c3f..0000000 --- a/manifest.json +++ /dev/null @@ -1,115 +0,0 @@ -{ - "name": "Home Assistant", - "id": "homeassistant", - "packaging_format": 1, - "description": { - "en": "Home automation platform", - "fr": "Plateforme domotique" - }, - "version": "2023.2.3~ynh1", - "url": "https://github.com/home-assistant/home-assistant", - "upstream": { - "license": "Apache-2.0", - "website": "https://www.home-assistant.io", - "demo": "https://demo.home-assistant.io", - "admindoc": "https://www.home-assistant.io/docs/", - "code": "https://github.com/home-assistant/core" - }, - "license": "Apache-2.0", - "maintainer": { - "name": "ewilly", - "email": "ewilly@ewilly.fr" - }, - "requirements": { - "yunohost": ">= 11.0.0" - }, - "multi_instance": false, - "services": [ - "nginx" - ], - "arguments": { - "install": [ - { - "name": "domain", - "type": "domain" - }, - { - "name": "is_public", - "type": "boolean", - "help": { - "en": "If not public, Smartphone app will not work", - "fr": "Dans le cas contraire, l'application sur Smartphone ne fonctionnera pas" - }, - "default": true - }, - { - "name": "home", - "type": "string", - "ask": { - "en": "Name of the location where Home Assistant is running." - }, - "default": "Home" - }, - { - "name": "latitude", - "type": "string", - "ask": { - "en": "Latitude of your location required to calculate the time the sun rises and sets--> https://www.openstreetmap.org" - }, - "default": 32.87336 - }, - { - "name": "longitude", - "type": "string", - "ask": { - "en": "Longitude of your location required to calculate the time the sun rises and sets --> https://www.openstreetmap.org" - }, - "default": 117.22743 - }, - { - "name": "elevation", - "type": "number", - "ask": { - "en": "Altitude above sea level in meters. Impacts sunrise data." - }, - "default": 430 - }, - { - "name": "unit_system", - "type": "string", - "ask": { - "en": "metric for Metric, us_customary for US Customary. This also sets temperature_unit, Celsius for Metric and Fahrenheit for US Customary." - }, - "choices": [ - "metric", - "us_customary" - ], - "default": "metric" - }, - { - "name": "currency", - "type": "string", - "ask": { - "en": "Pick your currency code from the column Code of Wikipedia’s list of ISO 4217 active codes --> https://en.wikipedia.org/wiki/ISO_4217#Active_codes" - }, - "default": "USD" - }, - { - "name": "country", - "type": "string", - "ask": { - "en": "Country in which Home Assistant is running. This may, for example, influence radio settings to comply with local regulations. The country should be specified as an ISO 3166.1 alpha-2 code. Pick your country from the column Code of Wikipedia’s list of ISO 31661 alpha-2 officially assigned code --> https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" - }, - "default": "US" - }, - { - "name": "time_zone", - "type": "string", - "ask": { - "en": "Pick your time zone from the column TZ of Wikipedia’s list of tz database time zones --> https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" - }, - "default": "America/Los_Angeles" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..537fa87 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,103 @@ +packaging_format = 2 + +id = "homeassistant" +name = "Home Assistant" +description.en = "Home automation platform" +description.fr = "Plateforme domotique" + +version = "2023.2.3~ynh1" + +maintainers = ["ewilly"] + +[upstream] +license = "Apache-2.0" +website = "https://www.home-assistant.io" +demo = "https://demo.home-assistant.io" +admindoc = "https://www.home-assistant.io/docs/" +code = "https://github.com/home-assistant/core" +cpe = "cpe:2.3:a:home-assistant:home-assistant" + +[integration] +yunohost = ">= 11.0.0" +architectures = ["amd64", "arm64"] +multi_instance = false +ldap = true +sso = false +disk = "2G" +ram.build = "2G" +ram.runtime = "2G" + +[install] + [install.domain] + type = "domain" + full_domain = true + + [install.init_main_permission] + type = "group" + default = "visitors" + + [install.home] + ask.en = "Name of the location where Home Assistant is running." + type = "string" + default = "Home" + + [install.latitude] + ask.en = "Latitude of your location required to calculate the time the sun rises and sets--> https://www.openstreetmap.org" + type = "string" + default = 32.87336 + + [install.longitude] + ask.en = "Longitude of your location required to calculate the time the sun rises and sets --> https://www.openstreetmap.org" + type = "string" + default = 117.22743 + + [install.elevation] + ask.en = "Altitude above sea level in meters. Impacts sunrise data." + type = "number" + default = 430 + + [install.unit_system] + ask.en = "metric for Metric, us_customary for US Customary. This also sets temperature_unit, Celsius for Metric and Fahrenheit for US Customary." + type = "string" + choices = ["metric", "us_customary"] + default = "metric" + + [install.currency] + ask.en = "Pick your currency code from the column Code of Wikipedia’s list of ISO 4217 active codes --> https://en.wikipedia.org/wiki/ISO_4217#Active_codes" + type = "string" + default = "USD" + + [install.country] + ask.en = "Country in which Home Assistant is running. This may, for example, influence radio settings to comply with local regulations. The country should be specified as an ISO 3166.1 alpha-2 code. Pick your country from the column Code of Wikipedia’s list of ISO 31661 alpha-2 officially assigned code --> https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements" + type = "string" + default = "US" + + [install.time_zone] + ask.en = "Pick your time zone from the column TZ of Wikipedia’s list of tz database time zones --> https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" + type = "string" + default = "America/Los_Angeles" + +[resources] + [resources.system_user] + + [resources.install_dir] + dir = "/var/www/__APP__" + owner = "__APP__:rwx" + group = "__APP__:rx" + + [resources.data_dir] + dir = "/home/yunohost.app/__APP__" + owner = "__APP__:rwx" + group = "__APP__:rx" + + [resources.database] + type = "mysql" + + [resources.permissions] + main.url = "/" + + [resources.apt] + packages = "python3, python3-dev, python3-venv, python3-pip, libffi-dev, libssl-dev, libjpeg-dev, zlib1g-dev, autoconf, build-essential, libopenjp2-7, libtiff5, libturbojpeg0, libmariadb-dev, libmariadb-dev-compat, rustc, tk-dev, libncurses5-dev, libncursesw5-dev, libreadline6-dev, libdb5.3-dev, libgdbm-dev, libsqlite3-dev, libbz2-dev, libexpat1-dev, liblzma-dev, wget, tar, libnss3-dev, libreadline-dev" + + [resources.ports] + main.default = 8123 diff --git a/scripts/_common.sh b/scripts/_common.sh index 43b3c1e..9b91f84 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,9 +7,6 @@ # Release to install app_version=2023.2.3 -# Package dependencies -pkg_dependencies="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0 libmariadb-dev libmariadb-dev-compat rustc" - # Requirements (Major.Minor.Patch) # PY_VERSION=$(curl -s "https://www.python.org/ftp/python/" | grep ">3.9" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2) # Pyhton 3.9.2 will be shiped with bullseye @@ -19,16 +16,6 @@ py_required_version=3.10.9 # PERSONAL HELPERS #================================================= -# Create homeassistant user -mynh_system_user_create () { - user_groups="" - [ $(getent group dialout) ] && user_groups="${user_groups} dialout" - [ $(getent group gpio) ] && user_groups="${user_groups} gpio" - [ $(getent group i2c) ] && user_groups="${user_groups} i2c" - ynh_system_user_create --username=$app --groups="$user_groups" --home_dir="$data_path" -} - - # Check if directory/file already exists (path in argument) myynh_check_path () { [ -z "$1" ] && ynh_die "No argument supplied" @@ -85,11 +72,6 @@ myynh_install_python () { py_app_version="/usr/local/bin/python${py_built_version%.*}" else - ynh_print_info --message="Installing additional dependencies to build python..." - - pkg_dependencies="${pkg_dependencies} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar libnss3-dev libreadline-dev" - ynh_install_app_dependencies "${pkg_dependencies}" - # APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin ynh_print_info --message="Building python (may take a while)..." @@ -130,52 +112,52 @@ myynh_install_python () { # Install/Upgrade Homeassistant in virtual environement myynh_install_homeassistant () { # Create the virtual environment - ynh_exec_as $app $py_app_version -m venv --without-pip "$final_path" + ynh_exec_as $app $py_app_version -m venv --without-pip "$install_dir" # Run source in a 'sub shell' ( # activate the virtual environment set +o nounset - source "$final_path/bin/activate" + source "$install_dir/bin/activate" set -o nounset # add pip - ynh_exec_as $app "$final_path/bin/python3" -m ensurepip + ynh_exec_as $app "$install_dir/bin/python3" -m ensurepip # install last version of pip - ynh_exec_as $app "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade pip + ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade pip # install last version of wheel - ynh_exec_as $app "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade wheel + ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel # install last version of setuptools - ynh_exec_as $app "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade setuptools + ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade setuptools # install last version of mysqlclient - ynh_exec_as $app "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade mysqlclient + ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade mysqlclient # install Home Assistant - ynh_exec_as $app "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade $app==$app_version + ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade $app==$app_version ) } # Upgrade the virtual environment directory myynh_upgrade_venv_directory () { - ynh_exec_as $app $py_app_version -m venv --upgrade "$final_path" + ynh_exec_as $app $py_app_version -m venv --upgrade "$install_dir" } # Set permissions myynh_set_permissions () { - chown -R $app: "$final_path" - chmod 750 "$final_path" - chmod -R o-rwx "$final_path" + chown -R $app: "$install_dir" + chmod 750 "$install_dir" + chmod -R o-rwx "$install_dir" - chown -R $app: "$data_path" - chmod 750 "$data_path" - chmod -R o-rwx "$data_path" - chmod -R +x "$data_path/bin/" + chown -R $app: "$data_dir" + chmod 750 "$data_dir" + chmod -R o-rwx "$data_dir" + [ ! -e "$data_dir/bin/" ] || chmod -R +x "$data_dir/bin/" - chown -R $app: "$(dirname "$log_file")" + [ ! -e "$(dirname "$log_file")" ] || chown -R $app: "$(dirname "$log_file")" - chown -R root: "/etc/sudoers.d/$app" + [ ! -e "/etc/sudoers.d/$app" ] || chown -R root: "/etc/sudoers.d/$app" } diff --git a/scripts/backup b/scripts/backup index 023a201..3f84707 100644 --- a/scripts/backup +++ b/scripts/backup @@ -12,28 +12,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -log_file=$(ynh_app_setting_get --app=$app --key=log_file) -path_url=$(ynh_app_setting_get --app=$app --key=path_url) -python=$(ynh_app_setting_get --app=$app --key=python) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -44,13 +22,13 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="$data_path" --is_big +ynh_backup --src_path="$data_dir" --is_big #================================================= # BACKUP THE NGINX CONFIGURATION diff --git a/scripts/install b/scripts/install index 1b4b7d4..a7677c1 100644 --- a/scripts/install +++ b/scripts/install @@ -10,150 +10,76 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# MANAGE SCRIPT FAILURE +# DEFINE USEFULL VARS / SETTINGS #================================================= -ynh_clean_setup () { - true -} -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -domain=$YNH_APP_ARG_DOMAIN -is_public=$YNH_APP_ARG_IS_PUBLIC -home=$YNH_APP_ARG_HOME -latitude=$YNH_APP_ARG_LATITUDE -longitude=$YNH_APP_ARG_LONGITUDE -elevation=$YNH_APP_ARG_ELEVATION -unit_system=$YNH_APP_ARG_UNIT_SYSTEM -currency=$YNH_APP_ARG_CURRENCY -country=$YNH_APP_ARG_COUNTRY -time_zone=$YNH_APP_ARG_TIME_ZONE - -#================================================= -# DEFINE USEFULL VARS -#================================================= - -final_path="/var/www/$app" -data_path="/home/yunohost.app/$app" log_file="/var/log/$app/$app.log" -path_url="/" - -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." - -[ ! -d "$final_path" ] || ynh_die --message="There is already a directory: $final_path " -ynh_webpath_register --app=$app --domain="$domain" --path_url="$path_url" - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set --app=$app --key=domain --value="$domain" -ynh_app_setting_set --app=$app --key=final_path --value="$final_path" -ynh_app_setting_set --app=$app --key=data_path --value="$data_path" ynh_app_setting_set --app=$app --key=log_file --value="$log_file" -ynh_app_setting_set --app=$app --key=path_url --value="$path_url" #================================================= -# STANDARD MODIFICATIONS +# APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) #================================================= -# FIND AND OPEN A PORT +# CHECK PYTHON VERSION AND COMPILE IF NEEDED #================================================= -ynh_script_progression --message="Finding an available port..." - -port=$(ynh_find_port 8123) -ynh_app_setting_set --app=$app --key=port --value="$port" - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." - -ynh_install_app_dependencies $pkg_dependencies +ynh_script_progression --message="Check Python version & compile the required one if needed..." --weight=1 myynh_install_python --python="$py_required_version" -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -mynh_system_user_create - -#================================================= -# CREATE A MYSQL DATABASE -#================================================= -ynh_script_progression --message="Creating a MySQL database..." - -db_name=$(ynh_sanitize_dbid --db_name=$app) -db_user=$db_name -ynh_app_setting_set --app=$app --key=db_name --value=$db_name -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= + ynh_script_progression --message="Setting up source files..." # create a directory for the installation of Home Assistant -myynh_create_dir "$final_path" -chown -R $app: "$final_path" +myynh_create_dir "$install_dir" # create a directory for the datas of Home Assistant -myynh_create_dir "$data_path/.cache" -chown -R $app: "$data_path" +myynh_create_dir "$data_dir/.cache" + +# create a directory for the logs of Home Assistant +mkdir -p "$(dirname "$log_file")" +touch "$log_file" # installation in a virtual environment ynh_script_progression --message="Installing Home Assistant in a virtual environment..." myynh_install_homeassistant #================================================= -# NGINX CONFIGURATION +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." +ynh_script_progression --message="Adding system configurations related to $app ..." --weight=1 + +# Create a dedicated NGINX config using the conf/nginx.conf template ynh_add_nginx_config -#================================================= -# SPECIFIC SETUP -#================================================= +# Create a dedicated systemd config +ynh_add_systemd_config -# grant sudo permissions to the user to manage his own systemd service +# Create a dedicated service in YunoHost +yunohost service add $app --description="Home Assistant server" --log="$log_file" + +# Use logrotate to manage application logfile(s) +ynh_use_logrotate --logfile="$log_file" + +# Create a dedicated Fail2Ban config +ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " + +# Grant sudo permissions to the user to manage his own systemd service myynh_create_dir "/etc/sudoers.d" ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" +#================================================= +# APP INITIAL CONFIGURATION #================================================= # ADD A CONFIGURATION #================================================= -cp -r "../conf/homeassistant_conf_files/." "$data_path/" -ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_path/configuration.yaml" +ynh_script_progression --message="Adding a configuration file..." --weight=1 -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." - -# setup up systemd service -ynh_script_progression --message="Adding the dedicated service..." -ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= -ynh_script_progression --message="Configuring log rotation..." - -ynh_use_logrotate --logfile="$log_file" +cp -r "../conf/homeassistant_conf_files/." "$data_dir/" +ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml" #================================================= # SET FILE OWNERSHIP / PERMISSIONS @@ -161,17 +87,10 @@ ynh_use_logrotate --logfile="$log_file" myynh_set_permissions -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -# add service in admin panel -yunohost service add $app --description="Home Assistant server" --log="$log_file" - #================================================= # START SYSTEMD SERVICE #================================================= + ynh_script_progression --message="Starting a systemd service..." # start systemd service with --verbose @@ -183,30 +102,6 @@ ynh_store_file_checksum --file="/etc/systemd/system/$app.service" systemctl daemon-reload ynh_systemd_action --service_name=$app --action=restart -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression --message="Configuring Fail2Ban..." --weight=1 - -# Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " - -#================================================= -# SETUP SSOWAT -#================================================= -ynh_script_progression --message="Configuring permissions..." - -[ $is_public -eq 1 ] && ynh_permission_update --permission="main" --add="visitors" -# Allow the web UI to use its own API without Yunohost/SSOWat interfering with it. Home Assistant authentication should still be in effect. -ynh_permission_create --permission="api" --label="api" --url="/api" --allowed="visitors" "all_users" --auth_header="false" --show_tile="false" --protected="true" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 53cbdff..f3c354a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,115 +12,27 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS +# REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Loading installation settings..." -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -log_file=$(ynh_app_setting_get --app=$app --key=log_file) -path_url=$(ynh_app_setting_get --app=$app --key=path_url) -python=$(ynh_app_setting_get --app=$app --key=python) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST -#================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 if ynh_exec_warn_less yunohost service status $app >/dev/null ; then - ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - -ynh_remove_systemd_config --service=$app - -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." - -ynh_remove_logrotate - -#================================================= -# REMOVE THE MYSQL DATABASE -#================================================= -ynh_script_progression --message="Removing the MySQL database..." - -ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name - -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." - -ynh_secure_remove --file="$final_path" - -#================================================= -# REMOVE DATA DIR -#================================================= - -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then - ynh_script_progression --message="Removing app data directory..." - ynh_secure_remove --file="$data_path" -fi - -#================================================= -# REMOVE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Removing NGINX web server configuration..." +ynh_remove_systemd_config ynh_remove_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." +ynh_remove_logrotate -ynh_remove_app_dependencies - -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1 - -# Remove the dedicated Fail2Ban config ynh_remove_fail2ban_config -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= -ynh_script_progression --message="Removing various files..." - -# remove sudoers file ynh_secure_remove --file="/etc/sudoers.d/$app" -# Remove the log files ynh_secure_remove --file="$(dirname "$log_file")" -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 0ee07dd..0239f74 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,130 +14,65 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -log_file=$(ynh_app_setting_get --app=$app --key=log_file) -path_url=$(ynh_app_setting_get --app=$app --key=path_url) -python=$(ynh_app_setting_get --app=$app --key=python) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - -[ ! -d "$final_path" ] || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RESTORE THE NGINX CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the NGINX configuration..." - -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" - -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -mynh_system_user_create - #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path="$final_path" +ynh_script_progression --message="Restoring the app main directory..." +ynh_restore_file --origin_path="$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= + ynh_script_progression --message="Restoring the data directory..." - -ynh_restore_file --origin_path="$data_path" --not_mandatory - -mkdir -p $data_path - -#================================================= -# RESTORE FAIL2BAN CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" -ynh_systemd_action --action=restart --service_name=fail2ban - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." - -ynh_install_app_dependencies $pkg_dependencies -myynh_install_python --python="$python" +ynh_restore_file --origin_path="$data_dir" --not_mandatory +mkdir -p $data_dir #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." -db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) -ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd="$db_pwd" +ynh_script_progression --message="Restoring the MySQL database..." --weight=1 ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql #================================================= -# RESTORE VARIOUS FILES +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring various files..." -ynh_restore_file --origin_path="/etc/sudoers.d/$app" - -ynh_restore_file --origin_path="$(dirname "$log_file")" - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file --origin_path="/etc/systemd/system/$app.service" # add --verbose to track restart sed -i 's/ExecStart=.*/& --verbose/g' "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet -#================================================= -# RESTORE THE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." +yunohost service add $app --description="Home Assistant server" --log="$log_file" ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 +ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" +ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" +ynh_systemd_action --action=restart --service_name=fail2ban + +ynh_restore_file --origin_path="/etc/sudoers.d/$app" +ynh_restore_file --origin_path="$(dirname "$log_file")" + +#================================================= +# SPECIFIC RESTORATION +#================================================= +# CHECK PYTHON VERSION AND COMPILE IF NEEDED +#================================================= + +ynh_script_progression --message="Restoring Python..." --weight=1 +myynh_install_python --python="$python" + #================================================= # IF NEEDED UPDATE THE PYHTON LINK IN THE VIRUTAL ENV. #================================================= -ynh_script_progression --message="Updating the pyhton link in the pyhton virtual environment..." +ynh_script_progression --message="Updating the pyhton link in the pyhton virtual environment..." hass_python_link=$(head -1 /var/www/homeassistant/bin/hass | sed 's/#!//') if [ ! -e "$hass_python_link" ] ; then hass_python_new_dest=$(which `basename "$hass_python_link"`) @@ -150,21 +85,13 @@ fi myynh_set_permissions -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="Home Assistant server" --log="$log_file" - #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting a systemd service..." # start systemd service with --verbose ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600 - # remove --verbose from service ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service" ynh_store_file_checksum --file="/etc/systemd/system/$app.service" @@ -176,8 +103,8 @@ ynh_systemd_action --service_name=$app --action=restart #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." +ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." ynh_systemd_action --service_name=nginx --action=reload #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 59eeabf..ca76d40 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,65 +9,19 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -data_path=$(ynh_app_setting_get --app=$app --key=data_path) -log_file=$(ynh_app_setting_get --app=$app --key=log_file) -path_url=$(ynh_app_setting_get --app=$app --key=path_url) -python=$(ynh_app_setting_get --app=$app --key=python) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) - -#================================================= -# CHECK VERSION -#================================================= - upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# ENSURE DOWNWARD COMPATIBILITY -#================================================= -ynh_script_progression --message="Ensuring downward compatibility..." - -# Create a permission if needed -if ! ynh_permission_exists --permission="api"; then - ynh_permission_create --permission="api" --label="api" --url="/api" --allowed="visitors" "all_users" --auth_header="false" --show_tile="false" --protected="true" -fi - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_restore_upgradebackup -} -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" #================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -mynh_system_user_create - +# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -82,52 +36,30 @@ then fi #================================================= -# NGINX CONFIGURATION +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading NGINX web server configuration..." + +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 ynh_add_nginx_config -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating a configuration file..." - -cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/bin/" - -ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." - -# Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# SETUP FAIL2BAN -#================================================= -ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1 +yunohost service add $app --description="Home Assistant server" --log="$log_file" + +ynh_use_logrotate --logfile="$log_file" --non-append -# Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " #================================================= -# GENERIC FINALIZATION +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...) #================================================= -# SETUP LOGROTATE +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." -ynh_use_logrotate --logfile="$log_file" --non-append +ynh_script_progression --message="Updating a configuration file..." +cp -r "../conf/homeassistant_conf_files/bin/." "$data_dir/bin/" +ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" #================================================= # SET FILE OWNERSHIP / PERMISSIONS @@ -135,16 +67,10 @@ ynh_use_logrotate --logfile="$log_file" --non-append myynh_set_permissions -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." - -yunohost service add $app --description="Home Assistant server" --log="$log_file" - #================================================= # START SYSTEMD SERVICE #================================================= + ynh_script_progression --message="Starting a systemd service..." # start systemd service with --verbose @@ -156,13 +82,6 @@ ynh_store_file_checksum --file="/etc/systemd/system/$app.service" systemctl daemon-reload ynh_systemd_action --service_name=$app --action=restart -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." - -ynh_systemd_action --service_name=nginx --action=reload - #================================================= # END OF SCRIPT #================================================= diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..86b0231 --- /dev/null +++ b/tests.toml @@ -0,0 +1,22 @@ +test_format = 1.0 + +[default] + + # ------------ + # Tests to run + # ------------ + + + + # ------------------------------- + # Default args to use for install + # ------------------------------- + + + + # ------------------------------- + # Commits to test upgrade from + # ------------------------------- + + test_upgrade_from.c1690e4.name = "Upgrade from 2023.1.7~ynh2" +