diff --git a/scripts/includes/common.sh b/scripts/includes/common.sh index 2279e54e..4a82021a 100644 --- a/scripts/includes/common.sh +++ b/scripts/includes/common.sh @@ -167,48 +167,17 @@ configure_st2_user () { } +# Configure CLI config (write credentials for the root user and user which ran the script) configure_st2_cli_config() { - # Configure CLI config (write credentials for the root user and user which ran the script) - ROOT_USER="root" - CURRENT_USER=$(whoami) + # Write config for the root user + sudo -i st2 login "${USERNAME}" --password "${PASSWORD}" --write-password - ROOT_HOME=$(eval echo ~${ROOT_USER}) - : "${HOME:=$(eval echo ~${CURRENT_USER})}" - - ROOT_USER_CLI_CONFIG_DIRECTORY="${ROOT_HOME}/.st2" - ROOT_USER_CLI_CONFIG_PATH="${ROOT_USER_CLI_CONFIG_DIRECTORY}/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" - - # Write config for root user - if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then + if [ "$(whoami)" == "root" ]; then return 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" - - # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + st2 login "${USERNAME}" --password "${PASSWORD}" --write-password } diff --git a/scripts/st2bootstrap-deb.sh b/scripts/st2bootstrap-deb.sh index ebdd561e..02289639 100644 --- a/scripts/st2bootstrap-deb.sh +++ b/scripts/st2bootstrap-deb.sh @@ -284,48 +284,17 @@ configure_st2_user () { } +# Configure CLI config (write credentials for the root user and user which ran the script) configure_st2_cli_config() { - # Configure CLI config (write credentials for the root user and user which ran the script) - ROOT_USER="root" - CURRENT_USER=$(whoami) + # Write config for the root user + sudo -i st2 login "${USERNAME}" --password "${PASSWORD}" --write-password - ROOT_HOME=$(eval echo ~${ROOT_USER}) - : "${HOME:=$(eval echo ~${CURRENT_USER})}" - - ROOT_USER_CLI_CONFIG_DIRECTORY="${ROOT_HOME}/.st2" - ROOT_USER_CLI_CONFIG_PATH="${ROOT_USER_CLI_CONFIG_DIRECTORY}/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" - - # Write config for root user - if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then + if [ "$(whoami)" == "root" ]; then return 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" - - # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + st2 login "${USERNAME}" --password "${PASSWORD}" --write-password } diff --git a/scripts/st2bootstrap-el6.sh b/scripts/st2bootstrap-el6.sh index dcde3d49..4f6aabd9 100644 --- a/scripts/st2bootstrap-el6.sh +++ b/scripts/st2bootstrap-el6.sh @@ -279,48 +279,17 @@ configure_st2_user () { } +# Configure CLI config (write credentials for the root user and user which ran the script) configure_st2_cli_config() { - # Configure CLI config (write credentials for the root user and user which ran the script) - ROOT_USER="root" - CURRENT_USER=$(whoami) + # Write config for the root user + sudo -i st2 login "${USERNAME}" --password "${PASSWORD}" --write-password - ROOT_HOME=$(eval echo ~${ROOT_USER}) - : "${HOME:=$(eval echo ~${CURRENT_USER})}" - - ROOT_USER_CLI_CONFIG_DIRECTORY="${ROOT_HOME}/.st2" - ROOT_USER_CLI_CONFIG_PATH="${ROOT_USER_CLI_CONFIG_DIRECTORY}/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" - - # Write config for root user - if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then + if [ "$(whoami)" == "root" ]; then return 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" - - # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + st2 login "${USERNAME}" --password "${PASSWORD}" --write-password } diff --git a/scripts/st2bootstrap-el7.sh b/scripts/st2bootstrap-el7.sh index 07eb2715..85c00a10 100644 --- a/scripts/st2bootstrap-el7.sh +++ b/scripts/st2bootstrap-el7.sh @@ -279,48 +279,17 @@ configure_st2_user () { } +# Configure CLI config (write credentials for the root user and user which ran the script) configure_st2_cli_config() { - # Configure CLI config (write credentials for the root user and user which ran the script) - ROOT_USER="root" - CURRENT_USER=$(whoami) + # Write config for the root user + sudo -i st2 login "${USERNAME}" --password "${PASSWORD}" --write-password - ROOT_HOME=$(eval echo ~${ROOT_USER}) - : "${HOME:=$(eval echo ~${CURRENT_USER})}" - - ROOT_USER_CLI_CONFIG_DIRECTORY="${ROOT_HOME}/.st2" - ROOT_USER_CLI_CONFIG_PATH="${ROOT_USER_CLI_CONFIG_DIRECTORY}/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" - - # Write config for root user - if [ "${CURRENT_USER}" == "${ROOT_USER}" ]; then + if [ "$(whoami)" == "root" ]; then return 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" - - # Fix the permissions - sudo chown -R ${CURRENT_USER}:${CURRENT_USER} ${CURRENT_USER_CLI_CONFIG_DIRECTORY} + st2 login "${USERNAME}" --password "${PASSWORD}" --write-password }