1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00
This commit is contained in:
ewilly 2020-11-17 18:20:52 +01:00
parent d3dfc8b7d1
commit 4961ac8ca8
5 changed files with 31 additions and 15 deletions

View file

@ -121,7 +121,7 @@ myynh_install_dependencies () {
fi
fi
# Save python version in settings
ynh_app_setting_set $app python "$python"
ynh_app_setting_set --app="$app" --key=python --value="$python"
}
# Install/Upgrade Homeassistant in virtual environement

View file

@ -16,9 +16,17 @@ domain=$(ynh_app_setting_get --app="$app" --key=domain)
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

View file

@ -73,6 +73,7 @@ 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=3600
# remove --verbose from 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

View file

@ -17,6 +17,7 @@ ynh_abort_if_errors
app=$YNH_APP_INSTANCE_NAME
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"
@ -24,47 +25,52 @@ 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
[ ! -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."
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"
# add required packages
myynh_install_dependencies --python=$("$final_path/bin/python" --version | cut -d ' ' -f 2)
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" --needs_exposed_ports $port
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

View file

@ -69,6 +69,7 @@ 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=3600
# remove --verbose from 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