Eclipse

July 16, 2010

I’m sure that you have heard of Eclise.  If not then all you need to know is that it is a very popular (and for a good reason) IDE mainly for Java.  However, it does also have C/C++ support, but it is mostly used with Java.

As you know, I’m not big on programming in Java.  But I recently purchased a Nexus One phone, and the IEEE SECon got me a little interested in Android application development.  I don’t plan for anything I make to be widely distributed, but rather just for personal use.  In any case, I would still need a place to create my programs.  Sure this can be done with a normal text editor and the command line but why bother with that when Eclipse and the Android SDK make it so simple?

I’m going to talk about getting and installing Eclipse onto you system (which I will assume to be Ubuntu).  Sure you could just run sudo apt-get install eclipse but this way assumes that you are using the OpenJDK version of Java and not Sun’s. So if you are using SunJava, which it seems most people do, then this how-to is for you.

First head over to the Eclipse site and download the IDE. To find the site just use Google and then do some reading and clicking, so there is no need for me to post a link. If you can’t get past this step then you probably shouldn’t be thinking about using Eclipse.

Next we will open the package you have just downloaded and then move it to the /opt directory. To do this just run the following sequence of commands:

tar xzf <filename>
sudo mv eclipse /opt/eclipse
cd /opt
sudo chown -R root:root eclipse
sudo chmod -R +r eclipse
sudo chmod +x `sudo find eclipse -type d`

The chown command changes the owner of a file/directory, if you have been reading this blog then you should be able to figure out what the other commands do.

Next we will add eclipse executable to your path.

sudo touch /usr/bin/eclipse
sudo chmod 755 /usr/bin/eclipse
sudoedit /usr/bin/eclipse

then add this to the file

#!/bin/sh
#export MOZILLA_FIVE_HOME="/usr/lib/mozilla/"
export ECLIPSE_HOME="/opt/eclipse"

$ECLIPSE_HOME/eclipse $*

I’m not all to sure exactly what the touch command does but you can look that up yourself (either online or with man).

Finally, the “most important” part; creating a GNOME-menu icon. This is something that would normally be done when you use the apt-get method.


cd /usr/share/applications
sudo nano eclipse.desktop

And enter the following into the created file;

