1#!/bin/sh
2
3if [ $# -le 1 ]
4then
5  echo "Usage: `basename $0` phpfreechat_path checkmd5_output_filename"
6  echo "exempel: `basename $0` ~/pfc/misc/phpfreechat ~/pfc/misc/phpfreechat/checkmd5.php"
7  exit;
8fi
9
10PFC_PATH=$1
11DST=$2
12TMP=/tmp/checkmd5.php
13
14if ( test -f $DST )
15then
16  echo "$DST should not exist. Please delete this file."
17  exit;
18fi
19
20if ( test ! -f $PFC_PATH/version.txt  )
21then
22  echo "$PFC_PATH/version.txt doesn't exist."
23  exit;
24fi
25
26echo "--> Creating $DST"
27
28cd $PFC_PATH
29echo "<?php" > $TMP
30echo '$files_ok = array();' >> $TMP
31echo '$files_ko = array();' >> $TMP
32for f in `find . -type f`
33do
34  if ( test $f != "./index.php"  )
35  then
36    sum=`md5sum $f | sed "s/\s.*$//g"`
37    echo 'if (md5(file_get_contents("'$f'")) == "'$sum'")' >> $TMP
38    echo '  $files_ok[] = "<span style=\"color:#3A3\">ok - '$f'</span>\n";' >> $TMP
39    echo 'else' >> $TMP
40    echo '  $files_ko[] = "<span style=\"color:#F33\">corrupted - '$f' (please replace this file by a correct one)</span>\n";' >> $TMP
41  fi
42done
43
44echo 'echo "<h2>Checking phpfreechat files validity</h2>";' >> $TMP
45echo 'echo "<pre>\n";' >> $TMP
46echo '$arr = array_merge($files_ko,$files_ok);' >> $TMP
47echo 'foreach($arr as $file)' >> $TMP
48echo '  echo $file;' >> $TMP
49echo 'echo "</pre>\n";' >> $TMP
50echo "?>" >> $TMP
51cd - >/dev/null
52
53cp $TMP $DST
54
55echo "---> Done, $DST created"
56