From 5848826e4566a7e8b71d5cac02906c6466161eb6 Mon Sep 17 00:00:00 2001 From: guillem Date: Wed, 23 Jan 2019 14:38:05 -0300 Subject: [PATCH 1/3] - Increased 10 times the speed copy of the rootfs, the rsync is stuck by dialog. Now it's launched on background and communicate via files on the tmp --- .../bsp/common/usr/sbin/nand-sata-install | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/packages/bsp/common/usr/sbin/nand-sata-install b/packages/bsp/common/usr/sbin/nand-sata-install index 1044aed0f7..d2974cf578 100755 --- a/packages/bsp/common/usr/sbin/nand-sata-install +++ b/packages/bsp/common/usr/sbin/nand-sata-install @@ -140,9 +140,56 @@ create_armbian() echo -e "\nCopying ${TODO} files to $2. \c" >> $logfile # creating rootfs - rsync -avrltD --delete --exclude-from=$EX_LIST / ${TempDir}/rootfs | nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \ - | dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \ - This will take approximately $(( $((USAGE/300)) * 5 )) minutes to finish. Please wait!\n\n" 11 80 + # Speed copy increased x10 + # Variables for interfacing with rsync progress + nsi_conn_path="/tmp/nand-sata-install" + nsi_conn_done="${nsi_conn_path}/done" + nsi_conn_progress="${nsi_conn_path}/progress" + rm -rf "${nsi_conn_path}" + mkdir -p "${nsi_conn_path}" + echo 0 >"${nsi_conn_progress}" + echo no >"${nsi_conn_done}" + + # Launch rsync in backgroudn + { \ + rsync -avrltD --delete --exclude-from=$EX_LIST / ${TempDir}/rootfs | \ + nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \ + > "${nsi_conn_progress}" ; + # save exit code from rsync + echo ${PIPESTATUS[0]} >"${nsi_conn_done}" + } & + + # while varialbes + rsync_copy_finish=0 + rsync_progress=0 + prev_progress=0 + rsync_done="" + while [ "${rsync_copy_finish}" -eq 0 ]; do + # Sometimes reads the progress file while writing and only partial numbers (like 1 when is 15) + prev_progress=${rsync_progress} + rsync_progress=$(tail -n1 "${nsi_conn_progress}") + if [ ${prev_progress} -gt ${rsync_progress} ]; then + rsync_progress=${prev_progress} + fi + echo "${rsync_progress}" | \ + dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \ + This will take approximately $(( $((USAGE/300)) * 1 )) minutes to finish. Please wait!\n\n" 11 80 + # finish the while if the rsync is finished + rsync_done=$(cat ${nsi_conn_done}) + if [[ "${rsync_done}" != "no" ]]; then + if [[ ${rsync_done} -eq 0 ]]; then + rm -rf "${nsi_conn_path}" + rsync_copy_finish=1 + else + # if rsync return error + echo "Error: could not copy rootfs files, exiting" + exit 1 + fi + else + sleep 0.5 + fi + + done # run rsync again to silently catch outstanding changes between / and ${TempDir}/rootfs/ dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... Almost done." 5 40 From c4af6621477d965e8396bbdd1d4f1c04553e3c0a Mon Sep 17 00:00:00 2001 From: guillem Date: Wed, 23 Jan 2019 14:41:41 -0300 Subject: [PATCH 2/3] - Corrected misspelling on the comments --- packages/bsp/common/usr/sbin/nand-sata-install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bsp/common/usr/sbin/nand-sata-install b/packages/bsp/common/usr/sbin/nand-sata-install index d2974cf578..5cf12bf7f2 100755 --- a/packages/bsp/common/usr/sbin/nand-sata-install +++ b/packages/bsp/common/usr/sbin/nand-sata-install @@ -150,7 +150,7 @@ create_armbian() echo 0 >"${nsi_conn_progress}" echo no >"${nsi_conn_done}" - # Launch rsync in backgroudn + # Launch rsync in background { \ rsync -avrltD --delete --exclude-from=$EX_LIST / ${TempDir}/rootfs | \ nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \ @@ -159,7 +159,7 @@ create_armbian() echo ${PIPESTATUS[0]} >"${nsi_conn_done}" } & - # while varialbes + # while variables rsync_copy_finish=0 rsync_progress=0 prev_progress=0 From ddc71e0cf4892e5a503a82666401dc0d7fd29fb9 Mon Sep 17 00:00:00 2001 From: guillem Date: Wed, 23 Jan 2019 16:09:12 -0300 Subject: [PATCH 3/3] - Corrected visualization of the gauge, no flickering now --- packages/bsp/common/usr/sbin/nand-sata-install | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/bsp/common/usr/sbin/nand-sata-install b/packages/bsp/common/usr/sbin/nand-sata-install index 5cf12bf7f2..546c373a18 100755 --- a/packages/bsp/common/usr/sbin/nand-sata-install +++ b/packages/bsp/common/usr/sbin/nand-sata-install @@ -168,12 +168,13 @@ create_armbian() # Sometimes reads the progress file while writing and only partial numbers (like 1 when is 15) prev_progress=${rsync_progress} rsync_progress=$(tail -n1 "${nsi_conn_progress}") + if [[ -z ${rsync_progress} ]]; then + rsync_progress=${prev_progress} + fi if [ ${prev_progress} -gt ${rsync_progress} ]; then rsync_progress=${prev_progress} fi - echo "${rsync_progress}" | \ - dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \ - This will take approximately $(( $((USAGE/300)) * 1 )) minutes to finish. Please wait!\n\n" 11 80 + echo "${rsync_progress}" # finish the while if the rsync is finished rsync_done=$(cat ${nsi_conn_done}) if [[ "${rsync_done}" != "no" ]]; then @@ -189,7 +190,9 @@ create_armbian() sleep 0.5 fi - done + done | \ + dialog --backtitle "$backtitle" --title " $title " --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \ + This will take approximately $(( $((USAGE/300)) * 1 )) minutes to finish. Please wait!\n\n" 11 80 # run rsync again to silently catch outstanding changes between / and ${TempDir}/rootfs/ dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... Almost done." 5 40