. don't print error by usyslogd (for on CD)
. added progress bar technology to setup script
This commit is contained in:
parent
fc72c188bd
commit
d9b94b1997
4 changed files with 74 additions and 2 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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 $? $@
|
||||
|
||||
|
|
63
commands/simple/progressbar.c
Executable file
63
commands/simple/progressbar.c
Executable file
|
@ -0,0 +1,63 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
_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("[K%s", line);
|
||||
if(i <= count) prettyprogress(i, count, start);
|
||||
printf("[A");
|
||||
fflush(NULL);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nDone.[K\n");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -80,7 +80,6 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if(!(logfp = fopen("/usr/log/messages", "a"))) {
|
||||
perror("/usr/log/messages");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue