2023-01-05 14:48:22 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2023-01-05 14:48:22 +01:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
2023-01-05 14:48:22 +01:00
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-01-11 10:32:49 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=2
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="systemd"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
|
2023-07-05 16:20:06 +02:00
|
|
|
# Update forgejo login source (1.19.3-0~ynh2)
|
2023-06-25 12:11:59 +02:00
|
|
|
pushd "$install_dir"
|
|
|
|
old_login_source_id=$(ynh_exec_as $app ./forgejo admin auth list | grep "YunoHost LDAP" | grep "via BindDN" | cut -f 1)
|
|
|
|
if [ ! -z $old_login_source_id ]; then
|
2023-07-14 12:04:16 +02:00
|
|
|
ynh_print_info --message="Delete obsolete forgejo login source (LDAP via BindDN)"
|
|
|
|
|
|
|
|
# Ensure no user have this obsolete login source
|
|
|
|
ynh_psql_execute_as_root --database $db_name --sql "update public.user set login_source = 0, login_type = 0 where login_source = ${old_login_source_id}"
|
|
|
|
|
2023-06-25 12:11:59 +02:00
|
|
|
# Delete old login source
|
|
|
|
ynh_exec_as $app ./forgejo admin auth delete --id $old_login_source_id
|
2024-01-13 12:02:25 +01:00
|
|
|
fi
|
2023-06-25 12:11:59 +02:00
|
|
|
|
2024-01-13 12:02:25 +01:00
|
|
|
ynh_exec_as $app ./forgejo admin auth list | grep "YunoHost LDAP" | grep -q "LDAP (simple auth)" ||
|
|
|
|
# create new login source if not existing
|
2023-06-25 18:48:03 +02:00
|
|
|
set_forgejo_login_source
|
2023-06-25 12:11:59 +02:00
|
|
|
popd
|
|
|
|
|
2023-07-05 16:20:06 +02:00
|
|
|
# Update login source synchronization flag (1.19.3-0~ynh3)
|
|
|
|
enable_login_source_sync
|
|
|
|
|
2023-06-07 15:22:12 +02:00
|
|
|
# forgejo home directory has changed (yunohost packaging v2)
|
|
|
|
# .ssh directory should move from old home dir (data_dir) to new one
|
|
|
|
# (/var/www/$app is the default value for home in resources.system_user)
|
|
|
|
if [ -d "$data_dir/.ssh" ]; then
|
|
|
|
mv "$data_dir/.ssh" /var/www/$app
|
|
|
|
fi
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-22 08:10:43 +01:00
|
|
|
# If secret_key doesn't exist, create it
|
2023-07-05 16:20:06 +02:00
|
|
|
if [ -z ${secret_key:-} ]; then
|
2023-03-10 17:13:54 +01:00
|
|
|
secret_key=$($install_dir/forgejo generate secret SECRET_KEY)
|
2023-01-22 08:10:43 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=secret_key --value=$secret_key
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If lfs_jwt_secret doesn't exist, create it
|
2023-07-05 16:20:06 +02:00
|
|
|
if [ -z ${lfs_jwt_secret:-} ]; then
|
2023-03-10 17:13:54 +01:00
|
|
|
lfs_jwt_secret=$($install_dir/forgejo generate secret JWT_SECRET)
|
2023-01-22 08:10:43 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=lfs_jwt_secret --value=$lfs_jwt_secret
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If internal_token doesn't exist, create it
|
2023-07-05 16:20:06 +02:00
|
|
|
if [ -z ${internal_token:-} ]; then
|
2023-03-10 17:13:54 +01:00
|
|
|
internal_token=$($install_dir/forgejo generate secret INTERNAL_TOKEN)
|
2023-01-22 08:10:43 +01:00
|
|
|
ynh_app_setting_set --app=$app --key=internal_token --value=$internal_token
|
|
|
|
fi
|
|
|
|
|
2023-08-08 22:54:06 +02:00
|
|
|
# If oauth2_jwt_secret doesn't exist, create it
|
|
|
|
if [ -z ${oauth2_jwt_secret:-} ]; then
|
|
|
|
oauth2_jwt_secret=$($install_dir/forgejo generate secret JWT_SECRET)
|
|
|
|
ynh_app_setting_set --app=$app --key=oauth2_jwt_secret --value=$oauth2_jwt_secret
|
|
|
|
fi
|
|
|
|
|
2024-02-26 00:44:32 +01:00
|
|
|
# if we update from a version prior to the config panel, create new settings
|
|
|
|
if [ -z "${register_email_confirm:-}" ]; then
|
|
|
|
register_email_confirm=false
|
|
|
|
register_manual_confirm=false
|
|
|
|
disable_registration=true
|
|
|
|
require_signin_view=false
|
|
|
|
enable_notify_mail=true
|
|
|
|
show_registration_button=true
|
|
|
|
|
|
|
|
mirror_enabled=true
|
|
|
|
mirror_disable_new_pull=false
|
|
|
|
mirror_disable_new_push=false
|
|
|
|
mirror_default_interval="8h"
|
|
|
|
mirror_min_interval="10m"
|
|
|
|
|
|
|
|
ynh_app_setting_set --app="$app" --key=register_email_confirm --value=$register_email_confirm
|
|
|
|
ynh_app_setting_set --app="$app" --key=register_manual_confirm --value=$register_manual_confirm
|
|
|
|
ynh_app_setting_set --app="$app" --key=disable_registration --value=$disable_registration
|
|
|
|
ynh_app_setting_set --app="$app" --key=require_signin_view --value=$require_signin_view
|
|
|
|
ynh_app_setting_set --app="$app" --key=enable_notify_mail --value=$enable_notify_mail
|
|
|
|
ynh_app_setting_set --app="$app" --key=show_registration_button --value=$show_registration_button
|
|
|
|
|
|
|
|
ynh_app_setting_set --app="$app" --key=mirror_enabled --value=$mirror_enabled
|
|
|
|
ynh_app_setting_set --app="$app" --key=mirror_disable_new_pull --value=$mirror_disable_new_pull
|
|
|
|
ynh_app_setting_set --app="$app" --key=mirror_disable_new_push --value=$mirror_disable_new_push
|
|
|
|
ynh_app_setting_set --app="$app" --key=mirror_default_interval --value=$mirror_default_interval
|
|
|
|
ynh_app_setting_set --app="$app" --key=mirror_min_interval --value=$mirror_min_interval
|
|
|
|
fi
|
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Setting up source files..." --weight=3
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2024-03-16 17:35:23 +01:00
|
|
|
ynh_setup_source --dest_dir=$install_dir --full_replace=1 --keep="custom"
|
2023-05-27 17:52:29 +02:00
|
|
|
xz -f -d "$install_dir/forgejo.xz"
|
2023-03-10 17:22:52 +01:00
|
|
|
|
2023-03-10 17:13:54 +01:00
|
|
|
chmod -R o-rwx "$install_dir"
|
|
|
|
chown -R $app:$app "$install_dir"
|
|
|
|
chmod +x "$install_dir/forgejo"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# ADD A CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
|
|
|
|
|
|
|
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
|
2023-03-10 17:13:54 +01:00
|
|
|
ynh_add_config --template="app.ini" --destination="$install_dir/custom/conf/app.ini"
|
2023-01-11 10:32:49 +01:00
|
|
|
|
2023-03-10 17:13:54 +01:00
|
|
|
chmod 640 "$install_dir/custom/conf/app.ini"
|
|
|
|
chown $app:$app "$install_dir/custom/conf/app.ini"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
2023-01-11 10:32:49 +01:00
|
|
|
# SETUP SYSTEMD
|
2023-01-05 14:48:22 +01:00
|
|
|
#=================================================
|
2023-01-11 10:32:49 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
2023-03-10 17:22:52 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
ynh_add_systemd_config
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-03-10 17:22:52 +01:00
|
|
|
ynh_add_nginx_config
|
2023-01-05 14:48:22 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2023-01-11 10:32:49 +01:00
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
2023-02-25 22:09:33 +01:00
|
|
|
ynh_use_logrotate --logfile "/var/log/$app" --nonappend
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
chmod u=rwX,g=rX,o= "/var/log/$app"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
yunohost service add $app --description="Forgejo" --log="/var/log/$app/forgejo.log"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2023-05-27 17:52:29 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=3
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
# Start a systemd service
|
2023-01-06 10:12:01 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/forgejo.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-07-05 16:20:06 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# Synchronize users (backward compatibility 1.19.3-0~ynh3)
|
|
|
|
#=================================================
|
2023-11-15 11:29:57 +01:00
|
|
|
if [ -z ${forgejo_api_user:-} ]; then
|
|
|
|
create_forgejo_api_user
|
|
|
|
fi
|
|
|
|
|
|
|
|
set_users_login_source
|
|
|
|
|
2023-07-05 16:20:06 +02:00
|
|
|
synchronize_users
|
|
|
|
|
2023-01-11 10:32:49 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring Fail2Ban..." --weight=1
|
|
|
|
|
|
|
|
ynh_add_fail2ban_config --logpath "/var/log/$app/forgejo.log" --failregex ".*Failed authentication attempt for .* from <HOST>" --max_retry 5
|
|
|
|
|
2023-01-05 14:48:22 +01:00
|
|
|
#=================================================
|
2023-01-11 10:32:49 +01:00
|
|
|
# END OF SCRIPT
|
2023-01-05 14:48:22 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|