LibrePortal/scripts/config/password/password_replace.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

20 lines
716 B
Bash
Executable File

#!/bin/bash
replacePlainPasswords()
{
local file="$1"
# Only scan for placeholders that actually exist in the file
local existing_placeholders=$(runInstallOp grep -oE 'RANDOMIZEDPASSWORD[0-9]+' "$file" 2>/dev/null | sort -u)
if [[ -n "$existing_placeholders" ]]; then
while IFS= read -r password_placeholder; do
if [[ -n "$password_placeholder" ]]; then
local random_password=$(generateRandomPassword)
runInstallOp sed -i 's/'"${password_placeholder}"'/'"${random_password}"'/g' "$file"
checkSuccess "Updated ${password_placeholder} in $(basename "$file")."
fi
done <<< "$existing_placeholders"
fi
}