#!/ffp/bin/sh
# functions
retfunc()
{
read -p "Type your Gmail account's email address before "at" character:
Kerlek ird be a Gmail cimed "kukac" elotti reszet: " name
email=$(echo -e "$name")
if [ "$email" = "" ]; then
  echo -e "\n\033[4;31mPlease write your valid gmail username, not leave blank!\nKerlek ne hagyd uresen az elozo mezot!\x1b[m"
  echo -e "\n"
  retfunc
else
 retfunc1
fi
}

retfunc1()
{
read -p "This is your mail address: "$email"@gmail.com?
Ez az email cimed: "$email"@gmail.com (y/n)? " choice
case "$choice" in 
  y|Y ) passfunc;;
  n|N ) retfunc;;
  * ) echo "invalid / ertelmetlen";retfunc;;
esac
}

passfunc()
{
echo -e "\n"
read -p "Please input your password!
Kerlek ird be a jelszavad! " -s password
echo -e "\n"
read -p "Please input your password again!
Kerlek ird be ujra a jelszavad! " -s password2
if [ "$password" = "$password2" ]; then
 echo -e "\n\nFinish! Now I'm going to save your changes.\nKesz! Most elmentem a valtozasokat..."
 finishfunc
else
 echo -e "\n\n\033[4;31mError! The passwords don't match. Please try again!\n\nA jelszavak nem egyeztek meg. Kerlek probald ujra!\x1b[m"
 passfunc
fi
}

finishfunc()
{
chmod a+x /ffp/etc/torrentsend.sh
sed -i "s/googlemail/${email}/g" /ffp/etc/torrentsend.sh
sed -i "s/jelszo/${password}/g" /ffp/etc/torrentsend.sh
killall transmission-daemon
find / -name "settings.json" -print0 | xargs -0 sed -i '' -e 's/\"script\-torrent\-done\-enabled\"\:\ false\,/\"script\-torrent\-done\-enabled\"\:\ true\,/g' -i '' -e 's/\"script\-torrent\-done\-filename\"\:\ \"\"\,/\"script\-torrent\-done\-filename\"\:\ \"\/ffp\/etc\/torrentsend\.sh\"\,/g'
sleep 2
[ -f /ffp/start/transmission.sh ] && /ffp/start/transmission.sh start || /usr/local/zy-pkgs/bin/transmission-daemon -g /usr/local/zy-pkgs/config/Transmission/
clear
}

# start
clear
echo -e "\n------------------------------------------\n"
echo "English: Hello! I'm the installer of Mr Dini's nail and torrentsend. sh mod."
echo -e "I'm going to make some questions regarding your \033[4;31mVALID\x1b[m Gmail account."
echo -e "\n"

echo "Hungarian: Szia! Mr Dini nail es a torrentsend.sh mod telepitoje vagyok."
echo -e "Ahhoz, hogy a torrentsend.sh-t be tudjam allitani fel kell tennem nehany kerdest a \033[4;31mLETEZO\x1b[m Gmail fiokoddal kapcsolatban."
echo -e "\n"

retfunc


