Full rework of package with packaging v2

This commit is contained in:
Josué Tille 2023-09-27 19:21:58 +02:00
parent 1ec5cad38f
commit 3af93d1c42
No known key found for this signature in database
GPG key ID: 716A6C99B04194EF
13 changed files with 101 additions and 123 deletions

View file

@ -1,11 +1,4 @@
[General]
USER_NAME = Seafile
ID = __CCNET_ID__
NAME = __SERVER_NAME__
SERVICE_URL = https://__DOMAIN____PATH__
[Client]
PORT = 13419
[Database]
ENGINE = mysql

View file

@ -14,5 +14,5 @@
enabled = true
port = http,https
filter = seafile
logpath = __FINAL_PATH__/logs/seahub.log
logpath = __INSTALL_DIR__/logs/seahub.log
maxretry = 3

View file

@ -4,7 +4,7 @@ daemon = True
workers = 5
# default localhost:8000
bind = "127.0.0.1:__SEAHUB_PORT__"
bind = "127.0.0.1:__PORT_SEAHUB__"
# Pid
pids_dir = '__INSTALL_DIR__/pids'

View file

@ -1,6 +1,6 @@
location __PATH__ {
proxy_redirect http:// https://;
proxy_pass http://127.0.0.1:__SEAHUB_PORT__;
proxy_pass http://127.0.0.1:__PORT_SEAHUB__;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@ -17,7 +17,7 @@ location __PATH__ {
}
location /seafhttp/ {
proxy_pass http://127.0.0.1:__FILESERVER_PORT__/;
proxy_pass http://127.0.0.1:__PORT_FILESERVER__/;
client_max_body_size 0;
proxy_connect_timeout 36000s;
proxy_read_timeout 36000s;
@ -30,7 +30,7 @@ location __PATH__/media/ {
}
location /seafdav {
proxy_pass http://127.0.0.1:__WEBDAV_PORT__/seafdav;
proxy_pass http://127.0.0.1:__PORT_WEBDAV__/seafdav;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

View file

@ -1,5 +1,5 @@
[WEBDAV]
enabled = true
port = __WEBDAV_PORT__
port = __PORT_WEBDAV__
fastcgi = true
share_name = /seafdav

17
conf/seafile.conf Normal file
View file

@ -0,0 +1,17 @@
[fileserver]
port = __PORT_FILESERVER__
# Set maximum upload file size to 200M.
max_upload_size=1000
# Set maximum download directory size to 200M.
max_download_dir_size=1000
[database]
type = mysql
host = 127.0.0.1
port = 3306
user = __DB_USER__
password = __DB_PWD__
db_name = seafiledb
connection_charset = utf8

View file

@ -14,6 +14,7 @@ DATABASES = {
}
}
SERVICE_URL = "https://__DOMAIN____PATH__"
FILE_SERVER_ROOT = "https://__DOMAIN__/seafhttp"
SITE_ROOT = "__PATH2__"
SERVE_STATIC = False
@ -22,11 +23,11 @@ COMPRESS_URL = MEDIA_URL
STATIC_URL = MEDIA_URL + 'assets/'
EMAIL_USE_TLS = False
EMAIL_HOST = "localhost"
EMAIL_HOST_USER = "seafile@__DOMAIN__"
EMAIL_HOST_USER = "__APP__@__DOMAIN__"
EMAIL_HOST_PASSWORD = ""
EMAIL_PORT = "25"
DEFAULT_FROM_EMAIL = "seafile@__DOMAIN__"
SERVER_EMAIL = "seafile@__DOMAIN__"
DEFAULT_FROM_EMAIL = "__APP__@__DOMAIN__"
SERVER_EMAIL = "__APP__@__DOMAIN__"
LOGIN_URL = '__PATH2__accounts/login/'
ENABLE_WIKI = True
ALLOWED_HOSTS = ['__DOMAIN__']

View file

@ -5,7 +5,7 @@ name = "Seafile"
description.en = "Open Source Cloud Storage"
description.fr = "Stockage Cloud Open Source"
version = "9.0.2~ynh2"
version = "9.0.9~ynh1"
maintainers = ["Josué Tille"]
@ -61,9 +61,11 @@ ram.runtime = "500M"
[resources]
[resources.system_user]
allow_email = true
home = "/opt/yunohost/__APP__"
[resources.install_dir]
dir = "/opt/yunohost/$app"
dir = "/opt/yunohost/__APP__"
owner = "__APP__:rwX"
group = "__APP__:rX"
subdirs = ["installed", "logs"]
@ -78,6 +80,7 @@ ram.runtime = "500M"
file_server.label = "File server"
file_server.allowed = "visitors"
file_server.auth_header = false
file_server.show_tile = false
file_server.protected = true
webdav.url = "__DOMAIN__/seafdav"
@ -85,12 +88,14 @@ ram.runtime = "500M"
webdav.allowed = "visitors"
webdav.auth_header = true
webdav.protected = true
webdav.show_tile = false
media.url = "/media"
media.label = "Media"
media.allowed = "visitors"
media.auth_header = true
media.protected = true
media.show_tile = false
[resources.ports]
seahub.default = 8000
@ -98,17 +103,16 @@ ram.runtime = "500M"
webdav.default = 8080
[resources.sources.main]
amd64.url = "https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_9.0.2_x86-64.tar.gz"
amd64.sha256 = "5adb3c800cd48de38b6e5d9b073e03ff375cfa30208a7291c481cdf1e1cf167b"
arm64.url = "https://github.com/haiwen/seafile-rpi/releases/download/v9.0.2/seafile-server-9.0.2-buster-arm64v8l.tar.gz"
arm64.sha256 = "0332a57364f92eaefe0109e5a65f8e3a3b909c3805b9113431d4bde2a962d78c"
armhf.url = "https://github.com/haiwen/seafile-rpi/releases/download/v9.0.2/seafile-server-9.0.2-buster-arm32v7l.tar.gz"
armhf.sha256 = "2aa42caa1420842435ee8a386fb9f3244a0d286a4c1f829a97cba49b41b274df"
amd64.url = "https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_9.0.9_x86-64.tar.gz"
amd64.sha256 = "db76bb33572ad0a6860470e907bed4ed780aa17d9e022226d99448a7f9e4ba74"
arm64.url = "https://github.com/haiwen/seafile-rpi/releases/download/v9.0.9/seafile-server-9.0.9-bullseye-arm64v8l.tar.gz"
arm64.sha256 = "c58f5d6b741dec240be9d75d6e617102b7adbfeba98cbd866732822bf9ca10b7"
armhf.url = "https://github.com/haiwen/seafile-rpi/releases/download/v9.0.9/seafile-server-9.0.9-bullseye-arm32v7l.tar.gz"
armhf.sha256 = "171fcf08b726d452e1c4cd22dadb9f8f5cf6848424ebc1e04cde5be34ef3d7f6"
[resources.apt]
packages = """
python3 python3-setuptools python3-pip python3-requests python3-dev libmariadb-dev-compat libmariadb-dev \
expect ffmpeg \
memcached libmemcached-dev \
python3-scipy python3-matplotlib \
libjpeg62-turbo-dev zlib1g-dev libffi-dev"""
packages = ["expect", "ffmpeg", "pkgconf",
"python3", "python3-setuptools", "python3-pip", "python3-requests", "python3-dev", "libmariadb-dev-compat", "libmariadb-dev",
"memcached", "libmemcached-dev",
"python3-scipy", "python3-matplotlib",
"libjpeg62-turbo-dev", "zlib1g-dev", "libffi-dev"]

View file

@ -12,10 +12,11 @@ time_zone=$(cat /etc/timezone)
install_dependance() {
ynh_add_swap --size=2000
# We need to do that because we can have some issue about the permission access to the pip cache without this
chown -R $seafile_user:$seafile_user $install_dir
chown -R $YNH_APP_ID $install_dir
chmod u+rwX -R $install_dir
# Note that we install imageio to force the dependance, without this imageio 2.8 is installed and it need python3.5
sudo -u $seafile_user pip3 install --user --no-warn-script-location --upgrade future mysqlclient PyMySQL Pillow pylibmc captcha Jinja2 SQLAlchemy psd-tools django-pylibmc django-simple-captcha python3-ldap pycryptodome==3.12.0 cffi==1.14.0
sudo -u $YNH_APP_ID pip3 install --user --no-warn-script-location --upgrade future mysqlclient PyMySQL 'Pillow<10.0.0' pylibmc captcha Jinja2 SQLAlchemy psd-tools django-pylibmc django-simple-captcha python3-ldap pycryptodome==3.12.0 cffi==1.14.0 lxml
ynh_del_swap
}
@ -23,23 +24,30 @@ mv_expect_scripts() {
expect_scripts_dir=$(mktemp -d)
cp expect_scripts/* $expect_scripts_dir
chmod u=rwx,o= -R $expect_scripts_dir
chown $seafile_user -R $expect_scripts_dir
chown $YNH_APP_ID -R $expect_scripts_dir
}
set_permission() {
chown -R $seafile_user:$seafile_user $install_dir
chmod -R g-wx,o= $install_dir
chown -R $YNH_APP_ID:$YNH_APP_ID $install_dir
chmod -R u+rw,g-wx,o= $install_dir
setfacl -m user:www-data:rX $install_dir
setfacl -m user:www-data:rX $install_dir/seafile-server-$seafile_version
# At install time theses directory are not available
#REMOVEME? test -e $install_dir/seafile-server-latest/seahub && setfacl -m user:www-data:rX $install_dir/seafile-server-latest/seahub
#REMOVEME? test -e $install_dir/seafile-server-latest/seahub/media && setfacl -R -m user:www-data:rX $install_dir/seafile-server-latest/seahub/media
#REMOVEME? test -e $install_dir/seahub-data && setfacl -R -m user:www-data:rX $install_dir/seahub-data
test -e $install_dir/seafile-server-latest/seahub && setfacl -m user:www-data:rX $install_dir/seafile-server-latest/seahub
test -e $install_dir/seafile-server-latest/seahub/media && setfacl -R -m user:www-data:rX $install_dir/seafile-server-latest/seahub/media
test -e $install_dir/seahub-data && setfacl -R -m user:www-data:rX $install_dir/seahub-data
# check that this directory exist because in some really old install the data could still be in the main seafile directory
# We also check at the install time when data directory is not already initialised
if [ -e /home/yunohost.app/seafile-data ]; then
chown -R $seafile_user:$seafile_user /home/yunohost.app/seafile-data
chown -R $YNH_APP_ID /home/yunohost.app/seafile-data
chmod -R o= /home/yunohost.app/seafile-data
fi
}
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
sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"'
ynh_mysql_execute_as_root --sql "$sql_request" --database seahubdb
}

View file

@ -11,55 +11,16 @@ source ./_common.sh
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
#REMOVEME? ynh_abort_if_errors
#REMOVEME? ynh_script_progression --message="Loading installation settings..."
# Retrive arguments
#REMOVEME? old_domain=$YNH_APP_OLD_DOMAIN
domain=$YNH_APP_NEW_DOMAIN
#REMOVEME? old_path=$(ynh_normalize_url_path --path $YNH_APP_OLD_PATH)
path=$(ynh_normalize_url_path --path $YNH_APP_NEW_PATH)
#REMOVEME? seahub_port=$(ynh_app_setting_get --app $app --key seahub_port)
#REMOVEME? fileserver_port=$(ynh_app_setting_get --app $app --key fileserver_port)
#REMOVEME? webdav_port=$(ynh_app_setting_get --app $app --key webdav_port)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app $app --key install_dir)
seafile_user=$app
# Create special path with / at the end
if [[ $old_path == '/' ]]
then
old_path2=$old_path
else
old_path2=$old_path'/'
fi
if [[ $path == '/' ]]
then
path2=$path
else
path2=$path'/'
fi
#=================================================
# STANDARD MODIFICATIONS
#=================================================
#REMOVEME? ynh_script_progression --message="Updating nginx configuration..."
ynh_script_progression --message="Updating NGINX web server configuration..." --weight=1
ynh_change_url_nginx_config
#REMOVEME? # Update nginx config
if [ "$old_domain" != "$domain" ]
then
# Delete file checksum for the old conf file location
#REMOVEME? ynh_delete_file_checksum --file "/etc/nginx/conf.d/$old_domain.d/$app.conf"
#REMOVEME? mv "/etc/nginx/conf.d/$old_domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf"
# Store file checksum for the new config file location
#REMOVEME? ynh_store_file_checksum --file "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
#REMOVEME? ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
#=================================================
# SPECIFIC MODIFICATIONS
#=================================================
ynh_script_progression --message="Stoping services..."
@ -75,16 +36,13 @@ pkill -f seahub || true
ynh_script_progression --message="Updating seafile configuration..."
# Update Seafile Config
ynh_replace_string --match_string "SERVICE_URL = https://$old_domain$old_path" --replace_string "SERVICE_URL = https://$domain$path" --target_file $install_dir/conf/ccnet.conf
ynh_add_config --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_replace_string --match_string 'FILE_SERVER_ROOT = "https://'"$old_domain"'/seafhttp"' --replace_string 'FILE_SERVER_ROOT = "https://'"$domain"'/seafhttp"' --target_file $install_dir/conf/seahub_settings.py
ynh_replace_string --match_string 'SITE_ROOT = "'"$old_path2"'"' --replace_string 'SITE_ROOT = "'"$path2"'"' --target_file $install_dir/conf/seahub_settings.py
ynh_replace_string --match_string 'MEDIA_URL = "'"$old_path2"'media/"' --replace_string 'MEDIA_URL = "'"$path2"'media/"' --target_file $install_dir/conf/seahub_settings.py
ynh_replace_string --match_string "LOGIN_URL = '${old_path2}accounts/login/'" --replace_string "LOGIN_URL = '${path2}accounts/login/'" --target_file $install_dir/conf/seahub_settings.py
ynh_replace_string --match_string ' = "seafile@'"$old_domain"'"' --replace_string ' = "seafile@'"$domain"'"' --target_file $install_dir/conf/seahub_settings.py
sed --in-place "s@ALLOWED_HOSTS = \['${old_domain}'\]@ALLOWED_HOSTS = \['${domain}'\]@g" $install_dir/conf/seahub_settings.py
ynh_replace_string --match_string "REMOTE_USER_DOMAIN = '$old_domain'" --replace_string "REMOTE_USER_DOMAIN = '$domain'" --target_file $install_dir/conf/seahub_settings.py
sed --in-place "s@REMOTE_USER_PROTECTED_PATH = \['$old_path', '$old_path/accounts/login'\]@REMOTE_USER_PROTECTED_PATH = \['$path', '$path/accounts/login'\]@g" $install_dir/conf/seahub_settings.py
# Clean url in config in DB
clean_url_in_db_config
# Avoid the current effect
sleep 2

View file

@ -48,18 +48,17 @@ ynh_script_progression --message="Configuring application..." --weight=3
mv_expect_scripts
chmod +x $install_dir/seafile-server-$seafile_version/setup-seafile-mysql.sh
set_permission
sudo -u $seafile_user $expect_scripts_dir/install.exp "$install_dir/seafile-server-$seafile_version" "$server_name" "$domain" "$fileserver_port" "$db_pwd"
sudo -u $YNH_APP_ID $expect_scripts_dir/install.exp "$install_dir/seafile-server-$seafile_version" "$server_name" "$domain" "$port_fileserver" "$db_pwd"
sleep 3
# Retrive values from auto generated config file
seahub_secret_key=$(grep -P 'SECRET_KEY\s*=\s*"[\w-]+"' $install_dir/conf/seahub_settings.py | cut -d'"' -f2)
ccnet_id=$(grep -P 'ID\s*=\s*\w+$' $install_dir/conf/ccnet.conf | cut -d= -f2 | grep -o -P '\w+')
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 --app $app --key ccnet_id --value $ccnet_id
# Update seafile config files
ynh_add_config --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
@ -75,13 +74,27 @@ ynh_replace_special_string --match_string __PASSWORD__ --replace_string $admin_p
ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh
# Add Seafile Server to startup
ynh_script_progression --message="Configuring a systemd service..." --weight=2
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
# register yunohost service
yunohost service add seafile
yunohost service add seahub
# Config nginx
ynh_script_progression --message="Configuring nginx..." --weight=1
ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
ynh_script_progression --message="Configuring nginx..."
ynh_add_nginx_config
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile $install_dir/logs
ln -s $install_dir/logs /var/log/seafile
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..."
touch $install_dir/logs/seahub.log
ynh_add_fail2ban_config --use_template
#=================================================
# GENERIC FINALIZATION
@ -91,26 +104,13 @@ ynh_add_nginx_config 'seahub_port fileserver_port webdav_port'
ynh_script_progression --message="Protecting directory..."
set_permission
# Add logrotate
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate --logfile $install_dir/logs
ln -s $install_dir/logs /var/log/seafile
# register yunohost service
yunohost service add seafile
yunohost service add seahub
ynh_script_progression --message="Stoping services..." --weight=3
# Start service
ynh_script_progression --message="Starting seafile services..." --weight=3
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
sleep 2
ynh_systemd_action --service_name seahub -l "Started Seafile hub." -p "systemd"
sleep 2
# Add fail2ban
ynh_script_progression --message="Configuring fail2ban..." --weight=10
ynh_add_fail2ban_config --use_template
ynh_script_progression --message="Installation of $app completed" --last

View file

@ -32,7 +32,6 @@ ynh_secure_remove --file=/var/log/seafile
ynh_script_progression --message="Removing code..."
ynh_secure_remove --file=/var/www/$app
ynh_secure_remove --file=/opt/yunohost/$app
ynh_secure_remove --file=/tmp/seahub_cache
# Remove databases
ynh_script_progression --message="Removing databases..."

View file

@ -55,8 +55,6 @@ set_permission
chmod u+x,o= $install_dir/seafile-server-$seafile_version/upgrade/upgrade_*.sh
chmod u+x,o= $install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh
# TODO !! retrive config from config file if not already set
# do the upgrade ( the ";&" syntax mean when it go in the first case which is true it do all the next case)
case $installed_version in
"4."* )
@ -88,7 +86,6 @@ case $installed_version in
;&
"7.1."* )
sudo -u $seafile_user $expect_scripts_dir/upgrade_8.0.exp $install_dir/seafile-server-$seafile_version
echo "FILTER = permission=cn=$app.main,ou=permission,dc=yunohost,dc=org" | tee -a $install_dir/conf/ccnet.conf
;&
"8.0."* )
sudo -u $seafile_user $expect_scripts_dir/upgrade_9.0.exp $install_dir/seafile-server-$seafile_version
@ -97,8 +94,12 @@ esac
sudo -u $seafile_user $expect_scripts_dir/minor-upgrade.exp $install_dir/seafile-server-$seafile_version
# Clean url in config in DB
clean_url_in_db_config
# Update seafile config files
ynh_add_config --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
@ -106,9 +107,6 @@ ynh_add_config --template=seafdav.conf --destination=$install_dir/conf/seafdav.c
# Fix local warning
ynh_replace_string --match_string en_US.UTF-8 --replace_string ${LANG:-'en_US.UTF-8'} --target_file $install_dir/seafile-server-$seafile_version/seahub.sh
# Update gunicorn config
sed --in-place -r "s@bind = \"0\.0\.0\.0:[[:digit:]]+\"@bind = \"0.0.0.0:$seahub_port\"@g" $install_dir/conf/gunicorn.conf.py
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
@ -143,11 +141,11 @@ yunohost service add seafile
yunohost service add seahub
# delete seafile cache
ynh_secure_remove --file=/tmp/seahub_cache
# restart seafile server
ynh_script_progression --message="Starting seafile services..." --weight=3
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"
sleep 2