Skip to content

Commit b6ce66e

Browse files
committed
save the keystore passphrase when agent.properties is missing on a new kvm host
1 parent 17294ca commit b6ce66e

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

‎scripts/util/keystore-setup‎

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,25 @@ fi
4444

4545
$LOGGER_CMD "$(date) - starting keystore-setup"
4646

47+
# Create the props file if missing, so the new password can be saved
48+
if [ ! -f "$PROPS_FILE" ]; then
49+
$LOGGER_CMD "Props file does not exist, creating it"
50+
touch "$PROPS_FILE"
51+
chmod 600 "$PROPS_FILE" || $LOGGER_CMD "Cannot chmod $PROPS_FILE"
52+
fi
53+
4754
# Re-use existing password or use the one provided
48-
if [ -f "$PROPS_FILE" ]; then
49-
$LOGGER_CMD "Previous props file exists, trying to extract password"
50-
OLD_PASS=$(sed -n '/^keystore.passphrase/p' "$PROPS_FILE" | sed 's/^keystore.passphrase=//g')
51-
if [ -n "${OLD_PASS// }" ]; then
52-
KS_PASS="$OLD_PASS"
53-
$LOGGER_CMD "Password extraction successful"
55+
OLD_PASS=$(sed -n '/^keystore.passphrase/p' "$PROPS_FILE" | sed 's/^keystore.passphrase=//g')
56+
if [ -n "${OLD_PASS// }" ]; then
57+
KS_PASS="$OLD_PASS"
58+
$LOGGER_CMD "Password extraction successful"
59+
else
60+
sed -i "/^keystore.passphrase.*/d" "$PROPS_FILE" 2>&1 | $LOGGER_CMD || true
61+
echo "keystore.passphrase=$KS_PASS" >> "$PROPS_FILE"
62+
if [ $? != 0 ]; then
63+
$LOGGER_CMD "Could not add new password to agent.properties"
5464
else
55-
sed -i "/^keystore.passphrase.*/d" "$PROPS_FILE" 2>&1 | $LOGGER_CMD || true
56-
echo "keystore.passphrase=$KS_PASS" >> "$PROPS_FILE"
57-
if [ $? != 0 ]; then
58-
$LOGGER_CMD "Could not add new password to agent.properties"
59-
else
60-
$LOGGER_CMD "New keystore password set"
61-
fi
65+
$LOGGER_CMD "New keystore password set"
6266
fi
6367
fi
6468

0 commit comments

Comments
 (0)