merge with spawn branch
[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
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 function imglist () {
34     ls -S `find $1 -type f -name '*.jpg' -o -name '*.png' -o -name '*.gif' | grep -v '/src_' | sort`
35 }
36
37 rm -f $OUTFILE
38
39 (
40 echo "var g_preload_img_arr = new Array( "
41 first=1
42 spa="            "
43 ltri="`echo "$IMGPATH" | wc -c`"
44 for i in `imglist $IMGPATH`; do
45    if [ $first -ne 1 ]; then
46       echo -n ", "
47       if [ $((ct % 2)) -eq 0 ]; then
48          echo
49          echo -n "$spa"
50       fi
51    else
52       echo -n "$spa"
53    fi
54    outna="`echo "$i" | cut -c $((ltri + 1))-`"
55    echo -n "\"$outna\""
56    ct=$((ct + 1))
57    first=0
58 done
59 echo "CT: $ct" >&2
60 echo ");"
61 ) >> $OUTFILE
62
63 (
64 echo "var g_preload_imgsz_arr = new Array( "
65 first=1
66 sum=0
67 spa="            "
68 tot=0
69 for i in `imglist $IMGPATH`; do
70    sz="`stat -c '%s' $IMGPATH/$i`"
71    tot=$((tot + sz))
72 done
73
74 for i in `imglist $IMGPATH`; do
75    if [ $first -ne 1 ]; then
76       echo -n ", "
77       if [ $((ct % 8)) -eq 0 ]; then
78          echo
79          echo -n "$spa"
80       fi
81    else
82       echo -n "$spa"
83    fi
84    sz="`stat -c '%s' $IMGPATH/$i`"
85    sum=$((sum + sz))
86    cur="`echo "100.0 * $sum / $tot" | bc -l | sed 's/\(\.[0-9]\)[0-9]*/\1/g'`"
87    echo -n "\"$cur\""
88    ct=$((ct + 1))
89    first=0
90 done
91
92 echo "CT2: $ct" >&2
93
94 echo ");"
95 ) >> $OUTFILE
96
97 exit 0