From 0bd40cdd73b6dc37cf374f044472dae0d65ce21b Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 4 Sep 2024 13:21:36 +0900 Subject: [PATCH] Create user: skip zip creation run if there are no PEM files Avoid "file not found" zip file creation and remove if there are no PEM files created, eg if we have a pre defined pub file --- bin/create_user.sh | 59 ++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/bin/create_user.sh b/bin/create_user.sh index e12ec69..184733a 100755 --- a/bin/create_user.sh +++ b/bin/create_user.sh @@ -421,34 +421,37 @@ done; if [ ${INFO} -eq 1 ]; then exit; fi; -# zip everything and remove data in ssh key folder, delete output file with passwords -if [ ${TEST} -eq 0 ]; then - zip -r \ - "${ROOT_FOLDER}${output_zip_folder}${output_zip}" \ - "${input_file}" \ - "${output_file}" \ - "${SSH_KEYGEN_FOLDER}" \ - -x\*.gitignore; -else - echo "zip -r \\" - echo "${ROOT_FOLDER}${output_zip_folder}${output_zip} \\" - echo "${input_file} \\" - echo "${output_file} \\" - echo "${SSH_KEYGEN_FOLDER} \\" - echo "-x\*.gitignore;" -fi; -echo "Download: ${ROOT_FOLDER}${output_zip_folder}${output_zip}"; -# cleam up user log file and ssh keys -if [ ${TEST} -eq 0 ]; then - # move pub to created folders - mv "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*.pub "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB}"; - # delete the rest - rm "${ROOT_FOLDER}${output_file}"; - rm "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*; -else - echo "$> mv ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}*.pub ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB};"; - echo "$> rm ${ROOT_FOLDER}${output_file}"; - echo "$> rm ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}*"; +# check if there are any files in the SSH_KEYGEN_FOLDER, else skip zip file creation and file move +if (shopt -s nullglob dotglob; f=("${SSH_KEYGEN_FOLDER}"*".pem"*); ((${#f[@]}))); then + # zip everything and remove data in ssh key folder, delete output file with passwords + if [ ${TEST} -eq 0 ]; then + zip -r \ + "${ROOT_FOLDER}${output_zip_folder}${output_zip}" \ + "${input_file}" \ + "${output_file}" \ + "${SSH_KEYGEN_FOLDER}" \ + -x\*.gitignore; + else + echo "zip -r \\" + echo "${ROOT_FOLDER}${output_zip_folder}${output_zip} \\" + echo "${input_file} \\" + echo "${output_file} \\" + echo "${SSH_KEYGEN_FOLDER} \\" + echo "-x\*.gitignore;" + fi; + echo "Download: ${ROOT_FOLDER}${output_zip_folder}${output_zip}"; + # cleam up user log file and ssh keys + if [ ${TEST} -eq 0 ]; then + # move pub to created folders + mv "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*.pub "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB}"; + # delete the rest + rm "${ROOT_FOLDER}${output_file}"; + rm "${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}"*; + else + echo "$> mv ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}*.pub ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER_CREATED_PUB};"; + echo "$> rm ${ROOT_FOLDER}${output_file}"; + echo "$> rm ${ROOT_FOLDER}${SSH_KEYGEN_FOLDER}*"; + fi; fi; # __END__