2024-11-12 14:33:29 +00:00
|
|
|
#!/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} <mountid> <user> [<container>]"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z ${container} ]]; then
|
|
|
|
container="nextcloud_app_1"
|
|
|
|
fi
|
|
|
|
|
2024-11-12 15:44:22 +00:00
|
|
|
occ="/usr/local/bin/occ ${container}"
|
2024-11-12 14:33:29 +00:00
|
|
|
function get_config {
|
2024-11-12 14:44:15 +00:00
|
|
|
${occ} files_external:config ${mountid} ${1} | tr -d '\n\t\r'
|
2024-11-12 14:33:29 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 15:01:43 +00:00
|
|
|
echo "Gathering information, hang tight."
|
|
|
|
|
|
|
|
echo -n "."
|
2024-11-12 14:33:29 +00:00
|
|
|
bucket="$(get_config bucket)"
|
2024-11-12 15:01:43 +00:00
|
|
|
echo -n "."
|
2024-11-12 14:33:29 +00:00
|
|
|
hostname="$(get_config hostname)"
|
2024-11-12 15:01:43 +00:00
|
|
|
echo -n "."
|
2024-11-12 14:33:29 +00:00
|
|
|
key="$(get_config key)"
|
2024-11-12 15:01:43 +00:00
|
|
|
echo -n "."
|
2024-11-12 14:33:29 +00:00
|
|
|
region="$(get_config region)"
|
2024-11-12 15:01:43 +00:00
|
|
|
echo -n "."
|
2024-11-12 14:33:29 +00:00
|
|
|
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,
|
2024-11-12 15:01:43 +00:00
|
|
|
"port": "443",
|
2024-11-12 14:33:29 +00:00
|
|
|
"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}
|
2024-11-12 14:51:54 +00:00
|
|
|
rm ${jsonfile}
|
2024-11-12 14:33:29 +00:00
|
|
|
${occ} files_external:delete ${mountid}
|