#Creating Ringtones
	if [ -d "/var/mobile/Media/RingRing-Ringtones" ];
	then
	echo "--------English--------

Move these files to /var/stash/Ringtones/, if you're running 3.1.3 (3.2.1 on iPad) or lower the Ringtones folder will have some random letters behind it, nevermind that, just put these files in there.

Running RingRing as root will automatically move your ringtones to the right directory. Have fun.

--------Deutsch--------

Verschiebe alle diese Dateien nach /var/stash/Ringtones/, wenn du OS 3.1.3 oder niedriger hast (3.2.1 für iPad) wird die Ringtones directory noch zufällige Buchstaben dahinter haben, ignorier das, pack einfach die Dateien da rein.

Wenn du RingRing mit root-Rechten ausfuehrst wird es alle Ringtones automatisch verschieben. Geniess es." > "/var/mobile/Media/RingRing-Ringtones/What now?.txt"
	chown mobile:mobile "/var/mobile/Media/RingRing-Ringtones/What now?.txt"
	else
	mkdir /var/mobile/Media/RingRing-Ringtones
	chown mobile:mobile /var/mobile/Media/RingRing-Ringtones
	echo "--------English--------

Move these files to /var/stash/Ringtones/, if you're running 3.1.3 (3.2.1 on iPad) or lower the Ringtones folder will have some random letters behind it, nevermind that, just put these files in there.

Running RingRing as root will automatically move your ringtones to the right directory. Have fun.

--------Deutsch--------

Verschiebe alle diese Dateien nach /var/stash/Ringtones/, wenn du OS 3.1.3 oder niedriger hast (3.2.1 für iPad) wird die Ringtones directory noch zufällige Buchstaben dahinter haben, ignorier das, pack einfach die Dateien da rein.

Wenn du RingRing mit root-Rechten ausfuehrst wird es alle Ringtones automatisch verschieben. Geniess es." > "/var/mobile/Media/RingRing-Ringtones/What now?.txt"
	chown mobile:mobile "/var/mobile/Media/RingRing-Ringtones/What now?.txt"
	echo
	fi
	if [ -d /var/mobile/Media/RingRing-Settings ];
	then
	echo
	else
	mkdir /var/mobile/Media/RingRing-Settings /var/mobile/Media/RingRing-Settings/tmp
	chown mobile:mobile /var/mobile/Media/RingRing-Settings /var/mobile/Media/RingRing-Settings/tmp
	fi
	if [ -d "/var/mobile/Media/Old Files" ];
	then
	echo
	else
	mkdir "/var/mobile/Media/Old Files"
	chown mobile:mobile "/var/mobile/Media/Old Files"
	echo
	fi
	if [ -d "/var/mobile/Media/Convert" ];
	then
	echo
	else
	mkdir "/var/mobile/Media/Convert"
	chown mobile:mobile "/var/mobile/Media/Convert"
	echo
	fi
	if [ -d /var/mobile/Media/RingRing-Ringtonestemp ];
	then
	echo
	else
	mkdir /var/mobile/Media/RingRing-Ringtonestemp
	chown mobile:mobile /var/mobile/Media/RingRing-Ringtonestemp
	echo
	fi
somethingnew=0
newdb=0
importedfromipod=0
echo "
Welcome to"
sleep 1
echo "
88888		      
8   8  e  eeeee eeeee  
8eee8e 8  8   8 8   8  
88   8 8e 8e  8 8e     
88   8 88 88  8 88 88  
88   8 88 88  8 88ee8  
		
		88888		      88  
		8   8  e  eeeee eeeee 88 
		8eee8e 8  8   8 8   8 88 
		88   8 8e 8e  8 8e    88 
		88   8 88 88  8 88 88	 
		88   8 88 88  8 88ee8 88
"
sleep 1.5
echo "
Annoy the world with your cool, new ringtone.
Huge props to Stanislaw Pusep for brand new iPod import. 

(www.github.com/creaktive/myTunes)
"
sleep 1
mxtubecontent=$(ls /var/mobile/Media/MxTube)
anothertimecontent=$(ls /var/mobile/Media/Convert)
importedfrommxtube="0"
Current=$(ls "/var/mobile/Media/Convert")


###Annoying ass beginning###
if [ "$(whoami)" = "root" ];
then
echo "Ah, you're root, that's good. RingRing will move your newly converted ringtones automatically!

