Index: src/backend/sys_update.c
===================================================================
--- src/backend/sys_update.c	(revision 9240)
+++ src/backend/sys_update.c	(working copy)
@@ -30,6 +30,7 @@
 #include "ca_util.h"
 #include "va_constants.h"
 #include "va_xmlrpc.h"
+#include <curl/curl.h>
 
 #define AVX_PACKAGE_URL "http://10.8.1.23/avxupdate.array"
 #define AVX_PACKAGE_NAME "avxupdate.array"
@@ -75,7 +76,142 @@
     }
     return 0;
 }
-                                              
+
+
+struct download_ctx {
+    FILE *fp;
+};
+
+/* Writes received data chunk to file */
+static size_t write_cb(void *ptr, size_t size, size_t nmemb, void *stream)
+{
+    struct download_ctx *ctx = (struct download_ctx *)stream;
+    return fwrite(ptr, size, nmemb, ctx->fp);
+}
+
+/* Human readable size */
+static void print_size(double bytes)
+{
+    const char *units[] = {"B", "KB", "MB", "GB"};
+    int i = 0;
+
+    while (bytes >= 1024 && i < 3) {
+        bytes /= 1024;
+        i++;
+    }
+
+    printf("%.2f %s", bytes, units[i]);
+}
+
+/* Reports download progress (compatible with curl 7.29.0) */
+static int progress_cb(void *clientp,
+                       double dltotal,
+                       double dlnow,
+                       double ultotal,
+                       double ulnow)
+{
+    (void)clientp;
+    (void)ultotal;
+    (void)ulnow;
+
+    if (dltotal > 0) {
+        int percent = (int)((dlnow * 100.0) / dltotal);
+        printf("\rDownloading the upgrade package..... %4d%%", percent);
+        fflush(stdout);
+    } else {
+        printf("\rDownloading the upgrade package... %.0f bytes", dlnow);
+        fflush(stdout);
+    }
+
+    return 0;
+}
+
+size_t discard(void *ptr, size_t size, size_t nmemb, void *userdata)
+{
+    return size * nmemb;
+}
+
+int download_file(const char *url, const char *output_path)
+{
+    CURL *curl;
+    CURLcode res;
+    double content_length = -1;
+
+    struct download_ctx ctx;
+
+    curl_global_init(CURL_GLOBAL_DEFAULT);
+    curl = curl_easy_init();
+    if (!curl) {
+        printf("Error: curl initialization failed.\n");
+        return -1;
+    }
+
+    curl_easy_setopt(curl, CURLOPT_URL, url);
+
+    /* IMPORTANT: fail on HTTP/FTP error */
+    curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+
+    /* network settings */
+    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+    curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
+
+
+    /* =========================
+       STEP 1: Probe size (HEAD)
+       ========================= */
+    curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, discard);  // Prevent header output to stdout
+    res = curl_easy_perform(curl);
+    if (res == CURLE_OK) {
+        curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &content_length);
+    }
+
+    if (content_length > 0) {
+        printf("The package size is : ");
+        print_size(content_length);
+        printf("\n");
+    } else {
+        printf("The package Size is: Unknown\n");
+    }
+
+
+    /* =========================
+       STEP 2: Real download
+       ========================= */
+    ctx.fp = fopen(output_path, "wb");
+    if (!ctx.fp) {
+        perror("fopen");
+        curl_easy_cleanup(curl);
+        curl_global_cleanup();
+        return -1;
+    }
+
+    /* reset handle status */
+    curl_easy_setopt(curl, CURLOPT_NOBODY, 0L);
+
+    /* write file */
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ctx);
+
+    /* progress (OLD API) */
+    curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_cb);
+    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
+
+    res = curl_easy_perform(curl);
+
+    fclose(ctx.fp);
+    curl_easy_cleanup(curl);
+    curl_global_cleanup();
+
+    if (res != CURLE_OK) {
+        printf("\nError: %s\n", curl_easy_strerror(res));
+        return -1;
+    }
+
+    printf("\nPackage download completed.\n");
+    return 0;
+}
+
 int
 avx_system_update(const char *url, char *option)
 {
@@ -194,41 +330,13 @@
             goto cleanup;
         }
     } else {
-        snprintf(cmd, sizeof(cmd), "/usr/bin/wget \"%s\" --connect-timeout=10 --tries=3 -O \"%s\" 2>&1 | awk '/%%/{printf(\"Downloading the upgrade package... %%s\\r\", $7)} /^Length/ {print(\"The package Size is : \", $3)}'",url,package_url);
-        pid = forkpty(&childfd, NULL, NULL, NULL);
-        if (pid == -1 || childfd == -1) {
-            printf("Internal Error\n");
+        ret = download_file(url, package_url);
+        if (ret != 0) {
+            printf("Error: Upgrade package download failed.\n");
             goto cleanup;
         }
-        if (pid == 0) {
-            if (fcntl(STDOUT_FILENO, F_SETFD, 0) < 0) {
-                printf("Internal Error\n");
-                exit(1);
-            }
-            fclose(stderr);
-            dup2(STDOUT_FILENO, STDERR_FILENO);
-            setbuf(stdout, NULL);
-            ret = system(cmd);
-            if(ret != 0) {
-                printf("Error: Upgrade package download failed.\n");
-                goto cleanup;
-            }
-            exit(ret);
-        }
-        for (;;) {
-            char buf[256];
-            int n;
-            n = read(childfd, buf, sizeof(buf));
-            if (n <= 0) {
-                break;
-            }
+    }
 
-            if (write(STDOUT_FILENO, buf, n) < 0) {
-                break;
-            }
-        }
-       close(childfd);
-    } 
     snprintf(unpack_cli, AVX_CLI_SIZE, "/ca/bin/sign_unpack -i %s -o %s -c %s",
             package_url, package_tar, AVX_PUB_KEY);
     system(unpack_cli);
