From 75a59d7e6c2a5193708f2bbf22b54d0350226d4b Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Sun, 12 Feb 2023 19:34:21 +0000 Subject: [PATCH 01/14] Auto-update README --- README.md | 1 + README_fr.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 9cd4ce8..6e03706 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ It shall NOT be edited by hand. # Home Assistant for YunoHost [![Integration level](https://dash.yunohost.org/integration/homeassistant.svg)](https://dash.yunohost.org/appci/app/homeassistant) ![Working status](https://ci-apps.yunohost.org/ci/badges/homeassistant.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/homeassistant.maintain.svg) + [![Install Home Assistant with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=homeassistant) *[Lire ce readme en français.](./README_fr.md)* diff --git a/README_fr.md b/README_fr.md index ff967e2..430480f 100644 --- a/README_fr.md +++ b/README_fr.md @@ -6,6 +6,7 @@ It shall NOT be edited by hand. # Home Assistant pour YunoHost [![Niveau d’intégration](https://dash.yunohost.org/integration/homeassistant.svg)](https://dash.yunohost.org/appci/app/homeassistant) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/homeassistant.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/homeassistant.maintain.svg) + [![Installer Home Assistant avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=homeassistant) *[Read this readme in english.](./README.md)* From 992c8941a59818470cd890e6f926e5a156d34fa6 Mon Sep 17 00:00:00 2001 From: ewilly Date: Sun, 12 Feb 2023 22:01:31 +0100 Subject: [PATCH 02/14] Update to packaging v2 --- check_process | 27 ---- .../bin/upgrade_homeassistant.sh | 24 ++-- .../configuration.yaml | 4 +- conf/systemd.service | 4 +- manifest.json | 115 ----------------- manifest.toml | 87 +++++++++++++ scripts/_common.sh | 44 ++----- scripts/backup | 26 +--- scripts/install | 121 +++--------------- scripts/remove | 71 +--------- scripts/restore | 83 +++--------- scripts/upgrade | 77 ++--------- test.toml | 22 ++++ 13 files changed, 190 insertions(+), 515 deletions(-) delete mode 100644 check_process delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 test.toml 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/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..e31dc03 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,87 @@ +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 = "all" +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] + + [resources.data_dir] + + [resources.permissions] diff --git a/scripts/_common.sh b/scripts/_common.sh index 4ea9640..a3f53a5 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,41 +112,41 @@ 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 wheel, pip & mysqlclient - ynh_exec_as $app "$final_path/bin/pip3" --cache-dir "$data_path/.cache" install --upgrade wheel pip mysqlclient + ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel pip 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" + chmod -R +x "$data_dir/bin/" chown -R $app: "$(dirname "$log_file")" 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..c86bb2a 100644 --- a/scripts/install +++ b/scripts/install @@ -9,107 +9,40 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -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" +chown -R $app: "$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" +chown -R $app: "$data_dir" # installation in a virtual environment ynh_script_progression --message="Installing Home Assistant in a virtual environment..." @@ -118,8 +51,8 @@ myynh_install_homeassistant #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring NGINX web server..." +ynh_script_progression --message="Configuring NGINX web server..." ynh_add_nginx_config #================================================= @@ -130,19 +63,19 @@ ynh_add_nginx_config 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" +cp -r "../conf/homeassistant_conf_files/." "$data_dir/" +ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml" #================================================= # 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 @@ -151,27 +84,28 @@ ynh_add_systemd_config #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." +ynh_script_progression --message="Configuring log rotation..." ynh_use_logrotate --logfile="$log_file" #================================================= # SET FILE OWNERSHIP / PERMISSIONS #================================================= +ynh_script_progression --message="Configuring files permissions..." myynh_set_permissions #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." -# add service in admin panel +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 @@ -186,27 +120,10 @@ 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..6f2983c 100644 --- a/scripts/remove +++ b/scripts/remove @@ -11,23 +11,6 @@ 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) -db_user=$db_name - #================================================= # STANDARD REMOVE #================================================= @@ -42,61 +25,29 @@ fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd 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_nginx_config -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." - -ynh_remove_app_dependencies - #================================================= # REMOVE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1 -# Remove the dedicated Fail2Ban config +ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1 ynh_remove_fail2ban_config #================================================= @@ -104,23 +55,11 @@ ynh_remove_fail2ban_config #================================================= # 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..8a62a3a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,76 +14,33 @@ 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 +ynh_restore_file --origin_path="$data_dir" --not_mandatory +mkdir -p $data_dir #================================================= # RESTORE FAIL2BAN CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 +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 @@ -91,36 +48,32 @@ ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # SPECIFIC RESTORATION #================================================= -# REINSTALL DEPENDENCIES +# CHECK PYTHON VERSION AND COMPILE IF NEEDED #================================================= -ynh_script_progression --message="Reinstalling dependencies..." -ynh_install_app_dependencies $pkg_dependencies +ynh_script_progression --message="Restoring Python..." --weight=1 myynh_install_python --python="$python" #================================================= # 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 #================================================= + 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_script_progression --message="Restoring the systemd configuration..." 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" @@ -129,15 +82,15 @@ systemctl enable $app.service --quiet #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the logrotate configuration..." +ynh_script_progression --message="Restoring the logrotate configuration..." ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # 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"`) @@ -148,23 +101,23 @@ fi # SET FILE OWNERSHIP / PERMISSIONS #================================================= +ynh_script_progression --message="Configuring files permissions..." myynh_set_permissions #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating 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 +129,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..388e3b2 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,65 +9,21 @@ 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_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 - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -84,39 +40,31 @@ fi #================================================= # NGINX CONFIGURATION #================================================= + ynh_script_progression --message="Upgrading NGINX web server configuration..." - 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/" - +cp -r "../conf/homeassistant_conf_files/bin/." "$data_dir/bin/" ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." +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 +ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1 # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " @@ -125,26 +73,28 @@ ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or requ #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." +ynh_script_progression --message="Upgrading logrotate configuration..." ynh_use_logrotate --logfile="$log_file" --non-append #================================================= # SET FILE OWNERSHIP / PERMISSIONS #================================================= +ynh_script_progression --message="Configuring files permissions..." myynh_set_permissions #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating 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 +106,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/test.toml b/test.toml new file mode 100644 index 0000000..86b0231 --- /dev/null +++ b/test.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" + From 13fc51b77d0c5e5dbbc6d3cb2a70e42acf48c75b Mon Sep 17 00:00:00 2001 From: ewilly Date: Sun, 12 Feb 2023 22:11:52 +0100 Subject: [PATCH 03/14] Fix CI linter --- doc/DESCRIPTION.md | 11 +++++++++++ test.toml => tests.toml | 0 2 files changed, 11 insertions(+) create mode 100644 doc/DESCRIPTION.md rename test.toml => tests.toml (100%) 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/test.toml b/tests.toml similarity index 100% rename from test.toml rename to tests.toml From 418a0f2db4cd685723c57ceaa29facc525b5cd14 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Sun, 12 Feb 2023 21:12:04 +0000 Subject: [PATCH 04/14] Auto-update README --- README.md | 13 ++++++++++++- README_fr.md | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e03706..77b1e48 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 diff --git a/README_fr.md b/README_fr.md index 430480f..3dfbb81 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 From 48879441aa0a97e0cfee889d5e313c69142f08c3 Mon Sep 17 00:00:00 2001 From: ewilly Date: Mon, 13 Feb 2023 19:08:15 +0100 Subject: [PATCH 05/14] Update manifest.toml Co-authored-by: Alexandre Aubin --- manifest.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.toml b/manifest.toml index e31dc03..46a71da 100644 --- a/manifest.toml +++ b/manifest.toml @@ -85,3 +85,4 @@ ram.runtime = "2G" [resources.data_dir] [resources.permissions] + main.url = "/" From a1258d7b242b094461815e9e5156732699e48bd7 Mon Sep 17 00:00:00 2001 From: ewilly Date: Wed, 15 Feb 2023 12:31:34 +0100 Subject: [PATCH 06/14] Fix packaging v2 --- manifest.toml | 17 ++++++++++- scripts/_common.sh | 19 +++++++++--- scripts/install | 74 ++++++++++++++------------------------------ scripts/remove | 39 ++++-------------------- scripts/restore | 76 ++++++++++++++-------------------------------- scripts/upgrade | 60 +++++++++--------------------------- 6 files changed, 96 insertions(+), 189 deletions(-) diff --git a/manifest.toml b/manifest.toml index 46a71da..537fa87 100644 --- a/manifest.toml +++ b/manifest.toml @@ -19,7 +19,7 @@ cpe = "cpe:2.3:a:home-assistant:home-assistant" [integration] yunohost = ">= 11.0.0" -architectures = "all" +architectures = ["amd64", "arm64"] multi_instance = false ldap = true sso = false @@ -81,8 +81,23 @@ ram.runtime = "2G" [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 a3f53a5..9b91f84 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -124,8 +124,17 @@ myynh_install_homeassistant () { # add pip ynh_exec_as $app "$install_dir/bin/python3" -m ensurepip - # install last version of wheel, pip & mysqlclient - ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel pip mysqlclient + # install last version of 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 "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel + + # install last version of 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 "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade mysqlclient # install Home Assistant ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade $app==$app_version @@ -146,9 +155,9 @@ myynh_set_permissions () { chown -R $app: "$data_dir" chmod 750 "$data_dir" chmod -R o-rwx "$data_dir" - chmod -R +x "$data_dir/bin/" + [ ! -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/install b/scripts/install index c86bb2a..9bf31eb 100644 --- a/scripts/install +++ b/scripts/install @@ -10,15 +10,10 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# DEFINE USEFULL VARS +# DEFINE USEFULL VARS / SETTINGS #================================================= log_file="/var/log/$app/$app.log" - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= - ynh_app_setting_set --app=$app --key=log_file --value="$log_file" #================================================= @@ -38,28 +33,40 @@ ynh_script_progression --message="Setting up source files..." # create a directory for the installation of Home Assistant myynh_create_dir "$install_dir" -chown -R $app: "$install_dir" # create a directory for the datas of Home Assistant myynh_create_dir "$data_dir/.cache" -chown -R $app: "$data_dir" + +# 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" @@ -69,39 +76,11 @@ ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" # ADD A CONFIGURATION #================================================= +ynh_script_progression --message="Adding a configuration file..." --weight=1 + cp -r "../conf/homeassistant_conf_files/." "$data_dir/" ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml" -#================================================= -# SETUP SYSTEMD -#================================================= - -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" - -#================================================= -# SET FILE OWNERSHIP / PERMISSIONS -#================================================= - -ynh_script_progression --message="Configuring files permissions..." -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 #================================================= @@ -117,13 +96,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 -ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 6f2983c..f3c354a 100644 --- a/scripts/remove +++ b/scripts/remove @@ -12,52 +12,25 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +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_remove_systemd_config -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 NGINX CONFIGURATION -#================================================= - -ynh_script_progression --message="Removing NGINX web server configuration..." ynh_remove_nginx_config -#================================================= -# REMOVE FAIL2BAN CONFIGURATION -#================================================= +ynh_remove_logrotate -ynh_script_progression --message="Removing Fail2Ban configuration..." --weight=1 ynh_remove_fail2ban_config -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE VARIOUS FILES -#================================================= - -ynh_script_progression --message="Removing various files..." ynh_secure_remove --file="/etc/sudoers.d/$app" + ynh_secure_remove --file="$(dirname "$log_file")" #================================================= diff --git a/scripts/restore b/scripts/restore index 8a62a3a..edba961 100644 --- a/scripts/restore +++ b/scripts/restore @@ -14,13 +14,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# 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" - #================================================= # RESTORE THE APP MAIN DIR #================================================= @@ -37,14 +30,35 @@ ynh_restore_file --origin_path="$data_dir" --not_mandatory mkdir -p $data_dir #================================================= -# RESTORE FAIL2BAN CONFIGURATION +# RESTORE THE MYSQL DATABASE #================================================= +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 SYSTEM CONFIGURATIONS +#================================================= + +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 + +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 #================================================= @@ -54,38 +68,6 @@ ynh_systemd_action --action=restart --service_name=fail2ban ynh_script_progression --message="Restoring Python..." --weight=1 myynh_install_python --python="$python" -#================================================= -# RESTORE THE MYSQL DATABASE -#================================================= - -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 -#================================================= - -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/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..." -ynh_restore_file --origin_path="/etc/logrotate.d/$app" - #================================================= # IF NEEDED UPDATE THE PYHTON LINK IN THE VIRUTAL ENV. #================================================= @@ -97,20 +79,6 @@ if [ ! -e "$hass_python_link" ] ; then ln -sfn "$hass_python_new_dest" "$hass_python_link" fi -#================================================= -# SET FILE OWNERSHIP / PERMISSIONS -#================================================= - -ynh_script_progression --message="Configuring files permissions..." -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 #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 388e3b2..161ec68 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,10 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# CHECK VERSION -#================================================= - upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -24,6 +20,8 @@ upgrade_type=$(ynh_check_app_version_changed) ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +#================================================= +# "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -38,12 +36,23 @@ 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 +ynh_add_systemd_config + +yunohost service add $app --description="Home Assistant server" --log="$log_file" + +ynh_use_logrotate --logfile="$log_file" --non-append + +ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " + +#================================================= +# RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...) #================================================= # UPDATE A CONFIG FILE #================================================= @@ -52,45 +61,6 @@ 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" -#================================================= -# 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 -# Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="$log_file" --failregex="Login attempt or request with invalid authentication from " - -#================================================= -# GENERIC FINALIZATION -#================================================= -# SETUP LOGROTATE -#================================================= - -ynh_script_progression --message="Upgrading logrotate configuration..." -ynh_use_logrotate --logfile="$log_file" --non-append - -#================================================= -# SET FILE OWNERSHIP / PERMISSIONS -#================================================= - -ynh_script_progression --message="Configuring files permissions..." -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 #================================================= From c15a3f8ad1d64dbb28b1881d10a8e747551fd931 Mon Sep 17 00:00:00 2001 From: ewilly Date: Wed, 15 Feb 2023 18:15:32 +0100 Subject: [PATCH 07/14] Fix permissions --- scripts/install | 6 ++++++ scripts/restore | 6 ++++++ scripts/upgrade | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/scripts/install b/scripts/install index 9bf31eb..a7677c1 100644 --- a/scripts/install +++ b/scripts/install @@ -81,6 +81,12 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1 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 +#================================================= + +myynh_set_permissions + #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/restore b/scripts/restore index edba961..0239f74 100644 --- a/scripts/restore +++ b/scripts/restore @@ -79,6 +79,12 @@ if [ ! -e "$hass_python_link" ] ; then ln -sfn "$hass_python_new_dest" "$hass_python_link" fi +#================================================= +# SET FILE OWNERSHIP / PERMISSIONS +#================================================= + +myynh_set_permissions + #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 161ec68..ca76d40 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -61,6 +61,12 @@ 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 +#================================================= + +myynh_set_permissions + #================================================= # START SYSTEMD SERVICE #================================================= From 53e3c76a54efc8299baf845c4ef1f691945143bd Mon Sep 17 00:00:00 2001 From: ewilly Date: Wed, 15 Feb 2023 20:30:25 +0100 Subject: [PATCH 08/14] refactor DISCLAIMER --- doc/DISCLAIMER.md | 7 ------- doc/notifications/pre_install.md | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 doc/DISCLAIMER.md create mode 100644 doc/notifications/pre_install.md 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). From fe4596bd0cec89108b5fa8a6e72382742dfe3fbc Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Wed, 15 Feb 2023 19:30:42 +0000 Subject: [PATCH 09/14] Auto-update README --- README.md | 10 ---------- README_fr.md | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/README.md b/README.md index 77b1e48..865b5ce 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,6 @@ Open source home automation that puts local control and privacy first. Powered b ![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 3dfbb81..41c8d1a 100644 --- a/README_fr.md +++ b/README_fr.md @@ -37,16 +37,6 @@ Open source home automation that puts local control and privacy first. Powered b ![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 : From 449aa6f1cd0c658fd924894a9ea5ce311220eb96 Mon Sep 17 00:00:00 2001 From: ewilly Date: Wed, 15 Feb 2023 22:06:44 +0100 Subject: [PATCH 10/14] Fix updater workflow --- .github/workflows/updater.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index 2f7072a..4b69443 100644 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -17,8 +17,10 @@ #================================================= # Fetching information -app=$(cat manifest.json | jq -j '.id') -current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') +#app=$(cat manifest.json | jq -j '.id') +#current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') +app=$(cat manifest.toml | awk -v key="id" '$1 == key { gsub("\"","",$3);print $3 }') +current_version=$(cat manifest.toml | awk -v key="version" '$1 == key { gsub("\"","",$3);print $3 }' | awk -F'~' '{print $1}') upstream_version=$(curl -Ls https://pypi.org/pypi/$app/json | jq -r .info.version) # Setting up the environment variables @@ -50,7 +52,8 @@ sed -i "s/^app_version=.*/app_version=$upstream_version/" scripts/_common.sh #================================================= # Replace new version in manifest -echo "$(jq -s --indent 4 ".[] | .version = \"$upstream_version~ynh1\"" manifest.json)" > manifest.json +#echo "$(jq -s --indent 4 ".[] | .version = \"$upstream_version~ynh1\"" manifest.json)" > manifest.json +sed -i "s/^version = .*/version = \"$upstream_version~ynh1\"/" manifest.toml # No need to update the README, yunohost-bot takes care of it From f3ab7a68c9848411be1dc8b30fbbe338f98742c3 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Wed, 15 Feb 2023 21:09:56 +0000 Subject: [PATCH 11/14] Upgrade to v2023.2.5 --- manifest.toml | 2 +- scripts/_common.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.toml b/manifest.toml index 537fa87..58caeb4 100644 --- a/manifest.toml +++ b/manifest.toml @@ -5,7 +5,7 @@ name = "Home Assistant" description.en = "Home automation platform" description.fr = "Plateforme domotique" -version = "2023.2.3~ynh1" +version = "2023.2.5~ynh1" maintainers = ["ewilly"] diff --git a/scripts/_common.sh b/scripts/_common.sh index 9b91f84..5cf7004 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # Release to install -app_version=2023.2.3 +app_version=2023.2.5 # 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) From cdd404b3a772f2bc73f2855bfeadddaadd254d1b Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Wed, 15 Feb 2023 21:10:00 +0000 Subject: [PATCH 12/14] Auto-update README --- README.md | 2 +- README_fr.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 865b5ce..ea71fef 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Open source home automation that puts local control and privacy first. Powered b - Home Energy Management." -**Shipped version:** 2023.2.3~ynh1 +**Shipped version:** 2023.2.5~ynh1 **Demo:** https://demo.home-assistant.io diff --git a/README_fr.md b/README_fr.md index 41c8d1a..087f4bd 100644 --- a/README_fr.md +++ b/README_fr.md @@ -29,7 +29,7 @@ Open source home automation that puts local control and privacy first. Powered b - Home Energy Management." -**Version incluse :** 2023.2.3~ynh1 +**Version incluse :** 2023.2.5~ynh1 **Démo :** https://demo.home-assistant.io From 2d5c6071cb0ca21d89f8c0ae0729a1f81e1a380b Mon Sep 17 00:00:00 2001 From: ewilly Date: Wed, 15 Feb 2023 22:38:23 +0100 Subject: [PATCH 13/14] Fix cache permission --- scripts/install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/install b/scripts/install index a7677c1..df45cc7 100644 --- a/scripts/install +++ b/scripts/install @@ -36,6 +36,7 @@ myynh_create_dir "$install_dir" # create a directory for the datas of Home Assistant myynh_create_dir "$data_dir/.cache" +chown -R $app: "$data_dir" # create a directory for the logs of Home Assistant mkdir -p "$(dirname "$log_file")" From 093f0803fea80a61bb395c948081bc85bce7f648 Mon Sep 17 00:00:00 2001 From: ewilly Date: Wed, 15 Feb 2023 22:40:55 +0100 Subject: [PATCH 14/14] Update yunohost version required --- manifest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.toml b/manifest.toml index 58caeb4..927fa74 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,7 @@ code = "https://github.com/home-assistant/core" cpe = "cpe:2.3:a:home-assistant:home-assistant" [integration] -yunohost = ">= 11.0.0" +yunohost = ">= 11.1.0" architectures = ["amd64", "arm64"] multi_instance = false ldap = true