Migrate to manifestv2 and other changes:

* Move app install dir from /opt to /var/www
* Revamp the way binaries are downloaded thanks to manifestv2 (no need to check for arch, etc)
* Remove custom helpers (exec_as, ynh_handle_app_migration)
* Rename LFS_KEY as LFS_JWT_SECRET and KEY as SECRET_KEY as named in app.ini
* Add JWT_SECRET for oauth and INTERNAL_TOKEN in app.ini
* update upstream sample app.ini URL
* Disable actions for now.
* Automatically add ssh permissions to the system user
* Remove support for upgrade before 1.6.4. Edit test_upgrade_from accordingly.
This commit is contained in:
Félix Piédallu
2023-09-09 11:17:52 +02:00
committed by Félix Piédallu
parent b51febc0f9
commit 60cb5e5ae4
128 changed files with 474 additions and 1648 deletions

View File

@ -5,53 +5,35 @@
#=================================================
# Load common variables and helpers
source ../settings/scripts/experimental_helper.sh
source ../settings/scripts/_common.sh
# IMPORT GENERIC HELPERS
source /usr/share/yunohost/helpers
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
ynh_script_progression --message="Loading settings..."
# Retrieve old app settings
domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_app_setting_get --app $app --key path)
db_password=$(ynh_app_setting_get --app $app --key mysqlpwd)
admin=$(ynh_app_setting_get --app $app --key adminusername)
port=$(ynh_app_setting_get --app $app --key web_port)
upstream_version=$(ynh_app_setting_get $app upstream_version)
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die --message "The chosen admin user does not exist."
# Check Final Path availability
test ! -e "$final_path" || ynh_die --message "This path already contains a folder"
#=================================================
# STANDARD RESTORATION STEPS
# RESTORE THE APP MAIN DIR
#=================================================
# Add users
ynh_script_progression --message="Configuring system user..."
ynh_system_user_create --username=$app --home_dir=$datadir --use_shell
# Restore all files
ynh_script_progression --message="Restoring files..." --weight=10
ynh_script_progression --message="Restoring the app files..." --weight=1
ynh_restore
# Create and restore the database
ynh_script_progression --message="Restoring database..." --weight=3
ynh_mysql_create_db "$dbname" "$db_user" "$db_password"
ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" < ./db.sql
# Also sets the permissions
_gitea_mkdirs
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=1
ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
#=================================================
# RESTORE SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
# Restore systemd files
systemctl daemon-reload
systemctl enable "$app".service --quiet
yunohost service add "$app" --log="/var/log/$app/gitea.log"
# SETUP FAIL2BAN
ynh_script_progression --message="Configuring fail2ban..."
ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
@ -59,23 +41,17 @@ ynh_add_fail2ban_config --logpath "/var/log/$app/gitea.log" --failregex ".*Faile
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
#=================================================
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
# Set permissions
ynh_script_progression --message="Protecting directory..."
set_permission
# Typically you only have either $app or php-fpm but not both at the same time...
ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -t 10
# Configure logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile "/var/log/$app"
ynh_systemd_action --service_name=nginx --action=reload
# Add gitea to YunoHost's monitored services
ynh_script_progression --message="Register Gitea service..."
yunohost service add "$app" --log=/var/log/$app/gitea.log
# Reload services
ynh_script_progression --message="Reloading services..."
systemctl reload nginx.service
ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10
sleep 1
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last