From d7dede1d7b9474a857e3be4dbd2dcb96e15e69b3 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 30 Apr 2025 03:33:02 +0200 Subject: [PATCH] Fix. --- testing/scripts/init_server_access.sh | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/testing/scripts/init_server_access.sh b/testing/scripts/init_server_access.sh index 290995c..5fed9ee 100755 --- a/testing/scripts/init_server_access.sh +++ b/testing/scripts/init_server_access.sh @@ -10,11 +10,12 @@ cd $(dirname "$0") PATH_KNOWN_HOSTS="${PATH_USER_SSH}/known_hosts" URL_REPO_CLONE='https://plomlompom.com/repos/clone/config' -expect_n_args 1 2 'SERVER [ROOT_LOGIN_PW]' $@ +expect_n_args 2 3 'SERVER NEW_ROOT_PW [OLD_ROOT_PW]' $@ SERVER="$1" -ROOT_LOGIN_PW="$2" -if [ ! -z "${ROOT_LOGIN_PW}" ]; then - echo '# Provided ROOT_LOGIN_PW, so will later try to log-in with that and place local key file …' +NEW_ROOT_PW="$2" +OLD_ROOT_PW="$3" +if [ ! -z "${OLD_ROOT_PW}" ]; then + echo '# Provided OLD_ROOT_PW, so will later try to log-in with that and place local key file …' abort_if_command_unknown sshpass fi @@ -38,24 +39,25 @@ ${CMD_RM_LOG} trapp SSH_TARGET="root@${SERVER}" -if [ ! -z "${ROOT_LOGIN_PW}" ]; then +if [ ! -z "${OLD_ROOT_PW}" ]; then echo '# Logging in with provided password to place local key file …' - SSHPASS="${ROOT_LOGIN_PW}" sshpass -e scp "${PATH_USER_SSH}/id_rsa.pub" "root@${SERVER}:~/${PATH_REL_SSH}/authorized_keys" + SSHPASS="${OLD_ROOT_PW}" sshpass -e scp -q "${PATH_USER_SSH}/id_rsa.pub" "root@${SERVER}:~/${PATH_REL_SSH}/authorized_keys" fi CMD_SSH="ssh ${SSH_TARGET}" -CMD_STTY_ECHO='stty echo' -echo '# On server, asking for new root password …' -stty echonl -stty -echo -trapp "${CMD_STTY_ECHO}" -${CMD_SSH} 'passwd' -${CMD_STTY_ECHO} +echo '# On server, setting new root password …' +PATH_NEW_ROOT_PW=$(path_tmp_timestamped new_server_root_pw) +CMD_RM_ROOT_PW="rm ${PATH_NEW_ROOT_PW}" +trapp "${CMD_RM_ROOT_PW}" +echo "root:${NEW_ROOT_PW}" > "${PATH_NEW_ROOT_PW}" +scp -q "${PATH_NEW_ROOT_PW}" "${SSH_TARGET}:${PATH_NEW_ROOT_PW}" +${CMD_RM_ROOT_PW} trapp +${CMD_SSH} "cat ${PATH_NEW_ROOT_PW} | chpasswd; ${CMD_RM_ROOT_PW}" echo '# On server, ensuring some minimum locale presence …' -${CMD_SSH} 'if [ ! -z "$(locale 2>&1 1>/dev/null)" ]; then localectl set-locale en_US.UTF8; done' +${CMD_SSH} 'if [ ! -z "$(locale 2>&1 1>/dev/null)" ]; then localectl set-locale en_US.UTF-8; fi' echo '# On server, updating package database …' ${CMD_SSH} 'apt-get -q -q update' -- 2.30.2