My code is a mess right now, but what I'm trying to do and I don't know if there is a more elegant way of doing this or not since I'm trying to work on multiple operating systems (Mint and Ubuntu mostly, but I think it'll probably be expanded when I get the core figured out). What I'm trying to do is check for my Ubuntu users if the canonical repository is active and then install the Sun JRE for them. I don't really want to duplicate entries in case they run the script multiple times, so I believe I want to run the statement like so:

-Check if Sun JRE is installed
-If JRE installed, then do nothing
-Else move to next if
-+If -> Check if canonical package with # exists.
Then -> Remove #, apt-get JRE
-+Else -> Check if one exists without the # sign.
+> If it doesn't create one, apt-get JRE
+> if it does, apt get JRE


#Check if Java6 Runtime Environment is installed
	echo "checking if $c is installed" 2>&1
if [[ $(dpkg-query -f'${Status}' --show $c 2>/dev/null) = *\ installed ]]; 
	echo "echo #1 installed" 2>&1
if grep -q "# deb ht*p:// natty partner" /etc/apt/sources.list; 
           sed -i 's\# deb ht*p:// natty partner\\deb ht*p:// natty partner/g' /etc/apt/sources.list
        else echo "echo #2"
I can't figure out how to find and replace the text with what I'm looking for..