#!/bin/bash
# Usage:  bash ./clear_cyrillic.bash
# Bash only!!! Do not use sh interpretator
CWD=`pwd`
OSNAME=`uname`
USERNAME=`whoami`
MACHINE=`uname -m`
date=`date +%Y%m%d%m%s`
shortdate=`echo ${date} | sed s/^...//`
shortname=fidoip_configs_${shortdate}.tar

T1="root"

if [ "$T1" = "$USERNAME" ]; then
echo  ''
else
echo 'Please run this script as root' ; exit
fi


echo "--------------------------------------------------------------------"
echo ""
echo "This script will clear russian support in fidoip's configuration files for you."
echo ""
echo "--------------------------------------------------------------------"
echo ""

echo
echo "Are you sure to clear russian support from fidoip's configuration files?"
echo "If you will select 'y' you will not able use cyrillic characters at all..."
echo "[y/n]"
read reply
echo ""  
if [ "$reply" = "y" ];
	then 

if [ -e /usr/local/etc/binkd.cfg ]; then
echo '------------------------------------------------------------------------'
echo 'Previos configuration files saved to file:'
echo ''
echo $CWD/$shortname
echo ''
echo '------------------------------------------------------------------------'
echo ''

tar -cf $CWD/$shortname /usr/local/etc/binkd.cfg /usr/local/etc/golded+/g* /usr/local/etc/fido/config /usr/local/bin/recv /usr/local/bin/send > /dev/null 2>&1
sleep 3 
fi

sed "s|\â\Å\Ú\Ä\Õ\Í\Î\Ù\Ê\ \Ò\Ï\Â\Ï\Ô|Stupid\ robot|" /usr/local/etc/fido/config > /tmp/config1
sed "s|XLAT|;XLAT|g" /usr/local/etc/golded+/golded.cfg > /tmp/golded.cfg1
sed "s|IGNORECHARSET|;IGNORECHARSET|" /tmp/golded.cfg1 > /tmp/golded.cfg2
sed "s|DispSoftCr|;DispSoftCr|" /tmp/golded.cfg2 > /tmp/golded.cfg3
sed "s|\á\ \×\Ù\ \Â\Ù\ \É\Ó\Ë\Õ\Ó\Ó\Ô\×\Ï\Í\ \Ú\Á\Î\Ñ\Ì\É\Ó\Ø\.\ \ð\Ï\Ü\Ú\É\Å\Ê\,\ ÞÔÏ\ ÌÉ|And\ you\ would\ be\ better\ to\ engaged\ in\ art\.\ Poetry\,\ for\ example|" /tmp/golded.cfg3 > /tmp/golded.cfg4
sed "s|\í\Õ\Ò\Á\×\Ø\É\Î\Ù\Í\ \Ó\Ð\É\Ò\Ô\Ï\Í\ \Ó\Ï\×\Å\Ô\Õ\À\ \Î\Á\Ô\Å\Ò\Å\Ô\Ø|Advising\ to\ rub\ down\ ant\'s\ alcohol|" /tmp/golded.cfg4 > /tmp/golded.cfg5
sed "s|EditSoftCrXLat|;EditSoftCrXLat|" /tmp/golded.cfg5 > /tmp/golded.cfg6 
sed "s|EditCompletion|;EditCompletion|" /tmp/golded.cfg6 > /tmp/golded.cfg7
sed "s|\H\Á\Þ\Á\Ì\Ï\ \Æ\Á\Ê\Ì\Á|Begin\ file|" /tmp/golded.cfg7 > /tmp/golded.cfg8
sed "s|\ë\Ï\Î\Å\Ã\ \Æ\Á\Ê\Ì\Á|End\ file|" /tmp/golded.cfg8 > /tmp/golded.cfg9
sed "s|\ï\Ó\Î\Ï\×\Î\Ï\Ê\ \Û\Á\Â\Ì\Ï\Î|Main\ template|" /tmp/golded.cfg9 > /tmp/golded.cfg10
sed "s|\ð\Ï\Þ\Ô\Á|Mail|" /tmp/golded.cfg10 > /tmp/golded.cfg11
sed "s|\ô\Õ\Ô\ \Ì\Ï\Ë\Á\Ì\Ë\Á\ \Õ\ \Î\Á\Ó\ \Ð\Ò\Ï\Ó\Ô\Á\Ñ|Local\ area|" /tmp/golded.cfg11 > /tmp/golded.cfg12
sed "s|\ä\Õ\Ð\Ì\É\ \Õ\ \Î\Á\Ó\ \×\Ô\Ï\Ò\Ù\Å|Dupes\ area|" /tmp/golded.cfg12 > /tmp/golded.cfg13
sed "s|\á \Ë\Ï\Ó\Ñ\Ë\É\ -\ \Ë\Ò\É\×\Ù\Å|Bad\ area|" /tmp/golded.cfg13 > /tmp/golded.cfg14
sed "s|\ë\Á\Ò\Â\Ï\Î\Ë\Á\ \Î\Å\ \Ð\Õ\Ó\Ô\Á\Ñ|Carbon\ area|" /tmp/golded.cfg14 > /tmp/golded.cfg15
sed "s|\ó\Ð\Ò\Ï\Ó\É\Ô\Ø\ \Ð\Ï\Ì\Ø\Ú\Ï\×\Á\Ô\Å\Ì\Ñ|Ask\ user|" /tmp/golded.cfg15 > /tmp/golded.cfg16
sed "s|\ð\Ï\Ì\Õ\Þ\Å\Î\Î\Ï\Å\ \Ó|Recieved\ from|" /tmp/golded.cfg16 > /tmp/golded.cfg17

