[doc_tool] Show leading zeros in percentage of install script.
authorDaniel G <daniel@giritzer.eu>
Fri, 11 May 2018 22:28:01 +0000 (00:28 +0200)
committerDaniel G <daniel@giritzer.eu>
Fri, 11 May 2018 22:28:01 +0000 (00:28 +0200)
This fixes the gauge 'running away' in console mode.

scripts/gen_package_linux.sh

index 4ca8075..b9c6eee 100755 (executable)
@@ -27,7 +27,7 @@ fi
 if [ "\$ans" == "yes" ]; then
     TOSKIP=\$(awk '/^#----- ARCHIVE STARTS HERE -----#/ {print NR + 1; exit 0; }' \$0)
     COUNT=$FILECOUNT
-    echo "Self extracting archive created with Daniel Giritzer's script! (For details see: https://page.nwrk.biz/giri)"& 
+    echo "Installing Doc Tool: "& 
     PID=\$!
     LINE="                                                  "
     LINENUM=0
@@ -38,13 +38,14 @@ if [ "\$ans" == "yes" ]; then
         x=\$((x+1))
 
         # calculate percentage
-       PERCENTAGE=\$(((x*100)/COUNT))
+       PERCENTAGE_NUM=\$(((x*100)/COUNT))
+       PERCENTAGE=\$(printf '%03d' \$PERCENTAGE_NUM)   
 
         # create gauge line
-        if [ "\$PERCENTAGE" -ge "\$LINENUM" ]; then
+        if [ "\$PERCENTAGE_NUM" -ge "\$LINENUM" ]; then
                LINE=\${LINE/ />}
 
-                if [ "\$PERCENTAGE" -ge "100" ]; then
+                if [ "\$PERCENTAGE_NUM" -ge "100" ]; then
                         LINE=\${LINE// />}
                 fi
        fi
@@ -52,12 +53,12 @@ if [ "\$ans" == "yes" ]; then
         # display gauge line
         if [ -z \${XMESSAGE+x} ]; then
               echo -en "[\$LINE] \$x / \$COUNT extracted (\$PERCENTAGE%)\r"
-                if [ "\$PERCENTAGE" -ge "\$LINENUM" ]; then
-                     LINENUM=\$((PERCENTAGE+2))
+                if [ "\$PERCENTAGE_NUM" -ge "\$LINENUM" ]; then
+                     LINENUM=\$((PERCENTAGE_NUM+2))
                fi
         else
-               if [ "\$PERCENTAGE" -ge "\$LINENUM" ]; then
-                     LINENUM=\$((PERCENTAGE+2))
+               if [ "\$PERCENTAGE_NUM" -ge "\$LINENUM" ]; then
+                     LINENUM=\$((PERCENTAGE_NUM+2))
                       if ps -p \$PID > /dev/null 
                       then
                             kill \$PID 2> /dev/null