From de8a66848d3f836d0d62949ee7ed544cdf77037c Mon Sep 17 00:00:00 2001 From: Drew Hubl Date: Thu, 14 Jun 2018 16:51:11 -0700 Subject: [PATCH] Fix configuration directory and file permissions --- scripts/includes/common.sh | 26 +++++++------------------- scripts/st2bootstrap-deb.sh | 26 +++++++------------------- scripts/st2bootstrap-el6.sh | 26 +++++++------------------- scripts/st2bootstrap-el7.sh | 26 +++++++------------------- 4 files changed, 28 insertions(+), 76 deletions(-) diff --git a/scripts/includes/common.sh b/scripts/includes/common.sh index 2279e54e..61c6a6f1 100644 --- a/scripts/includes/common.sh +++ b/scripts/includes/common.sh @@ -181,15 +181,9 @@ configure_st2_cli_config() { CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2" CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config" - if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then - sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${ROOT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Write config for root user if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then @@ -197,18 +191,12 @@ EOT" fi # Write config for current user (in case current user != root) - if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then - sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${CURRENT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} } diff --git a/scripts/st2bootstrap-deb.sh b/scripts/st2bootstrap-deb.sh index ebdd561e..86a09329 100644 --- a/scripts/st2bootstrap-deb.sh +++ b/scripts/st2bootstrap-deb.sh @@ -298,15 +298,9 @@ configure_st2_cli_config() { CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2" CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config" - if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then - sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${ROOT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Write config for root user if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then @@ -314,18 +308,12 @@ EOT" fi # Write config for current user (in case current user != root) - if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then - sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${CURRENT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} } diff --git a/scripts/st2bootstrap-el6.sh b/scripts/st2bootstrap-el6.sh index dcde3d49..ee768909 100644 --- a/scripts/st2bootstrap-el6.sh +++ b/scripts/st2bootstrap-el6.sh @@ -293,15 +293,9 @@ configure_st2_cli_config() { CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2" CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config" - if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then - sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${ROOT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Write config for root user if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then @@ -309,18 +303,12 @@ EOT" fi # Write config for current user (in case current user != root) - if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then - sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${CURRENT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} } diff --git a/scripts/st2bootstrap-el7.sh b/scripts/st2bootstrap-el7.sh index 07eb2715..2e5d36c4 100644 --- a/scripts/st2bootstrap-el7.sh +++ b/scripts/st2bootstrap-el7.sh @@ -293,15 +293,9 @@ configure_st2_cli_config() { CURRENT_USER_CLI_CONFIG_DIRECTORY="${HOME}/.st2" CURRENT_USER_CLI_CONFIG_PATH="${CURRENT_USER_CLI_CONFIG_DIRECTORY}/config" - if ! sudo test -d ${ROOT_USER_CLI_CONFIG_DIRECTORY}; then - sudo mkdir -p ${ROOT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${ROOT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + sudo st2 login --config-file ${ROOT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Write config for root user if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then @@ -309,18 +303,12 @@ EOT" fi # Write config for current user (in case current user != root) - if [ ! -d ${CURRENT_USER_CLI_CONFIG_DIRECTORY} ]; then - sudo mkdir -p ${CURRENT_USER_CLI_CONFIG_DIRECTORY} - fi - - sudo sh -c "cat < ${CURRENT_USER_CLI_CONFIG_PATH} -[credentials] -username = ${USERNAME} -password = ${PASSWORD} -EOT" + st2 login --config-file ${CURRENT_USER_CLI_CONFIG_PATH} \ + --write-password \ + --username ${USERNAME} --password ${PASSWORD} # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} }