"
else
	if [ ! -e /var/mobile/Media/RingRing-Settings/annoyingass ];
	then
	read -p "Do you know what a root user is? (y/n) " knowroot
	echo
		if [ "$knowroot" = "y" ];
		then
		read -p "Do you REALLY know what a root user is? It's important to understand what happens after conversion. (y/n) " knowrootr
		echo
			if [ "$knowrootr" = "y" ];
			then
			echo "Alright! I won't bother you anymore. Your converted Ringtones will be in /var/mobile/Media/RingRing-Ringtones/"
			sleep 5
			touch /var/mobile/Media/RingRing-Settings/annoyingass
			chown mobile:mobile /var/mobile/Media/RingRing-Settings/annoyingass
			else
			while true
			do
			read -p "Thought so. Your converted files will be in /var/mobile/Media/RingRing-Ringtones. If you're NOT root you need to move them manually (believe me, if you're root, you know). I suggest using iFile (free trial) from Cydia to move said files to /var/stash/Ringtones. This message won't be displayed again, to make sure you read this, type \"monkey\". " monkey
			echo
				if [ "$monkey" = "monkey" ];
				then
				touch /var/mobile/Media/RingRing-Settings/annoyingass
				chown mobile:mobile /var/mobile/Media/RingRing-Settings/annoyingass
				break
				else
				echo "PAY SOME FUCKING ATTENTION, MORON!"
				sleep 2
				clear
				fi
			done
			fi	
		else
		while true
		do
		read -p "Thought so. Your converted files will be in /var/mobile/Media/RingRing-Ringtones. If you're NOT root you need to move them manually (believe me, if you're root, you know). I suggest using iFile (free trial) from Cydia to move said files to /var/stash/Ringtones. This message won't be displayed again, to make sure you read this, type \"monkey\". " monkey
		echo
			if [ "$monkey" = "monkey" ];
			then
			touch /var/mobile/Media/RingRing-Settings/annoyingass
			chown mobile:mobile /var/mobile/Media/RingRing-Settings/annoyingass
			break
			else
			echo "PAY SOME FUCKING ATTENTION, MORON!"
			sleep 2
			clear
			fi
		done
		fi
	fi
fi
############################
if [ ! -e /var/mobile/Media/RingRing-Settings/RingRingDBnewtype ] && [ -e /var/mobile/Media/RingRing-Settings/tmp/RingRingDB ];
then
echo "




RingRing now uses a completely new database creation type. This is up to 10 times faster. Your old database was invalid and has been deleted. If RingRing is now hanging for more than 10 seconds, please kill your current terminal and restart RingRing. Thanks."
sleep 5
rm -f /var/mobile/Media/RingRing-Settings/tmp/RingRingDB /var/mobile/Media/RingRing-Settings/tmp/timez
rm -fr /var/mobile/Media/RingRing-Settings/tmp/RingRing-DB/
touch /var/mobile/Media/RingRing-Settings/RingRingDBnewtype
chown mobile:mobile /var/mobile/Media/RingRing-Settings/RingRingDBnewtype
chmod 777 /var/mobile/Media/RingRing-Settings/RingRingDBnewtype
fi

