Saturday, February 2, 2013

Run Bumblebee on Raspberry Pi boot

In my last post, I showed you how to set up a raspberry pi with BotQueue. This time, I want to show you how to start it on boot.

First, let's create an executable script to run bumblebee with a single command. I'm doing this so that if I ever change the directory BotQueue is in, I only have to change one file. So to edit the new executable, run the following command (replacing nano with your text editor of choice. I use vim personally):
sudo nano /usr/bin/bumblebee
You should be presented with a blank file. Add the following lines to it, before saving and exiting (replacing /home/pi/BotQueue/bumblebee/ with wherever you put bumblebee. Note that you should not use ~, but instead /home/pi/):
cd /home/pi/BotQueue/bumblebee/
After that's saved, you need to allow people to execute it. Type this to get the desired effect:
sudo chmod a+x /usr/bin/bumblebee 
Of course, you should run "bumblebee" now to see if it worked. Next up, we need to make the user automatically login on tty1. Again, I'm assuming you are using the pi user here. If you aren't then just change the username in the instructions accordingly. First, edit the /etc/inittab file. You'll need sudo permissions, of course:
sudo nano /etc/inittab
Find the line that looks like this:
1:2345:respawn:/sbin/getty 38400 tty1
Change it to this:
#1:2345:respawn:/sbin/getty 38400 tty1
And add this below that line (replacing pi with the username you want logged in and running bumblebee with):
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
 Good good. Now, in the home directory of the user you did that too (in most cases, that'll be your own), edit the ".profile" file. (notice the '.' at the beginning of profile):
nano .profile
At the bottom, add the following lines (If you don't care about the terminal screen going blank, leave out the setterm line):
if [ $(tty) = /dev/tty1 ]; then
    setterm -blank 0
    sleep 10
And now, just run this command to reboot:
sudo reboot
There you go. Once you have gone through a reboot, the program should be running in the main terminal window, while still giving you the ability to ssh in. The only problem with this is that you can't type things like q to quit the program. This is a problem with bumblebee, which I'm hoping to eventually fix. Although, I wrote this tutorial and the last one all over ssh, so it's completely possible to not need a keyboard on the host computer.