#!/bin/bash
#Website: http://www.2dan.cc
#IMPORTANT!!!Please Setting the following Values!

# START

		#download config.yml and config it
		cd /root/.flexget/
		wget -O /root/.flexget/config.yml http://www.2dan.cc/download/config.yml

		#modify pass
		#Pass=`awk -F ':' '{print $2}' /root/.config/deluge/auth`
		#sed -i s/"pass:"/"pass: $Pass"/g config.yml
		clear

		read -p "Please enter your CHD RSS url 1: " chdrss1
		read -p "Please enter your CHD RSS url 2: " chdrss2
		read -p "Please enter your HDC RSS url 1: " hdcrss1
		read -p "Please enter your HDC RSS url 2: " hdcrss2
		echo ""
		#modiry rss url and del no define variables
		if [ "$chdrss1" != "" ]
		then
			chdrss1=`echo "$chdrss1" | sed 's@\&@\\\&@g'`
			#modify CHD RSS url1 3 line
			sed -i 3,3s@rss:.*@"rss: $chdrss1\r"@ config.yml
		else
			#del 2-20 line
			sed -i '2,20s/.*//' config.yml
		fi

		if [ "$chdrss2" != "" ]
		then
			chdrss2=`echo "$chdrss2" | sed 's@\&@\\\&@g'`
			#modify CHD RSS url2 22 line
			sed -i 22,22s@rss:.*@"rss: $chdrss2\r"@ config.yml
		else
			#del 21-32 line
			sed -i '21,32s/.*//' config.yml
		fi

		if [ "$hdcrss1" != "" ]
		then
			hdcrss1=`echo "$hdcrss1" | sed 's@\&@\\\&@g'`
			#modify CHD HDC url1 34 line
			sed -i 34,34s@rss:.*@"rss: $hdcrss1\r"@ config.yml
		else
			#del 33-52 line
			sed -i '33,52s/.*//' config.yml
		fi

		if [ "$hdcrss2" != "" ]
		then
			hdcrss2=`echo "$hdcrss2" | sed 's@\&@\\\&@g'`
			#modify CHD HDC url2 54 line
			sed -i 54,54s@rss:.*@"rss: $hdcrss2\r"@ config.yml
		else
			#del 53-64 line
			sed -i '53,64s/.*//' config.yml
		fi

		#del space line
		sed -i '/^$/d' config.yml

		#dos2unix
		sed -i 's/\\r//' config.yml

		echo "Please wait,Script running...";echo "Please wait 5 Seconds ,Script running...";echo "5 .........";sleep 1;echo "4 ........";sleep 1;echo "3 ......";sleep 1;echo "2 ....";sleep 1;echo "1 ...GO";sleep 1;clear
		Pass=`awk -F ':' '{print $2}' /root/.config/deluge/auth`
		Username=`awk -F ':' '{print $1}' /root/.config/deluge/auth`
		sed -i s/"pass:"/"pass: $Pass"/g config.yml
	echo -e "\033[43;31;5m==              Flexget Config over             == \033[0m"
