#!/bin/bash replaceVAPIDKeys() { local file="$1" # Only scan for VAPID placeholders that actually exist in the file local existing_placeholders=$(runCfgOp grep -oE 'RANDOMIZEDVAPID[0-9]*' "$file" 2>/dev/null | sort -u) # \b on the substitution below: `sort -u` orders slots lexically (1, 10, 11, # 2), so without it slot 1's pattern matches inside slot 10's placeholder and # slots 10+ end up holding slot 1's secret with a digit appended. See # password_replace.sh for the full description. if [[ -n "$existing_placeholders" ]]; then while IFS= read -r placeholder; do if [[ -n "$placeholder" ]]; then local vapid_key vapid_key=$(openssl rand -base64 32 | tr -d '+/=' | tr -cd '[:alnum:]') runCfgOp sed -i "s/${placeholder}\\b/${vapid_key}/g" "$file" checkSuccess "Updated ${placeholder} in $(basename "$file") with a new VAPID key." fi done <<< "$existing_placeholders" fi }