function iPodimport () 
{
if [ -e /var/mobile/Media/RingRing-Settings/tmp/RingRingDB ];
then
	if [ ! -e /var/mobile/Media/RingRing-Settings/tmp/timez ];
	then
	read -p "Has your iPod Library changed since you last used RingRing? 
	(Hit \"d\" for \"No, don't ask me the next 3 times\" (y/n/d) " changedlib
		if [ "$changedlib" = "d" ];
		then
		echo 3 > /var/mobile/Media/RingRing-Settings/tmp/timez
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/timez
		changedlib=n
		fi
	else
	expr $(cat /var/mobile/Media/RingRing-Settings/tmp/timez) - 1 > /var/mobile/Media/RingRing-Settings/tmp/timez
	chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/timez
		if [ "$(cat /var/mobile/Media/RingRing-Settings/tmp/timez)" = "0" ];
		then
		rm -f /var/mobile/Media/RingRing-Settings/tmp/timez
		fi
	changedlib=n
	fi
echo
else
read -p "RingRing needs to create it's own database from your iPod Library.
(This only needs to be done once every time you add music to your iPod Library you want to use as a Ringtone)
Do this now? (y/n) " createlib
echo
fi



####
if [ "$createlib" == "y" ] || [ "$changedlib" == "y" ];
then
rm -f /var/mobile/Media/RingRing-Settings/tmp/RingRingDB 2>/dev/null
echo "
Compiling to database...Please wait a minute..."
c=0
MEDIA="/private/var/mobile/Media"
LIBFILE="$MEDIA/iTunes_Control/iTunes/iTunes Library.itlp/Library.itdb"
LOCFILE="$MEDIA/iTunes_Control/iTunes/iTunes Library.itlp/Locations.itdb"
ITFILES="$MEDIA/iTunes_Control/Music"
MYTUNES="$MEDIA/myTunes"


(
sqlite3 -list "$LIBFILE" << SQLITE_END | tr ':?*' '___'
	ATTACH '$LOCFILE' AS loc;
	SELECT '$ITFILES/' || location, title || SUBSTR(location, 9) FROM item LEFT JOIN loc.location ON (pid = item_pid) ORDER BY location ASC;
	DETACH DATABASE loc;
SQLITE_END
) | while read line
do
c=$(expr $c + 1)
clear
echo "
Processed $c files"
	file=$(echo $line | cut -d '|' -f1 | sed 's_/private__g')
	name=$(echo $line | cut -d '|' -f2 | cut -d '.' -f1)
echo "$file
$name" >> /var/mobile/Media/RingRing-Settings/tmp/RingRingDB
done
fi

###Actual import###
while true
do
read -p "Enter a title or a part of it to import: " titleimport
echo
esetitle=$(grep -i -n "$titleimport" /var/mobile/Media/RingRing-Settings/tmp/RingRingDB | grep -v "/var/mobile/Media/iTunes_Control/*" | tr -d '\v' | tr -d '\t' | tr -d '\a')
echo "$esetitle"
echo "$esetitle" > /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle
echo "" >> /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle
chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle
if [ "$esetitle" != "" ];
then
thatcount=$(wc -l /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle | cut -d ' ' -f1)
thatdacount=$(expr $thatcount ">" 2)
	if [ "$thatdacount"  = "1" ];
	then
	echo "
It seems multiple files have been found."
	read -p "Enter one of the numbers to choose the specific file or, if the file you're looking for is not listed, type \"c\" to choose again: " nrorc
	echo
		if [ "$nrorc"  != "c" ];
		then
		while read thatfile
		do
		numba=$(echo "$thatfile" | cut -d ':' -f1)
		secondpart=$(echo "$thatfile" | cut -d ':' -f2)
			if [ "$nrorc"  = "$numba" ];
			then
			titleinipod=$(expr $numba - 1)
			actualtitle=$(head -$titleinipod /var/mobile/Media/RingRing-Settings/tmp/RingRingDB | tail -1)
				if [ "$actualtitle"  != "" ];
				then
				cp "$actualtitle" "/var/mobile/Media/Convert/"
				break
				fi
			fi
		done < /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle
		####here rename after read
			if [ "$secondpart"  != "" ];
			then
			datbasename=$(basename "$actualtitle")
			if [ ! -e /var/mobile/Media/RingRing-Settings/titlefromnameoff ];
			then
			read -p "Rename file yourself or name it \"$secondpart\"? ([s]elf/[t]itle) " selftitle
			else
			selftitle=s
			fi
				if [ "$selftitle"  = "s" ];
				then
				read -p "New title: " newtitle
					if [ "$newtitle" != "$databasename" ];
					then
					mv "/var/mobile/Media/Convert/$datbasename" "/var/mobile/Media/Convert/$newtitle.$(echo $actualtitle | cut -d '.' -f2)"
					fi
				fi
				if [ "$selftitle"  = "t" ];
				then
				mv "/var/mobile/Media/Convert/$datbasename" "/var/mobile/Media/Convert/$secondpart.$(echo $actualtitle | cut -d '.' -f2)"
				fi
			fi
		fi	
	else
	nrindb=$(grep -n -i "$titleimport" /var/mobile/Media/RingRing-Settings/tmp/RingRingDB | cut -d ':' -f1)
	titleinipod=$(expr $nrindb - 1)
	actualtitle=$(head -$titleinipod /var/mobile/Media/RingRing-Settings/tmp/RingRingDB | tail -1)
	#if [ "$actualtitle"  = "" ];
	#then
	#titleinipod=$(expr $nrindb - 2)
	#fi
	cp "$actualtitle" /var/mobile/Media/Convert/
	datbasename=$(basename "${actualtitle}")
	if [ ! -e /var/mobile/Media/RingRing-Settings/titlefromnameoff ];
	then
	read -p "Rename file yourself or name it \"$(cat /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle | head -1 | cut -d ':' -f2)\"? ([s]elf/[t]itle) " selftitle
	else
	selftitle=s
	fi
		if [ "$selftitle"  = "s" ];
		then
		read -p "New title: " newtitle
			if [ "$newtitle" != "$databasename" ];
			then
			newtitle2=$(ls /var/mobile/Media/Convert/$databasename*)
			mv "/var/mobile/Media/Convert/$newtitle2" "/var/mobile/Media/Convert/$newtitle"
			fi
		fi
		if [ "$selftitle"  = "t" ];
		then
		newtitle3=$(ls /var/mobile/Media/Convert/$databasename*)
		mv "/var/mobile/Media/Convert/$datbasename" "/var/mobile/Media/Convert/$(cat /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle | head -1 | cut -d ':' -f2).$(echo $newtitle3 | cut -d '.' -f2)"
		fi
	fi
fi
rm -f /var/mobile/Media/RingRing-Settings/tmp/ringring.esetitle
if [ "$(ls /var/mobile/Media/Convert/)" != "" ];
then
read -p "
Import another song? (y/n) " importanother
	if [ "$importanother" = "n" ];
	then
	echo
	break
	fi
	if [ "$importanother" = "y" ];
	then
	echo "OK!
	"
	fi
fi
done
####################
}


###mxsafety
if [ ! -e /var/mobile/Media/RingRing-Settings/mxtubesafety ];
then
	if [ -e /var/mobile/Media/RingRing-Settings/mxtubeimported ] || [ -e /var/mobile/Media/FFaac-Settings/mxtubeimported ];
	then
	find /var/mobile/Media/Convert -type f | while read i
	do
	mv "$i" /var/mobile/Media/MxTube
	done
		if [ -e /var/mobile/Media/importedvideosfrommxtube ];
		then
		find /var/mobile/Media/importedvideosfrommxtube -type f | while read i
		do
		mv "$i" /var/mobile/Media/MxTube
		done
		rmdir /var/mobile/Media/importedvideosfrommxtube
		fi
	rm -f /var/mobile/Media/RingRing-Settings/mxtubeimported
	rm -f /var/mobile/Media/FFaac-Settings/mxtubeimported
	echo "!!!!!!!!!!!!!!!
It seems your last conversion didn't work out that well. RingRing moved the contents of /var/mobile/Media/Convert into /var/mobile/Media/MxTube for safety reasons. To disable this feature close RingRing and open the RingRing-Settings by typing \"setringring\".
!!!!!!!!!!!!!!!
	"
	fi
fi

while true
do
if [ "$anothertimecontent" = "" ];
then
	if [ -e /var/mobile/Media/MxTube  ];
	then	
	read -p "Do you want to import videos from MxTube or your iPod Library? ([m]xtube/[i]pod) " import
	echo
		
			if [ "$import" = "m" ];
			then
			importedfrommxtube="1"
			read -p "Import all videos or just specific ones? ([a]ll / [s]pecific) " importallspecific
			echo
				if [ "$importallspecific" = "a" ];
				then
				mkdir /var/mobile/Media/importedvideosfrommxtube
				chown mobile:mobile /var/mobile/Media/importedvideosfrommxtube
					if [ -e "/var/mobile/Media/thms" ];
					then
					echo "Folder thms exists"
					else
					mkdir /var/mobile/Media/thms
					echo "Folder thms created"
					fi
				find /var/mobile/Media/MxTube -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/thms
				done
				#insert downloading video here
					if [ "$mxtubecontent" = "" ];
					then
					echo "Couldn't import videos from MxTube. Nothing to import.
					"
					exit
					else
					if [ -e /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing ];
					then
					mkdir /var/mobile/Media/mxtmp
					while read line
					do
						if [ -e /var/mobile/Media/MxTube/"$line" ];
						then
						mv /var/mobile/Media/MxTube/"$line" /var/mobile/Media/mxtmp/
						fi
					done < /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing
					fi
					find /var/mobile/Media/MxTube -type f | while read Vid
					do
					tmpage=$(echo "${Vid}" | cut -d '/' -f6)
						if [ "$tmpage" = "tmp" ];
						then
						echo "RingRing will not import downloading files. Not importing ${Vid}.
Run RingRing again when your download is finished.
"
						else
						mv "${Vid}" /var/mobile/Media/Convert/
						fi
					done
					find /var/mobile/Media/mxtmp -type f | while read Vid
					do
					mv "$Vid" /var/mobile/Media/MxTube/
					done
					rmdir /var/mobile/Media/mxtmp
					echo "All videos imported
					"
					fi 
				find /var/mobile/Media/thms -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/MxTube
				done
				fi
	
				if [ "$importallspecific" = "s" ];
				then
					if [ -e "/var/mobile/Media/thms" ];
					then
					echo "Folder thms exists"
					else
					mkdir /var/mobile/Media/thms
					fi
				find /var/mobile/Media/MxTube -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/thms
				done
				mkdir /var/mobile/Media/importedvideosfrommxtube
				find /var/mobile/Media/MxTube -type f | while read Vid
				do
				tmpage=$(echo "${Vid}" | cut -d '/' -f6)
					if [ "$tmpage" = "tmp" ];
					then
					echo "RingRing will not import downloading files. Not importing ${Vid}.
Run RingRing again when your download is finished and you want to convert that new file."
					else
					mv "${Vid}" /var/mobile/Media/importedvideosfrommxtube
					fi
				done
				fi
				#From here     
				if [ -e /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing ];
				then
				while read line
				do
					if [ -e /var/mobile/Media/importedvideosfrommxtube/"$line" ];
					then
					mv /var/mobile/Media/importedvideosfrommxtube/"$line" /var/mobile/Media/MxTube/
					fi
				done < /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing
				fi
				Current=$(ls /var/mobile/Media/importedvideosfrommxtube)
				while true
				do
				echo "$Current" > /var/mobile/Media/RingRing-Settings/tmp/ringring.mxtubespecific.tmp
				chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/ringring.mxtubespecific.tmp
				Currentfile=$(head -1 /var/mobile/Media/RingRing-Settings/tmp/ringring.mxtubespecific.tmp)
					if [ "$Current" != "" ];
					then
					chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/ringring.mxtubespecific.tmp
						read -p "Import $(echo $Currentfile | cut -d '-' -f1)? ([y]es/[n]o/[s]tart ripping/no, [d]on't ask me again) " importcurrent
						if [ "$importcurrent" = "y" ];
						then
						mv /var/mobile/Media/importedvideosfrommxtube/"$Currentfile" /var/mobile/Media/Convert
						echo "$Currentfile imported
						"
						echo "$Current" > /var/mobile/Media/RingRing-Settings/tmp/ringring.mxtubespecific.tmp
						chown mobile:mobile /var/mobile/Media/ringring.mxtubespecific.tmp
						fi
						if [ "$importcurrent" = "d" ];
						then
						echo "$Currentfile" >> /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing
						chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/DontAskMeRingRing
						mv "/var/mobile/Media/importedvideosfrommxtube/$Currentfile" /var/mobile/Media/MxTube
						echo "
---
$Currentfile not imported and you won't be asked again, to be asked again, delete the file DontAskMeRingRing in /var/mobile/Media/ using iFile, ssh or iPhone Browser
---
						"
						fi
						if [ "$importcurrent" = "n" ];
						then
						mv /var/mobile/Media/importedvideosfrommxtube/"$Currentfile" /var/mobile/Media/MxTube
						echo "$Currentfile not imported
						"
						fi
						if [ "$importcurrent" = "s" ];
						then
						Current=""
						find /var/mobile/Media/importedvideosfrommxtube -type f | while read Vid
						do
						mv "${Vid}" /var/mobile/Media/MxTube
						done
						echo
						else
							if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
							then
							Current=$(ls /var/mobile/Media/importedvideosfrommxtube)
							echo
							fi
						fi	
					else
					if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
					then
					find /var/mobile/Media/importedvideosfrommxtube/ -type f | while read Vid
					do
					mv "$Vid" /var/mobile/Media/MxTube
					done
					fi
					contentafterimport=$(ls /var/mobile/Media/Convert/)							       
						if [ "$contentafterimport" = "" ];
						then
							if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
							then
							rm -f /var/mobile/Media/ringring.mxtubespecific.tmp
							rmdir /var/mobile/Media/importedvideosfrommxtube/
							echo "Nothing imported
Your Convert folder is still empty, maybe you should try to filling something in first."
							exit
							fi
						fi
					if [ -e /var/mobile/Media/importedvideosfrommxtube/ ];
					then	
					rm -f /var/mobile/Media/ringring.mxtubespecific.tmp
					rmdir /var/mobile/Media/importedvideosfrommxtube/
					fi
					break
					fi
				done
				#till here
				find /var/mobile/Media/thms -type f -name "*.THM" | while read thm
				do
				mv "${thm}" /var/mobile/Media/MxTube
				done 
				rmdir /var/mobile/Media/thms
			fi
			###Import from iPod###
			if [ "$import" = "i" ];
			then
			importedfromipod=1
			iPodimport
			fi
		else
		###Import from iPod if MxTube doesn't exist###
		read -p "Import from iPod Library? (y/n) " ipodimport
			if [ "$ipodimport" = "y" ];
			then
			importedfromipod=1
			iPodimport
			fi
				if [ $(ls /var/mobile/Media/Convert/) = "" ];
				then
				echo "
Nothing imported. Import something manually or start RingRing again."
				exit
				fi
		fi
fi

if [ -e /var/mobile/Media/RingRing-Settings/alwaysmakering ];
then
Createringtone=y
echo
else
read -p "Do you want to create ringtones now? ([y]es/[n]o/[c]hoose again) " Createringtone
echo
fi

if [ "$Createringtone" = "y" ];
then
createring="1"
Current=$(ls "/var/mobile/Media/Convert")

###audio quality
	if [ ! -e /var/mobile/Media/RingRing-Settings/quality ];
	then
	read -p "

High or normal quality audio? (high will take longer, default is high) ([h]igh/[n]ormal) " hilow
	else
	hilow=$(cat /var/mobile/Media/RingRing-Settings/quality)
	fi

if [ "$hilow" = "h" ];
then
abrate="192k"
else
abrate="128k"
fi
#################


if [ ! -e "/var/mobile/Media/RingRing-Settings/cuttingoff" ];
then
read -p "Do you want to cut some of the files? (y/n) " cutconv
else
cutconv=n
fi
echo
###custom start
if [ "$cutconv" = "y" ];
then
numbr=1
mkdir /var/mobile/Media/RingRing-Settings/tmp/custmcut
chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/custmcut
find /var/mobile/Media/Convert -type f | while read i
do
mv "$i" /var/mobile/Media/RingRing-Settings/tmp/custmcut
done
while true
do
	if [ "$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut)" != "" ];
	newtitle2=$(ls /var/mobile/Media/Convert/$databasename)
	then
		if [ "$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | wc -l)" != "$numbr" ];
		then
		read -p "How many seconds do you want to cut off of the beginning of $(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1): " strt
		####Here audio preview
		first=$(expr "$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1 | wc -m)" - 3)
		second="$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1 | wc -m)"
		ending="$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1 | cut -c$first-$second)"
		nohup ffmpeg -i "/var/mobile/Media/RingRing-Settings/tmp/custmcut/$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1)" -vn -acodec copy -ss $strt -t "$(expr $strt + 3)" /var/mobile/Media/PreviewRingRing.$ending 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Your file will start here:
		"
		nohup play /var/mobile/Media/PreviewRingRing.$ending 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewRingRing.$ending
		read -p "Is that ok? (y/n) " oklikethis
			if [ "$oklikethis" = "y" ];
			then
			echo "$strt" >> /var/mobile/Media/RingRing-Settings/tmp/customstart
			chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/customstart
			numbr=$(expr $numbr + 1)
			fi
		else
		read -p "How many seconds do you want to cut off of the beginning of $(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1): " strt
		####Here audio preview
		first=$(expr "$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1 | wc -m)" - 3)
		second="$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1 | wc -m)"
		ending="$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1 | cut -c$first-$second)"
		nohup ffmpeg -i "/var/mobile/Media/RingRing-Settings/tmp/custmcut/$(ls /var/mobile/Media/RingRing-Settings/tmp/custmcut | head -$numbr | tail -1)" -vn -acodec copy -ss $strt -t "$(expr $strt + 3)" /var/mobile/Media/PreviewRingRing.$ending 0>/dev/null 1>/dev/null 2>/dev/null
		echo "Your file will start here:
		"
		nohup play /var/mobile/Media/PreviewRingRing.$ending 1>/dev/null 2>/dev/null
		rm -f /var/mobile/Media/PreviewRingRing.$ending
		read -p "Is that ok? (y/n) " oklikethis
			if [ "$oklikethis" = "y" ];
			then
			echo "$strt" >> /var/mobile/Media/RingRing-Settings/tmp/customstart
			chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/customstart
			find /var/mobile/Media/RingRing-Settings/tmp/custmcut -type f | while read file
			do
			mv "$file" /var/mobile/Media/Convert/
			done
			rmdir /var/mobile/Media/RingRing-Settings/tmp/custmcut
			break
			fi
		fi
	fi
done
fi
###/custom start



while true
do
if [ ! -e /var/mobile/Media/RingRing-Settings/defaultlength ];
then
read -p "Convert full songs to ringtones, 60 seconds of them or define a custom length?
([f]ull/[6]0/[c]ustom) " makefullsec
else
makefullsec=$(cat /var/mobile/Media/RingRing-Settings/defaultlength)
fi
echo
if [ "$makefullsec" = "6" ] || [ "$makefullsec" = "f" ];
then
break
fi
####custom -t length
if [ "$makefullsec" = "c" ];
then
numbr=1
mkdir /var/mobile/Media/RingRing-Settings/tmp/custml
chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/custml
find /var/mobile/Media/Convert -type f | while read i
do
mv "$i" /var/mobile/Media/RingRing-Settings/tmp/custml
done
while true
do
	if [ "$(ls /var/mobile/Media/RingRing-Settings/tmp/custml)" != "" ];
	then
		if [ "$(ls /var/mobile/Media/RingRing-Settings/tmp/custml | wc -l)" != "$numbr" ];
		then
		read -p "Length in seconds for $(ls /var/mobile/Media/RingRing-Settings/tmp/custml | head -$numbr | tail -1): " length
		echo "$length" >> /var/mobile/Media/RingRing-Settings/tmp/customlength
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/customlength
		numbr=$(expr $numbr + 1)
		else
		read -p "Length in seconds for $(ls /var/mobile/Media/RingRing-Settings/tmp/custml | head -$numbr | tail -1): " length
		echo "$length" >> /var/mobile/Media/RingRing-Settings/tmp/customlength
		chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/customlength
		find /var/mobile/Media/RingRing-Settings/tmp/custml -type f | while read file
		do
		mv "$file" /var/mobile/Media/Convert/
		done
		rmdir /var/mobile/Media/RingRing-Settings/tmp/custml
		break
		fi
	fi
done
break
fi
done
###/custom -t length

if [ "$cutconv" = "y" ];
then
numbr=1
numbercut=1
mkdir /var/mobile/Media/RingRing-Settings/tmp/cutconvringring
chown mobile:mobile /var/mobile/Media/RingRing-Settings/tmp/cutconvringring
find /var/mobile/Media/Convert -type f | while read File
do
mv "$File" /var/mobile/Media/RingRing-Settings/tmp/cutconvringring
done
while true
do
sec=$(head -$numbercut /var/mobile/Media/RingRing-Settings/tmp/customstart | tail -1) 
	if [ "$(ls /var/mobile/Media/RingRing-Settings/tmp/cutconvringring)" != "" ];
	then
	File=$(find /var/mobile/Media/RingRing-Settings/tmp/cutconvringring -type f | head -1)
		if [ $importedfrommxtube = "1" ];
		then
		ffile=$(echo ${File} | cut -d '/' -f7 | cut -d '.' -f1 | cut -d '-' -f1)
		else
		ffile=$(echo ${File} | cut -d '/' -f6 | cut -d '.' -f1)
		fi
	Basename="$(basename "${File}")"
		if [ "$importedfrommxtube" = "1" ];
		then
		line1=$(echo "${Basename}" | cut -d '.' -f1 | cut -d '-' -f1)
		else
		line1=$(echo "${Basename}" | cut -d '.' -f1)
		fi
		if [ "$(echo $File | cut -c$(expr $(echo $File | wc -m) - 3)-$(echo $File | wc -m) | tr '[a-z]' '[A-Z]' )" != "M4A" ];
		then
			if [ "$makefullsec" = "f" ];
			then
			ffmpeg -i "$File" -ss "$sec" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
			wait $!
			fi
			if [ "$makefullsec" = "c" ];
			then
			length=$(head -$numbr /var/mobile/Media/RingRing-Settings/tmp/customlength | tail -1) 
			ffmpeg -i "$File" -ss "$sec" -t "$length" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
			wait $!
			numbr=$(expr $numbr + 1)
			fi
			if [ "$makefullsec" = "6" ];
			then
			ffmpeg -i "$File" -ss "$sec" -t 60 -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
			wait $!
			fi
		else
			if [ "$makefullsec" = "f" ];
			then
			ffmpeg -i "$File" -acodec copy -ss "$sec" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
			wait $!
			fi
			if [ "$makefullsec" = "c" ];
			then
			length=$(head -$numbr /var/mobile/Media/RingRing-Settings/tmp/customlength | tail -1) 
			ffmpeg -i "$File" -acodec copy -ss "$sec" -t "$length" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
			wait $!
			numbr=$(expr $numbr + 1)
			fi
			if [ "$makefullsec" = "6" ];
			then
			ffmpeg -i "$File" -acodec copy -ss "$sec" -t 60 -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
			wait $!
			fi
		fi
	numbercut=$(expr $numbercut + 1)
	mv "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4r"
	chown mobile:mobile "/var/mobile/Media/RingRing-Ringtones/${line1}.m4r"
		if [ $importedfrommxtube = "0" ];
		then
			if [ ! -e /var/mobile/Media/RingRing-Settings/deleteall ];
			then
			rm -f "$File"
			else
			mv "$File" "/var/mobile/Media/Old Files/"
			fi
		else
		mv "$File" "/var/mobile/Media/MxTube/"
		fi
#####checken  ob es mit mehreren files geht!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	else
	break
	fi
done
fi
if [ -e /var/mobile/Media/RingRing-Settings/tmp/cutconvringring ];
then
rmdir /var/mobile/Media/RingRing-Settings/tmp/cutconvringring
fi
if [ "$cutconv" = "n" ];
then
numbr=1
while true
do
if [ "$(ls /var/mobile/Media/Convert)" != "" ];
then
find /var/mobile/Media/Convert -type f | while read File
do
Basename="$(basename "${File}")"
	if [ $importedfrommxtube = "1" ];
	then
	line1=$(echo "${Basename}" | cut -d '.' -f1 | cut -d '-' -f1)
	else
	line1=$(echo "${Basename}" | cut -d '.' -f1)
	fi
	if [ "$(echo $File | cut -c$(expr $(echo $File | wc -m) - 3)-$(echo $File | wc -m) | tr '[a-z]' '[A-Z]' )" != "M4A" ];
	then
		if [ "$makefullsec" = "f" ];
		then
		ffmpeg -i "$File" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
		wait $!
		fi
		if [ "$makefullsec" = "c" ];
		then
		length=$(head -$numbr /var/mobile/Media/RingRing-Settings/tmp/customlength | tail -1)
		ffmpeg -i "$File" -t "$length" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
		wait $!
		numbr=$(expr $numbr + 1)
		fi
		if [ "$makefullsec" = "6" ];
		then
		ffmpeg -i "$File" -t 60 -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
		wait $!
		fi
	else
		if [ "$makefullsec" = "f" ];
		then
		ffmpeg -i "$File" -acodec copy -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
		wait $!
		fi
		if [ "$makefullsec" = "c" ];
		then
		length=$(head -$numbr /var/mobile/Media/RingRing-Settings/tmp/customlength | tail -1)
		ffmpeg -i "$File" -acodec copy -t "$length" -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
		wait $!
		numbr=$(expr $numbr + 1)
		fi
		if [ "$makefullsec" = "6" ];
		then
		ffmpeg -i "$File" -acodec copy -t 60 -ab "$abrate" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" &
		wait $!
		fi
	fi
mv "/var/mobile/Media/RingRing-Ringtones/${line1}.m4a" "/var/mobile/Media/RingRing-Ringtones/${line1}.m4r"
chown mobile:mobile "/var/mobile/Media/RingRing-Ringtones/${line1}.m4r"
	if [ $importedfrommxtube = "0" ];
	then
			if [ ! -e /var/mobile/Media/RingRing-Settings/deleteall ];
			then
			rm -f "$File"
			else
			mv "$File" "/var/mobile/Media/Old Files/"
			fi
	else
	mv "$File" "/var/mobile/Media/MxTube/"
	fi
done
else
break
fi
done
	if [ ! -e /var/mobile/Media/RingRing-Settings/sound ];
	then
	play /System/Library/Audio/UISounds/sms-received1.caf &
	fi
	if [ ! -e /var/mobile/Media/RingRing-Settings/mxtubesafety ];
	then
		if [ -e /var/mobile/Media/RingRing-Settings/mxtubeimported ] || [ -e /var/mobile/Media/FFaac-Settings/mxtubeimported ];
		then
		rm -f /var/mobile/Media/FFaac-Settings/mxtubeimported
		rm -f /var/mobile/Media/RingRing-Settings/mxtubeimported
		fi
	fi
fi
break
fi


if [ -e /var/mobile/DonationRingRing ];
then
echo
else
read -p "
A lot of work went into RingRing. (Especially into iPod import)
A donation would greatly be appreciated. Donate now? (y/n) " donate

	if [ "$donate" = "y" ];
	then
	uiopen "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=679V7DHFCR8V6"
	echo "Donated" > /var/mobile/DonationRingRing
	chown mobile:mobile /var/mobile/DonationRingRing
	else
	
	echo "
	Maybe next time ;)
	This won't be asked again. If you reconsider, go to RingRing's Cydia page."
	sleep 3
	echo "Not donated, meh, at least he used it :)" > /var/mobile/DonationRingRing
	chown mobile:mobile /var/mobile/DonationRingRing
	fi
