seafile_ynh/scripts/_common.sh

97 lines
4.4 KiB
Bash
Raw Normal View History

#=================================================
# SET ALL CONSTANTS
#=================================================
2024-04-26 23:35:01 +02:00
readonly time_zone="$(cat /etc/timezone)"
readonly python_version="$(python3 -V | cut -d' ' -f2 | cut -d. -f1-2)"
2017-12-09 20:56:20 +01:00
# Create special path with / at the end
2024-04-26 23:35:14 +02:00
if [[ "$path" == '/' ]]
then
2024-04-26 23:35:01 +02:00
readonly path2="$path"
else
2024-04-26 23:35:01 +02:00
readonly path2="$path/"
fi
2024-04-26 23:35:01 +02:00
if [ "${LANG:0:2}" == C. ]; then
readonly language=en
else
readonly language="${LANG:0:2}"
fi
2024-04-12 21:22:21 +02:00
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
2024-04-21 01:50:52 +02:00
install_pkg_conf() {
# Install manually pkgconf
# WARNING don't move this to dependencies
# We install this manually because we have an issue between pkgconf and pkg-config.
# If pkg-config is already installed on the system we can't declare pkgconf as dependency as pkg-config need to be removed to install pkgconf (note that pkgconf replace pkg-config and both can't be installed)
ynh_apt install pkgconf
}
2017-07-21 14:56:41 +02:00
install_dependance() {
# Clean venv is it was on python3 with old version in case major upgrade of debian
2024-04-26 23:35:14 +02:00
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/lib
ynh_secure_remove --file="$install_dir"/venv/lib64
ynh_secure_remove --file="$install_dir"/venv/include
ynh_secure_remove --file="$install_dir"/venv/share
ynh_secure_remove --file="$install_dir"/venv/pyvenv.cfg
fi
# Create venv if it don't exist
2024-04-26 23:35:14 +02:00
test -e "$install_dir"/venv/bin/python3 || python3 -m venv "$install_dir"/venv
2024-04-12 21:22:21 +02:00
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"
2024-04-26 23:35:14 +02:00
"$install_dir"/venv/bin/pip3 install --upgrade --timeout=3600 $py_dependancy
# Create symbolic link to venv package on seahub
2024-04-12 21:22:21 +02:00
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
2024-04-12 21:22:21 +02:00
ln -s "../../../venv/lib/python$python_version/site-packages/$f" "$install_dir/seafile-server-$seafile_version/seahub/thirdpart/$f"
fi
done
2017-01-31 23:25:17 +01:00
}
2024-04-12 21:22:21 +02:00
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
}
2019-06-11 22:28:26 +02:00
set_permission() {
2024-04-12 21:22:21 +02:00
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"
2022-11-02 17:19:55 +01:00
# At install time theses directory are not available
2024-04-26 23:35:14 +02:00
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
2021-06-26 12:22:45 +02:00
2024-04-12 21:22:21 +02:00
find "$data_dir" \( \! -perm -o= \
-o \! -user "$app" \
-o \! -group "$app" \) \
-exec chown "$app:$app" {} \; \
-exec chmod o= {} \;
2019-06-11 22:28:26 +02:00
}
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
}
2024-04-12 21:22:21 +02:00
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
}