mirror of
https://github.com/YunoHost-Apps/homeassistant_ynh.git
synced 2024-09-03 19:26:16 +02:00
58 lines
1.9 KiB
Bash
58 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# to test the functionnality :
|
|
# yunohost backup create -n "homeassistant-test" --apps homeassistant
|
|
# yunohost app remove homeassistant
|
|
# yunohost backup restore "homeassistant-test"
|
|
|
|
source ../settings/scripts/_common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
# manage script failure
|
|
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)
|
|
|
|
# definie useful vars
|
|
final_path="/opt/yunohost/$app"
|
|
home_path="/home/$app"
|
|
data_path="/home/$app/.$app"
|
|
|
|
# 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."
|
|
|
|
# add required packages
|
|
ynh_install_app_dependencies "$PKG_DEPENDENCIES"
|
|
|
|
# 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"
|
|
|
|
# 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
|
|
|
|
# add service in admin panel
|
|
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server"
|
|
|
|
# enable & restart systemd service
|
|
ynh_system_reload --service_name="$app@$app" --action=enable
|
|
ynh_check_starting --line_to_match="Home Assistant initialized" --app_log="systemd" --timeout=1000 --service_name="$app@$app"
|
|
|
|
# reload nginx
|
|
ynh_system_reload --service_name=nginx
|