mirror of
https://github.com/YunoHost-Apps/gitea_ynh.git
synced 2024-09-03 20:36:22 +02:00
Fix
This commit is contained in:
parent
346cfb26db
commit
bf6efb89c7
3 changed files with 19 additions and 276 deletions
|
@ -1,4 +1,6 @@
|
||||||
;https://github.com/gogits/gogs/blob/master/conf/app.ini
|
;; see https://docs.gitea.io/en-us/config-cheat-sheet/ for additional documentation.
|
||||||
|
;; https://github.com/go-gitea/gitea/blob/main/custom/conf/app.example.ini
|
||||||
|
|
||||||
APP_NAME = Gitea
|
APP_NAME = Gitea
|
||||||
RUN_USER = __APP__
|
RUN_USER = __APP__
|
||||||
RUN_MODE = prod
|
RUN_MODE = prod
|
||||||
|
@ -24,7 +26,7 @@ ROOT_URL = https://__DOMAIN____PATH_URL__
|
||||||
DISABLE_SSH = false
|
DISABLE_SSH = false
|
||||||
SSH_PORT = __SSH_PORT__
|
SSH_PORT = __SSH_PORT__
|
||||||
OFFLINE_MODE = false
|
OFFLINE_MODE = false
|
||||||
APP_DATA_PATH = __DATADIR__
|
APP_DATA_PATH = __DATADIR__/data
|
||||||
LANDING_PAGE = explore
|
LANDING_PAGE = explore
|
||||||
LFS_START_SERVER = true
|
LFS_START_SERVER = true
|
||||||
LFS_JWT_SECRET = __LFS_KEY__
|
LFS_JWT_SECRET = __LFS_KEY__
|
||||||
|
@ -41,11 +43,12 @@ ENABLE_NOTIFY_MAIL = true
|
||||||
DISABLE_REGISTRATION = true
|
DISABLE_REGISTRATION = true
|
||||||
ENABLE_CAPTCHA = false
|
ENABLE_CAPTCHA = false
|
||||||
REQUIRE_SIGNIN_VIEW = false
|
REQUIRE_SIGNIN_VIEW = false
|
||||||
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
|
ENABLE_REVERSE_PROXY_AUTHENTICATION = true
|
||||||
ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
|
ENABLE_REVERSE_PROXY_AUTO_REGISTRATION = false
|
||||||
|
|
||||||
[picture]
|
[picture]
|
||||||
AVATAR_UPLOAD_PATH = __DATADIR_/data/avatars
|
AVATAR_UPLOAD_PATH = __DATADIR_/data/avatars
|
||||||
|
REPOSITORY_AVATAR_UPLOAD_PATH = __DATADIR__/data/repo-avatars
|
||||||
|
|
||||||
[attachment]
|
[attachment]
|
||||||
PATH = __DATADIR__/data/attachments
|
PATH = __DATADIR__/data/attachments
|
||||||
|
|
|
@ -1,257 +0,0 @@
|
||||||
# Execute a command as another user
|
|
||||||
# usage: exec_as USER COMMAND [ARG ...]
|
|
||||||
exec_as() {
|
|
||||||
local USER=$1
|
|
||||||
shift 1
|
|
||||||
|
|
||||||
if [[ $USER = $(whoami) ]]; then
|
|
||||||
eval "$@"
|
|
||||||
else
|
|
||||||
sudo -u "$USER" "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Need also the helper https://github.com/YunoHost-Apps/Experimental_helpers/blob/master/ynh_handle_getopts_args/ynh_handle_getopts_args
|
|
||||||
|
|
||||||
# Make the main steps to migrate an app to its fork.
|
|
||||||
#
|
|
||||||
# This helper has to be used for an app which needs to migrate to a new name or a new fork
|
|
||||||
# (like owncloud to nextcloud or zerobin to privatebin).
|
|
||||||
#
|
|
||||||
# This helper will move the files of an app to its new name
|
|
||||||
# or recreate the things it can't move.
|
|
||||||
#
|
|
||||||
# To specify which files it has to move, you have to create a "migration file", stored in ../conf
|
|
||||||
# This file is a simple list of each file it has to move,
|
|
||||||
# except that file names must reference the $app variable instead of the real name of the app,
|
|
||||||
# and every instance-specific variables (like $domain).
|
|
||||||
# $app is especially important because it's this variable which will be used to identify the old place and the new one for each file.
|
|
||||||
#
|
|
||||||
# If a database exists for this app, it will be dumped and then imported in a newly created database, with a new name and new user.
|
|
||||||
# Don't forget you have to then apply these changes to application-specific settings (depends on the packaged application)
|
|
||||||
#
|
|
||||||
# Same things for an existing user, a new one will be created.
|
|
||||||
# But the old one can't be removed unless it's not used. See below.
|
|
||||||
#
|
|
||||||
# If you have some dependencies for your app, it's possible to change the fake debian package which manages them.
|
|
||||||
# You have to fill the $pkg_dependencies variable, and then a new fake package will be created and installed,
|
|
||||||
# and the old one will be removed.
|
|
||||||
# If you don't have a $pkg_dependencies variable, the helper can't know what the app dependencies are.
|
|
||||||
#
|
|
||||||
# The app settings.yml will be modified as follows:
|
|
||||||
# - finalpath will be changed according to the new name (but only if the existing $final_path contains the old app name)
|
|
||||||
# - The checksums of php-fpm and nginx config files will be updated too.
|
|
||||||
# - If there is a $db_name value, it will be changed.
|
|
||||||
# - And, of course, the ID will be changed to the new name too.
|
|
||||||
#
|
|
||||||
# Finally, the $app variable will take the value of the new name.
|
|
||||||
# The helper will set the $migration_process variable to 1 if a migration has been successfully handled.
|
|
||||||
#
|
|
||||||
# You have to handle by yourself all the migrations not done by this helper, like configuration or special values in settings.yml
|
|
||||||
# Also, at the end of the upgrade script, you have to add a post_migration script to handle all the things the helper can't do during YunoHost upgrade (mostly for permission reasons),
|
|
||||||
# especially remove the old user, move some hooks and remove the old configuration directory
|
|
||||||
# To launch this script, you have to move it elsewhere and start it after the upgrade script.
|
|
||||||
# `cp ../conf/$script_post_migration /tmp`
|
|
||||||
# `(cd /tmp; echo "/tmp/$script_post_migration" | at now + 2 minutes)`
|
|
||||||
#
|
|
||||||
# usage: ynh_handle_app_migration migration_id migration_list
|
|
||||||
# | arg: -i, --migration_id= - ID from which to migrate
|
|
||||||
# | arg: -l, --migration_list= - File specifying every file to move (one file per line)
|
|
||||||
ynh_handle_app_migration () {
|
|
||||||
# Need for end of install
|
|
||||||
ynh_package_install at
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# LOAD SETTINGS
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
old_app=$YNH_APP_INSTANCE_NAME
|
|
||||||
local old_app_id=$YNH_APP_ID
|
|
||||||
local old_app_number=$YNH_APP_INSTANCE_NUMBER
|
|
||||||
|
|
||||||
# Declare an array to define the options of this helper.
|
|
||||||
declare -Ar args_array=( [i]=migration_id= [l]=migration_list= )
|
|
||||||
# Get the id from which to migrate
|
|
||||||
local migration_id
|
|
||||||
# And the file with the paths to move
|
|
||||||
local migration_list
|
|
||||||
# Manage arguments with getopts
|
|
||||||
ynh_handle_getopts_args "$@"
|
|
||||||
|
|
||||||
# Get the new app id in the manifest
|
|
||||||
local new_app_id=$(grep \"id\": ../manifest.json | cut -d\" -f4)
|
|
||||||
if [ $old_app_number -eq 1 ]; then
|
|
||||||
local new_app=$new_app_id
|
|
||||||
else
|
|
||||||
local new_app=${new_app_id}__${old_app_number}
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CHECK IF IT HAS TO MIGRATE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
migration_process=0
|
|
||||||
|
|
||||||
if [ "$old_app_id" == "$new_app_id" ]
|
|
||||||
then
|
|
||||||
# If the 2 id are the same
|
|
||||||
# No migration to do.
|
|
||||||
echo 0
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
if [ "$old_app_id" != "$migration_id" ]
|
|
||||||
then
|
|
||||||
# If the new app is not the authorized id, fail.
|
|
||||||
ynh_die --message "Incompatible application for migration from $old_app_id to $new_app_id"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Migrate from $old_app_id to $new_app_id" >&2
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CHECK IF THE MIGRATION CAN BE DONE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# TODO Handle multi instance apps...
|
|
||||||
# Check that there is not already an app installed for this id.
|
|
||||||
(yunohost app list --installed -f "$new_app" | grep -q id) \
|
|
||||||
&& ynh_die "$new_app is already installed"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CHECK THE LIST OF FILES TO MOVE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
local temp_migration_list="$(tempfile)"
|
|
||||||
|
|
||||||
# Build the list by removing blank lines and comment lines
|
|
||||||
sed '/^#.*\|^$/d' "../conf/$migration_list" > "$temp_migration_list"
|
|
||||||
|
|
||||||
# Check if there is no file in the destination
|
|
||||||
local file_to_move=""
|
|
||||||
while read file_to_move
|
|
||||||
do
|
|
||||||
# Replace all occurences of $app by $new_app in each file to move.
|
|
||||||
local move_to_destination="${file_to_move//\$app/$new_app}"
|
|
||||||
test -e "$move_to_destination" && ynh_die "A file named $move_to_destination already exists."
|
|
||||||
done < "$temp_migration_list"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# COPY YUNOHOST SETTINGS FOR THIS APP
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
local settings_dir="/etc/yunohost/apps"
|
|
||||||
cp -a "$settings_dir/$old_app" "$settings_dir/$new_app"
|
|
||||||
cp -a ../{scripts,conf} "$settings_dir/$new_app"
|
|
||||||
|
|
||||||
# Replace the old id by the new one
|
|
||||||
ynh_replace_string "\(^id: .*\)$old_app" "\1$new_app" "$settings_dir/$new_app/settings.yml"
|
|
||||||
# INFO: There a special behavior with yunohost app setting:
|
|
||||||
# if the id given in argument does not match with the id
|
|
||||||
# stored in the config file, the config file will be purged.
|
|
||||||
# That's why we use sed instead of app setting here.
|
|
||||||
# https://github.com/YunoHost/yunohost/blob/c6b5284be8da39cf2da4e1036a730eb5e0515096/src/yunohost/app.py#L1316-L1321
|
|
||||||
|
|
||||||
# Change the label if it's simply the name of the app
|
|
||||||
old_label=$(ynh_app_setting_get $new_app label)
|
|
||||||
if [ "${old_label,,}" == "$old_app_id" ]
|
|
||||||
then
|
|
||||||
# Build the new label from the id of the app. With the first character as upper case
|
|
||||||
new_label=$(echo $new_app_id | cut -c1 | tr [:lower:] [:upper:])$(echo $new_app_id | cut -c2-)
|
|
||||||
ynh_app_setting_set $new_app label $new_label
|
|
||||||
fi
|
|
||||||
|
|
||||||
yunohost tools shell -c "from yunohost.permission import permission_delete; permission_delete('$old_app.main', force=True, sync_perm=False)"
|
|
||||||
yunohost tools shell -c "from yunohost.permission import permission_create; permission_create('$new_app.main', url='/' , sync_perm=True)"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# MOVE FILES TO THE NEW DESTINATION
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
while read file_to_move
|
|
||||||
do
|
|
||||||
# Replace all occurence of $app by $new_app in each file to move.
|
|
||||||
move_to_destination="$(eval echo "${file_to_move//\$app/$new_app}")"
|
|
||||||
local real_file_to_move="$(eval echo "${file_to_move//\$app/$old_app}")"
|
|
||||||
echo "Move file $real_file_to_move to $move_to_destination" >&2
|
|
||||||
mv "$real_file_to_move" "$move_to_destination"
|
|
||||||
done < "$temp_migration_list"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# UPDATE SETTINGS KNOWN ENTRIES
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Replace nginx checksum
|
|
||||||
ynh_replace_string "\(^checksum__etc_nginx.*\)_$old_app" "\1_$new_app/" "$settings_dir/$new_app/settings.yml"
|
|
||||||
|
|
||||||
# Replace php5-fpm checksums
|
|
||||||
ynh_replace_string "\(^checksum__etc_php5.*[-_]\)$old_app" "\1$new_app/" "$settings_dir/$new_app/settings.yml"
|
|
||||||
|
|
||||||
# Replace final_path
|
|
||||||
ynh_replace_string "\(^final_path: .*\)$old_app" "\1$new_app" "$settings_dir/$new_app/settings.yml"
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# MOVE THE DATABASE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
db_pwd=$(ynh_app_setting_get $old_app mysqlpwd)
|
|
||||||
db_name=$dbname
|
|
||||||
|
|
||||||
# Check if a database exists before trying to move it
|
|
||||||
local mysql_root_password=$(cat $MYSQL_ROOT_PWD_FILE)
|
|
||||||
if [ -n "$db_name" ] && mysqlshow -u root -p$mysql_root_password | grep -q "^| $db_name"
|
|
||||||
then
|
|
||||||
new_db_name=$(ynh_sanitize_dbid $new_app)
|
|
||||||
echo "Rename the database $db_name to $new_db_name" >&2
|
|
||||||
|
|
||||||
local sql_dump="/tmp/${db_name}-$(date '+%s').sql"
|
|
||||||
|
|
||||||
# Dump the old database
|
|
||||||
ynh_mysql_dump_db "$db_name" > "$sql_dump"
|
|
||||||
|
|
||||||
# Create a new database
|
|
||||||
ynh_mysql_setup_db $new_db_name $new_db_name $db_pwd
|
|
||||||
# Then restore the old one into the new one
|
|
||||||
ynh_mysql_connect_as $new_db_name $db_pwd $new_db_name < "$sql_dump"
|
|
||||||
|
|
||||||
# Remove the old database
|
|
||||||
ynh_mysql_remove_db $db_name $db_name
|
|
||||||
# And the dump
|
|
||||||
ynh_secure_remove --file="$sql_dump"
|
|
||||||
|
|
||||||
# Update the value of $db_name
|
|
||||||
db_name=$new_db_name
|
|
||||||
ynh_app_setting_set $new_app db_name $db_name
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# CHANGE THE FAKE DEPENDENCIES PACKAGE
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
# Check if a variable $pkg_dependencies exists
|
|
||||||
# If this variable doesn't exist, this part shall be managed in the upgrade script.
|
|
||||||
if [ -n "${pkg_dependencies:-}" ]
|
|
||||||
then
|
|
||||||
# Define the name of the package
|
|
||||||
local old_package_name="${old_app//_/-}-ynh-deps"
|
|
||||||
local new_package_name="${new_app//_/-}-ynh-deps"
|
|
||||||
|
|
||||||
if ynh_package_is_installed "$old_package_name"
|
|
||||||
then
|
|
||||||
# Install a new fake package
|
|
||||||
app=$new_app
|
|
||||||
ynh_install_app_dependencies $pkg_dependencies
|
|
||||||
# Then remove the old one
|
|
||||||
app=$old_app
|
|
||||||
ynh_remove_app_dependencies
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
#=================================================
|
|
||||||
# UPDATE THE ID OF THE APP
|
|
||||||
#=================================================
|
|
||||||
|
|
||||||
app=$new_app
|
|
||||||
|
|
||||||
# Set migration_process to 1 to inform that an upgrade has been made
|
|
||||||
migration_process=1
|
|
||||||
fi
|
|
||||||
}
|
|
|
@ -3,12 +3,10 @@
|
||||||
#=================================================
|
#=================================================
|
||||||
# GENERIC START
|
# GENERIC START
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
# Load common variables and helpers
|
|
||||||
source ./experimental_helper.sh
|
|
||||||
source ./_common.sh
|
|
||||||
|
|
||||||
# IMPORT GENERIC HELPERS
|
# IMPORT GENERIC HELPERS
|
||||||
|
#=================================================
|
||||||
|
|
||||||
|
source _common.sh
|
||||||
source /usr/share/yunohost/helpers
|
source /usr/share/yunohost/helpers
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
|
@ -26,7 +24,8 @@ lfs_key=$(ynh_app_setting_get --app=$app --key=lfs_key)
|
||||||
port=$(ynh_app_setting_get --app=$app --key=web_port)
|
port=$(ynh_app_setting_get --app=$app --key=web_port)
|
||||||
upstream_version=$(ynh_app_setting_get --app=$app --key=upstream_version)
|
upstream_version=$(ynh_app_setting_get --app=$app --key=upstream_version)
|
||||||
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
||||||
db_password=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
db_user=$db_name
|
||||||
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
||||||
|
@ -52,7 +51,7 @@ ynh_abort_if_errors
|
||||||
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
||||||
|
|
||||||
# We stop the service before to set ynh_clean_setup
|
# We stop the service before to set ynh_clean_setup
|
||||||
ynh_systemd_action --service_name=$app --action="stop"
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# ENSURE DOWNWARD COMPATIBILITY
|
# ENSURE DOWNWARD COMPATIBILITY
|
||||||
|
@ -134,15 +133,15 @@ if [ -e "/home/""$app" ] && [ ! -e $datadir ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# STANDARD UPGRADE STEPS
|
# ADD A CONFIGURATION
|
||||||
#=================================================
|
#=================================================
|
||||||
ynh_script_progression --message="Configuring application..."
|
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||||
|
|
||||||
# Clean template to fix issue : https://github.com/gogits/gogs/issues/4585
|
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
|
||||||
ynh_secure_remove --file="/opt/$app/templates"
|
ynh_add_config --template="../conf/app.ini" --destination="$final_path/custom/conf/app.ini"
|
||||||
|
|
||||||
# Configure gitea with app.ini file
|
chmod 640 "$final_path/custom/conf/app.ini"
|
||||||
config_gitea
|
chown $app:$app "$final_path/custom/conf/app.ini"
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# NGINX CONFIGURATION
|
# NGINX CONFIGURATION
|
||||||
|
@ -161,9 +160,8 @@ ynh_script_progression --message="Upgrading systemd configuration..." --time --w
|
||||||
ynh_add_systemd_config
|
ynh_add_systemd_config
|
||||||
|
|
||||||
#=================================================
|
#=================================================
|
||||||
# DB migration
|
# DATA BASE MIGRATION
|
||||||
#=================================================
|
#=================================================
|
||||||
|
|
||||||
ynh_script_progression --message="Upgrading database and sources..." --weight=6
|
ynh_script_progression --message="Upgrading database and sources..." --weight=6
|
||||||
|
|
||||||
# Before the version 1.7 the upstream version was not stored
|
# Before the version 1.7 the upstream version was not stored
|
||||||
|
@ -299,7 +297,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
|
||||||
|
|
||||||
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Starting new Web server: tcp:127.0.0.1:"
|
||||||
|
|
||||||
|
|
||||||
# Store the checksum with the 'INTERNAL_TOKEN' value.
|
# Store the checksum with the 'INTERNAL_TOKEN' value.
|
||||||
# Should be removed when the issue https://github.com/go-gitea/gitea/issues/3246 is fixed
|
# 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"
|
ynh_store_file_checksum --file "$final_path/custom/conf/app.ini"
|
||||||
|
|
Loading…
Add table
Reference in a new issue