mirror of
				https://framagit.org/YunoHost-Apps/gitea_ynh.git
				synced 2025-10-31 05:45:30 +01:00 
			
		
		
		
	 60cb5e5ae4
			
		
	
	60cb5e5ae4
	
	
	
		
			
			* 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.
		
			
				
	
	
		
			140 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			140 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| #=================================================
 | |
| # GENERIC START
 | |
| #=================================================
 | |
| # IMPORT GENERIC HELPERS
 | |
| #=================================================
 | |
| 
 | |
| source _common.sh
 | |
| source /usr/share/yunohost/helpers
 | |
| 
 | |
| upgrade_type=$(ynh_check_app_version_changed)
 | |
| 
 | |
| #=================================================
 | |
| # STANDARD UPGRADE STEPS
 | |
| #=================================================
 | |
| # ENSURE DOWNWARD COMPATIBILITY
 | |
| #=================================================
 | |
| ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
 | |
| 
 | |
| # If lfs_key doesn't exist, create it
 | |
| if [ -z "${lfs_key:-}" ]; then
 | |
|    lfs_key=$(ynh_string_random)
 | |
|    ynh_app_setting_set --app="$app" --key=lfs_key --value="$lfs_key"
 | |
| fi
 | |
| 
 | |
| # This is not handled by the core because the previous package did not define final_path...
 | |
| if [ -d "/opt/$app" ]; then
 | |
|     # This is the package version of the manifestv2
 | |
|     rsync -a "/opt/$app/" "$install_dir"
 | |
|     ynh_secure_remove "/opt/$app"
 | |
| fi
 | |
| 
 | |
| # Move data directory
 | |
| if [ -d "/home/$app" ]; then
 | |
|     rsync -a "/home/$app/" "$data_dir"
 | |
|     ynh_secure_remove "/home/$app"
 | |
| fi
 | |
| 
 | |
| # Ensure the user has the correct home dir
 | |
| if [ ~"$app" != "$data_dir" ]; then
 | |
|     usermod --home "$data_dir" "$app"
 | |
| fi
 | |
| 
 | |
| # Ensure secrets are defined
 | |
| # Some workaround around `gitea secret generate` not available in old versions
 | |
| mv "$install_dir/gitea" "$install_dir/gitea_orig"
 | |
| ynh_setup_source --dest_dir="$install_dir" --source_id=main
 | |
| chmod +x "$install_dir/gitea"
 | |
| _gitea_set_secrets
 | |
| ynh_secure_remove "$install_dir/gitea"
 | |
| mv "$install_dir/gitea_orig" "$install_dir/gitea"
 | |
| 
 | |
| # Ensure directories are created
 | |
| _gitea_mkdirs
 | |
| 
 | |
| #=================================================
 | |
| # STOP SYSTEMD SERVICE
 | |
| #=================================================
 | |
| ynh_script_progression --message="Stopping a systemd service..." --weight=1
 | |
| 
 | |
| ynh_systemd_action --service_name="$app" --action="stop"
 | |
| 
 | |
| #=================================================
 | |
| # REAPPLY SYSTEM CONFIGURATIONS
 | |
| #=================================================
 | |
| ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
 | |
| 
 | |
| ynh_add_nginx_config
 | |
| 
 | |
| ynh_add_systemd_config
 | |
| 
 | |
| yunohost service add "$app" --log="/var/log/$app/gitea.log"
 | |
| 
 | |
| ynh_use_logrotate --non-append
 | |
| 
 | |
| ynh_add_fail2ban_config --logpath="/var/log/$app/gitea.log" --failregex=".*Failed authentication attempt for .* from <HOST>" --max_retry 5
 | |
| 
 | |
| #=================================================
 | |
| # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
 | |
| #=================================================
 | |
| # UPDATE A CONFIG FILE
 | |
| #=================================================
 | |
| ynh_script_progression --message="Updating configuration files..." --weight=1
 | |
| 
 | |
| # Clean template to fix issue : https://github.com/gogits/gogs/issues/4585
 | |
| ynh_secure_remove --file="$install_dir/templates"
 | |
| 
 | |
| # Configure gitea with app.ini file
 | |
| _gitea_add_config
 | |
| _gitea_permissions_install_dir
 | |
| 
 | |
| #=================================================
 | |
| # DB migration
 | |
| #=================================================
 | |
| ynh_script_progression --message="Upgrading database and sources..." --weight=6
 | |
| 
 | |
| if ynh_compare_current_package_version --comparison lt --version "1.6.4~ynh1"; then
 | |
|     message="Upgrade from $YNH_APP_CURRENT_VERSION was dropped. You need to run this, then upgrade to the latest version:
 | |
| sudo yunohost app upgrade $app -u https://github.com/YunoHost-Apps/gitea_ynh/commit/a9ceb157032ae2290e944c1d0a255451ff2d133d"
 | |
|     ynh_print_info "$message"
 | |
|     ynh_die --message="$message" --ret_code 1
 | |
| fi
 | |
| 
 | |
| ynh_setup_source --dest_dir="$install_dir"
 | |
| chmod +x "$install_dir/gitea"
 | |
| _gitea_permissions_install_dir
 | |
| ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/gitea.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
 | |
| # FIXME: Leave the time to update the database schema
 | |
| sleep 5
 | |
| systemctl stop "$app"
 | |
| 
 | |
| 
 | |
| #=================================================
 | |
| # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS...)
 | |
| #=================================================
 | |
| # UPDATE A CONFIG FILE
 | |
| #=================================================
 | |
| ynh_script_progression --message="Updating LDAP configuration..." --weight=1
 | |
| # Should be done after DB migration I guess
 | |
| if ! ynh_permission_exists --permission admin; then
 | |
|     # Update ldap config
 | |
|     ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="../conf/login_source.sql"
 | |
|     ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ../conf/login_source.sql
 | |
| fi
 | |
| 
 | |
| 
 | |
| #=================================================
 | |
| # 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/gitea.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
 | |
| 
 | |
| #=================================================
 | |
| # END OF SCRIPT
 | |
| #=================================================
 | |
| 
 | |
| ynh_script_progression --message="Upgrade of $app completed" --last
 |