From d8f3952f6349b830afe9f13ecf2181043537a2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Fri, 12 Apr 2024 21:22:21 +0200 Subject: [PATCH] Update scripts --- scripts/_common.sh | 75 ++++++++++++++++++++++++---------------------- scripts/install | 23 +++++++------- scripts/upgrade | 52 +++++++++++++++++++------------- 3 files changed, 84 insertions(+), 66 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 3ee6dfa..fb4a9b7 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,6 +3,7 @@ #================================================= time_zone=$(cat /etc/timezone) +language=$(echo $LANG | cut -d_ -f1) python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" # Create special path with / at the end @@ -13,6 +14,18 @@ else path2="$path/" fi +lang_map() { + while read -r item; do + if [ "$item" == en ]; then + lang_name=english + else + lang_name="$((grep -E "^[a-z]+[[:space:]]+${item}_" /usr/share/locale/locale.alias || echo "$item") | head -n1 | cut -f1)" + fi + echo "$item,$lang_name" + done +} +lang_list=$(grep -E '^[a-z]' /etc/locale.gen | cut -d_ -f1 | uniq | lang_map) + #================================================= # DEFINE ALL COMMON FONCTIONS #================================================= @@ -26,8 +39,6 @@ install_pkg_conf() { } install_dependance() { - ynh_add_swap --size=2000 - # Clean venv is it was on python3 with old version in case major upgrade of debian if [ ! -e $install_dir/venv/bin/python3 ] || [ ! -e $install_dir/venv/lib/python$python_version ]; then ynh_secure_remove --file=$install_dir/venv/bin @@ -41,54 +52,39 @@ install_dependance() { # Create venv if it don't exist test -e $install_dir/venv/bin/python3 || python3 -m venv $install_dir/venv - u_arg='u' - set +$u_arg; - source $install_dir/venv/bin/activate - set -$u_arg; - - # Note that we install imageio to force the dependance, without this imageio 2.8 is installed and it need python3.5 - if [ $(lsb_release --codename --short) == "bookworm" ]; then - # Fix cffi installtion issue cf: https://github.com/haiwen/seahub/issues/5166 - pip3 install --upgrade 'cffi==1.15.1' - sed -e "s|1.14.0|1.15.1|" -i $install_dir/seafile-server-$seafile_version/seahub/thirdpart/cffi/__init__.py - else - pip3 install --upgrade cffi==1.14.0 - fi - if [ -n "$(uname -m | grep x86_64)" ]; then - py_dependancy="django==3.2.* Pillow<10.0.0 pylibmc captcha jinja2 SQLAlchemy<2 django-pylibmc django-simple-captcha python3-ldap mysqlclient pycryptodome==3.12.0 lxml python3-ldap" - else - py_dependancy="lxml python3-ldap" - fi - pip3 install --upgrade --timeout=3600 $py_dependancy - - set +$u_arg; - deactivate - set -$u_arg; - ynh_del_swap + py_dependancy="django==4.2.* future==0.18.* mysqlclient==2.1.* pymysql pillow==10.2.* pylibmc captcha==0.5.* markupsafe==2.0.1 jinja2 sqlalchemy==2.0.18 psd-tools django-pylibmc django_simple_captcha==0.6.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 lxml python-ldap==3.4.3" + $install_dir/venv/bin/pip3 install --upgrade --timeout=3600 $py_dependancy # Create symbolic link to venv package on seahub - ls $install_dir/venv/lib/python$python_version/site-packages | while read f; do + ls "$install_dir/venv/lib/python$python_version/site-packages" | while read -r f; do if [ ! -e "$install_dir/seafile-server-$seafile_version/seahub/thirdpart/$f" ]; then - ln -s ../../../venv/lib/python$python_version/site-packages/$f $install_dir/seafile-server-$seafile_version/seahub/thirdpart/$f + ln -s "../../../venv/lib/python$python_version/site-packages/$f" "$install_dir/seafile-server-$seafile_version/seahub/thirdpart/$f" fi done } +install_source() { + ynh_setup_source --dest_dir="$install_dir"/docker_image --full_replace + ynh_secure_remove --file="$install_dir/seafile-server-$seafile_version" + mv "$install_dir/docker_image/opt/seafile/seafile-server-$seafile_version" "$install_dir/seafile-server-$seafile_version" + ynh_secure_remove --file="$install_dir"/docker_image +} + set_permission() { - chown -R $app:$app $install_dir - chmod -R u+rwX,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 + chown -R "$app:$app" "$install_dir" + chmod -R u+rwX,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 test -e $install_dir/seafile-server-$seafile_version/seahub && setfacl -m user:www-data:rX $install_dir/seafile-server-$seafile_version/seahub test -e $install_dir/seafile-server-$seafile_version/seahub/media && setfacl -R -m user:www-data:rX $install_dir/seafile-server-$seafile_version/seahub/media 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 - find $data_dir \( \! -perm -o= \ - -o \! -user $app \ - -o \! -group $app \) \ - -exec chown $app:$app {} \; \ + find "$data_dir" \( \! -perm -o= \ + -o \! -user "$app" \ + -o \! -group "$app" \) \ + -exec chown "$app:$app" {} \; \ -exec chmod o= {} \; } @@ -98,3 +94,10 @@ clean_url_in_db_config() { sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"' ynh_mysql_execute_as_root --sql "$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 +} diff --git a/scripts/install b/scripts/install index ad85c79..dfa8e7c 100644 --- a/scripts/install +++ b/scripts/install @@ -15,6 +15,8 @@ seafile_version=$(ynh_app_upstream_version) install_pkg_conf +ensure_vars_set + #================================================= # STANDARD MODIFICATIONS #================================================= @@ -33,7 +35,7 @@ mkdir -p "$data_dir"/{seafile-data,seahub-data} # Download new version from sources ynh_script_progression --message="Installing sources files..." --weight=7 -ynh_setup_source --dest_dir=$install_dir/seafile-server-$seafile_version +install_source ynh_script_progression --message="Installing python dependancies..." install_dependance @@ -60,20 +62,21 @@ sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/setup-seafile- --mysql-port 3306 \ --mysql-user "$db_user" \ --mysql-user-passwd "$db_pwd" \ - --seafile-db "$db_name" \ - --ccnet-db ccnetdb \ - --seahub-db seahubdb + -s "$db_name" \ + -c ccnetdb \ + -b seahubdb # 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" # 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 +ynh_add_jinja_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 +ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf # Configure admin info # It will be used the first start @@ -100,7 +103,7 @@ 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 $install_dir/seafile-server-$seafile_version/seahub.sh +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..." diff --git a/scripts/upgrade b/scripts/upgrade index ce218d4..e330457 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,10 +12,10 @@ source ./_common.sh source /usr/share/yunohost/helpers seafile_version=$(ynh_app_upstream_version) - -# Retrieve arguments installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/} +ensure_vars_set + if [ "$YNH_APP_CURRENT_VERSION" == '-' ] || ynh_compare_current_package_version --comparison=le --version='7.0~ynh1'; then ynh_die "Upgrade from this version not supported" fi @@ -100,7 +100,9 @@ ynh_script_progression --message="Upgrading source files..." --weight=6 # Download new version from sources ynh_script_progression --message="Installing sources files..." --weight=7 -ynh_setup_source --dest_dir="$install_dir"/seafile-server-$seafile_version +if [ "$YNH_APP_UPGRADE_TYPE" == UPGRADE_APP ]; then + install_source +fi ynh_script_progression --message="Installing python dependancies..." install_dependance @@ -125,46 +127,56 @@ case $installed_version in ;& "7.0"* ) # Fix file comment - pushd $install_dir/seafile-server-$seafile_version - sudo -u $app $install_dir/seafile-server-$seafile_version/seahub.sh python-env python3 seahub/manage.py migrate_file_comment + pushd "$install_dir/seafile-server-$seafile_version" + sudo -u "$app" "$install_dir/seafile-server-$seafile_version/seahub.sh" python-env python3 seahub/manage.py migrate_file_comment popd # Update seafile by script - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file=$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh - sudo -u $app bash $install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.0_7.1.sh" + sudo -u "$app" bash "$install_dir/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 - if [ -e $install_dir/seafile-data ]; then + if [ -e "$install_dir"/seafile-data ]; then old_data_dir_path="$install_dir/seafile-data$(date '+%Y%m%d.%H%M%S')" mv "$install_dir/seafile-data" "$old_data_dir_path" fi - ln -s $data_dir $install_dir/seafile-data + ln -s "$data_dir" "$install_dir"/seafile-data ;& "7.1."* ) - ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file=$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh - sudo -u $app bash $install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" + sudo -u "$app" bash "$install_dir/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=$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh - sudo -u $app bash $install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh" + sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_7.1_8.0.sh" +;& +"9."* ) + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" + sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh" +;& +"10."* ) + ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh" + sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_9.0_10.0.sh" + sudo -u "$app" "$install_dir"/venv/bin/python "$install_dir/seafile-server-$seafile_version/migrate_ldapusers.py" ;& esac -ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file=$install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh -sudo -u $app bash $install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh +ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file="$install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh" +sudo -u "$app" bash "$install_dir/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 --template=seahub_settings.py --destination=$install_dir/conf/seahub_settings.py +ynh_add_jinja_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 +ynh_add_config --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 $install_dir/seafile-server-$seafile_version/seahub.sh +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" #================================================= # STANDARD UPGRADE STEPS @@ -211,10 +223,10 @@ sleep 2 # remove old version files ynh_script_progression --message="Cleaning system and updating settings..." -ls $install_dir | grep "seafile-server-" | egrep -v "(${seafile_version//./\\.})|(latest)" | \ -while read f +ls "$install_dir" | grep "seafile-server-" | grep -E -v "(${seafile_version//./\\.})|(latest)" | \ +while read -r f do - ynh_secure_remove --file=$install_dir/$f + ynh_secure_remove --file="$install_dir/$f" done ynh_script_progression --message="Upgrade of $app completed" --last