2022-07-20 12:04:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
|
|
|
source ../settings/scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_clean_setup () {
|
2022-09-03 18:58:58 +02:00
|
|
|
true
|
2022-07-20 12:04:29 +02:00
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
2022-07-21 08:24:29 +02:00
|
|
|
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
|
2022-07-20 12:04:29 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2022-07-21 08:24:29 +02:00
|
|
|
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
|
2022-07-23 04:57:16 +02:00
|
|
|
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
|
2022-07-21 08:24:29 +02:00
|
|
|
http_port=$(ynh_app_setting_get --app=$app --key=http_port)
|
|
|
|
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
|
|
|
|
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE DATA DIRECTORY
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Restoring the data directory..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$datadir" --not_mandatory
|
|
|
|
|
|
|
|
mkdir -p $datadir
|
|
|
|
|
|
|
|
chmod 750 "$datadir"
|
|
|
|
chmod -R o-rwx "$datadir"
|
2022-07-21 08:24:29 +02:00
|
|
|
chown -R $app:$app "$datadir"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-23 04:57:16 +02:00
|
|
|
if [ "$node_type" == "server" ]
|
|
|
|
then
|
2022-07-23 17:10:52 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
|
2022-07-23 04:57:16 +02:00
|
|
|
fi
|
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
2022-07-23 04:57:16 +02:00
|
|
|
if [ $driver_lxc -eq 1 ]
|
|
|
|
then
|
2022-07-23 05:17:02 +02:00
|
|
|
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
|
2022-07-23 04:57:16 +02:00
|
|
|
fi
|
2022-07-23 17:10:52 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $client_pkg_dependencies"
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-23 17:10:52 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE VARIOUS FILES
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Restoring various files..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_restore_file --origin_path="$config_path"
|
|
|
|
|
|
|
|
chmod 750 "$config_path"
|
|
|
|
chmod -R o-rwx "$config_path"
|
|
|
|
chown -R $app:$app "$config_path"
|
|
|
|
|
|
|
|
# Open the port
|
|
|
|
ynh_script_progression --message="Configuring firewall..."
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $rpc_port
|
2022-07-21 19:51:27 +02:00
|
|
|
needs_exposed_ports="$rpc_port"
|
2022-07-21 08:24:29 +02:00
|
|
|
if [ "$node_type" == "server" ]
|
|
|
|
then
|
|
|
|
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $serf_port
|
2022-07-21 19:51:27 +02:00
|
|
|
needs_exposed_ports="$serf_port $needs_exposed_ports"
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$node_type" == "client" ]
|
2022-07-23 04:57:16 +02:00
|
|
|
then
|
|
|
|
if [ $driver_lxc -eq 1 ]
|
|
|
|
then
|
2022-07-23 16:56:59 +02:00
|
|
|
client_lxc_bridge=$(ynh_app_setting_get --app=$app --key=client_lxc_bridge)
|
|
|
|
client_lxc_plage_ip=$(ynh_app_setting_get --app=$app --key=client_lxc_plage_ip)
|
|
|
|
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
|
|
|
|
ynh_app_setting_set --app=$app --key=client_lxc_main_iface --value=$client_lxc_main_iface
|
2022-07-23 04:57:16 +02:00
|
|
|
|
|
|
|
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
|
|
|
|
systemctl restart dnsmasq
|
|
|
|
|
|
|
|
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
|
|
|
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
|
|
|
|
fi
|
2022-07-23 15:57:35 +02:00
|
|
|
ynh_secure_remove --file="/etc/lxc/default.conf"
|
2022-07-23 04:57:16 +02:00
|
|
|
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
|
|
|
|
systemctl enable lxc-net --quiet
|
2022-09-03 19:23:27 +02:00
|
|
|
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Finished LXC network bridge setup" --log_path="systemd"
|
2022-07-23 03:41:02 +02:00
|
|
|
fi
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
|
|
|
systemctl enable $app.service --quiet
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 19:56:12 +02:00
|
|
|
mkdir -p /var/log/$app
|
|
|
|
chown -R $app:$app "/var/log/$app"
|
2022-07-20 12:04:29 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 23:14:02 +02:00
|
|
|
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2022-07-21 08:24:29 +02:00
|
|
|
# RELOAD NGINX
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|