From f63b081bdf1738f846625aef4816dbae0c7c2082 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Tue, 3 Oct 2023 16:17:27 -0700 Subject: [PATCH] Fix the .sh script for removing admin block and append it to the end of internal users file Signed-off-by: Ryan Liang --- tools/install_demo_configuration.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tools/install_demo_configuration.sh b/tools/install_demo_configuration.sh index 01bc1bfed1..b7003f9310 100755 --- a/tools/install_demo_configuration.sh +++ b/tools/install_demo_configuration.sh @@ -392,6 +392,9 @@ echo 'plugins.security.system_indices.indices: [".plugins-ml-config", ".plugins- ADMIN_PASSWORD_FILE="$OPENSEARCH_CONF_DIR/initialAdminPassword.txt" INTERNAL_USERS_FILE="$OPENSEARCH_CONF_DIR/opensearch-security/internal_users.yml" +# Use sed to delete the block +sed -i.bak '/^admin:/,/description: "Demo admin user"/d' $INTERNAL_USERS_FILE + if [[ -n "$initialAdminPassword" ]]; then ADMIN_PASSWORD="$initialAdminPassword" elif [[ -f "$ADMIN_PASSWORD_FILE" && -s "$ADMIN_PASSWORD_FILE" ]]; then @@ -415,15 +418,18 @@ if [ $? -ne 0 ]; then exit 1 fi -# Find the line number containing 'admin:' in the internal_users.yml file -ADMIN_HASH_LINE=$(grep -n 'admin:' "$INTERNAL_USERS_FILE" | cut -f1 -d:) +# Append content to the end of the YAML file +cat >> $INTERNAL_USERS_FILE < temp_file && mv temp_file "$INTERNAL_USERS_FILE" +echo "Admin user has been appended to $INTERNAL_USERS_FILE" #network.host if $SUDO_CMD grep --quiet -i "^network.host" "$OPENSEARCH_CONF_FILE"; then