#!/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 #================================================= #REMOVEME? ynh_clean_setup () { #### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script #REMOVEME? ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= #REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 #REMOVEME? app="$YNH_APP_INSTANCE_NAME" #REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app="$app" --key=install_dir) #REMOVEME? landing_page_user=$(ynh_app_setting_get --app="$app" --key=landing_page_user) #REMOVEME? domain=$(ynh_app_setting_get --app="$app" --key=domain) #REMOVEME? port=$(ynh_app_setting_get --app="$app" --key=port) #REMOVEME? path=$(ynh_app_setting_get --app="$app" --key=path) #REMOVEME? client_max_body_size=$(ynh_app_setting_get --app="$app" --key=client_max_body_size) #REMOVEME? db_name=$(ynh_app_setting_get --app="$app" --key=db_name) #REMOVEME? db_user=$(ynh_app_setting_get --app="$app" --key=db_user) #REMOVEME? db_pwd=$(ynh_app_setting_get --app="$app" --key=db_pwd) #REMOVEME? data_dir=$(ynh_app_setting_get --app="$app" --key=data_dir) #REMOVEME? cache_memory_target=$(ynh_app_setting_get --app="$app" --key=cache_memory_target) #REMOVEME? instance_federation_mode=$(ynh_app_setting_get --app="$app" --key=instance_federation_mode) #REMOVEME? instance_expose_peers=$(ynh_app_setting_get --app="$app" --key=instance_expose_peers) #REMOVEME? instance_expose_suspended=$(ynh_app_setting_get --app="$app" --key=instance_expose_suspended) #REMOVEME? instance_expose_suspended_web=$(ynh_app_setting_get --app="$app" --key=instance_expose_suspended_web) #REMOVEME? instance_expose_public_timeline=$(ynh_app_setting_get --app="$app" --key=instance_expose_public_timeline) #REMOVEME? instance_deliver_to_shared_inboxes=$(ynh_app_setting_get --app="$app" --key=instance_deliver_to_shared_inboxes) #REMOVEME? instance_inject_mastodon_version=$(ynh_app_setting_get --app="$app" --key=instance_inject_mastodon_version) #REMOVEME? accounts_registration_open=$(ynh_app_setting_get --app="$app" --key=accounts_registration_open) #REMOVEME? accounts_approval_required=$(ynh_app_setting_get --app="$app" --key=accounts_approval_required) #REMOVEME? accounts_reason_required=$(ynh_app_setting_get --app="$app" --key=accounts_reason_required) #REMOVEME? accounts_allow_custom_css=$(ynh_app_setting_get --app="$app" --key=accounts_allow_custom_css) #REMOVEME? accounts_custom_css_length=$(ynh_app_setting_get --app="$app" --key=accounts_custom_css_length) #REMOVEME? media_image_max_size=$(ynh_app_setting_get --app="$app" --key=media_image_max_size) #REMOVEME? media_video_max_size=$(ynh_app_setting_get --app="$app" --key=media_video_max_size) #REMOVEME? media_description_min_chars=$(ynh_app_setting_get --app="$app" --key=media_description_min_chars) #REMOVEME? media_description_max_chars=$(ynh_app_setting_get --app="$app" --key=media_description_max_chars) #REMOVEME? media_remote_cache_days=$(ynh_app_setting_get --app="$app" --key=media_remote_cache_days) #REMOVEME? media_emoji_local_max_size=$(ynh_app_setting_get --app="$app" --key=media_emoji_local_max_size) #REMOVEME? media_emoji_remote_max_size=$(ynh_app_setting_get --app="$app" --key=media_emoji_remote_max_size) #REMOVEME? storage_backend=$(ynh_app_setting_get --app="$app" --key=storage_backend) #REMOVEME? storage_s3_endpoint=$(ynh_app_setting_get --app="$app" --key=storage_s3_endpoint) #REMOVEME? storage_s3_proxy=$(ynh_app_setting_get --app="$app" --key=storage_s3_proxy) #REMOVEME? storage_s3_access_key=$(ynh_app_setting_get --app="$app" --key=storage_s3_access_key) #REMOVEME? storage_s3_secret_key=$(ynh_app_setting_get --app="$app" --key=storage_s3_secret_key) #REMOVEME? storage_s3_bucket=$(ynh_app_setting_get --app="$app" --key=storage_s3_bucket) #REMOVEME? statuses_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_max_chars) #REMOVEME? statuses_cw_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_cw_max_chars) #REMOVEME? statuses_poll_max_options=$(ynh_app_setting_get --app="$app" --key=statuses_poll_max_options) #REMOVEME? statuses_poll_option_max_chars=$(ynh_app_setting_get --app="$app" --key=statuses_poll_option_max_chars) #REMOVEME? statuses_media_max_files=$(ynh_app_setting_get --app="$app" --key=statuses_media_max_files) #REMOVEME? oidc_enabled=$(ynh_app_setting_get --app="$app" --key=oidc_enabled) #REMOVEME? oidc_idp_name=$(ynh_app_setting_get --app="$app" --key=oidc_idp_name) #REMOVEME? oidc_skip_verification=$(ynh_app_setting_get --app="$app" --key=oidc_skip_verification) #REMOVEME? oidc_issuer=$(ynh_app_setting_get --app="$app" --key=oidc_issuer) #REMOVEME? oidc_client_id=$(ynh_app_setting_get --app="$app" --key=oidc_client_id) #REMOVEME? oidc_client_secret=$(ynh_app_setting_get --app="$app" --key=oidc_client_secret) #REMOVEME? oidc_link_existing=$(ynh_app_setting_get --app="$app" --key=oidc_link_existing) #REMOVEME? smtp_host=$(ynh_app_setting_get --app="$app" --key=smtp_host) #REMOVEME? smtp_port=$(ynh_app_setting_get --app="$app" --key=smtp_port) #REMOVEME? smtp_username=$(ynh_app_setting_get --app="$app" --key=smtp_username) #REMOVEME? smtp_password=$(ynh_app_setting_get --app="$app" --key=smtp_password) #REMOVEME? smtp_from=$(ynh_app_setting_get --app="$app" --key=smtp_from) #REMOVEME? smtp_disclose_recipients=$(ynh_app_setting_get --app="$app" --key=smtp_disclose_recipients) #REMOVEME? advanced_cookies_samesite=$(ynh_app_setting_get --app="$app" --key=advanced_cookies_samesite) #REMOVEME? advanced_rate_limit_requests=$(ynh_app_setting_get --app="$app" --key=advanced_rate_limit_requests) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= #REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1 #REMOVEME? test ! -d "$install_dir" \ || ynh_die --message="There is already a directory: $install_dir " #================================================= # STANDARD RESTORATION STEPS #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= ynh_script_progression --message="Restoring the NGINX configuration..." --weight=1 ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RECREATE THE DEDICATED USER #================================================= #REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) #REMOVEME? ynh_system_user_create --username="$app" --home_dir="$install_dir" #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$install_dir" # FIXME: this should be managed by the core in the future # Here, as a packager, you may have to tweak the ownerhsip/permissions # such that the appropriate users (e.g. maybe www-data) can access # files in some cases. # But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - # this will be treated as a security issue. chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= ynh_script_progression --message="Restoring the data directory..." --weight=5 ynh_restore_file --origin_path="$data_dir" --not_mandatory mkdir -p "$data_dir" # FIXME: this should be managed by the core in the future # Here, as a packager, you may have to tweak the ownerhsip/permissions # such that the appropriate users (e.g. maybe www-data) can access # files in some cases. # But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder - # this will be treated as a security issue. chmod 750 "$data_dir" chmod -R o-rwx "$data_dir" chown -R "$app:www-data" "$data_dir" #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= #REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=5 # Define and install dependencies #REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies "$pkg_dependencies" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= #REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 #REMOVEME? ynh_psql_test_if_first_run #REMOVEME? ynh_psql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS unaccent;" --database="$db_name" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS pg_trgm;" --database="$db_name" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS citext;" --database="$db_name" ynh_psql_execute_as_root --sql="CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" --database="$db_name" ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 ### `ynh_setup_source` is used to install an app from a zip or tar.gz file, ### downloaded from an upstream source, like a git repository. ### `ynh_setup_source` use the file conf/app.src # detect_arch comes from _common.sh / personnal helpers architecture="$(detect_arch)" # compare if the system arch is different from the binary arch # if so, download the correct binary if [ "$architecture" != "$(file "$install_dir"/gotosocial | cut -d ',' -f 2 | tr -d ' ')" ] then ynh_script_progression --message="Migrating binary architecture..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" --keep="config.yaml" fi # FIXME: this should be managed by the core in the future # Here, as a packager, you may have to tweak the ownerhsip/permissions # such that the appropriate users (e.g. maybe www-data) can access # files in some cases. # But FOR THE LOVE OF GOD, do not allow r/x for "others" on the entire folder _ # this will be treated as a security issue. chmod 750 "$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # RESTORE VARIOUS FILES #================================================= mkdir -p "/var/log/$app" #================================================= # RESTORE SYSTEMD #================================================= ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable "$app.service" --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 yunohost service add "$app" --description="Gotosocial server" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= # RESTORE THE FAIL2BAN CONFIGURATION #================================================= ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" ynh_systemd_action --action=restart --service_name=fail2ban #================================================= # GENERIC FINALIZATION #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading NGINX web server..." --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Restoration completed for $app" --last