This commit is contained in:
YunoHost Bot 2024-09-02 22:31:30 +02:00 committed by GitHub
commit 1af5396776
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 244 additions and 278 deletions

1
.gitignore vendored
View file

@ -221,3 +221,4 @@ pip-log.txt
*-swp
auto_update_config.sh
*.sw[op]

View file

@ -1,3 +1,5 @@
# WARNING: Don't edit this file. All change will be removed after each app upgrade
import os
daemon = True

View file

@ -1,3 +1,5 @@
# WARNING: Don't edit this file. All change will be removed after each app upgrade
[DATABASE]
type = mysql
host = 127.0.0.1

View file

@ -1,3 +1,5 @@
# WARNING: Don't edit this file. All change will be removed after each app upgrade
[fileserver]
port = __PORT_FILESERVER__

View file

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
# WARNING: Don't edit this file. All change will be removed after each app upgrade
SECRET_KEY = "{{ seahub_secret_key }}"
DATABASES = {

View file

@ -18,7 +18,8 @@ code = "https://github.com/haiwen/seafile-server"
cpe = "cpe:2.3:a:seafile:seafile"
[integration]
yunohost = ">= 11.2.13"
yunohost = ">= 11.2.30"
helpers_version = "2.1"
architectures = ["amd64", "arm64"]
multi_instance = false
ldap = true
@ -62,12 +63,10 @@ ram.runtime = "500M"
[resources]
[resources.system_user]
allow_email = true
home = "/opt/yunohost/__APP__"
[resources.install_dir]
dir = "/opt/yunohost/__APP__"
owner = "__APP__:rwx"
group = "www-data:rx"
group = "www-data:r-x"
[resources.data_dir]
dir = "/home/yunohost.app/__APP__"

View file

@ -31,7 +31,7 @@ fi
#=================================================
run_seafile_cmd() {
ynh_exec_warn_less systemd-run --wait --uid="$app" --gid="$app" \
ynh_hide_warnings systemd-run --wait --uid="$app" --gid="$app" \
--property=RootDirectory="$install_dir"/seafile_image \
--property="BindPaths=$systemd_seafile_bind_mount" \
$@
@ -47,8 +47,10 @@ install_source() {
}
set_permission() {
chown "$app:$app" "$install_dir"
chmod u=rwx,g=rx,o= "$install_dir"
chown -R "$app:$app" "$install_dir"/{conf,ccnet}
chmod -R u+rwX,g-w,o= "$install_dir"/{conf,ccnet}
chmod -R u+rwX,g+rX-w,o= "$install_dir"/{conf,ccnet}
chown -R "$app:$app" "$install_dir"/seafile_image/opt/seafile
chmod -R u+rwX,g-w,o= "$install_dir"/seafile_image/opt/seafile
@ -67,6 +69,7 @@ set_permission() {
test -e "$install_dir"/seahub-data && setfacl -m user:www-data:rX "$data_dir"
test -e "$install_dir"/seahub-data && setfacl -R -m user:www-data:rX "$data_dir"/seahub-data
chmod u=rwx,g=rx,o= "$data_dir"
find "$data_dir" \( \! -perm -o= \
-o \! -user "$app" \
-o \! -group "$app" \) \
@ -76,14 +79,11 @@ set_permission() {
clean_url_in_db_config() {
sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "SERVICE_URL"'
ynh_mysql_execute_as_root --sql="$sql_request" --database=seahubdb
ynh_mysql_db_shell <<< "$sql_request" --database=seahubdb
sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"'
ynh_mysql_execute_as_root --sql="$sql_request" --database=seahubdb
ynh_mysql_db_shell <<< "$sql_request" --database=seahubdb
}
ensure_vars_set() {
if [ -z "${jwt_private_key_notification_server:-}" ]; then
jwt_private_key_notification_server=$(ynh_string_random -l 32)
ynh_app_setting_set --app="$app" --key=jwt_private_key_notification_server --value="$jwt_private_key_notification_server"
fi
ynh_app_setting_set_default --key=jwt_private_key_notification_server --value=$(ynh_string_random -l 32)
}

View file

@ -15,7 +15,7 @@ seafile_version=$(ynh_app_upstream_version)
seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version"
if systemctl is-active seafile --quiet || systemctl is-active seahub --quiet; then
ynh_print_warn --message="It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'"
ynh_print_warn "It's hightly recommended to make your backup when the service is stopped. Please stop seafile service and seahub service with this command before to run the backup 'systemctl stop seafile.service seahub.service'"
fi
#=================================================
@ -23,24 +23,25 @@ fi
#=================================================
# # Backup app files
ynh_print_info --message="Backing up code..."
ynh_backup --src_path="$install_dir"
ynh_print_info --message="Backing up user data..."
ynh_backup --src_path="$data_dir" --dest_path="data" --is_big=1
ynh_print_info --message="Backing up configuration..."
ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/${app}.conf"
ynh_backup --src_path=/etc/systemd/system/seafile.service
ynh_backup --src_path=/etc/systemd/system/seahub.service
ynh_backup --src_path=/etc/fail2ban/jail.d/"$app".conf
ynh_backup --src_path=/etc/fail2ban/filter.d/"$app".conf
ynh_print_info "Backing up code..."
ynh_backup "$install_dir"
ynh_print_info "Backing up user data..."
ynh_backup "$data_dir" --dest_path="data"
ynh_print_info "Backing up configuration..."
ynh_backup "/etc/nginx/conf.d/$domain.d/${app}.conf"
ynh_backup /etc/systemd/system/seafile.service
ynh_backup /etc/systemd/system/seahub.service
ynh_backup /etc/fail2ban/jail.d/"$app".conf
ynh_backup /etc/fail2ban/filter.d/"$app".conf
# Backup logs
ynh_backup --src_path="/var/log/$app"
ynh_backup "/var/log/$app"
# Backup mysql
ynh_print_info --message="Backing up database"
ynh_mysql_dump_db --database="$db_name" > "${YNH_CWD}"/seafiledb.dmp
ynh_mysql_dump_db --database=ccnetdb > "${YNH_CWD}"/ccnetdb.dmp
ynh_mysql_dump_db --database=seahubdb > "${YNH_CWD}"/seahubdb.dmp
ynh_print_info "Backing up database"
ynh_mysql_dump_db > "${YNH_CWD}"/seafiledb.dmp
ynh_mysql_dump_db ccnetdb > "${YNH_CWD}"/ccnetdb.dmp
ynh_mysql_dump_db seahubdb > "${YNH_CWD}"/seahubdb.dmp
ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."

View file

@ -14,35 +14,33 @@ source /usr/share/yunohost/helpers
seafile_version="$(ynh_app_upstream_version)"
seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_change_url_nginx_config
ynh_script_progression "Updating NGINX web server configuration..."
ynh_config_change_url_nginx
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
ynh_script_progression --message="Stoping services..."
ynh_script_progression "Stoping services..."
# Stop service before any change
ynh_systemd_action --service_name=seafile --action=stop
ynh_systemd_action --service_name=seahub --action=stop
ynh_systemctl --service=seafile --action=stop
ynh_systemctl --service=seahub --action=stop
sleep 2
pkill -f seafile-controller || true
pkill -f seaf-server || true
pkill -f ccnet-server || true
pkill -f seahub || true
ynh_script_progression --message="Updating seafile configuration..."
ynh_script_progression "Updating seafile configuration..."
# Update Seafile Config
ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
# Update permissions
ynh_permission_url --permission=file_server --url="$domain"/seafhttp
@ -55,9 +53,10 @@ clean_url_in_db_config
sleep 2
# Reload services
ynh_script_progression --message="Starting services..."
ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd"
ynh_script_progression "Starting services..."
ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log
sleep 2
ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd"
sleep 2
ynh_script_progression --message="Change of URL completed for $app" --time=--last
ynh_script_progression "Change of URL completed for $app" --time=

View file

@ -17,11 +17,9 @@ seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_ver
ensure_vars_set
#=================================================
# STANDARD MODIFICATIONS
#=================================================
ynh_script_progression --message="Creating base directory..."
ynh_script_progression "Creating base directory..."
if [ -n "$(ls -A "$data_dir")" ]; then
old_data_dir_path="${data_dir}_$(date '+%Y%m%d.%H%M%S')"
@ -35,25 +33,25 @@ mkdir -p "$data_dir"/{seafile-data,seahub-data}
mkdir -p "$install_dir"/{conf,ccnet}
# Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7
ynh_script_progression "Installing sources files..."
install_source
# init databases
ynh_script_progression --message="Configuring MySQL database..."
ynh_script_progression "Configuring MySQL database..."
db_user=seafile
ynh_''mysql_setup_db --db_user="$db_user" --db_name=ccnetdb --db_pwd="$db_pwd"
ynh_''mysql_setup_db --db_user="$db_user" --db_name=seahubdb --db_pwd="$db_pwd"
ynh_''mysql_create_db ccnetdb "$db_user" "$db_pwd"
ynh_''mysql_create_db seahubdb "$db_user" "$db_pwd"
ynh_script_progression --message="Configuring application..." --weight=3
ynh_script_progression "Configuring application..."
# Run install script
set_permission
ynh_replace_special_string --match_string='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \
--replace_string='seafile_config.seafile_dir = seafile_dir' \
--target_file="$seafile_code/setup-seafile-mysql.py"
ynh_replace_special_string --match_string="Utils.error('Ccnet config dir \\\"%s\\\" already exists.' % ccnet_config.ccnet_dir)" \
--replace_string='patched = 1' \
--target_file="$seafile_code/setup-seafile-mysql.py"
ynh_replace_regex --match='seafile_config.seafile_dir = seafile_config.validate_seafile_dir(seafile_dir)' \
--replace='seafile_config.seafile_dir = seafile_dir' \
--file="$seafile_code/setup-seafile-mysql.py"
ynh_replace_regex --match="Utils.error('Ccnet config dir \\\"%s\\\" already exists.' % ccnet_config.ccnet_dir)" \
--replace='patched = 1' \
--file="$seafile_code/setup-seafile-mysql.py"
run_seafile_cmd bash "/opt/seafile/seafile-server-$seafile_version/setup-seafile-mysql.sh" auto \
--server-name "$server_name" \
--server-ip "$domain" \
@ -69,79 +67,77 @@ run_seafile_cmd bash "/opt/seafile/seafile-server-$seafile_version/setup-seafile
# Retrive values from auto generated config file
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)
ynh_app_setting_set --app="$app" --key=seahub_secret_key --value="$seahub_secret_key"
ynh_app_setting_set --key=seahub_secret_key --value="$seahub_secret_key"
# Update seafile config files
ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_add_config --template=seafile.conf --destination="$install_dir"/conf/seafile.conf
ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_config_add --template=seafile.conf --destination="$install_dir"/conf/seafile.conf
ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_config_add --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
# Configure admin info
# It will be used the first start
admin_email=$(ynh_user_get_info --username="$admin" --key='mail')
cp ../conf/create_admin.json $install_dir/conf/admin.txt
ynh_replace_string --match_string=__ADMIN__ --replace_string="$admin_email" --target_file=$install_dir/conf/admin.txt
ynh_replace_special_string --match_string=__PASSWORD__ --replace_string="$admin_password" --target_file=$install_dir/conf/admin.txt
cp ../conf/create_admin.json "$install_dir"/conf/admin.txt
ynh_replace --match=__ADMIN__ --replace="$admin_email" --file="$install_dir"/conf/admin.txt
ynh_replace_regex --match=__PASSWORD__ --replace="$admin_password" --file="$install_dir"/conf/admin.txt
# Use symlink to store data
if [ -e "$install_dir"/seafile-data ]; then
mv -t "$data_dir"/seafile-data "$install_dir"/seafile-data/*
ynh_secure_remove --file="$install_dir"/seafile-data
ynh_safe_rm "$install_dir"/seafile-data
fi
if [ -e "$install_dir"/seahub-data ]; then
mv -t "$data_dir"/seahub-data "$install_dir"/seahub-data/*
ynh_secure_remove --file="$install_dir"/seahub-data
ynh_safe_rm "$install_dir"/seahub-data
fi
if [ -e "$install_dir"/logs ]; then
mv -t /var/log/"$app" "$install_dir"/logs/*
ynh_secure_remove --file="$install_dir"/logs
ynh_safe_rm "$install_dir"/logs
fi
ln -s "$data_dir"/seafile-data "$install_dir"/seafile-data
ln -s "$data_dir"/seahub-data "$install_dir"/seahub-data
ln -s /var/log/"$app" "$install_dir"/logs
# Fix local warning
ynh_replace_string --match_string=en_US.UTF-8 --replace_string="${LANG:-'en_US.UTF-8'}" --target_file="$seafile_code/seahub.sh"
ynh_replace --match=en_US.UTF-8 --replace="${LANG:-'en_US.UTF-8'}" --file="$seafile_code/seahub.sh"
# Add Seafile Server to startup
ynh_script_progression --message="Configuring a systemd service..."
ynh_add_systemd_config --service=seafile --template=seafile.service
ynh_add_systemd_config --service=seahub --template=seahub.service
ynh_script_progression "Configuring $app's systemd service..."
ynh_config_add_systemd --service=seafile --template=seafile.service
ynh_config_add_systemd --service=seahub --template=seahub.service
# register yunohost service
yunohost service add seafile --description 'Main service for seafile server.'
yunohost service add seahub --description 'Seafile server web interface.'
# Config nginx
ynh_script_progression --message="Configuring nginx..."
ynh_add_nginx_config
ynh_script_progression "Configuring nginx..."
ynh_config_add_nginx
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile=/var/log/"$app"
ynh_script_progression "Configuring log rotation..."
ynh_config_add_logrotate /var/log/"$app"
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..."
ynh_add_fail2ban_config --use_template
ynh_script_progression "Configuring fail2ban..."
ynh_config_add_fail2ban
#=================================================
# GENERIC FINALIZATION
#=================================================
# Set all permissions
ynh_script_progression --message="Protecting directory..."
ynh_script_progression "Protecting directory..."
set_permission
# Start service
sleep 3
ynh_script_progression --message="Starting seafile services..."
ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
ynh_script_progression "Starting seafile services..."
ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log
sleep 2
ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd"
ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd"
sleep 2
ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"

View file

@ -18,11 +18,11 @@ seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_ver
# STANDARD REMOVE
#=================================================
ynh_script_progression --message="Stoping services..."
ynh_script_progression "Stoping services..."
# Stop all services
ynh_systemd_action --service_name=seafile --action=stop
ynh_systemd_action --service_name=seahub --action=stop
ynh_systemctl --service=seafile --action=stop
ynh_systemctl --service=seahub --action=stop
# Force to kill all process in case of a process is not stoped cleanly
pkill -f seafile-controller || true
@ -30,35 +30,35 @@ pkill -f seaf-server || true
pkill -f ccnet-server || true
pkill -f seahub || true
ynh_script_progression --message="Removing code..."
ynh_secure_remove --file=/var/www/"$app"
ynh_secure_remove --file=/opt/yunohost/"$app"
ynh_script_progression "Removing code..."
ynh_safe_rm /var/www/"$app"
ynh_safe_rm /opt/yunohost/"$app"
# Remove databases
ynh_script_progression --message="Removing databases..."
db_helper=ynh_"mysql"_remove_db
$db_helper --db_name ccnetdb --db_user seafile
$db_helper --db_name seahubdb --db_user seafile
ynh_script_progression "Removing databases..."
ynh_''mysql_drop_db ccnetdb
ynh_''mysql_drop_db seahubdb
# Remove systemd service
ynh_script_progression --message="Removing systemd units..."
ynh_remove_systemd_config --service=seafile
ynh_remove_systemd_config --service=seahub
ynh_script_progression "Removing systemd units..."
ynh_config_remove_systemd seafile
ynh_config_remove_systemd seahub
# Remove nginx config
ynh_script_progression --message="Removing nginx configuration..."
ynh_remove_nginx_config
ynh_script_progression "Removing nginx configuration..."
ynh_config_remove_nginx
# Remove logrotate
ynh_remove_logrotate
ynh_config_remove_logrotate
# Remove the dedicated fail2ban config
ynh_script_progression --message="Removing fail2ban configuration..."
ynh_remove_fail2ban_config
ynh_script_progression "Removing fail2ban configuration..."
ynh_config_remove_fail2ban
ynh_script_progression --message="Removing seafile service..."
ynh_script_progression "Removing seafile service..."
yunohost service remove seafile
yunohost service remove seahub
ynh_script_progression --message="Removal of $app completed" --last
ynh_script_progression "Removal of $app completed"
sleep 1

View file

@ -14,64 +14,61 @@ source /usr/share/yunohost/helpers
seafile_version="$(ynh_app_upstream_version)"
seafile_code="$install_dir/seafile_image/opt/seafile/seafile-server-$seafile_version"
ynh_script_progression --message="Loading settings..."
ynh_script_progression "Loading settings..."
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# Restore all config and data
ynh_script_progression --message="Restoring files..." --weight=10
ynh_restore
ynh_script_progression "Restoring files..."
ynh_restore_everything
# Restore mysql dump
ynh_script_progression --message="Restoring database..." --weight=3
db_helper=ynh_"mysql"_setup_db
$db_helper --db_user "$db_user" --db_name ccnetdb --db_pwd "$db_pwd"
$db_helper --db_user "$db_user" --db_name seahubdb --db_pwd "$db_pwd"
ynh_script_progression "Restoring database..."
ynh_''mysql_create_db ccnetdb "$db_user" "$db_pwd"
ynh_''mysql_create_db seahubdb "$db_user" "$db_pwd"
su -c "mysql -u ${app} -p$db_pwd $db_name < ${YNH_CWD}/seafiledb.dmp"
su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${YNH_CWD}/ccnetdb.dmp"
su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp"
#=================================================
# GENERIC FINALIZATION
#=================================================
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_script_progression "Configuring log rotation..."
mkdir -p /var/log/"$app"
ynh_use_logrotate --logfile="$install_dir"/logs
ynh_config_add_logrotate "$install_dir"/logs
# Set all permissions
ynh_script_progression --message="Protecting directory..."
ynh_script_progression "Protecting directory..."
set_permission
# Enable service and start seafile
ynh_script_progression --message="Reconfiguring application..."
ynh_script_progression "Reconfiguring application..."
systemctl daemon-reload
systemctl enable seafile --quiet
systemctl enable seahub --quiet
# Add Seafile to YunoHost's monitored services
ynh_script_progression --message="Register seafile service..."
ynh_script_progression "Register seafile service..."
yunohost service add seafile --description 'Main service for seafile server.'
yunohost service add seahub --description 'Seafile server web interface.'
ynh_script_progression --message="Reloading services..."
ynh_script_progression "Reloading services..."
# Reload nginx
systemctl reload nginx.service
# Reload fail2ban
ynh_systemd_action --service_name=fail2ban --action=reload
ynh_systemctl --service=fail2ban --action=reload
# Avoid the current effect
sleep 5
# Restart service
ynh_script_progression --message="Starting seafile services..." --weight=3
ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd"
ynh_script_progression "Starting seafile services..."
ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log
sleep 2
ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd"
sleep 2
ynh_script_progression --message="Restoration completed for $app" --last
ynh_script_progression "Restoration completed for $app"

View file

@ -23,10 +23,10 @@ if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version
ynh_die "Upgrade from this version not supported"
fi
ynh_script_progression --message="Stoping services..."
ynh_script_progression "Stoping services..."
ynh_systemd_action --service_name=seafile --action=stop
ynh_systemd_action --service_name=seahub --action=stop
ynh_systemctl --service=seafile --action=stop
ynh_systemctl --service=seahub --action=stop
sleep 5
pkill -f seafile-controller || true
pkill -f seaf-server || true
@ -42,15 +42,12 @@ if mysqlshow | grep -q seafiledb; then
$mysqlconn -e "RENAME TABLE seafiledb.$name to $db_name.$name";
done;
$mysqlconn -e "DROP DATABASE seafiledb"
ynh_replace_string --match_string='db_name = seafiledb' --replace_string='db_name = seafile' --target_file="$install_dir"/conf/seafile.conf
ynh_replace --match='db_name = seafiledb' --replace='db_name = seafile' --file="$install_dir"/conf/seafile.conf
sed -i "s|password\s*=\s*.*^|password = $db_pwd|g" "$install_dir"/conf/seafile.conf
fi
# Set missing settings
if [ -z "${seahub_secret_key:-}" ]; then
seahub_secret_key="$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)"
ynh_app_setting_set --app="$app" --key=seahub_secret_key --value="$seahub_secret_key"
fi
ynh_app_setting_set_default --key=seahub_secret_key --value="$(grep -P 'SECRET_KEY\s*=\s*".+"' "$install_dir"/conf/seahub_settings.py | cut -d'"' -f2)"
#
# Update data dir if needed
@ -97,15 +94,15 @@ if [ ! -L "$install_dir"/logs ]; then
ln -s /var/log/"${app}" "$install_dir"/logs
fi
ynh_script_progression --message="Upgrading source files..." --weight=6
ynh_script_progression "Upgrading source files..."
# Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7
ynh_script_progression "Installing sources files..."
if [ "$YNH_APP_UPGRADE_TYPE" == UPGRADE_APP ]; then
install_source
fi
ynh_script_progression --message="Configuring application..."
ynh_script_progression "Configuring application..."
# permission to execute update script and expect helper
set_permission
@ -128,7 +125,7 @@ case "$installed_version" in
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/seahub.sh" python-env python3 "/opt/seafile/seafile-server-$seafile_version/seahub/manage.py" migrate_file_comment
# Update seafile by script
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_7.0_7.1.sh"
ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_7.0_7.1.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh"
# Fix seafile data link. Look like that the upgrade script of seafile don't always work correctly
@ -139,90 +136,87 @@ case "$installed_version" in
ln -s "$data_dir" "$install_dir"/seafile-data
;&
"7.1."* )
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_8.0_9.0.sh"
ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_8.0_9.0.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
;&
"8.0."* )
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_7.1_8.0.sh"
ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_7.1_8.0.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh"
;&
"9."* )
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_8.0_9.0.sh"
ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_8.0_9.0.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
;&
"10."* )
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/upgrade_9.0_10.0.sh"
ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/upgrade_9.0_10.0.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/seahub.sh" python-env python3 "/opt/seafile/seafile-server-$seafile_version/migrate_ldapusers.py"
;&
esac
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$seafile_code/upgrade/minor-upgrade.sh"
ynh_replace --match='read dummy' --replace='# patched' --file="$seafile_code/upgrade/minor-upgrade.sh"
run_seafile_cmd "/opt/seafile/seafile-server-$seafile_version/upgrade/minor-upgrade.sh"
# Clean url in config in DB
clean_url_in_db_config
# Update seafile config files
ynh_add_config --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_add_config --template=seafile.conf --destination="$install_dir"/conf/seafile.conf
ynh_add_config --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_add_config --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_add_config --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
ynh_config_add --jinja --template=seahub_settings.py --destination="$install_dir"/conf/seahub_settings.py
ynh_config_add --template=seafile.conf --destination="$install_dir"/conf/seafile.conf
ynh_config_add --template=ccnet.conf --destination="$install_dir"/conf/ccnet.conf
ynh_config_add --template=gunicorn.conf.py --destination="$install_dir"/conf/gunicorn.conf.py
ynh_config_add --template=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_config_add --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
# Fix local warning
ynh_replace_string --match_string=en_US.UTF-8 --replace_string="${LANG:-'en_US.UTF-8'}" --target_file="$seafile_code/seahub.sh"
ynh_replace --match=en_US.UTF-8 --replace="${LANG:-'en_US.UTF-8'}" --file="$seafile_code/seahub.sh"
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# Config nginx
ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
ynh_config_add_nginx 'seahub_port fileserver_port webdav_port'
# Add Seafile Server to startup
ynh_script_progression --message="Updating systemd units..."
ynh_add_systemd_config --service=seafile --template=seafile.service
ynh_add_systemd_config --service=seahub --template=seahub.service
ynh_script_progression "Updating systemd units..."
ynh_config_add_systemd --service=seafile --template=seafile.service
ynh_config_add_systemd --service=seahub --template=seahub.service
#=================================================
# GENERIC FINALIZATION
#=================================================
# Set all permissions
ynh_script_progression --message="Protecting directory..."
ynh_script_progression "Protecting directory..."
set_permission
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile=/var/log/"$app" --nonappend
ynh_script_progression "Configuring log rotation..."
ynh_config_add_logrotate /var/log/"$app"
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." --weight=10
ynh_add_fail2ban_config --use_template
ynh_script_progression "Configuring fail2ban..."
ynh_config_add_fail2ban
# register yunohost service
ynh_script_progression --message="Register seafile service..."
ynh_script_progression "Register seafile service..."
yunohost service add seafile --description 'Main service for seafile server.'
yunohost service add seahub --description 'Seafile server web interface.'
# delete seafile cache
# restart seafile server
ynh_script_progression --message="Starting seafile services..." --weight=3
ynh_script_progression "Starting seafile services..."
sleep 5
ynh_systemd_action --service_name=memcached.service -p "systemd"
ynh_systemd_action --service_name=seafile -l "spawned seaf-server, pid " -p /var/log/seafile/controller.log
ynh_systemd_action --service_name=seahub -l "Started Seafile hub." -p "systemd"
ynh_systemctl --service=memcached.service -p "systemd"
ynh_systemctl --service=seafile --wait_until="spawned seaf-server, pid " --log_path=/var/log/seafile/controller.log
sleep 2
ynh_systemctl --service=seahub --wait_until="Started Seafile hub." --log_path="systemd"
sleep 2
# remove old version files
ynh_script_progression --message="Cleaning system and updating settings..."
ynh_script_progression "Cleaning system and updating settings..."
for f in "$install_dir"/seafile-server-*;do
if [[ ! "$f" =~ ${seafile_version//./\\.}|latest ]]; then
ynh_secure_remove --file="$f"
ynh_safe_rm "$f"
fi
done
ynh_script_progression --message="Upgrade of $app completed" --last
ynh_script_progression "Upgrade of $app completed"

View file

@ -1,80 +1,62 @@
# Download, check integrity, uncompress and patch the source from app.src
# Download, check integrity, uncompress and patch upstream sources
#
# Requires YunoHost version 2.6.4 or higher.
# NOTE this is a full copy of upstream ynh_setup_source but with some specific patch releated to seafile docker archive
ynh_setup_source_custom() {
# Declare an array to define the options of this helper.
local legacy_args=dsk
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace=)
# ============ Argument parsing =============
local -A args_array=([d]=dest_dir= [s]=source_id= [k]=keep= [r]=full_replace)
local dest_dir
local source_id
local keep
local full_replace
# Manage arguments with getopts
ynh_handle_getopts_args "$@"
keep="${keep:-}"
full_replace="${full_replace:-0}"
source_id="${source_id:-main}"
# ===========================================
if test -e $YNH_APP_BASEDIR/manifest.toml && cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq -e '.resources.sources' >/dev/null
local sources_json=$(ynh_read_manifest "resources.sources[\"$source_id\"]")
if jq -re ".url" <<< "$sources_json"
then
source_id="${source_id:-main}"
local sources_json=$(cat $YNH_APP_BASEDIR/manifest.toml | toml_to_json | jq ".resources.sources[\"$source_id\"]")
if jq -re ".url" <<< "$sources_json"
then
local arch_prefix=""
else
local arch_prefix=".$YNH_ARCH"
fi
local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')"
local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')"
local src_sumprg="sha256sum"
local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')"
local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')"
local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')"
local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')"
local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')"
[[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?"
if [[ -z "$src_format" ]]
then
if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]]
then
src_format="zip"
elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]]
then
src_format="tar.gz"
elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]]
then
src_format="tar.xz"
elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]
then
src_format="tar.bz2"
elif [[ -z "$src_extract" ]]
then
src_extract="false"
fi
fi
local arch_prefix=""
else
source_id="${source_id:-app}"
local src_file_path="$YNH_APP_BASEDIR/conf/${source_id}.src"
# Load value from configuration file (see above for a small doc about this file
# format)
local src_url=$(grep 'SOURCE_URL=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_sum=$(grep 'SOURCE_SUM=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_sumprg=$(grep 'SOURCE_SUM_PRG=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_format=$(grep 'SOURCE_FORMAT=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_in_subdir=$(grep 'SOURCE_IN_SUBDIR=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_rename=$(grep 'SOURCE_FILENAME=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_extract=$(grep 'SOURCE_EXTRACT=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local src_platform=$(grep 'SOURCE_PLATFORM=' "$src_file_path" | cut --delimiter='=' --fields=2-)
local arch_prefix=".$YNH_ARCH"
fi
# Default value
src_sumprg=${src_sumprg:-sha256sum}
local src_url="$(jq -r "$arch_prefix.url" <<< "$sources_json" | sed 's/^null$//')"
local src_sum="$(jq -r "$arch_prefix.sha256" <<< "$sources_json" | sed 's/^null$//')"
local src_format="$(jq -r ".format" <<< "$sources_json" | sed 's/^null$//')"
local src_in_subdir="$(jq -r ".in_subdir" <<< "$sources_json" | sed 's/^null$//')"
src_in_subdir=${src_in_subdir:-true}
local src_extract="$(jq -r ".extract" <<< "$sources_json" | sed 's/^null$//')"
local src_platform="$(jq -r ".platform" <<< "$sources_json" | sed 's/^null$//')"
local src_rename="$(jq -r ".rename" <<< "$sources_json" | sed 's/^null$//')"
[[ -n "$src_url" ]] || ynh_die "No URL defined for source $source_id$arch_prefix ?"
[[ -n "$src_sum" ]] || ynh_die "No sha256 sum defined for source $source_id$arch_prefix ?"
if [[ -z "$src_format" ]]
then
if [[ "$src_url" =~ ^.*\.zip$ ]] || [[ "$src_url" =~ ^.*/zipball/.*$ ]]
then
src_format="zip"
elif [[ "$src_url" =~ ^.*\.tar\.gz$ ]] || [[ "$src_url" =~ ^.*\.tgz$ ]] || [[ "$src_url" =~ ^.*/tar\.gz/.*$ ]] || [[ "$src_url" =~ ^.*/tarball/.*$ ]]
then
src_format="tar.gz"
elif [[ "$src_url" =~ ^.*\.tar\.xz$ ]]
then
src_format="tar.xz"
elif [[ "$src_url" =~ ^.*\.tar\.bz2$ ]]
then
src_format="tar.bz2"
elif [[ "$src_url" =~ ^.*\.tar$ ]]
then
src_format="tar"
elif [[ -z "$src_extract" ]]
then
src_extract="false"
fi
fi
src_format=${src_format:-tar.gz}
src_format=$(echo "$src_format" | tr '[:upper:]' '[:lower:]')
src_extract=${src_extract:-true}
@ -84,10 +66,6 @@ ynh_setup_source_custom() {
ynh_die "For source $source_id, expected either 'true' or 'false' for the extract parameter"
fi
# (Unused?) mecanism where one can have the file in a special local cache to not have to download it...
local local_src="/opt/yunohost-apps-src/${YNH_APP_ID}/${source_id}"
# Gotta use this trick with 'dirname' because source_id may contain slashes x_x
mkdir -p $(dirname /var/cache/yunohost/download/${YNH_APP_ID}/${source_id})
src_filename="/var/cache/yunohost/download/${YNH_APP_ID}/${source_id}"
@ -100,14 +78,10 @@ ynh_setup_source_custom() {
fi
# END APP CUSTOMIZATION
else
if test -e "$local_src"; then
cp $local_src $src_filename
fi
[ -n "$src_url" ] || ynh_die "Couldn't parse SOURCE_URL from $src_file_path ?"
# If the file was prefetched but somehow doesn't match the sum, rm and redownload it
if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status
if [ -e "$src_filename" ] && ! echo "${src_sum} ${src_filename}" | sha256sum --check --status
then
rm -f "$src_filename"
fi
@ -121,16 +95,16 @@ ynh_setup_source_custom() {
local out
# Timeout option is here to enforce the timeout on dns query and tcp connect (c.f. man wget)
out=$(wget --tries 3 --no-dns-cache --timeout 900 --no-verbose --output-document=$src_filename $src_url 2>&1) \
|| ynh_die --message="$out"
|| ynh_die "$out"
fi
# Check the control sum
if ! echo "${src_sum} ${src_filename}" | ${src_sumprg} --check --status
if ! echo "${src_sum} ${src_filename}" | sha256sum --check --status
then
local actual_sum="$(${src_sumprg} ${src_filename} | cut --delimiter=' ' --fields=1)"
local actual_sum="$(sha256sum ${src_filename} | cut --delimiter=' ' --fields=1)"
local actual_size="$(du -hs ${src_filename} | cut --fields=1)"
rm -f ${src_filename}
ynh_die --message="Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})."
ynh_die "Corrupt source for ${src_url}: Expected sha256sum to be ${src_sum} but got ${actual_sum} (size: ${actual_size})."
fi
fi
@ -150,19 +124,12 @@ ynh_setup_source_custom() {
fi
if [ "$full_replace" -eq 1 ]; then
ynh_secure_remove --file="$dest_dir"
ynh_safe_rm "$dest_dir"
fi
# Extract source into the app dir
mkdir --parents "$dest_dir"
if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then
_ynh_apply_default_permissions $dest_dir
fi
if [ -n "${final_path:-}" ] && [ "$dest_dir" == "$final_path" ]; then
_ynh_apply_default_permissions $dest_dir
fi
if [[ "$src_extract" == "false" ]]; then
if [[ -z "$src_rename" ]]
then
@ -179,11 +146,11 @@ ynh_setup_source_custom() {
local tmp_dir=$(mktemp --directory)
unzip -quo $src_filename -d "$tmp_dir"
cp --archive $tmp_dir/*/. "$dest_dir"
ynh_secure_remove --file="$tmp_dir"
ynh_safe_rm "$tmp_dir"
else
unzip -quo $src_filename -d "$dest_dir"
fi
ynh_secure_remove --file="$src_filename"
ynh_safe_rm "$src_filename"
else
local strip=""
if [ "$src_in_subdir" != "false" ]; then
@ -194,30 +161,29 @@ ynh_setup_source_custom() {
fi
strip="--strip-components $sub_dirs"
fi
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz$ ]]; then
if [[ "$src_format" =~ ^tar.gz|tar.bz2|tar.xz|tar$ ]]; then
tar --extract --file=$src_filename --directory="$dest_dir" $strip
else
ynh_die --message="Archive format unrecognized."
ynh_die "Archive format unrecognized."
fi
ynh_secure_remove --file="$src_filename"
ynh_safe_rm "$src_filename"
fi
# Apply patches
if [ -d "$YNH_APP_BASEDIR/sources/patches/" ]; then
local patches_folder=$(realpath $YNH_APP_BASEDIR/sources/patches/)
if (($(find $patches_folder -type f -name "${source_id}-*.patch" 2>/dev/null | wc --lines) > "0")); then
pushd "$dest_dir"
for p in $patches_folder/${source_id}-*.patch; do
echo $p
patch --strip=1 <$p || ynh_print_warn --message="Packagers /!\\ patch $p failed to apply"
done
popd
fi
fi
# Add supplementary files
if test -e "$YNH_APP_BASEDIR/sources/extra_files/${source_id}"; then
cp --archive $YNH_APP_BASEDIR/sources/extra_files/$source_id/. "$dest_dir"
if [ -d "$YNH_APP_BASEDIR/patches/" ]; then
local patches_folder=$(realpath "$YNH_APP_BASEDIR/patches/$source_id")
pushd "$dest_dir"
for patchfile in "$patches_folder/"*.patch; do
echo "Applying $patchfile"
if ! patch --strip=1 < "$patchfile"; then
if ynh_in_ci_tests; then
ynh_die "Patch $patchfile failed to apply!"
else
ynh_print_warn "Warn your packagers /!\\ Patch $patchfile failed to apply"
fi
fi
done
popd
fi
# Keep files to be backup/restored at the end of the helper
@ -239,4 +205,8 @@ ynh_setup_source_custom() {
done
fi
rm -rf /var/cache/yunohost/files_to_keep_during_setup_source/
if [ -n "${install_dir:-}" ] && [ "$dest_dir" == "$install_dir" ]; then
_ynh_apply_default_permissions $dest_dir
fi
}

View file

@ -24,3 +24,4 @@ test_format = 1.0
test_upgrade_from.8d41482.name = "Version 7.1 (Old_version_for_CI_4 branch)"
test_upgrade_from.c11c24b.name = "Version 8.x (Old_version_for_CI_5 branch)"
test_upgrade_from.7a4d00a.name = "Version 9.x"
test_upgrade_from.5a4717a.name = "Before helper 2.1"