echo "*******************Install dependencies***************************"
sudo apt-get -qq install tesseract-ocr bc libtesseract-dev
pip install python-bidi

echo "********************Verify installation**************************"
which tesseract

echo "******************Download training data********************"
rm -rf ./*
mkdir -p ./data/ben-ground-truth
wget https://github.com/srdg/unarchived_ben_tess/\
releases/download/v0.0.4-alpha/data.zip -q --show-progress 
unzip -q ./data.zip -d ./data/ben-ground-truth && rm -rf ./data.zip

echo "******************Download training tools********************"
wget https://github.com/tesseract-ocr/tesstrain/\
archive/master.zip -q --show-progress && unzip -q ./master.zip 
rm -rf ./master.zip ./sample_data

echo "***********************Move training  data***********************"
mv ./data ./tesstrain-master/

echo "======================= Get traineddata ========================="
cd ./tesstrain-master/
mkdir -p tessdata_best
rm -rf tessdata_best/*.traineddata.*
wget https://github.com/tesseract-ocr/tessdata_best/raw/master/\
ben.traineddata -q --show-progress && cp ben.traineddata tessdata_best/
cp -r tessdata_best $HOME

echo "======================= READY TO TRAIN ========================="
echo "Current working directory is $(pwd)"
echo "======================= TRAINING MODEL ========================="
nohup make MODEL_NAME=ben START_MODEL=ben LANG_TYPE=Indic \
GROUND_TRUTH_DIR=data/ben-ground-truth TESSDATA=$HOME/tessdata_best \
DEBUG_INTERVAL=-1 training MAX_ITERATIONS=50000 >> data/ben.log &
echo "======================= TRAINING DONE ========================="

echo "Command and evaluation results are as follows -- "
tail -10 ./data/ben.log
echo "====================== Making model =========================="
make traineddata MODEL_NAME=ben
echo "********************** Archiving results ***********************"
zip ben.zip ./data/ben/* -q
echo "Model ready to download. "
cd ..