sed "/\ì\É\Î\Õ\Ë\Ó/d" /tmp/golded.cfg17 > /tmp/golded.cfg18
sed "/\â\Ü\ü\Ó\ä\Ü\Û\Î\É\Ë\É/d" /tmp/golded.cfg18 > /tmp/golded.cfg19
sed "/\é\Ú\\Í\Å\Î\É\Ô\Å/d" /tmp/golded.cfg19 > /tmp/golded.cfg20
sed "/\ó\Ë\Ï\Ð\É\Ò\Õ\Ê\Ô\Å/d" /tmp/golded.cfg20 > /tmp/golded.cfg21
sed "/\Ç\Å\Î\Å\Ò\Á\Ã\É\É/d" /tmp/golded.cfg21 > /tmp/golded.cfg22
sed "/\Ð\Ò\É\×\Å\Ô\×\Ï\×\Á\Ô\Ø/d" /tmp/golded.cfg22 > /tmp/golded.cfg23
sed "/\í\Á\Ë\Ò\Ï\Ó/d" /tmp/golded.cfg23 > /tmp/golded.cfg24
sed "/\Ó\Ï\Ë\Ò\Á\Ý\Å\Î\É\Ñ/d" /tmp/golded.cfg24 > /tmp/golded.cfg25
sed "/\ä\Ï\Â\Á\×\Ì\Å\Î\É\Å/d" /tmp/golded.cfg25 > /tmp/golded.cfg26
sed "/\Ë\Î\É\Ç\Õ/d" /tmp/golded.cfg26 > /tmp/golded.cfg27
sed "/\ð\Ò\Ï\Ó\Í\Ï\Ô\Ò/d" /tmp/golded.cfg27 > /tmp/golded.cfg28
sed "/\ï\Ð\É\Ó\Á\Î\É\Ñ/d"  /tmp/golded.cfg28 > /tmp/golded.cfg29

cat /tmp/config1 > /usr/local/etc/fido/config
cat /tmp/golded.cfg29 > /usr/local/etc/golded+/golded.cfg

if [ -e /usr/local/etc/golded+/goldlang.cfg ];then
mv /usr/local/etc/golded+/goldlang.cfg /usr/local/etc/golded+/goldlang.cfg.rus
fi

cp /usr/local/etc/fidoip/golded.cfm.eng /usr/local/etc/golded+/golded.cfm
cp /usr/local/etc/fidoip/golded.tpl.eng /usr/local/etc/golded+/golded.tpl
cp /usr/local/etc/fidoip/goldhelp.cfg.eng /usr/local/etc/golded+/goldhelp.cfg

rm -rf /tmp/config*
rm -rf /tmp/golded.cfg*

echo "OK. Original configuration files modified successfully."
echo "Please review configuration files."  


elif [ "$reply" = "n" ];
	then 
echo "Support of russian language leaved as is."

fi
