diff --git a/manifests/app_type.pp b/manifests/app_type.pp index b377c8a..5e8f6a2 100644 --- a/manifests/app_type.pp +++ b/manifests/app_type.pp @@ -141,6 +141,14 @@ define sunetdrive::app_type ( content => template('sunetdrive/application/upgrade23-25.erb.sh'), mode => '0744', } + file { '/usr/local/bin/remount_user_bucket_as_project.sh': + ensure => present, + force => true, + owner => 'root', + group => 'root', + content => template('sunetdrive/application/remount_user_bucket_as_project.sh'), + mode => '0744', + } file { '/opt/rotate/conf.d/nextcloud.conf': ensure => file, force => true, diff --git a/templates/application/remount_user_bucket_as_project.sh b/templates/application/remount_user_bucket_as_project.sh new file mode 100755 index 0000000..4192993 --- /dev/null +++ b/templates/application/remount_user_bucket_as_project.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +mountid="${1}" +user="${2}" +container="${3}" +if [[ -z ${mountid} ]] || [[ -z ${user} ]]; then + echo "We need a valid mount id and user to proceed" + echo "Usage: ${0} []" + exit +fi + +if [[ -z ${container} ]]; then + container="nextcloud_app_1" +fi + +occ="/usr/local/bin/occ" +function get_config { + ${occ} files_external:config ${mountid} ${1} +} + +bucket="$(get_config bucket)" +hostname="$(get_config hostname)" +key="$(get_config key)" +port="$(get_config port)" +region="$(get_config region)" +secret="$(get_config secret)" +jsonfile="/tmp/${user}-user-bucket.json" +mount_point="${user/@/-}" +mount_point="${mount_point/./-}-user-bucket" + +echo "This will remount the user bucket with mountid ${mountid} for ${user} as project bucket with mountpoint ${mount_point}." +read -r -p "Press enter to continue" + +echo ' +[ + { + "mount_point": "\/'${mount_point}'", + "storage": "\\OCA\\Files_External\\Lib\\Storage\\AmazonS3", + "authentication_type": "amazons3::accesskey", + "configuration": { + "bucket": "'${bucket}'", + "hostname": "'${hostname}'", + "key": "'${key}'", + "legacy_auth": false, + "port": "'${port}'", + "region": "'${region}'", + "secret": "'${secret}'", + "storageClass": "", + "useMultipartCopy": false, + "use_path_style": true, + "use_ssl": true + }, + "options": { + "encrypt": true, + "previews": true, + "enable_sharing": true, + "filesystem_check_changes": 0, + "encoding_compatibility": false, + "readonly": false + }, + "applicable_users": [ + ], + "applicable_groups": ["admin"] + } +] +' > "${jsonfile}" + + +docker cp ${jsonfile} ${container}:/${jsonfile} +${occ} files_external:import /${jsonfile} +docker exec ${container} rm /${jsonfile} +${occ} files_external:delete ${mountid}