Skip to content

Commit

Permalink
Full rework of package with packaging v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Josue-T committed Sep 27, 2023
1 parent 1ec5cad commit 3af93d1
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 123 deletions.
7 changes: 0 additions & 7 deletions conf/ccnet.conf
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion conf/f2b_jail.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion conf/gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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'
Expand Down
6 changes: 3 additions & 3 deletions conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion conf/seafdav.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[WEBDAV]
enabled = true
port = __WEBDAV_PORT__
port = __PORT_WEBDAV__
fastcgi = true
share_name = /seafdav
17 changes: 17 additions & 0 deletions conf/seafile.conf
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions conf/seahub_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
}

SERVICE_URL = "https://__DOMAIN____PATH__"
FILE_SERVER_ROOT = "https://__DOMAIN__/seafhttp"
SITE_ROOT = "__PATH2__"
SERVE_STATIC = False
Expand All @@ -22,11 +23,11 @@
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__']
Expand Down
32 changes: 18 additions & 14 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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"]
Expand All @@ -78,37 +80,39 @@ 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"
webdav.label = "Webdav"
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
fileserver.default = 8082
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"]
26 changes: 17 additions & 9 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,42 @@ 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
}

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
}
64 changes: 11 additions & 53 deletions scripts/change_url
Original file line number Diff line number Diff line change
Expand Up @@ -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..."

Expand All @@ -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
Expand Down
46 changes: 23 additions & 23 deletions scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Loading

0 comments on commit 3af93d1

Please sign in to comment.