mirror of
https://github.com/YunoHost-Apps/homeassistant_ynh.git
synced 2024-09-03 19:26:16 +02:00
commit
186f53face
12 changed files with 342 additions and 127 deletions
70
README.md
70
README.md
|
@ -1,11 +1,71 @@
|
|||
# Home Assistant for YunoHost
|
||||
|
||||
Home Assistant is a home automation platform running on Python 3. It is able to track and control all devices at home and offer a platform for automating control.
|
||||
|
||||
[](https://dash.yunohost.org/appci/app/homeassistant)  
|
||||
[](https://install-app.yunohost.org/?app=homeassistant)
|
||||
|
||||
[](https://ci-apps.yunohost.org/jenkins/job/homeassistant%20%28Community%29/lastBuild/consoleFull)
|
||||
*[Lire ce readme en français.](./README_fr.md)*
|
||||
|
||||
> *This package allows you to install Home Assistant quickly and simply on a YunoHost server.
|
||||
If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.*
|
||||
|
||||
## Overview
|
||||
Home Assistant is free, open-source home automation software designed to be the central control system of a smart home or smart home. Written in Python, its main focus is local control and privacy.
|
||||
|
||||
**Shipped version:** 0.117.6
|
||||
|
||||
## Screenshots
|
||||
|
||||

|
||||
|
||||
## Demo
|
||||
|
||||
* [Official demo](https://demo.home-assistant.io/)
|
||||
|
||||
## Configuration
|
||||
|
||||
How to configure this app: From an admin panel
|
||||
|
||||
## Documentation
|
||||
|
||||
* Official documentation: https://www.home-assistant.io/docs/
|
||||
* YunoHost documentation: If specific documentation is needed, feel free to contribute.
|
||||
|
||||
## YunoHost specific features
|
||||
|
||||
#### Multi-user support
|
||||
|
||||
* Are LDAP and HTTP auth supported? LDAP=Yes | HTTP auth=No
|
||||
* Can the app be used by multiple users? Yes
|
||||
|
||||
#### Supported architectures
|
||||
|
||||
* x86-64 - [](https://ci-apps.yunohost.org/ci/apps/homeassistant/)
|
||||
* ARMv8-A - [](https://ci-apps-arm.yunohost.org/ci/apps/homeassistant/)
|
||||
|
||||
## Limitations
|
||||
|
||||
* Any known limitations.
|
||||
|
||||
## Additional information
|
||||
|
||||
* As the pyhton version shipped in Debian stable is not supported, a recent version will be built during the installation process. it may take a while to achive that (15 to 60 minutes)
|
||||
|
||||
## Links
|
||||
* [Home Assistant website](https://www.home-assistant.io/)
|
||||
* [Home Assistant git repository](https://github.com/home-assistant/home-assistant)
|
||||
|
||||
* Report a bug: https://github.com/YunoHost-Apps/homeassistant_ynh/issues
|
||||
* App website: https://www.home-assistant.io/
|
||||
* Upstream app repository: https://github.com/home-assistant/home-assistant
|
||||
* YunoHost website: https://yunohost.org/
|
||||
|
||||
---
|
||||
|
||||
## Developer info
|
||||
|
||||
Please send your pull request to the [testing branch](https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing).
|
||||
|
||||
To try the testing branch, please proceed like that.
|
||||
```
|
||||
sudo yunohost app install https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug
|
||||
or
|
||||
sudo yunohost app upgrade homeassistant -u https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug
|
||||
```
|
||||
|
|
|
@ -1,31 +1,25 @@
|
|||
;; Test complet
|
||||
; Manifest
|
||||
domain="domain.tld" (DOMAIN)
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
is_public=1 (PUBLIC|public=1|private=0)
|
||||
; Actions
|
||||
is_public=1|0
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=0
|
||||
setup_root=1
|
||||
setup_nourl=0
|
||||
setup_private=0
|
||||
setup_public=0
|
||||
setup_private=1
|
||||
setup_public=1
|
||||
upgrade=1
|
||||
upgrade=1 from_commit=b07405d0f885f28764031dd80d27af84a90007b1
|
||||
backup_restore=1
|
||||
multi_instance=0
|
||||
incorrect_path=0
|
||||
port_already_use=1
|
||||
change_url=0
|
||||
change_url=1
|
||||
actions=1
|
||||
config_panel=0
|
||||
;;; Levels
|
||||
Level 1=auto
|
||||
Level 2=auto
|
||||
Level 3=auto
|
||||
Level 4=na
|
||||
Level 5=1
|
||||
Level 6=auto
|
||||
Level 7=auto
|
||||
Level 8=0
|
||||
Level 9=0
|
||||
Level 10=0
|
||||
Level 5=auto
|
||||
;;; Options
|
||||
Email=
|
||||
Notification=none
|
||||
Notification=all
|
||||
|
|
|
@ -4,20 +4,22 @@
|
|||
app="homeassistant"
|
||||
final_path="/opt/yunohost/$app"
|
||||
|
||||
# stop homeassistant systemd service
|
||||
#sudo systemctl stop $app@$app.service
|
||||
local MY_PYTHON=$(readlink -e "$final_path/bin/python")
|
||||
|
||||
# create the virtual environment
|
||||
python3 -m venv "$final_path"
|
||||
$MY_PYTHON -m venv "$final_path"
|
||||
|
||||
# activate the virtual environment
|
||||
. "$final_path/bin/activate"
|
||||
source "$final_path/bin/activate"
|
||||
|
||||
# upgrade required python package
|
||||
python3 -m pip install --upgrade wheel
|
||||
# install last version of pip
|
||||
pip install --upgrade pip
|
||||
|
||||
# install last version of wheel
|
||||
pip install --upgrade wheel
|
||||
|
||||
# upgrade homeassistant python package
|
||||
pip3 install --upgrade $app
|
||||
pip install --upgrade $app
|
||||
|
||||
# restart homeassistant systemd service
|
||||
sudo systemctl restart $app@$app.service
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
title: Home
|
||||
views:
|
||||
- path: default_view
|
||||
title: Home
|
||||
badges:
|
||||
- entity: sun.sun
|
||||
cards:
|
||||
- type: entities
|
||||
entities:
|
||||
- sensor.current_version
|
||||
- sensor.latest_available_version
|
||||
- switch.upgrade_homeassistant
|
||||
title: Home Assistant
|
|
@ -6,7 +6,7 @@
|
|||
"en": "Home automation platform",
|
||||
"fr": "Plateforme domotique"
|
||||
},
|
||||
"version": "1.1.0",
|
||||
"version": "0.117.6~ynh1",
|
||||
"url": "https://github.com/home-assistant/home-assistant",
|
||||
"license": "Apache-2.0",
|
||||
"maintainer": {
|
||||
|
@ -14,7 +14,7 @@
|
|||
"email": "ewilly@ewilly.fr"
|
||||
},
|
||||
"requirements": {
|
||||
"yunohost": ">= 4.0"
|
||||
"yunohost": ">= 4.0.0"
|
||||
},
|
||||
"multi_instance": false,
|
||||
"services": [
|
||||
|
@ -39,8 +39,8 @@
|
|||
"name": "is_public",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "Should this application be public ? (if not, Smartphone app will not work)",
|
||||
"fr": "Est-ce que cette application doit être visible publiquement ? (dans le cas contraire, l'application sur Smartphone ne fonctionnera pas)"
|
||||
"en": "Should this application be public?",
|
||||
"fr": "Est-ce que cette application doit être visible publiquement ?"
|
||||
},
|
||||
"help": {
|
||||
"en": "If not public, Smartphone app will not work",
|
||||
|
|
|
@ -3,22 +3,14 @@
|
|||
#
|
||||
|
||||
# Release to install
|
||||
VERSION=0.114.4
|
||||
VERSION=0.117.6
|
||||
|
||||
# Package dependencies
|
||||
PKG_DEPENDENCIES="python3 python3-venv python3-pip build-essential libssl-dev libffi-dev python3-dev"
|
||||
PKG_DEPENDENCIES="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5"
|
||||
|
||||
# Check if directory/file already exists (path in argument)
|
||||
myynh_check_path () {
|
||||
[ -z "$1" ] && ynh_die "No argument supplied"
|
||||
[ ! -e "$1" ] || ynh_die "$1 already exists"
|
||||
}
|
||||
|
||||
# Create directory only if not already exists (path in argument)
|
||||
myynh_create_dir () {
|
||||
[ -z "$1" ] && ynh_die "No argument supplied"
|
||||
[ -d "$1" ] || mkdir -p "$1"
|
||||
}
|
||||
# Requirements (Major.Minor.Patch)
|
||||
# PY_VERSION=$(curl -s "https://www.python.org/ftp/python/" | grep ">3.8" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2)
|
||||
PY_REQUIRED_VERSION=3.8.6
|
||||
|
||||
# Execute a command as another user
|
||||
# usage: exec_as USER COMMAND [ARG ...]
|
||||
|
@ -32,3 +24,130 @@ exec_as() {
|
|||
sudo -u "$USER" "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# Compare version in arguments
|
||||
myynh_version_compare () {
|
||||
# myynh_version_compare A B
|
||||
# 0 -> A = B
|
||||
# 1 -> A > B
|
||||
# 2 -> A < B
|
||||
if [[ $1 == $2 ]] ; then
|
||||
echo 0; return
|
||||
fi
|
||||
local IFS=.
|
||||
local i ver1=($1) ver2=($2)
|
||||
# fill empty fields in ver1 with zeros
|
||||
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) ; do
|
||||
ver1[i]=0
|
||||
done
|
||||
for ((i=0; i<${#ver1[@]}; i++)) ; do
|
||||
if [[ -z ${ver2[i]} ]] ; then
|
||||
# fill empty fields in ver2 with zeros
|
||||
ver2[i]=0
|
||||
fi
|
||||
if ((10#${ver1[i]} > 10#${ver2[i]})) ; then
|
||||
echo 1; return
|
||||
fi
|
||||
if ((10#${ver1[i]} < 10#${ver2[i]})) ; then
|
||||
echo 2; return
|
||||
fi
|
||||
done
|
||||
echo 1; return
|
||||
}
|
||||
|
||||
# Package dependencies
|
||||
# usage: myynh_install_dependencies --python="3.8.6"
|
||||
# | arg: -p, --python= - the python version to install
|
||||
myynh_install_dependencies () {
|
||||
# Declare an array to define the options of this helper.
|
||||
local legacy_args=u
|
||||
local -A args_array=( [p]=python= )
|
||||
local python
|
||||
# Manage arguments with getopts
|
||||
ynh_handle_getopts_args "$@"
|
||||
|
||||
# Install main dependencies from apt
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
ynh_install_app_dependencies "${PKG_DEPENDENCIES}"
|
||||
|
||||
# Check python version from APT
|
||||
local PY_APT_VERSION=$(python3 --version | cut -d ' ' -f 2)
|
||||
|
||||
# Check existing built version of python in /usr/local/bin
|
||||
if [ -e "/usr/local/bin/python${python:0:3}" ]; then
|
||||
local PY_BUILT_VERSION=$(/usr/local/bin/python${python:0:3} --version \
|
||||
| cut -d ' ' -f 2)
|
||||
else
|
||||
local PY_BUILT_VERSION=0
|
||||
fi
|
||||
|
||||
# Compare version
|
||||
if [ $(myynh_version_compare $PY_APT_VERSION $python) -le 1 ]; then
|
||||
# APT >= Required
|
||||
ynh_script_progression --message="Using provided python3..."
|
||||
MY_PYTHON="python3"
|
||||
else
|
||||
# Either python already built or to build
|
||||
ynh_script_progression --message="Installing additional dependencies..."
|
||||
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"
|
||||
ynh_install_app_dependencies "${PKG_DEPENDENCIES}"
|
||||
if [ $(myynh_version_compare $PY_BUILT_VERSION $python) -le 1 ]; then
|
||||
# Built >= Required
|
||||
ynh_script_progression --message="Using already used python3 built version..."
|
||||
MY_PYTHON="/usr/local/bin/python${PY_BUILT_VERSION:0:3}"
|
||||
else
|
||||
# APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin
|
||||
ynh_script_progression --message="Building python (may take a while)..."
|
||||
# Store current direcotry
|
||||
local MY_DIR=$(pwd)
|
||||
# Download
|
||||
wget -O "/tmp/Python-$python.tar.xz" "https://www.python.org/ftp/python/$python/Python-$python.tar.xz"
|
||||
# Extract
|
||||
cd /tmp
|
||||
tar xf "Python-$python.tar.xz"
|
||||
# Install
|
||||
cd "Python-$python"
|
||||
./configure --enable-optimizations
|
||||
make -j4
|
||||
make altinstall
|
||||
# Clean
|
||||
cd ..
|
||||
ynh_secure_remove "Python-$python"
|
||||
ynh_secure_remove "Python-$python.tar.xz"
|
||||
# Set version
|
||||
MY_PYTHON="/usr/local/bin/python${python:0:3}"
|
||||
# Go back to working directory
|
||||
cd $MY_DIR
|
||||
fi
|
||||
fi
|
||||
# Save python version in settings
|
||||
ynh_app_setting_set --app="$app" --key=python --value="$python"
|
||||
}
|
||||
|
||||
# Install/Upgrade Homeassistant in virtual environement
|
||||
myynh_install_homeassistant () {
|
||||
exec_as $app -H -s /bin/bash -c " \
|
||||
echo 'create the virtual environment' \
|
||||
&& $MY_PYTHON -m venv "$final_path" \
|
||||
&& echo 'activate the virtual environment' \
|
||||
&& source "$final_path/bin/activate" \
|
||||
&& echo 'install last version of pip' \
|
||||
&& pip install --upgrade pip \
|
||||
&& echo 'install last version of wheel' \
|
||||
&& pip install --upgrade wheel \
|
||||
&& echo 'install Home Assistant' \
|
||||
&& pip install --upgrade $app==$VERSION \
|
||||
"
|
||||
}
|
||||
|
||||
# Check if directory/file already exists (path in argument)
|
||||
myynh_check_path () {
|
||||
[ -z "$1" ] && ynh_die "No argument supplied"
|
||||
[ ! -e "$1" ] || ynh_die "$1 already exists"
|
||||
}
|
||||
|
||||
# Create directory only if not already exists (path in argument)
|
||||
myynh_create_dir () {
|
||||
[ -z "$1" ] && ynh_die "No argument supplied"
|
||||
[ -d "$1" ] || mkdir -p "$1"
|
||||
}
|
||||
|
|
|
@ -10,15 +10,23 @@ ynh_abort_if_errors
|
|||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
||||
|
||||
# definie useful vars
|
||||
final_path="/opt/yunohost/$app"
|
||||
home_path="/home/$app"
|
||||
|
||||
ynh_script_progression --message="Storing the python version in settings..."
|
||||
# store python version
|
||||
python=$(cat "$final_path/bin/python3" --version | cut -d ' ' -f 2)
|
||||
ynh_app_setting_set --app="$app" --key=python --value="$python"
|
||||
|
||||
# backup source & conf files
|
||||
ynh_script_progression --message="Backuping the app, datas & ystem files..."
|
||||
ynh_backup --src_path="$final_path"
|
||||
ynh_backup --src_path="$home_path"
|
||||
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_backup --src_path="/etc/sudoers.d/$app"
|
||||
ynh_backup --src_path="/etc/systemd/system/$app@$app.service"
|
||||
|
||||
ynh_script_progression --message="Backup of $app completed" --last
|
||||
|
|
45
scripts/change_url
Normal file
45
scripts/change_url
Normal file
|
@ -0,0 +1,45 @@
|
|||
#!/bin/bash
|
||||
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
old_domain=$YNH_APP_OLD_DOMAIN
|
||||
new_domain=$YNH_APP_NEW_DOMAIN
|
||||
|
||||
# load settings
|
||||
ynh_script_progression --message="Loading installation settings..." --time --weight=1
|
||||
old_nginx_conf="/etc/nginx/conf.d/$old_domain.d/$app.conf"
|
||||
new_nginx_conf="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
|
||||
# manage script failure
|
||||
ynh_script_progression --message="Backing up the app before changing its url (may take a while)..." --time --weight=1
|
||||
ynh_backup_before_upgrade
|
||||
ynh_clean_setup () {
|
||||
ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf"
|
||||
ynh_restore_upgradebackup
|
||||
}
|
||||
ynh_abort_if_errors
|
||||
|
||||
# check which parts should be changed
|
||||
change_domain=0
|
||||
if [ "$old_domain" != "$new_domain" ]; then
|
||||
change_domain=1
|
||||
fi
|
||||
|
||||
# Change the domain for nginx
|
||||
if [ $change_domain -eq 1 ]; then
|
||||
ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1
|
||||
# Delete file checksum for the old conf file location
|
||||
ynh_delete_file_checksum --file="$old_nginx_conf"
|
||||
mv "$old_nginx_conf" "$new_nginx_conf"
|
||||
# Store file checksum for the new config file location
|
||||
ynh_store_file_checksum --file="$new_nginx_conf"
|
||||
fi
|
||||
|
||||
# reload nginx
|
||||
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
ynh_script_progression --message="Change of URL completed for $app" --time --last
|
|
@ -18,30 +18,26 @@ is_public=$YNH_APP_ARG_IS_PUBLIC
|
|||
final_path="/opt/yunohost/$app"
|
||||
home_path="/home/$app"
|
||||
data_path="/home/$app/.$app"
|
||||
path_url=$(ynh_normalize_url_path --path_url="/")
|
||||
|
||||
# check domain/path availability
|
||||
ynh_script_progression --message="Validating installation parameters..."
|
||||
path_url=$(ynh_normalize_url_path "/")
|
||||
ynh_webpath_available "$domain" "$path_url" || ynh_die "$domain/$path_url is not available, please use an other domain."
|
||||
ynh_webpath_register $app "$domain" "$path_url"
|
||||
|
||||
# add required packages
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
||||
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
|
||||
ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url"
|
||||
|
||||
# save app settings
|
||||
ynh_script_progression --message="Storing installation settings..."
|
||||
ynh_app_setting_set $app domain "$domain"
|
||||
ynh_app_setting_set --app="$app" --key=domain --value="$domain"
|
||||
|
||||
# find a free port & open it
|
||||
ynh_script_progression --message="Looking for a free port and opening it..."
|
||||
port=$(ynh_find_port 8123)
|
||||
ynh_app_setting_set $app port $port
|
||||
ynh_exec_fully_quiet yunohost firewall allow TCP $port
|
||||
ynh_app_setting_set --app="$app" --key=port --value="$port"
|
||||
ynh_exec_fully_quiet yunohost firewall allow TCP "$port"
|
||||
|
||||
# create a dedicated system user
|
||||
ynh_script_progression --message="Creating dedicated user, rights and folders..."
|
||||
ynh_system_user_create $app
|
||||
ynh_system_user_create --username="$app"
|
||||
## grant sudo permissions to the user to manage his own systemd service
|
||||
myynh_create_dir "/etc/sudoers.d"
|
||||
cp "../conf/sudoers" "/etc/sudoers.d/$app"
|
||||
|
@ -52,38 +48,32 @@ chown $app: "$final_path"
|
|||
myynh_create_dir "$data_path"
|
||||
chown -R $app: "$home_path"
|
||||
|
||||
# build (if needed) & install Pyhton
|
||||
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
|
||||
|
||||
# installation in a virtual environment
|
||||
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
||||
exec_as $app -H -s /bin/bash -c " \
|
||||
echo 'create the virtual environment' \
|
||||
&& python3 -m venv "$final_path" \
|
||||
&& echo 'activate the virtual environment' \
|
||||
&& source "$final_path/bin/activate" \
|
||||
&& echo 'install a required python package' \
|
||||
&& python3 -m pip install --upgrade wheel \
|
||||
&& echo 'install Home Assistant' \
|
||||
&& pip3 install --upgrade $app==$VERSION \
|
||||
"
|
||||
myynh_install_homeassistant
|
||||
|
||||
# set default configuration files
|
||||
# set default configuration files and move all homeassistant_conf_files
|
||||
ynh_script_progression --message="Configuring the installation..."
|
||||
ynh_replace_string "__PORT__" "$port" "../conf/homeassistant_conf_files/configuration.yaml"
|
||||
chmod -R +x "../conf/homeassistant_conf_files/bin/"
|
||||
## move all homeassistant_conf_files
|
||||
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="../conf/homeassistant_conf_files/configuration.yaml"
|
||||
cp -r "../conf/homeassistant_conf_files/." "$data_path/"
|
||||
chown -R $app: "$data_path"
|
||||
chmod -R +x "$data_path/bin/"
|
||||
|
||||
# setup up systemd service
|
||||
ynh_script_progression --message="Adding the dedicated service..."
|
||||
ynh_add_systemd_config --service="$app@$app"
|
||||
## add service in admin panel
|
||||
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server"
|
||||
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
|
||||
|
||||
# start systemd service
|
||||
ynh_script_progression --message="Starting the Home Assistant server..."
|
||||
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=1000
|
||||
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
|
||||
# remove --verbose from service
|
||||
ynh_replace_string " --verbose" "" "/etc/systemd/system/$app@$app.service"
|
||||
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
|
||||
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name="$app@$app" --action=restart
|
||||
|
||||
|
@ -95,6 +85,6 @@ ynh_systemd_action --service_name=nginx --action=reload
|
|||
|
||||
# unprotect app access if public (needed for Android app to work)
|
||||
ynh_script_progression --message="Configuring permissions..."
|
||||
[ $is_public -eq 1 ] && ynh_permission_update --permission "main" --add "visitors"
|
||||
[ $is_public -eq 1 ] && ynh_permission_update --permission="main" --add="visitors"
|
||||
|
||||
ynh_script_progression --message="Installation of $app completed" --last
|
||||
|
|
|
@ -40,7 +40,7 @@ ynh_secure_remove --file="/etc/systemd/system/$app@$app.service"
|
|||
ynh_exec_fully_quiet yunohost firewall disallow TCP $port
|
||||
|
||||
# delete a system user
|
||||
ynh_system_user_delete --username=$app
|
||||
ynh_system_user_delete --username="$app"
|
||||
|
||||
# remove sudoers file
|
||||
ynh_secure_remove --file="/etc/sudoers.d/$app"
|
||||
|
|
|
@ -15,46 +15,62 @@ ynh_abort_if_errors
|
|||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
||||
port=$(ynh_app_setting_get --app="$app" --key=port)
|
||||
python=$(ynh_app_setting_get --app="$app" --key=python)
|
||||
|
||||
# definie useful vars
|
||||
final_path="/opt/yunohost/$app"
|
||||
home_path="/home/$app"
|
||||
data_path="/home/$app/.$app"
|
||||
path_url=$(ynh_normalize_url_path --path_url="/")
|
||||
|
||||
ynh_script_progression --message="Validating recovery parameters..."
|
||||
# check domain/path availability
|
||||
path_url=$(ynh_normalize_url_path "/")
|
||||
ynh_webpath_available $domain $path_url || ynh_die "$domain/$path_url is not available, please use an other domain."
|
||||
[ ! -d "$final_path" ] || ynh_die --message="This path already contains a folder"
|
||||
ynh_webpath_available --domain="$domain" --path_url="$path_url" || ynh_die "$domain/$path_url is not available, please use an other domain."
|
||||
|
||||
# add required packages
|
||||
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
||||
ynh_script_progression --message="Restoring the port and opening it..."
|
||||
# restore port
|
||||
[ $port -eq $(ynh_find_port $port) ] || ynh_die "$port is not available, please use an other port"
|
||||
ynh_exec_fully_quiet yunohost firewall allow TCP $port
|
||||
|
||||
ynh_script_progression --message="Restoring dedicated user, rights and folders..."
|
||||
# restore dedicated system user
|
||||
ynh_system_user_create --username="$app"
|
||||
|
||||
# restore conf files
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
ynh_restore_file --origin_path="/etc/sudoers.d/$app"
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service"
|
||||
|
||||
# restore source
|
||||
ynh_restore_file --origin_path="$final_path"
|
||||
chown -R $app: "$final_path"
|
||||
|
||||
ynh_script_progression --message="Restoring the data..."
|
||||
# restore data
|
||||
ynh_restore_file --origin_path="$home_path"
|
||||
chown -R $app: "$home_path"
|
||||
chmod -R +x "$home_path/.homeassistant/bin"
|
||||
|
||||
# restore port
|
||||
[ $port -eq $(ynh_find_port $port) ] || ynh_die "$port is not available, please use an other port"
|
||||
ynh_exec_fully_quiet yunohost firewall allow TCP $port
|
||||
ynh_script_progression --message="Restoring the packages dependencies..."
|
||||
# add required packages
|
||||
myynh_install_dependencies --python="$python"
|
||||
|
||||
ynh_script_progression --message="Restoring the dedicated service..."
|
||||
ynh_restore_file --origin_path="/etc/systemd/system/$app@$app.service"
|
||||
# add service in admin panel
|
||||
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server"
|
||||
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
|
||||
|
||||
# start systemd service
|
||||
ynh_systemd_action --service_name="$app@$app" --action=start
|
||||
ynh_script_progression --message="Starting the Home Assistant server..."
|
||||
# add --verbose to service
|
||||
sed --in-place "/ExecStart/s/$/ --verbose/" "/etc/systemd/system/$app@$app.service"
|
||||
# start
|
||||
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
|
||||
# remove --verbose from service and restart
|
||||
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name="$app@$app" --action=restart
|
||||
|
||||
ynh_script_progression --message="Restoring nginx web server..."
|
||||
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
||||
# reload nginx
|
||||
ynh_systemd_action --service_name=nginx --action=reload
|
||||
|
||||
ynh_script_progression --message="Recovery of $app completed" --last
|
||||
|
|
|
@ -11,15 +11,15 @@ ynh_abort_if_errors
|
|||
|
||||
# retrieve arguments
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
||||
port=$(ynh_app_setting_get --app=$app --key=port)
|
||||
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
||||
port=$(ynh_app_setting_get --app="$app" --key=port)
|
||||
|
||||
# Cleaning legacy permissions
|
||||
ynh_script_progression --message="Cleaning legacy permissions..."
|
||||
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
||||
is_public=$(ynh_app_setting_get --app="$app" --key=is_public)
|
||||
if [ -n "$is_public" ]; then
|
||||
ynh_app_setting_delete --app=$app --key=is_public
|
||||
ynh_app_setting_delete --app=$app --key=unprotected_uris
|
||||
ynh_app_setting_delete --app="$app" --key=is_public
|
||||
ynh_app_setting_delete --app="$app" --key=unprotected_uris
|
||||
fi
|
||||
|
||||
# definie useful vars
|
||||
|
@ -41,9 +41,8 @@ ynh_script_progression --message="Creating dedicated user, rights and folders...
|
|||
myynh_create_dir "/etc/sudoers.d"
|
||||
cp "../conf/sudoers" "/etc/sudoers.d/$app"
|
||||
|
||||
# add required packages
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
||||
# build (if needed) & install Pyhton
|
||||
myynh_install_dependencies --python="$PY_REQUIRED_VERSION"
|
||||
|
||||
# stop systemd service
|
||||
ynh_script_progression --message="Stoping service..."
|
||||
|
@ -51,16 +50,8 @@ ynh_systemd_action --service_name="$app@$app" --action=stop
|
|||
|
||||
# installation in a virtual environment
|
||||
ynh_script_progression --message="Installing Home Assistant in a virtual environment..."
|
||||
exec_as $app -H -s /bin/bash -c " \
|
||||
echo 'create the virtual environment' \
|
||||
&& python3 -m venv "$final_path" \
|
||||
&& echo 'activate the virtual environment' \
|
||||
&& source "$final_path/bin/activate" \
|
||||
&& echo 'install a required python package' \
|
||||
&& python3 -m pip install --upgrade wheel \
|
||||
&& echo 'install Home Assistant' \
|
||||
&& pip3 install --upgrade $app==$VERSION \
|
||||
"
|
||||
myynh_install_homeassistant
|
||||
|
||||
# update script in bin
|
||||
ynh_script_progression --message="Updating yunohost script used by homeassitant..."
|
||||
cp -r "../conf/homeassistant_conf_files/bin/." "$data_path/bin/"
|
||||
|
@ -70,12 +61,15 @@ chmod -R +x "$data_path/bin/"
|
|||
# setup up systemd service
|
||||
ynh_script_progression --message="Adding the dedicated service..."
|
||||
ynh_add_systemd_config --service="$app@$app"
|
||||
## add service in admin panel
|
||||
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
|
||||
|
||||
# start systemd service
|
||||
ynh_script_progression --message="Starting the Home Assistant server..."
|
||||
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=1000
|
||||
ynh_systemd_action --service_name="$app@$app" --action=start --line_match="Home Assistant initialized" --log_path="systemd" --timeout=3600
|
||||
# remove --verbose from service
|
||||
ynh_replace_string " --verbose" "" "/etc/systemd/system/$app@$app.service"
|
||||
ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app@$app.service"
|
||||
ynh_store_file_checksum --file="/etc/systemd/system/$app@$app.service"
|
||||
systemctl daemon-reload
|
||||
ynh_systemd_action --service_name="$app@$app" --action=restart
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue