From 5f83ba9ff860bc4da76fba2fefc939a26bb8a781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 2 Aug 2022 00:02:13 +0200 Subject: [PATCH] Only try to create the subdir if does not already exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- deploy.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index 59c54669..fb7c3a4b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -37,8 +37,20 @@ unset IFS old_path="." for dir in "${path[@]}"; do - sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path} - -mkdir ${dir}" + mapfile -t dir_content <<< "$( + sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path} + ls -1" + )" + + # Only try to create the subdir if does not already exist + if [[ "${dir_content[*]}" =~ "${dir}" ]]; then + echo "Dir: ${old_path}/${dir} already exists" + else + echo "Creating dir: ${old_path}/${dir}" + sftp -b - "${USER}"@"${HOST}" <<< "cd ${old_path} + -mkdir ${dir}" + fi + old_path="${old_path}/${dir}" done