From e422efbd30c4b6286b5e6ec27ea9ca2c3c461427 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 27 Nov 2023 16:05:12 +0100 Subject: [PATCH] create-lx-container.sh: skip creating directory '.ssh' if it already exists. --- create-lx-container.sh | 77 +++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/create-lx-container.sh b/create-lx-container.sh index c1051d3..47a7b20 100755 --- a/create-lx-container.sh +++ b/create-lx-container.sh @@ -2568,28 +2568,16 @@ echo -en "\033[1G \033[1;30m[ ... ] \033[32m$msg\033[m" if [[ -f "${working_dir}/supported-files/templates_root/.ssh/authorized_keys2" ]] || [[ -f "${working_dir}/supported-files/templates_root/.ssh/authorized_keys" ]]; then - mkdir "${LXC_CONTAINER_DIR}/rootfs/root/.ssh" > $err_msg 2>&1 + if [[ -d "${LXC_CONTAINER_DIR}/rootfs/root/.ssh" ]] ; then - if [[ $? -eq 0 ]] ; then - msg_ok="New directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh' created." - length_msg_ok=${#msg_ok} - blank_signs="" - if [[ $length_msg -gt $length_msg_ok ]]; then - number_blank_sign=$(expr $length_msg - $length_msg_ok) - index_i=0 - while [[ $index_i -lt $number_blank_sign ]] ; do - blank_signs="$blank_signs " - (( index_i++ )) - done - fi - echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}" + echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] $msg" - msg="Copy supported files to '${LXC_CONTAINER_DIR}/rootfs/root/.ssh/' .." - cp -a "${working_dir}/supported-files/templates_root/.ssh" \ - "${LXC_CONTAINER_DIR}/rootfs/root/" > $err_msg 2>&1 + else + + mkdir "${LXC_CONTAINER_DIR}/rootfs/root/.ssh" > $err_msg 2>&1 if [[ $? -eq 0 ]] ; then - msg_ok="Supported files copied to new directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'." + msg_ok="New directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh' created." length_msg_ok=${#msg_ok} blank_signs="" if [[ $length_msg -gt $length_msg_ok ]]; then @@ -2601,8 +2589,42 @@ if [[ -f "${working_dir}/supported-files/templates_root/.ssh/authorized_keys2" ] done fi echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}" + + msg="Copy supported files to '${LXC_CONTAINER_DIR}/rootfs/root/.ssh/' .." + cp -a "${working_dir}/supported-files/templates_root/.ssh" \ + "${LXC_CONTAINER_DIR}/rootfs/root/" > $err_msg 2>&1 + + if [[ $? -eq 0 ]] ; then + msg_ok="Supported files copied to new directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'." + length_msg_ok=${#msg_ok} + blank_signs="" + if [[ $length_msg -gt $length_msg_ok ]]; then + number_blank_sign=$(expr $length_msg - $length_msg_ok) + index_i=0 + while [[ $index_i -lt $number_blank_sign ]] ; do + blank_signs="$blank_signs " + (( index_i++ )) + done + fi + echo -e "\033[1G [ \033[32m\033[1mok\033[m ] ${msg_ok}${blank_signs}" + else + msg_failed="Failed to copy supported files to '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'!" + length_msg_failed=${#msg_failed} + blank_signs="" + if [[ $length_msg -gt $length_msg_failed ]]; then + number_blank_sign=$(expr $length_msg - $length_msg_failed) + index_i=0 + while [[ $index_i -lt $number_blank_sign ]] ; do + blank_signs="$blank_signs " + (( index_i++ )) + done + fi + echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}" + error "$(cat $err_msg)" + fi + else - msg_failed="Failed to copy supported files to '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'!" + msg_failed="Failed to create directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'!" length_msg_failed=${#msg_failed} blank_signs="" if [[ $length_msg -gt $length_msg_failed ]]; then @@ -2613,24 +2635,9 @@ if [[ -f "${working_dir}/supported-files/templates_root/.ssh/authorized_keys2" ] (( index_i++ )) done fi - echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}" + echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}" error "$(cat $err_msg)" fi - - else - msg_failed="Failed to create directory '${LXC_CONTAINER_DIR}/rootfs/root/.ssh'!" - length_msg_failed=${#msg_failed} - blank_signs="" - if [[ $length_msg -gt $length_msg_failed ]]; then - number_blank_sign=$(expr $length_msg - $length_msg_failed) - index_i=0 - while [[ $index_i -lt $number_blank_sign ]] ; do - blank_signs="$blank_signs " - (( index_i++ )) - done - fi - echo -e "\033[1G [ \033[31m\033[1mfailed\033[m ] ${msg_failed}${blank_signs}" - error "$(cat $err_msg)" fi else echo -e "\033[1G [ \033[30m\033[1mskip\033[m ] $msg"