diff --git a/actions.toml b/actions.toml index 38c52a8..fc6cb0f 100644 --- a/actions.toml +++ b/actions.toml @@ -6,3 +6,12 @@ command = "/bin/bash scripts/actions/disable_maintenance" # accepted_return_codes = [0, 1, 2, 3] # optional accepted_return_codes = [0] description = "Disable the maintenance mode of Nextcloud if you're stuck after an upgrade" + +[add_multimedia_directories] +name = "Add multimedia directories" +command = "/bin/bash scripts/actions/add_multimedia_directories" +# user = "root" # optional +# cwd = "/" # optional +# accepted_return_codes = [0, 1, 2, 3] # optional +accepted_return_codes = [0] +description = "Add the multimedia and shared multimedia directories again" diff --git a/scripts/actions/add_multimedia_directories b/scripts/actions/add_multimedia_directories new file mode 100755 index 0000000..4dc7881 --- /dev/null +++ b/scripts/actions/add_multimedia_directories @@ -0,0 +1,66 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source scripts/_common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +#================================================= +# CHECK IF ARGUMENTS ARE CORRECT +#================================================= + +#================================================= +# DEFINE FUNCTION +#================================================= + +# Define a function to execute commands with `occ` +exec_occ() { + (cd "$final_path" && exec_as "$app" \ + php$YNH_PHP_VERSION occ --no-interaction --no-ansi "$@") +} + +# Define a function to add an 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 \ + "$mount_name" 'local' 'null::null' -c "datadir=$datadir" || true` +! [[ $mount_id =~ ^[0-9]+$ ]] \ + && ynh_print_warn --message="Unable to create external storage" \ + || exec_occ files_external:option "$mount_id" enable_sharing true +} + +#================================================= +# SPECIFIC ACTION +#================================================= +# YUNOHOST MULTIMEDIA INTEGRATION +#================================================= +ynh_script_progression --message="Updating multimedia directories..." --weight=6 + +# 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 + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Execution completed" --last diff --git a/scripts/upgrade b/scripts/upgrade index eb9c261..a6a467b 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -403,20 +403,6 @@ exec_occ background:cron # Set system group in hooks ynh_replace_string --match_string="__GROUP__" --replace_string="$app" --target_file=../hooks/post_user_create -#================================================= -# YUNOHOST MULTIMEDIA INTEGRATION -#================================================= -ynh_script_progression --message="Updating multimedia directories..." --weight=6 - -# 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 #=================================================