corretto preload
[brisk.git] / bin / preload.sh
1 #!/bin/bash
2 #
3 #  brisk - preload.sh
4 #
5 #  Copyright (C) 2006 matteo.nastasi@milug.org
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details. You should have received a
16 # copy of the GNU General Public License along with this program; if
17 # not, write to the Free Software Foundation, Inc, 59 Temple Place -
18 # Suite 330, Boston, MA 02111-1307, USA.
19 #
20 #
21
22
23 OUTFILE=web/preload_img.js
24 IMGPATH=../brisk-img/img
25
26 # (
27 # echo '<?php'
28 # echo 'header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1'
29 # echo 'header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past'
30 # echo '?>'
31 # ) > $OUTFILE
32
33 rm -f $OUTFILE
34
35 (
36 echo "var g_preload_img_arr = new Array( "
37 first=1
38 spa="            "
39 for i in `ls -S $IMGPATH/*.{jpg,png,gif} | grep -v '/src_'`; do
40    if [ $first -ne 1 ]; then
41       echo -n ", "
42       if [ $ct -eq 4 ]; then
43          echo
44          echo -n "$spa"
45          ct=0
46       fi
47    else
48       echo -n "$spa"
49    fi
50    outna="img/`basename $i`"
51    echo -n "\"$outna\""
52    ct=$((ct + 1))
53    first=0
54 done
55
56 echo ");"
57 ) >> $OUTFILE
58
59 (
60 echo "var g_preload_imgsz_arr = new Array( "
61 first=1
62 sum=0
63 spa="            "
64 tot=0
65 for i in `ls -S $IMGPATH`; do
66    sz="`stat -c '%s' $IMGPATH/$i`"
67    tot=$((tot + sz))
68 done
69
70 for i in `ls -S $IMGPATH`; do
71    if [ $first -ne 1 ]; then
72       echo -n ", "
73       if [ $ct -eq 8 ]; then
74          echo
75          echo -n "$spa"
76          ct=0
77       fi
78    else
79       echo -n "$spa"
80    fi
81    sz="`stat -c '%s' $IMGPATH/$i`"
82    sum=$((sum + sz))
83    cur="`echo "100.0 * $sum / $tot" | bc -l | sed 's/\(\.[0-9]\)[0-9]*/\1/g'`"
84    echo -n "\"$cur\""
85    ct=$((ct + 1))
86    first=0
87 done
88
89 echo ");"
90 ) >> $OUTFILE
91
92 exit 0