diff --git a/scripts/_common.sh b/scripts/_common.sh index 7a7b3b9..f1618eb 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -19,10 +19,12 @@ exec_occ() { php occ --no-interaction --no-ansi "$@") } -# Create the external storage for the home folders and enable sharing -create_home_external_storage() { +# Create the external storage for the given folders and enable sharing +create_external_storage() { + local datadir="$1" + local mount_name="$2" local mount_id=`exec_occ files_external:create --output=json \ - 'Home' 'local' 'null::null' -c 'datadir=/home/$user' || true` + "$2" 'local' 'null::null' -c "datadir=$datadir" || true` ! [[ $mount_id =~ ^[0-9]+$ ]] \ && echo "Unable to create external storage" >&2 \ || exec_occ files_external:option "$mount_id" enable_sharing true @@ -315,3 +317,31 @@ ynh_handle_app_migration () { migration_process=1 fi } + + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= + +# Install or update the main directory yunohost.multimedia +# +# usage: ynh_multimedia_build_main_dir +ynh_multimedia_build_main_dir () { + wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip 2>&1 + unzip -q master.zip + ./yunohost.multimedia-master/script/ynh_media_build.sh +} + +# Allow an user to have an write authorisation in multimedia directories +# +# usage: ynh_multimedia_addaccess user_name +# +# | arg: user_name - The name of the user which gain this access. +ynh_multimedia_addaccess () { + local user_name=$1 + groupadd -f multimedia + usermod -a -G multimedia $user_name +} diff --git a/scripts/install b/scripts/install index cf22534..6900ed2 100755 --- a/scripts/install +++ b/scripts/install @@ -182,7 +182,7 @@ exec_occ ldap:test-config \'\' \ # Enable External Storage and create local mount to home folder if [ $user_home -eq 1 ]; then exec_occ app:enable files_external - create_home_external_storage + create_external_storage "/home/\$user" "Home" fi #================================================= @@ -237,6 +237,19 @@ exec_occ background:cron # Set system group in hooks ynh_replace_string "#GROUP#" "$app" ../hooks/post_user_create +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= + +# Build YunoHost multimedia directories +ynh_multimedia_build_main_dir +# Mount the user directory in Nextcloud +exec_occ app:enable files_external +create_external_storage "/home/yunohost.multimedia/\$user" "Multimedia" +create_external_storage "/home/yunohost.multimedia/share" "Shared multimedia" +# Allow nextcloud to write into these directories +ynh_multimedia_addaccess $app + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index b476d80..44a7f58 100755 --- a/scripts/restore +++ b/scripts/restore @@ -134,6 +134,15 @@ for u in $(ynh_user_list); do setfacl -m g:$app:rwx "/home/$u" || true done +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= + +# Build YunoHost multimedia directories +ynh_multimedia_build_main_dir +# Allow nextcloud to write into these directories +ynh_multimedia_addaccess $app + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 099d842..5997003 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -272,7 +272,7 @@ if [ $user_home -eq 1 ]; then exec_occ app:enable files_external exec_occ files_external:list --output=json \ | grep -q '"storage":"\\\\OC\\\\Files\\\\Storage\\\\Local"' \ - || create_home_external_storage + || create_external_storage "/home/\$user" "Home" fi #================================================= @@ -303,6 +303,19 @@ exec_occ background:cron # Set system group in hooks ynh_replace_string "#GROUP#" "$app" ../hooks/post_user_create +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= + +# Build YunoHost multimedia directories +ynh_multimedia_build_main_dir +# Mount the user directory in Nextcloud +exec_occ app:enable files_external +create_external_storage "/home/yunohost.multimedia/\$user" "Multimedia" +create_external_storage "/home/yunohost.multimedia/share" "Shared multimedia" +# Allow nextcloud to write into these directories +ynh_multimedia_addaccess $app + #================================================= # GENERIC FINALIZATION #=================================================