#!/bin/bash
# Project: Twits is developed by Lance Seidman & Cherisse O.
# Powered by: Compulsive Technology <http://www.compulsivetech.biz>
# Project URL: http://www.code.google.com/p/twits
#
# About Twits
# This simple and easy to use script was designed for *NIX Consoles that use
# Bash or have access to using the Bash Scripting Language.
#
# Twitter 0.0.5 SE (Second Edition)
# I don't want to call this 0.0.6 cause Profiles still don't exist but I was
# playing around and I accidently forgot to put in a Username and it went on
# and tried to work anyways. So, I felt I needed to immediately update this
# version and upload it. Sorry for the sloppy coding, it will be better!
############################################################################
# Let's set the version of Twits...
version="0.0.5 SE (Second Editio)"

# Let's Define Twits Required Settings...
twits_url="http://twitter.com/statuses/update.xml" #TWITTER URL TO UPDATE
twits_req1="/usr/bin/curl" #Twits needs CURL to update anything. Must have!

# Twits needs CURL. Let's find it!
if [[ ! -x $twits_req1 ]];
then
  echo "Twits Requirement: You must have CURL Installed..."
  echo "Please install or update CURL Path."
  echo""
  echo "Mandriva Users and Other Distros (If applicable)"
  echo "As root (su enter; Password enter)  type "urpmi curl"."
  echo""
  echo "Alternatively you can obtain cURL Freely from: "
  echo "cURL Homepage: http://curl.haxx.se/download.html"
exit 1
fi

# Twits Welcome Screen
clear
echo "Welcome to Twits!"
echo "-----------------"

# Temp Profile... We will be having "Profiles" eventually. So you don't need
# to constantly type in your User/Pass.
 echo "Welcome! I need your Username and Password for Twitter."

 # Username
 read -p "Username: " -e twits_u
 if [ "$twits_u" = "" ]; then
	 echo "Sorry, I didn't get your Username."
	 read -p "Please type your Username: " -e twits_u
 fi
 # Let's run one more check. I will later on fix this up.
 if [ "$twits_u" = "" ]; then
         echo "I didn't get your Username again."
	 echo "Please run Twits again later. Bye!"
	 exit
# I know this is a Sad excuse to ensure a Username exists, but fine for now.
fi

 # Password
 read -p "Password: " -e twits_p
 if [ "$twits_p" = "" ]; then
	 echo "Sorry, I didn't get your Password."
	 read -p "Please type your Password: " -e twits_p
 fi
 # Let's run one more check. I will later on fix this up.
 if [ "$twits_p" = "" ]; then
	 echo "I didn't get a Password, again."
	 echo "Please run Twits again later. Bye!"
	 exit
 fi

 echo "Thanks, I got your Username as "$twits_u". I will now use this."

CHOICES="Version Status Exit" #We will be using this as our Menu Features.

select cho in $CHOICES; do
if [ "$cho" = "Version" ]; then
	echo "You are using Twits" $version
	echo "To find an update, visit http://code.google.com/p/twits."
elif [ "$cho" = "Status" ]; then
	 read -p "Set Status as: " -e twits_uinput
	 if [ "$twits_uinput" = "" ]; then
		 echo "I didn't get what to set your status update as."
		 read -p "Set Status as: " -e twits_uinput;
	 fi
	 # Yes, we're going to cheat and try again...
	 if [ "$twits_uinput" = "" ]; then
		 echo "Sorry, but I didn't get an update."
		 echo "Please run Twits later when you want to update."
		 exit
	 fi
	 # Now let's send Twitter the update!
	 echo "Ok, I am sending Twitter your Username ($twits_u) with: "
	 echo""
	 echo $twits_uinput
	 echo""
	 echo "Please wait a second...";
         curl --basic --user $twits_u:$twits_p --data status="$twits_uinput" --data source="twits" $twits_url > /dev/null

if [[ "$?" == 0 ]]; then
	 clear
	 echo "Your update has been sent sucessfully..."
	 echo""
	 echo "Press Enter to show the Menu or type a Menu Number."
 else
	 echo""
	 echo "Twits was not able to update your status. Try again."
	 echo""
	 echo "Press Enter to show the Menu or type a Menu Number."
 fi
	elif [ "$cho" = "Exit" ]; then
	
	 clear 
	 echo "Thanks for using Twits!"
	 exit
else
	clear
	echo "Error: That was not a choice. "
	echo "Please type a Menu Number or Press Enter for the Menu"
fi
done

