From b6ce66e522a987c3dfe6ecfe63a715adda09cf5e Mon Sep 17 00:00:00 2001 From: Daman Arora Date: Thu, 8 Oct 2026 07:32:11 -0400 Subject: [PATCH] save the keystore passphrase when agent.properties is missing on a new kvm host --- scripts/util/keystore-setup | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/scripts/util/keystore-setup b/scripts/util/keystore-setup index 88f5a87d6095..1abd1b2dbada 100755 --- a/scripts/util/keystore-setup +++ b/scripts/util/keystore-setup @@ -44,21 +44,25 @@ fi $LOGGER_CMD "$(date) - starting keystore-setup" +# Create the props file if missing, so the new password can be saved +if [ ! -f "$PROPS_FILE" ]; then + $LOGGER_CMD "Props file does not exist, creating it" + touch "$PROPS_FILE" + chmod 600 "$PROPS_FILE" || $LOGGER_CMD "Cannot chmod $PROPS_FILE" +fi + # Re-use existing password or use the one provided -if [ -f "$PROPS_FILE" ]; then - $LOGGER_CMD "Previous props file exists, trying to extract password" - OLD_PASS=$(sed -n '/^keystore.passphrase/p' "$PROPS_FILE" | sed 's/^keystore.passphrase=//g') - if [ -n "${OLD_PASS// }" ]; then - KS_PASS="$OLD_PASS" - $LOGGER_CMD "Password extraction successful" +OLD_PASS=$(sed -n '/^keystore.passphrase/p' "$PROPS_FILE" | sed 's/^keystore.passphrase=//g') +if [ -n "${OLD_PASS// }" ]; then + KS_PASS="$OLD_PASS" + $LOGGER_CMD "Password extraction successful" +else + sed -i "/^keystore.passphrase.*/d" "$PROPS_FILE" 2>&1 | $LOGGER_CMD || true + echo "keystore.passphrase=$KS_PASS" >> "$PROPS_FILE" + if [ $? != 0 ]; then + $LOGGER_CMD "Could not add new password to agent.properties" else - sed -i "/^keystore.passphrase.*/d" "$PROPS_FILE" 2>&1 | $LOGGER_CMD || true - echo "keystore.passphrase=$KS_PASS" >> "$PROPS_FILE" - if [ $? != 0 ]; then - $LOGGER_CMD "Could not add new password to agent.properties" - else - $LOGGER_CMD "New keystore password set" - fi + $LOGGER_CMD "New keystore password set" fi fi