fi


if [ "$importedfrommxtube" = "1" ];
then
Outputfolder="MxTube"
else
Outputfolder="Old Files"
fi

if [ "$Createringtone" = "n" ];
then
break
fi

if [ "$Createringtone" = "c" ];
then
find /var/mobile/Media/Convert -type f | while read File
do
file=$(basename "$File")
mv "$File" "/var/mobile/Media/$Outputfolder/"
	if [ "$importedfromipod" = "1" ];
	then
	rm -f "/var/mobile/Media/$Outputfolder/$file"
	fi
done
fi
done


Ringdirectory=$(ls /var/stash/ | grep Ringtones)
whoami > /var/mobile/whom 
chown mobile:mobile /var/mobile/whom
User=$(cat /var/mobile/whom)

if [ -e /var/mobile/Media/RingRing-Settings/tmp/customlength ];
then
rm -f /var/mobile/Media/RingRing-Settings/tmp/customlength
fi

if [ -e /var/mobile/Media/RingRing-Settings/tmp/customstart ];
then
rm -f /var/mobile/Media/RingRing-Settings/tmp/customstart
fi


if [ "$createring" = "1" ];
then
if [ "$User" = "mobile" ];
then
echo "-----------
!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!!
RingRing! is intended to run with low permissions and therefore cannot move your newly created ringtones to the respective directory.
To do this yourself, move the contents of /var/mobile/Media/RingRing-Ringtones/ to /Library/Ringtones. I recommend using iFile from Cydia. Have fun.
!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!!
-----------"
fi

