2023-01-05 14:48:22 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Load common variables and helpers
|
|
|
|
source ./_common.sh
|
|
|
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
2023-01-06 16:08:56 +01:00
|
|
|
path_url=$(ynh_app_setting_get --app $app --key path)
|
2023-01-05 14:48:22 +01:00
|
|
|
db_password=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=adminusername)
|
|
|
|
key=$(ynh_app_setting_get --app=$app --key=secret_key)
|
|
|
|
lfs_key=$(ynh_app_setting_get --app=$app --key=lfs_key)
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=web_port)
|
|
|
|
upstream_version=$(ynh_app_setting_get --app=$app --key=upstream_version)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# We stop the service before to set ynh_clean_setup
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
|
|
|
|
if [ "0$(ynh_app_setting_get --app=$app --key=disable_backup_before_upgrade)" -ne 1 ]
|
|
|
|
then
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
# Clean installation remainings that are not handled by the remove script.
|
|
|
|
ynh_clean_check_starting
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Move data directory
|
|
|
|
if [ -e "/home/""$app" ] && [ ! -e $datadir ]; then
|
|
|
|
mv "/home/""$app" "$datadir"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensuring the user has the right home dir
|
|
|
|
if [ ~$app != "$datadir" ]; then
|
|
|
|
usermod -d "$datadir" $app
|
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Configuring application..."
|
|
|
|
|
|
|
|
# Clean template to fix issue : https://github.com/gogits/gogs/issues/4585
|
|
|
|
ynh_secure_remove --file="/opt/$app/templates"
|
|
|
|
|
2023-01-06 10:12:01 +01:00
|
|
|
# Configure forgejo with app.ini file
|
|
|
|
config_forgejo
|
2023-01-05 14:48:22 +01:00
|
|
|
|
|
|
|
# Configure init script
|
|
|
|
ynh_script_progression --message="Updating systemd units..."
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to NGINX conf directory
|
|
|
|
ynh_script_progression --message="Configuring NGINX..." --weight=1
|
|
|
|
config_nginx
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# DB migration
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading database and sources..." --weight=6
|
|
|
|
|
2023-01-06 10:12:01 +01:00
|
|
|
restart_forgejo() {
|
2023-01-05 14:48:22 +01:00
|
|
|
# Set permissions
|
|
|
|
set_permission
|
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
|
|
|
# Leave the time to update the database schema
|
|
|
|
sleep 5
|
|
|
|
systemctl stop $app
|
|
|
|
}
|
|
|
|
|
2023-01-06 10:12:01 +01:00
|
|
|
# Install forgejo source
|
2023-01-05 14:48:22 +01:00
|
|
|
ynh_setup_source $final_path source/$architecture
|
2023-01-06 10:12:01 +01:00
|
|
|
restart_forgejo
|
2023-01-05 14:48:22 +01:00
|
|
|
|
|
|
|
# SETUP FAIL2BAN
|
|
|
|
ynh_script_progression --message="Configuring Fail2Ban..."
|
2023-01-06 10:12:01 +01:00
|
|
|
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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Set all permissions
|
|
|
|
ynh_script_progression --message="Update permission..."
|
|
|
|
if ! ynh_permission_exists --permission admin; then
|
|
|
|
ynh_app_setting_delete --app $app --key unprotected_uris
|
|
|
|
ynh_permission_create --permission="admin" --allowed="$admin"
|
|
|
|
# Update ldap config
|
2023-01-06 16:08:56 +01:00
|
|
|
ynh_add_config --template="login_source.sql.template" --destination="../conf/login_source.sql"
|
2023-01-05 14:48:22 +01:00
|
|
|
ynh_mysql_connect_as "$db_user" "$db_password" "$dbname" < ../conf/login_source.sql
|
|
|
|
fi
|
|
|
|
|
2023-01-06 10:12:01 +01:00
|
|
|
# Add forgejo to YunoHost's monitored services
|
|
|
|
ynh_script_progression --message="Register Forgejo service..."
|
|
|
|
yunohost service add "$app" --log="/var/log/$app/forgejo.log"
|
2023-01-05 14:48:22 +01:00
|
|
|
|
2023-01-06 10:12:01 +01:00
|
|
|
# Add ssh permission for forgejo user
|
2023-01-05 14:48:22 +01:00
|
|
|
adduser $app ssh.app
|
|
|
|
|
|
|
|
# Set permissions
|
|
|
|
ynh_script_progression --message="Protecting directory"
|
|
|
|
set_permission
|
|
|
|
|
|
|
|
# Save Version
|
|
|
|
ynh_app_setting_set --app=$app --key=upstream_version --value=$(ynh_app_upstream_version)
|
|
|
|
|
|
|
|
# Reload services
|
2023-01-06 10:12:01 +01:00
|
|
|
ynh_script_progression --message="Starting Forgejo services..." --weight=3
|
2023-01-05 14:48:22 +01:00
|
|
|
#ynh_systemd_action -l "Starting new Web server: tcp:127.0.0.1:" -p "/var/log/$app/gitea.log" -t 10
|
|
|
|
#sleep 1
|
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
|
|
|
|
|
|
|
# Store the checksum with the 'INTERNAL_TOKEN' value.
|
|
|
|
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
|
|
|
|
ynh_store_file_checksum --file="$final_path/custom/conf/app.ini"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# FINISH MIGRATION PROCESS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|