#!/bin/bash
p=$1

for path in `ls -a $p`
do

if [ x"$path" != x"." -a x"$path" != x".." -a x"$path" != x".dirindex" ];then
 pa=$p/$path

 dirindexfile=$pa/.dirindex
 rm $dirindexfile
 echo "version:1" >> $dirindexfile
 echo "path:/${pa#*/Terrain}" >> $dirindexfile 
 for file2 in `ls -a $pa`
 do
     if [ x"$file2" != x"." -a x"$file2" != x".." -a x"$file2" != x".dirhash" -a x"$file2" != x".dirindex" -a x"$file2" != x".zj" ];then
        pc=$pa/$file2
        echo f:$file2:`sha1sum $pc | awk '{print $1}'`:`ls $pc -l | awk '{print $5}'` >> $dirindexfile
     fi
 done

fi
done
