From 5455f699d96da0d3d6803aa9ce3363a24d3c31aa Mon Sep 17 00:00:00 2001 From: saarloos <9090-90-90-9090@163.com> Date: Wed, 4 Jan 2023 09:41:31 +0800 Subject: [PATCH] embedded: fix del dir and copy bug fix del dir function, add do not del gcc, and add copy param copy date dir date or date dir Signed-off-by: saarloos <9090-90-90-9090@163.com> --- script/tools/copy_embedded_img.sh | 44 ++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/script/tools/copy_embedded_img.sh b/script/tools/copy_embedded_img.sh index f5a4e52..69e8df9 100644 --- a/script/tools/copy_embedded_img.sh +++ b/script/tools/copy_embedded_img.sh @@ -1,6 +1,6 @@ #!/bin/bash -#Usage: bash copy_embedded_img.sh source_user source_ip source_pwd source_dir daily_ip ssh_key latest_iso_dir +#Usage: bash copy_embedded_img.sh source_user source_ip source_pwd source_dir daily_ip ssh_key latest_iso_dir copy_date_data_only function cp_embedded_img() { @@ -11,25 +11,34 @@ function cp_embedded_img() dest_ip=$5 ssh_key=$6 latest_iso_dir=$7 - local copydir="${source_dir}" + copy_date_data_only=$8 + local copydir="${source_dir}" res=$(ssh -i ${ssh_key} -o StrictHostKeyChecking=no -o LogLevel=ERROR -o ServerAliveInterval=60 root@${dest_ip} " +if [ ! -e ${latest_iso_dir} ]; then + mkdir -p ${latest_iso_dir} +fi cd ${latest_iso_dir} if [ ! -d embedded_img ];then mkdir embedded_img else - rm -rf embedded_img - echo "[INFO]: old embedded_img directory will deleted." + allFile=\$(ls ./embedded_img/) + for oneFile in \${allFile[@]}; do + if [[ \${oneFile} != \"gcc\" ]]; then + rm -rf embedded_img/\${oneFile} + fi + done + echo \"[INFO]: old embedded_img directory will deleted.\" fi ") if [ -n "$res" ];then echo $res fi - echo source_user="${source_user}" - if [[ -z "${source_user}" ]];then - echo "copy files at this host" - ret=0 - else - copydir="tmpdir" + echo source_user="${source_user}" + if [[ -z "${source_user}" ]];then + echo "copy files at this host" + ret=0 + else + copydir="tmpdir" mkdir "${copydir}" expect <<-END1 set timeout 3600 @@ -48,15 +57,20 @@ fi exit [lindex \${result} 3] } END1 - ret=$? - fi + ret=$? + fi if [ $ret -ne 0 ];then echo "[ERROR]: scp failed." exit 1 else - find ${copydir}/ -type f - echo "==================================" - scp -v -i ${ssh_key} -o StrictHostKeyChecking=no -o LogLevel=ERROR -o ServerAliveInterval=60 -r "${copydir}"/* root@${dest_ip}:${latest_iso_dir}/embedded_img/ + find ${copydir}/ -type f + echo "==================================" + if [ -z ${copy_date_data_only} ]; then + scp -v -i ${ssh_key} -o StrictHostKeyChecking=no -o LogLevel=ERROR -o ServerAliveInterval=60 -r "${copydir}"/* root@${dest_ip}:${latest_iso_dir}/embedded_img/ + else + copyDateDir=$(ls -r ${copydir}/ | head -1) + scp -v -i ${ssh_key} -o StrictHostKeyChecking=no -o LogLevel=ERROR -o ServerAliveInterval=60 -r "${copydir}"/${copyDateDir}/* root@${dest_ip}:${latest_iso_dir}/embedded_img/ + fi if [ $? -ne 0 ];then echo "[ERROR]: scp embedded_img to dailybuild failed." exit 1 -- Gitee