LibrePortal/scripts/config/password/password_replace hex.sh
librelad 5ceef2df6a refactor(de-sudo): config/password processors off raw sudo
scanConfigsForRandomPassword iterates $configs_dir (manager-owned), so the
placeholder grep/sed/awk on the config file -> runInstallOp. The bcrypt export
log ($containers_dir/bcrypt.txt) is docker-install-owned, so its touch/chmod/
sed/grep/append -> runFileOp/runFileWrite (NOT runInstallOp). Covers all
password_replace*/password_user_replace/password_update_all and bcrypt/*.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-24 17:30:25 +01:00

22 lines
706 B
Bash
Executable File

#!/bin/bash
replaceHexKeys()
{
local file="$1"
# Only scan for hex placeholders that actually exist in the file
local existing_placeholders=$(runInstallOp grep -oE 'RANDOMIZEDHEX[0-9]*' "$file" 2>/dev/null | sort -u)
if [[ -n "$existing_placeholders" ]]; then
while IFS= read -r placeholder; do
if [[ -n "$placeholder" ]]; then
local hex_key
hex_key=$(openssl rand -hex 32)
runInstallOp sed -i "s/${placeholder}/${hex_key}/g" "$file"
checkSuccess "Updated ${placeholder} in $(basename "$file") with a new hex key."
fi
done <<< "$existing_placeholders"
fi
}