seafile_ynh/scripts/_common.sh

89 lines
3.6 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)"
systemd_seafile_bind_mount="$data_dir/seafile-data:/opt/seafile/seafile-data "
systemd_seafile_bind_mount+="$data_dir/seahub-data:/opt/seafile/seahub-data "
systemd_seafile_bind_mount+="/var/log/$app:/opt/seafile/logs "
systemd_seafile_bind_mount+="$install_dir/conf:/opt/seafile/conf "
systemd_seafile_bind_mount+="/proc "
systemd_seafile_bind_mount+="/dev"
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
#=================================================
run_seafile_cmd() {
ynh_exec_warn_less systemd-run --wait --uid="$app" --gid="$app" \
--property=RootDirectory="$install_dir"/seafile_image \
--property="BindPaths=$systemd_seafile_bind_mount" \
$@
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"/seafile_image --full_replace
mkdir -p "$install_dir"/seafile_image/opt/seafile/{seafile-data,seahub-data,conf,logs}
grep "^$app:x" /etc/passwd | sed "s|$install_dir|/opt/seafile|" >> "$install_dir"/seafile_image/etc/passwd
grep "^$app:x" /etc/group >> "$install_dir"/seafile_image/etc/group
grep "^$app:x" /etc/group- >> "$install_dir"/seafile_image/etc/group-
grep "^$app:" /etc/shadow >> "$install_dir"/seafile_image/etc/shadow
2024-04-12 21:22:21 +02:00
}
2019-06-11 22:28:26 +02:00
set_permission() {
chown -R "$app:$app" "$install_dir"/conf
chmod -R u+rwX,g-w,o= "$install_dir"/conf
chown -R "$app:$app" "$install_dir"/seafile_image/opt/seafile
chmod -R u+rwX,g-w,o= "$install_dir"/seafile_image/opt/seafile
# Allow to www-data to each dir between /opt/yunohost/seafile and /opt/yunohost/seafile/seafile_image/opt/seafile/seahub/media
local dir_path=''
while read -r -d/ dir_name; do
dir_path+="$dir_name/"
if [[ "$dir_path" == "$install_dir"* ]] && [ -e "$dir_path" ]; then
setfacl -m user:www-data:rX "$dir_path"
fi
done <<< "$seafile_code/seahub/media"
test -e "$install_dir/seafile_image/opt/seafile/seahub-data" && setfacl -m user:www-data:rX "$install_dir/seafile_image/opt/seafile/seahub-data"
test -e "$seafile_code/seahub/media" && setfacl -R -m user:www-data:rX "$seafile_code/seahub/media"
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"/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
}