-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreconvert.sh
executable file
·63 lines (55 loc) · 1.2 KB
/
preconvert.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# We're passed a directory that contains thousands of images. This
# script runs preconvert on each image. Results should be 144 subdirs
# chopped/1, chopped/2, ..., each of which should contains thousands
# images.
dir="$1"
preconvertdist="/home/theapp/pca/dist/build/preconvert/preconvert"
filelist=$(find "$dir" -maxdepth 1 -iname "*.png")
numfiles=$(echo "$filelist" | wc -l)
function preconvert {
$preconvertdist "$1"
}
function format {
date -u -d @"$1" +"%T"
}
starttime=$(date +%s)
function progress {
current=$1
max=$2
elapsed=$(expr $(date +%s) - $starttime)
width=78
let numeq=current*width/max
let numspace=width-numeq
let estimated_remaining=max*elapsed/current-elapsed
#elapsed/total = current/max
#total = max * elapsed / current
echo -n '['
for j in $(seq 1 $numeq);
do
echo -n "="
done
for j in $(seq 1 $numspace);
do
echo -n " "
done
echo -n -e "]\r"
echo -n "[$(format $elapsed)/$(format $estimated_remaining)]"
}
function clearline {
echo -n -e "\r"
for z in $(seq 1 80)
do
echo -n ' '
done
echo -n -e "\r"
}
i=0
for f in $filelist
do
out=$(preconvert $f)
clearline
echo "$out"
let i=i+1
progress $i $numfiles
done