mirror of
https://framagit.org/YunoHost-Apps/gitea_ynh.git
synced 2024-11-22 02:51:35 +01:00
133 lines
4.8 KiB
Bash
133 lines
4.8 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 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
|
|
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message='Stopping a systemd service...' --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action=stop
|
|
|
|
#=================================================
|
|
# MIGRATION STEP 1 (migrate path from packagin v1)
|
|
#=================================================
|
|
|
|
# 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
|
|
mv -t "$install_dir/" "/opt/$app/"*
|
|
ynh_secure_remove --file="/opt/$app"
|
|
fi
|
|
|
|
# Move data directory
|
|
if [ -d /home"/$app" ]; then
|
|
mv /home"/$app/" "$data_dir"
|
|
fi
|
|
|
|
# Ensure the user has the correct home dir
|
|
if [ ~"$app" != "$data_dir" ]; then
|
|
usermod --home "$data_dir" "$app"
|
|
fi
|
|
|
|
# Ensure secrets are defined
|
|
ynh_setup_source --dest_dir="$install_dir" --source_id=main
|
|
_set_permissions
|
|
|
|
#=================================================
|
|
# MIGRATION STEP 2 (Set undefined Vars)
|
|
#=================================================
|
|
|
|
if [[ -z "${internal_token:-}" ]]; then
|
|
internal_token=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret INTERNAL_TOKEN)
|
|
ynh_app_setting_set --app "$app" --key internal_token --value="$internal_token"
|
|
fi
|
|
|
|
if [[ -z "${secret_key:-}" ]]; then
|
|
secret_key=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret SECRET_KEY)
|
|
ynh_app_setting_set --app "$app" --key secret_key --value="$secret_key"
|
|
fi
|
|
|
|
if [[ -n "${lfs_key:-}" ]]; then
|
|
lfs_jwt_secret="$lfs_key"
|
|
ynh_app_setting_delete --app "$app" --key lfs_key
|
|
ynh_app_setting_set --app "$app" --key lfs_jwt_secret --value="$lfs_jwt_secret"
|
|
fi
|
|
|
|
if [[ -z "${lfs_jwt_secret:-}" ]]; then
|
|
lfs_jwt_secret=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret JWT_SECRET)
|
|
ynh_app_setting_set --app "$app" --key lfs_jwt_secret --value="$lfs_jwt_secret"
|
|
fi
|
|
|
|
if [[ -z "${jwt_secret:-}" ]]; then
|
|
jwt_secret=$(ynh_exec_as "$app" "$install_dir/gitea" generate secret JWT_SECRET)
|
|
ynh_app_setting_set --app "$app" --key jwt_secret --value="$jwt_secret"
|
|
fi
|
|
|
|
#=================================================
|
|
# 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
|
|
ynh_add_config --template=app.ini --destination="$install_dir/custom/conf/app.ini"
|
|
_set_permissions
|
|
|
|
# Update ldap config
|
|
ynh_replace_string --match_string=__APP__ --replace_string="$app" --target_file=./login_source.sql
|
|
ynh_mysql_connect_as "$db_user" "$db_pwd" "$db_name" < ./login_source.sql
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
#=================================================
|
|
# 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="$systemd_match_start_line"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|