[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Eclipse IDE
Exec=eclipse
Icon=/opt/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true

All the stuff entered into the file makes perfect sense, so if you ever wanted to make a menu item for any other program you now know how.

All of these steps can be found at http://flurdy.com/docs/eclipse/install.html.

Advertisements

Acrobat Reader

March 25, 2010

Well long (though interesting) story short I had to reinstall Ubuntu (still version 8.04).  I’ll give you th long story soon enough, but first here is something that might be useful.

At first I was fine with using Evince for viewing PDF files but there are just a few things that Acrobat does that I like.  Overall I still prefer Evince since it is much faster at loading and not “bloated” with features that I won’t ever use.  Regardless I still needed to install Acrobat.

Normally you would be able to just run sudo apt-get install acroread, but for some reason acroread is no longer in the Ubuntu list of provided programs.  So I had to do some work on Google.  Sure finding Acrobat was easy but I needed to make sure that it would work on an 64bit OS.  As usual, a pain in the ass.

I won’t go into all that I tried, I’ll just tell you what worked.  First go to this site http://get.adobe.com/reader/ and choose the appropriate OS (Linux) and the .bin file.  Apparently choosing the x86 version is fine.  Assuming that it was downloaded to your desktop run chmod u+x *.bin, where * is whatever the file is called.  Then finally run sudo ./*.bin.  Make sure to add the sudo or you’ll run into some issues (I’ll let you see what kind).  During the install when asked where to store the file(s) make sure to pick a location that is in your PATH.  I chose /usr/bin but I suppose that any location will work.

Now you can run acroread and be on your way.


Linux File System: Part 2

September 7, 2009

This is a continuation from part 1, so you might want to read that first in order to get a general idea of what’s going on.  That is  of course you are a somewhat experienced Linux user.

In this part of the series I will be discussing the following directories/partitions: /bin /boot /dev /etc /home.

/home

I will start by discussing the partition that is most familiar to most new users, /home.  First you should know that Linux, unlike Windows, was originally designed to be a multi-user system.  Thus in the home directory you will find a set of directories, one for each user.  Every user (along with the system administrator) can access their directory by entering cd /home/[user name].  Each user’s home directory contains their own personal files in addition to their personal settings for programs.

/bin

This directory contains programs that are able to be used by the system(Linux), the administrator and non-privileged users. Examples of such programs would include cp, mv, rm, and other such commands/programs. In addition to programs it also contains the shells, like bash, csh, sh, and so on. Just as a side note, you should be aware that there is also a /usr/bin which also contains programs that the system, administrator, and non-privileged users can use. However, unlike those in /bin, these programs are not essential-meaning that you can do without them and not have any real problems. Some programs that are located in my /usr/bin are: g++, apt-get, javac, whoami, and acroread. Sure it would be a pain not having these programs, but the system would still run perfectly fine.

/boot

All of the system startup files and the kernel (vmlinuz) are located in this directory (also I would suggest reading the Wikipedia article on System.map, which is also stored in this directory). On Ubuntu, this is also where Grub (GRand Unified Boot loader) stored.  For those of you that are dual-booting here is something that might interest you.  When you start up your system you will normally see a list asking you which OS you want to enter.  This list normally contains the various Linux kernels along with Windows (or whatever OS you have on your computer).  If you would like to change the order these elements are presented along with other properties here is what you need to do.  cd /boot/grub then sudo gedit menu.lst (actually you can use whatever text editor you desire)  The file is pretty well documented so editing it is pretty straight forward.

/dev

All computers have hardware, and this is where the information on all your hardware is stored. Once again let me reiterate that EVERYTHING is a file (or directory but I don’t distinguish between them in this case). If you list all of the files here, you should find sda, sda1, sda2… which represent the partitions of you master drive (instead of sda you might have hda depending on your drive type). Also you might see a files /dev/cdrom and /dev/fd or (/dev/fd0). These represent your CDROM and floppy drive (if you have them that is, because really who still has a floppy drive?). Here is something “cool” that you should all try (don’t worry it won’t damage your computer. I have done it on mine if that makes you feel any better). The file /dev/dsp represents your speakers (or whatever sound output device you have). So anything written to this file will be redirected to your speakers and played for you to hear. Thus if you run cat ~/funfile.java > /dev/dsp you will hear what funfile.java “sounds like”, assuming that you have a file called funfile.java in your home directory. Pretty cool hu?

/etc

Finally, I will slightly discuss the /etc directory.  One overview that I read, described this directory as the Linux equivalent to the Control Panel in Windows.  Basically most of the important configuration files are located here.  There are a lot of important files here that have to do with system start up (one being /etc/rc.d which contains the startup scripts for the system). It is always a good idea to back up your system, but this file more than any other I would say should really be backed up. Doing so would save you a lot of headache later when you have to reconfigure your settings, because you reinstalled your system or somehow managed to lose your installation.

Well that’s all there is for part 2. Hope you will stick around for part 3.


Choosing the Right $PATH

August 23, 2009

Sorry for the long delay, but I have been busy with getting ready for school again and moving into my new apartment.

This is in some ways a continuation of my post Changing Modes.  As pointed out in one of the comments (thanks to Miorel) some people might wonder why you would have to type ./hello_world instead of just hello_world in order to execute the Perl script.  Well I though about this for a second and thought, “Well to run a script that isn’t one implemented by the OS you must place ./ before it.  This tells the OS that you are trying to execute a file.”  For example, if you want to run Firefox you just need to type firefox and not ./firefox.  If you are curious-and you should be-and enter ./firefox into the terminal you should get the following message, “bash: ./firefox: No such file or directory” (unless you for some reason have a file or directory called ./firefox, but why would you?).

Though that might answer might be good enough for some, I wanted to know why this was so, and if it was possible to change it so that you would only need to type hello_world (and not ./hello_world).  This is where $PATH comes into play.  I am going to try my best to explain this, and will also provide links to other sites for further reference.

To begin with here is a one line definition-which sadly isn’t mine, but gets the point across-of what the PATH variable is.

PATH is a list of directories where commands are looked for.

So when I type echo $PATH into the terminal I get the following:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Returning to our original example; if you were to type hello_world into the terminal. The OS would first look for a command (a file with the x bit set) with that name in /usr/local/sbin. If one is found it is run, if not it continues onto /usr/local/bin, and so on.

Now if we would like to only have to type hello_world, all we would have to do is add its directory to the PATH variable. Suppose that our script is in the directory /Mine. First I will show you the WRONG WAY to do this. Then two different correct ways (though I am not all that sure about which is better to use as of yet).

THIS IS THE WRONG WAY!!! $PATH=/Mine
This is wrong because it will replace the original PATH variable with /Mine, and I am sure that you don’t want this.

Correct way #1: PATH=/Mine:$PATH
Correct way #2: PATH=$PATH:/Mine

As you can see, the first one will add /Mine to the beginning, and the seoncdd to the end of the PATH.

Here are two sites you can visit if you wish to learn more about the PATH variable. http://www.faqs.org/docs/Linux-mini/Path.html and http://www.troubleshooters.com/linux/prepostpath.htm


On my First Script

July 15, 2009

Well as promised it is time to explain parts of my script. Well I shall start at the beginning.  The !#/bin/bash tell the OS where the interpretor for the script can be found. The following line is just a place where most of the work will be done.  This should actually be changed to cd ~ if I were planning on sharning this script (which I am).

Now for the more “interesting” aspects.

ls -a | grep “^\.” > temp

This line will first list all the fils found in a directory (ls -a). Then it will find those that begin with a ‘.’ (dot) and print them to a file called temp.  This is done through the use of grep “^\.” grep works with regx, and in the one used here it will match ‘phrases’ that begin with a ‘.’ (dot).  Pretty much grep can do a lot of things (or so I have read) but they rely on regx so needless to say I am currently working on learning regx.  Anyway back to the code. After this I do a search to find a file called .myPw, this is where the password will be stored.  So if the file doesn’t exist we shall create it, along with a password to place into it.

After this I basically use some basic loops to test the user’s input to see if it matches the password.  I won’t talk about the loop structure since 1: this isn’t a tutorial on bash, and 2: it is easy enough to figure out from just reading the code.  I won’t explain what echo does, if you don’t know just click on the man link at the top of this blog and then click on echo.  It’s actually a pretty “simple” command.

One last thing, I would like to point out that after making the file temp I deleted it once I no longer needed it. This turns out to be somewhat optinal (I’ll explain in a moment), but I think it’s just “polite” to delete temporary files you put on someone else’s system.  Now for why this is optional.  The way the code is set up, if there already exist a file called temp it will overwrite it.  If however I had used

ls -a | grep “^\.” >> temp

It would append the output to the end of the file (in which case who knows what was in there before and how much you will have to seach through while looking for .myPw).  So there is a BIG difference between > and >>, both direct output to a file but in differnt fashions.


First Complete Script

July 12, 2009

Here is my first “real” script. It does what it was designed to do, but not as nicely as I would have liked. So needless to say there will be some updating.  As for the script itself it is supposed to prompt the user for a password before opening firefox.  If a password doesn’t currently exist it will ask them to make a new one, that will be saved into a “hidden” file. Really it’s pretty easy to get around but it should be enough to keep your computer illiterate friends away/busy at least.

Here is the script:

#!/bin/bash

cd <path> #location of password file
there=false
ls -a | egrep '^\.' > mytemp

#chek if file with password exists
while read f
do
	if [ "$f" = ".myPw" ]; then
		there=true;
	fi
done < mytemp
rm mytemp 

#if not make it
if [ "$there" = "false" ]; then
   echo "Enter a password:"
   read newPass
   echo $newPass > .myPw
   chmod 777 .myPw #make possible to read and write to file (needed for later on)
fi

input=:
correct=false
j=:

#get actuall password
while read j
do
	PW=$j
done < .myPw

#read until correct pw is given
while [ "$correct" = "false" ]
do
	echo "Enter password or ^C (Ctrl + C) to quit:"
	read input
	if [ "$input" = "$PW" ]
	then
		correct=true
	else
		echo "Incorrect password"
	fi
done
firefox&

while :
do
   ii=2
done

Sorry it’s not in the best font but at least the formatting is there. Anyway the part I don’t like is the infinite loop at the end. However, I haven’t found a way to keep firefox open if it’s not there. With out it, once the correct password is entered the script will end but firefox won’t start.

Well in my next post I’ll try to explain what each line does. Should be a good exercise in talking about terminal commands.