sunetdrive/templates/application/migrate_external_mounts.erb

35 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

2023-02-13 09:44:56 +00:00
#!/bin/bash
keymapping=${1}
if ! [[ -f ${keymapping} ]]; then
echo "We need a valid keymapping file to proceed"
exit
fi
function get_secrets {
# Expects a space separated file with oldkey newkey newsecret
grep ${1} ${keymapping} | awk '{print $2, $3}'
}
for line in $(docker exec -u www-data nextcloud_app_1 /var/www/html/occ files_external:list --all --output json | jq -r '.[] | "\(.mount_id);\(.configuration.key)"'); do
id=$(echo ${line} | awk -F ';' '{print $1}')
key=$(echo ${line} | awk -F ';' '{print $2}')
if [[ "x${key}" == "x" ]] || [[ "${id}" == "x" ]]; then
echo "Old key or mount id is empty, bailing out."
exit 1
fi
secrets="$(get_secrets ${key})"
newkey="$(echo ${secrets} | awk '{print $1}')"
secret="$(echo ${secrets} | awk '{print $2}')"
if [[ "x${newkey}" == "x" ]] || [[ "x${secret}" == "x" ]]; then
echo "New key or secret is empty, skipping mount id ${id}."
continue
fi
docker exec -u www-data nextcloud_app_1 /var/www/html/occ files_external:config ${id} region us-east-1
docker exec -u www-data nextcloud_app_1 /var/www/html/occ files_external:config ${id} hostname s3.sto4.safedc.net
docker exec -u www-data nextcloud_app_1 /var/www/html/occ files_external:config ${id} key ${newkey}
docker exec -u www-data nextcloud_app_1 /var/www/html/occ files_external:config ${id} secret ${secret}
done