if [ "$User" = "root" ];
then
find /var/mobile/Media/RingRing-Ringtones/ -type f -name "*.m4r" | while read File
do
foo=$(basename "${File}" | cut -d '.' -f1)
mv "${File}" "/Library/Ringtones/$foo.m4r"
done
echo "
-------------
Ringtones moved. You can now set them as alarms or when someone is calling you.
-------------"
fi
fi

if [ -e /var/mobile/Media/RingRing-Ringtonestemp ];
then
rmdir /var/mobile/Media/RingRing-Ringtonestemp
fi

if [ -e /var/mobile/Media/RingRing-Settings/tmp/ls.ringring.tmp ];
then
rm -f /var/mobile/Media/RingRing-Settings/tmp/ls.ringring.tmp
fi

#Mail
if [ ! -e "/var/mobile/Media/RingRing-Settings/mailoff" ];
then
read -p "
Would you like to send me a mail? Crash reports, other bugs, questions or just saying hi? (y/n) " sendmail
else
sendmail=n
fi

if [ "$sendmail" = "y" ];
then
uiopen "mailto:Schweinsfuss.Nasenbeutler@googlemail.com?subject=RingRing"
else
#Linking to FFaac
	if [ ! -e /usr/bin/ffaac ];
	then
	if [ ! -e "/var/mobile/Media/RingRing-Settings/otheroff" ];
	then
		read -p "
	Would you like to take a look at my other great app: FFaac?
	It extracts audio from YouTube videos within seconds.
	100% confirmed functionality (y/n) " openffaac
	
		if [ "$openffaac" = "y" ];
		then
		uiopen "cydia:///package/com.pigfoot.ffaac"
		fi
	fi
	fi
fi

echo "Bye."


