Update scripts

This commit is contained in:
Josué Tille 2024-04-12 21:22:21 +02:00
parent 7d8568c2d1
commit d8f3952f63
No known key found for this signature in database
GPG key ID: 5F259226AD51F2F5
3 changed files with 84 additions and 66 deletions

View file

@ -3,6 +3,7 @@
#================================================= #=================================================
time_zone=$(cat /etc/timezone) time_zone=$(cat /etc/timezone)
language=$(echo $LANG | cut -d_ -f1)
python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)" python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)"
# Create special path with / at the end # Create special path with / at the end
@ -13,6 +14,18 @@ else
path2="$path/" path2="$path/"
fi 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 # DEFINE ALL COMMON FONCTIONS
#================================================= #=================================================
@ -26,8 +39,6 @@ install_pkg_conf() {
} }
install_dependance() { install_dependance() {
ynh_add_swap --size=2000
# Clean venv is it was on python3 with old version in case major upgrade of debian # 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 if [ ! -e $install_dir/venv/bin/python3 ] || [ ! -e $install_dir/venv/lib/python$python_version ]; then
ynh_secure_remove --file=$install_dir/venv/bin ynh_secure_remove --file=$install_dir/venv/bin
@ -41,54 +52,39 @@ install_dependance() {
# Create venv if it don't exist # Create venv if it don't exist
test -e $install_dir/venv/bin/python3 || python3 -m venv $install_dir/venv test -e $install_dir/venv/bin/python3 || python3 -m venv $install_dir/venv
u_arg='u' 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"
set +$u_arg; $install_dir/venv/bin/pip3 install --upgrade --timeout=3600 $py_dependancy
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
# Create symbolic link to venv package on seahub # 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 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 fi
done 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() { set_permission() {
chown -R $app:$app $install_dir chown -R "$app:$app" "$install_dir"
chmod -R u+rwX,g-wx,o= $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"
setfacl -m user:www-data:rX $install_dir/seafile-server-$seafile_version setfacl -m user:www-data:rX "$install_dir/seafile-server-$seafile_version"
# At install time theses directory are not available # 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 && 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/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 -m user:www-data:rX $data_dir
test -e $install_dir/seahub-data && setfacl -R -m user:www-data:rX $data_dir/seahub-data test -e $install_dir/seahub-data && setfacl -R -m user:www-data:rX $data_dir/seahub-data
find $data_dir \( \! -perm -o= \ find "$data_dir" \( \! -perm -o= \
-o \! -user $app \ -o \! -user "$app" \
-o \! -group $app \) \ -o \! -group "$app" \) \
-exec chown $app:$app {} \; \ -exec chown "$app:$app" {} \; \
-exec chmod o= {} \; -exec chmod o= {} \;
} }
@ -98,3 +94,10 @@ clean_url_in_db_config() {
sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"' sql_request='DELETE FROM `constance_config` WHERE `constance_key`= "FILE_SERVER_ROOT"'
ynh_mysql_execute_as_root --sql "$sql_request" --database seahubdb 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
}

View file

@ -15,6 +15,8 @@ seafile_version=$(ynh_app_upstream_version)
install_pkg_conf install_pkg_conf
ensure_vars_set
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS
#================================================= #=================================================
@ -33,7 +35,7 @@ mkdir -p "$data_dir"/{seafile-data,seahub-data}
# Download new version from sources # Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7 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..." ynh_script_progression --message="Installing python dependancies..."
install_dependance install_dependance
@ -60,20 +62,21 @@ sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/setup-seafile-
--mysql-port 3306 \ --mysql-port 3306 \
--mysql-user "$db_user" \ --mysql-user "$db_user" \
--mysql-user-passwd "$db_pwd" \ --mysql-user-passwd "$db_pwd" \
--seafile-db "$db_name" \ -s "$db_name" \
--ccnet-db ccnetdb \ -c ccnetdb \
--seahub-db seahubdb -b seahubdb
# Retrive values from auto generated config file # 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) 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 seahub_secret_key --value "$seahub_secret_key"
# Update seafile config files # 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=seafile.conf --destination="$install_dir"/conf/seafile.conf
ynh_add_config --template=ccnet.conf --destination=$install_dir/conf/ccnet.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=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=seafdav.conf --destination="$install_dir"/conf/seafdav.conf
ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
# Configure admin info # Configure admin info
# It will be used the first start # 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 ln -s /var/log/"$app" "$install_dir"/logs
# Fix local warning # 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 # Add Seafile Server to startup
ynh_script_progression --message="Configuring a systemd service..." ynh_script_progression --message="Configuring a systemd service..."

View file

@ -12,10 +12,10 @@ source ./_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
seafile_version=$(ynh_app_upstream_version) seafile_version=$(ynh_app_upstream_version)
# Retrieve arguments
installed_version=${YNH_APP_CURRENT_VERSION/~ynh*/} 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 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" ynh_die "Upgrade from this version not supported"
fi fi
@ -100,7 +100,9 @@ ynh_script_progression --message="Upgrading source files..." --weight=6
# Download new version from sources # Download new version from sources
ynh_script_progression --message="Installing sources files..." --weight=7 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..." ynh_script_progression --message="Installing python dependancies..."
install_dependance install_dependance
@ -125,46 +127,56 @@ case $installed_version in
;& ;&
"7.0"* ) "7.0"* )
# Fix file comment # Fix file comment
pushd $install_dir/seafile-server-$seafile_version 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 sudo -u "$app" "$install_dir/seafile-server-$seafile_version/seahub.sh" python-env python3 seahub/manage.py migrate_file_comment
popd popd
# Update seafile by script # 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 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 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 # 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')" old_data_dir_path="$install_dir/seafile-data$(date '+%Y%m%d.%H%M%S')"
mv "$install_dir/seafile-data" "$old_data_dir_path" mv "$install_dir/seafile-data" "$old_data_dir_path"
fi fi
ln -s $data_dir $install_dir/seafile-data ln -s "$data_dir" "$install_dir"/seafile-data
;& ;&
"7.1."* ) "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 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 sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/upgrade_8.0_9.0.sh"
;& ;&
"8.0."* ) "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 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 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 esac
ynh_replace_string --match_string='read dummy' --replace_string='# patched' --target_file=$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 sudo -u "$app" bash "$install_dir/seafile-server-$seafile_version/upgrade/minor-upgrade.sh"
# Clean url in config in DB # Clean url in config in DB
clean_url_in_db_config clean_url_in_db_config
# Update seafile config files # 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=seafile.conf --destination=$install_dir/conf/seafile.conf
ynh_add_config --template=ccnet.conf --destination=$install_dir/conf/ccnet.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=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=seafdav.conf --destination=$install_dir/conf/seafdav.conf
ynh_add_config --template=seafevents.conf --destination="$install_dir"/conf/seafevents.conf
# Fix local warning # 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 # STANDARD UPGRADE STEPS
@ -211,10 +223,10 @@ sleep 2
# remove old version files # remove old version files
ynh_script_progression --message="Cleaning system and updating settings..." ynh_script_progression --message="Cleaning system and updating settings..."
ls $install_dir | grep "seafile-server-" | egrep -v "(${seafile_version//./\\.})|(latest)" | \ ls "$install_dir" | grep "seafile-server-" | grep -E -v "(${seafile_version//./\\.})|(latest)" | \
while read f while read -r f
do do
ynh_secure_remove --file=$install_dir/$f ynh_secure_remove --file="$install_dir/$f"
done done
ynh_script_progression --message="Upgrade of $app completed" --last ynh_script_progression --message="Upgrade of $app completed" --last