2018-09-25 19:03:30 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# to test the functionnality :
|
2018-10-18 05:16:40 +02:00
|
|
|
# yunohost backup create -n "homeassistant-test" --apps homeassistant
|
2018-09-25 19:03:30 +02:00
|
|
|
# yunohost app remove homeassistant
|
|
|
|
# yunohost backup restore "homeassistant-test"
|
|
|
|
|
2018-10-18 05:16:40 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2018-09-25 19:03:30 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# manage script failure
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-09-25 19:03:30 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
# retrieve arguments
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2020-11-16 15:10:12 +01:00
|
|
|
domain=$(ynh_app_setting_get --app="$app" --key=domain)
|
|
|
|
port=$(ynh_app_setting_get --app="$app" --key=port)
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# definie useful vars
|
2018-10-18 05:16:40 +02:00
|
|
|
final_path="/opt/yunohost/$app"
|
2018-09-25 19:03:30 +02:00
|
|
|
home_path="/home/$app"
|
2018-10-17 16:00:04 +02:00
|
|
|
data_path="/home/$app/.$app"
|
2020-11-16 15:10:12 +01:00
|
|
|
path_url=$(ynh_normalize_url_path --path_url="/")
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# check domain/path availability
|
2020-11-16 15:10:12 +01:00
|
|
|
[ ! -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."
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# restore dedicated system user
|
2020-08-12 22:22:59 +02:00
|
|
|
ynh_system_user_create --username="$app"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# restore conf files
|
2020-08-12 22:22:59 +02:00
|
|
|
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"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# restore source
|
2020-08-12 22:22:59 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2020-11-16 15:10:12 +01:00
|
|
|
# add required packages
|
|
|
|
myynh_install_dependencies --python=$("$final_path/bin/python" --version | cut -d ' ' -f 2)
|
|
|
|
|
2018-09-25 19:03:30 +02:00
|
|
|
# restore data
|
2020-08-12 22:22:59 +02:00
|
|
|
ynh_restore_file --origin_path="$home_path"
|
|
|
|
chown -R $app: "$home_path"
|
|
|
|
chmod -R +x "$home_path/.homeassistant/bin"
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2018-10-18 05:16:40 +02:00
|
|
|
# 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
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# add service in admin panel
|
2020-11-14 14:10:51 +01:00
|
|
|
yunohost service add "$app@$app" --log "$data_path/home-assistant.log" --description "Home Assistant server" --needs_exposed_ports $port
|
2018-09-25 19:03:30 +02:00
|
|
|
|
2020-11-16 15:10:12 +01:00
|
|
|
|
|
|
|
# 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
|
2018-09-25 19:03:30 +02:00
|
|
|
|
|
|
|
# reload nginx
|
2020-08-13 20:50:44 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|