#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= email=$(ynh_user_get_info --username=$admin --key=mail) # Config stuff: accounts_registration_open=$(convert_bool "$YNH_APP_ARG_ACCOUNTS_REGISTRATION_OPEN") accounts_approval_required=$(convert_bool "$YNH_APP_ARG_ACCOUNTS_APPROVAL_REQUIRED") accounts_reason_required=$(convert_bool "$YNH_APP_ARG_ACCOUNTS_REASON_REQUIRED") #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_app_setting_set --app="$app" --key=accounts_registration_open --value="$accounts_registration_open" ynh_app_setting_set --app="$app" --key=accounts_approval_required --value="$accounts_approval_required" ynh_app_setting_set --app="$app" --key=accounts_reason_required --value="$accounts_reason_required" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=1 # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" chmod -R o-rwx "$install_dir" chown -R "$app:www-data" "$install_dir" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring NGINX web server..." --weight=1 # Create a dedicated NGINX config for the main domain ynh_add_nginx_config # Create a dedicated systemd config ynh_add_systemd_config # Use logrotate to manage application logfile(s) ynh_use_logrotate # Create the logfile, required before configuring fail2ban touch "/var/log/${app}/${app}.log" # Create a dedicated Fail2Ban config ynh_add_fail2ban_config --logpath="/var/log/${app}/${app}.log" --failregex="statusCode=401 path=/auth/sign_in clientIP= .* msg=\"Unauthorized:" --max_retry=5 #================================================= # ADD A CONFIGURATION #================================================= ynh_script_progression --message="Adding a configuration file..." --weight=1 ynh_add_config --template="../conf/config.yaml" --destination="$install_dir/config.yaml" chmod 400 "$install_dir/config.yaml" chown "$app:$app" "$install_dir/config.yaml" #================================================= # 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" #================================================= # CREATE ADMIN USER #================================================= ynh_script_progression --message="Creating gotosocial admin user..." --weight=1 pushd $install_dir ynh_exec_warn_less ./gotosocial --config-path "$install_dir/config.yaml" admin account create --username "$admin" --email "$email" --password "$password" ynh_exec_warn_less ./gotosocial --config-path "$install_dir/config.yaml" admin account promote --username "$admin" popd #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name="$app" --action="start" --log_path="systemd" #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --last