Saturday, April 28, 2012

Running Script on Startup - rc.local

By default there is a script that gets executed on startup. On a clean installation this is empty so it doesn't do anything. But you can add some nice function it, e.g. make your favourite programs load when you boot your system.

The file is
/etc/ec.local

Edit it with any application (I use nano or gedit these days)
sudo gedit /etc/ec.local

And just add any commands that you would normally run from a terminal window, these will be run every time you start your system.

Problems encountered

However, rc.local should be executed on startup, at the moment it isn't working for me. I was playing around with it a little, including changing permissions, but then finally changed:
sudo chmod -x /etc/ec.local

Don't know if this worked, its for sure that
sudo chmod 0755 /etc/rc.local

worked and I keft it like that.

sudo update-rc.d rc.local defaults
returned that the simlink already exists. Once again a little diging around (linuxquestions.org, wikipedia)


I discovered that the problem was that only the first line of rc.local was executed. This happens if there are mistakes in the commands, the script just terminates at that step. So I actually removed a bit from it, which wasn't necessary as it has tuned out.
sudo killall tor

(tor was removed from the runlevel, so it isn't started in the first place)

After this, the script was OK, runs on startup as expected.

Own startup script

Make a script and put it into /etc/init.d

Make it executable:
sudo chmod -x script_name
Add symbolic links with:
update-rc.d script_name defaults

And this should be it. Later on if you happen to want your script removed, run this command
update-rc.d -f script_name remove

Running Tor and Vidalia

Tor is free software and an open network that helps you defend against a form of network surveillance that threatens personal freedom and privacy[...]
Read more about the tor at https://www.torproject.org/

It is a very nice software that I have been using on windows and also wanted to use with linux. Luckily, there is a nice and easy to follow installation manual for Ubuntu, HERE. It is very easy to set it up and running, so I won't copy all the commands in here.

One thing to note though is that after installing, tor is ran on startup and when you want to start Vidalia (tor's UI for settings etc.) it will detect the running tor process and try to connect to it. This isn't working (or not for me at least) so before starting vidalia, make sure to kill off the running tor process

sudo killall tor

This command can be ran even on startup to make things easier and clear. After this vidalia can be started normally.

Edit

Its even easier to remove tor from your runlevel, preventing executing it at startup in the first place. If done this way, there is no need to kill tor at startup manually and vidalia will start it by itself fresh, guaranteeing that it runs as intended. Simply run
sudo update-rc.d -f tor remove


Others

One more thing, I remember having some trouble in the settings, but its like this at the moment:


I think once I had to set Authentication for "cookie" because it just wouldn't want to work with password, but apparently now it does, so I'm happy.

To use tor when browsing I'm using GProxy Toolbar for Firefox, a simple toolbar that lets me witch between proxies quickly without having to open the browser net configuration. Its set like this:


PirateBox under Ubuntu

So I took on a project once again that I have already started several times before. Hoping that now I could solve all the issues and make it work. 

I am not the inventor of PirateBox, I was using script packages created by others and also received help with my work from several people on forums. I was following the DIY (Do It Yourself) tutorials for installing PB directly on a laptop find here.


Running a PirateBox from Ubuntu 11.10
If you don't know about PirateBox (PB), shortly summarised its an anonymous file sharing LAN network with integrated chat function. Perfect for sharing files over wifi and chatting with people around you either at parties,  at home or basically anywhere you want.

Read more about the PirateBox project here

***

How PB works

PirateBox is not a single program running, not a one click install from the software centre. It is a range of scripts and daemons running together that finally turn your  wifi card into an open wifi network. Here people can connect and get automatically redirected to the main PB share page with the chat function and up/download. 

So the following things need to be done by the "software package":
  • First of all it has to turn your wifi card into an access point, creating a wifi network, SSID
  • It has to handle the connected users, managing local IP addresses
  • It has to manage up- and downloads
  • Needs tu run a simple chat client where people can talk
Difficulties
  • Not all wifi cards support AP mode (access point)
  • Differences in every single Linux system make it hard to create a "universal" installer or tutorial
  • Driver issues, supported devices
What you need
  • python
  • hostapd - with nl80211 header support
  • dnsmasq

Python comes installed by default, so there was nothing to do here. If you removed it manually or haven't got installed for any reason simply
sudo apt-get install python

The same way, dnsmasq can be installed without any trouble
sudo apt-get install dnsmasq

Hostapd on the other hand has causes quite some troubles. (Hostapd stands for host access point daemon) The main point about PB is that is has to turn you wifi card into an AP as mentioned before. No hostapd is doing this with the nl80211 header/deriver. The problem was that this driver isn't included in hostapd for Ubuntu 11.10.

So when I went to install hostapd with simply 
sudo apt-get install hostapd
and then tried to run it based on a simple config file
sudo hostapd -dd hostapd.conf
I received an error, saying
error: nl80211 generic netlink not found.
error: nl80211 driver not found.

Now I have tried to compile the package and allow the nl80211 header in the package many times, but it just wouldn't work. the tutorial I followed for this was on linuxwireless.
No matter how many times I tried to compile it and run the test above, the same error was returned over and over again.

With some help from forums and quite some time spent searching for possible errors, it turned out that the problem was with my wireless driver and firmware and not really with hostapd.

In the end I could install hostapd with
sudo apt-get install dhcp3-server hostapd
And it was running fine.

Wireless card issues

I have a Broadcom BCM 4312 wifi card in my laptop that in Ubuntu 11.10 ships by default with the "Broadcom STA proprietary wireless driver". This is not good, so remove it. Easiest way to remove it is using the synaptic package manager, that once again doesn't come installed in Ubuntu 11.10 so install that first by
sudo apt-get install synaptic

Now that synaptic is installed run it and search  your STA driver and mark it for removal. Also search for b43, add 2 things:
b43-fwcutter 
firmware-b43-lpphy-installer
and install those. (I had to use lpphy version of the firmware, depends on your card)
Find more detailed description in this thread, ubuntuforums.

Run
sudo modprobe -v b43
to see if it works.



Installing PB

Now that background requirements are are all installed and driver issues solved, the actual PirateBox can be installed. There is a detailed tutorial for this HERE so I will not go into details. One thing to mention is that you can either download the package and install manually or use Piratebox-Manager.sh script package



Running PB

There are a few things in Ubuntu that you have to do to run PB correctly. However these are also mentioned in the installation tutorial I put them down here again the way they worked for me.

sudo service network-manager stop
sudo killall dhclient
sudo killall dnsmasq
sudo iptables -t nat -A PREROUTING -i wlan0 --protocol tcp --match tcp --destination-port 80 -j DNAT --to-destination 192.168.77.1:80
sudo iwconfig wlan0 mode managed
sudo /etc/init.d/piratebox start

This is the way I start my piratebox and it works.
  • Network manager has to be stopped before starting the script or it will reset your wifi card and disable AP mode
  • dhclient and dnsmas have to be stopped in case they are running so they can be started with the proper configuration
  • Sometimes the Ubuntu firewall (ufw) is causing problems, so run the command and redirection will run smooth
  • Also in case your wifi card is not in managed mode it must be set

After all these steps are done, piratebox can be started with
sudo /etc/init.d/piratebox start

The piratebox project is still under development and I am also  looking into running it more efficiently, checking what's needed or not. But for now, the start, its up and running.

Building from source

Sometimes you can't get a simple software to install by one click or you have to enable a feature in its source which wouldn't come with a normal install. You will have to build it for yourself from source.
the procedure is the following
  1. Download the source
  2. Open terminal and unpack the package you downloaded
  3. cd into the unpacked folder
  4. Build it with the standard 3 steps:
./configure
In configure you normally have good comments and hence its easy to find what you want or need. Follow tutorial on the website of the software you are working with.

sudo make 
Running make will compile the package for you, this might take a while.

sudo make install
Make install actually installs the compiled package on your system. After this step you should be done.

Keeping track of installations


In Ubuntu you can take advantage of the software centre and with a little help you can build .deb files from your compilation that can be installed through the software centre. This is handy if you want to keep a better track of what's installed on your system.

First you will have to get checkinstall by
sudo apt-get install checkinstall

So with checkinstall you have to do all the steps until make. But instead of running make install, you can run (while in the appropriate folder)
sudo checkinstall -D make install

Using checkinstall Command:
sudo -- running as root, necessary
checkinstall -- call the checkinstall package
-D -- tells checkinstall to create Debian package
make install -- the command that checkinstall has to run and turn into a file

This will create a *.deb package in the folder where you are. You can run this file and install it through the software centre. if later on you want to remove it, you can simply remove it from the software centre as well.

Checkinstall does require some interaction from the user, but it is very straightforward and explained when running. Simply follow the instructions on screen. At the end of the process the created package will be installed automatically on your system.

Wednesday, April 18, 2012

In the beginning there was Ubuntu

Hello everybody!

This blog will be a guide and storage for myself and for everyone else with the knowledge and experiences I make while using the linux distribution Ubuntu. At the moment I am using the latest version of Ubuntu, 11.10.

Just a tip in advance: http://ubuntuforums.org is a nice place to look for answers.

I have some very basic knowledge about using the terminal, scripting etc. and I will try to be as specific and detailed with my work as I can, noting errors and possible workarounds I have discovered.

I hope this will be of some help to someone out there.
***
So some very basic commands in using the terminal:

(Ctrl+Alt+T starts the terminal by default)
The terminal if quite "friendly", if you don't know how to use a command juts type "command man". "man" stands for manual and this will bring up a short manual, how-to-use for the command within the terminal window.


sudo -- run a command as root (used quite often...)
cd -- change directory 
firefox -- typing a programmes name simply starts the program, e.g. firefox
ls -- list the contents of a directory
chmod 777  -- gives executable permission to a file like chmod 777 filename
./filename -- runs "filename" file (script for example)
rm -- remove file
sudo apt-get install application -- installs the program (you have to sudo it, aka run as root, else it will not work)
sudo apt-get remove application-- removes program
sudo apt-get autoclean -- removes unused libraries
ps -A -- list all running applications
sudo kill PID -- kills the application pased on PID number (application number, look it up with previous command)
sudo killall application -- it will kill the given application (no need to look up PID number, I personally find this way faster & esier)

That's a short list for some basic functions. Later post will explain other commands used.