#!/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