From d9b94b1997b313541804996a344abb38ba2dda5b Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 11 Aug 2005 15:17:52 +0000 Subject: [PATCH] . don't print error by usyslogd (for on CD) . added progress bar technology to setup script --- commands/scripts/setup.sh | 3 +- commands/simple/Makefile | 9 +++++ commands/simple/progressbar.c | 63 +++++++++++++++++++++++++++++++++++ commands/simple/usyslogd.c | 1 - 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100755 commands/simple/progressbar.c diff --git a/commands/scripts/setup.sh b/commands/scripts/setup.sh index 4cffc0884..a9f9e209c 100755 --- a/commands/scripts/setup.sh +++ b/commands/scripts/setup.sh @@ -335,7 +335,8 @@ echo "" mount /dev/$usr /mnt || exit # Mount the intended /usr. -cpdir -v /usr /mnt || exit # Copy the usr floppy. +files="`find /usr | wc -l`" +cpdir -v /usr /mnt | progressbar "$files" || exit # Copy the usr floppy. umount /dev/$usr || exit # Unmount the intended /usr. diff --git a/commands/simple/Makefile b/commands/simple/Makefile index bd23287bd..d0eae64aa 100755 --- a/commands/simple/Makefile +++ b/commands/simple/Makefile @@ -132,6 +132,7 @@ ALL = \ ping \ pr \ pr_routes \ + progressbar \ prep \ printf \ printroot \ @@ -579,6 +580,10 @@ pr_routes: pr_routes.c $(CCLD) -o $@ $? @install -S 4kw $@ +progressbar: progressbar.c + $(CCLD) -o $@ $? + @install -S 4kw $@ + prep: prep.c $(CCLD) -o $@ $? @install -S 4kw $@ @@ -964,6 +969,7 @@ install: \ /usr/bin/ping \ /usr/bin/pr \ /usr/bin/pr_routes \ + /usr/bin/progressbar \ /usr/bin/prep \ /usr/bin/printf \ /usr/bin/printenv \ @@ -1370,6 +1376,9 @@ install: \ /usr/bin/pr_routes: pr_routes install -cs -o root -m 4755 $? $@ +/usr/bin/progressbar: progressbar + install -cs -o root -m 4755 $? $@ + /usr/bin/prep: prep install -cs -o bin $? $@ diff --git a/commands/simple/progressbar.c b/commands/simple/progressbar.c new file mode 100755 index 000000000..10660320d --- /dev/null +++ b/commands/simple/progressbar.c @@ -0,0 +1,63 @@ + +#include +#include +#include + +_PROTOTYPE(int main, (int argc, char **argv)); + +void +prettyprogress(long b, long maxb, time_t starttime) +{ + /* print progress indication */ + time_t spent, now; + long bpsec; + time(&now); + spent = now - starttime; + if(spent > 0 && (bpsec = b / spent) > 0) { + int len, i; + long secremain, minremain, hremain; + secremain = (maxb - b) / bpsec; + minremain = (secremain / 60) % 60; + hremain = secremain / 3600; + len = fprintf(stderr, "Remain %ld files. ETA: %d:%02d:%02d [", + maxb - b, + hremain, minremain, secremain % 60); +#define WIDTH 77 + len = WIDTH - len; + for(i = 0; i < (b * (len-1) / maxb); i++) + fprintf(stderr, "="); + fprintf(stderr, "|"); + for(; i < len-2; i++) + fprintf(stderr, "-"); + fprintf(stderr, "]\r"); + fflush(stderr); + } + + return; +} + +int main(argc, argv) +int argc; +char *argv[]; +{ + long i = 0, count = 0; + char line[2000]; + time_t start; + if(argc < 2) return 1; + count = atol(argv[1]); + if(count < 1) return 1; + time(&start); + printf("\n"); + while(fgets(line, sizeof(line), stdin)) { + i++; + printf("%s", line); + if(i <= count) prettyprogress(i, count, start); + printf(""); + fflush(NULL); + sleep(1); + } + + fprintf(stderr, "\nDone.\n"); + + return 0; +} diff --git a/commands/simple/usyslogd.c b/commands/simple/usyslogd.c index e012d9734..edc3babc9 100644 --- a/commands/simple/usyslogd.c +++ b/commands/simple/usyslogd.c @@ -80,7 +80,6 @@ main(int argc, char *argv[]) } if(!(logfp = fopen("/usr/log/messages", "a"))) { - perror("/usr/log/messages"); return 1; } -- 2.44.0