create-lx-container.sh: skip creating directory '.ssh' if it already exists.

This commit is contained in:
Christoph 2023-11-27 16:05:12 +01:00
parent 968c35b61b
commit e422efbd30

View File

@ -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"