Wednesday 11 July 2012

Redmine Install

As predicted, installing redmine proved to be a hassle. I followed this guide, and while tedious, worked fine.

I ended up installing it on my main linux machine (FC15).  I lost track of the additional packages required ... here's the transcript ...

Note I already had mysql and apache running.
So I created a redmine database, as is described above, and then followed the remainder of the post.

 # Make somewhere to download and configure redmine
cd
mkdir redmine
cd redmine
wget http://rubyforge.org/frs/download.php/76259/redmine-2.0.3.tar.gz
gunzip -c redmine-2.0.3.tar.gz | tar xf -
cd redmine-2.0.3
cp config/database.yml.example config/database.yml

# Set up for production environment
emacs config/database.yml

# Install all the FC15 dependencies for a standard set up
sudo yum install -y phpmyadmin
sudo yum install -y ruby rails rake
sudo yum install -y rubygem-rake
sudo yum install -y ruby-devel
sudo yum install -y mysql-devel
sudo yum install -y postgresql-devel
sudo yum install -y ImageMagick-devel

# Use Ruby gems installer to get basic tool kit and installer
sudo gem install bundler
sudo bundle install --without development test

# Preconfigure Redmine
sudo rake generate_secret_token
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data

# Create a permanent home and redmine user
sudo mkdir /opt/redmine
sudo useradd redmine
sudo passwd redmine
sudo chown -R redmine.redmine /opt/redmine
sudo chmod -R 774 /opt/redmine

# Move redmine install to new home under /opt
cd ..
sudo mv redmine-2.0.3 /opt/redmine/
sudo chown -R redmine.ian /opt/redmine/redmine-2.0.3

# Restart web server
sudo service httpd restart
We can login as redmine user and start production mode with ...
nohup ruby script/rails server webrick -e production &
Running nohup means we can log out, and leave redmine running unattached. Fire up a web browser and navigate to localhost:3000 and first time login as admin admin Its then a case of making some customizations, and setting up a few basics such as a user account and example project ...
Next time we'll go through the business of using redmine to specify our first real python project

Thursday 5 July 2012

LAMP

Been thinking about installing Redmine as part of the Learning Python project management discussion.  Problem is redmine runs on Ruby on Rails, and I'm not sure that's going to go down too well.  Fact is I installed apache, mysql and the  phpMyAdmin helper module without much of an issue, but when I got to redmine things started to go awry.  As it is, I've been installing Ruby for the past two hours ... stuck at compiling ... as it describes here and judging by the speed of things, its not going to be much use even if it gets to the end.  Maybe I'll say a few things about Gtihub, and skirt over project management.
RPi running mysqld and phpmyadmin, viewed from another machine

Stronger than it may appear.

"Daddy what do those pointy  things do?", swipe, clatter, fall ...
Server unexpectedly disconnected ...

Hold breath. Count to 10.  Reconnect.  Phew.

"Its a general purpose input output port",  would you like daddy to teach you how to use it?

Yes, I can report that the Pi successfully passed the knocked off a desk by a 6 year old, whilst powered on. It really is tougher than it looks.

Tuesday 3 July 2012

Heads up - Python Tut

I've started a python tutorial. Going to post all the stuff I learned last year. Rather than focus on the language, I'm going to present the wider issues of building a development environment, source control and project management.  Well that's the plan at least.

Monday 2 July 2012

Sounds Great

Just thumbed through the MagPi, all good stuff.  Issue 3's got a nice page on finishing off the set up (page 4), especially mentions sound.   I'm not going to regurgitate the incantations verbatim, you can all go and read it from source.  Instead, below is a cut and paste recipe. What I forgot to mention yesterday, before signing off for the night, was that I did run the all important:

sudo apt-get update
 
And this proceeded with out error - wifi etc still intact this PM.

Sound
Will report that it took about 2 min and worked fine

sudo apt-get install alsa-utils
sudo modprobe snd_bcm2835
sudo amixer cset numid=3 2 # Setting up for HDMI out

sudo nano /etc/modules # enter snd_bcm2835 on bottom line ctrl-x Y

sudo reboot

Sunday 1 July 2012

First Boot

Power on Pi

What you see depends on how you've wired up your Pi. I strongly suggest you actually plug a telly or something in so you can monitor progress. I didn't, well not at first. And when SSH told me no route to host, that's when I resorted to making a video out connection. I plugged the Pi's composite out into my PVR-150 capture card ... so I could monitor booting and resolve SSH issues.
For those wanting a similar experience, this is how I got the grainy image of a Pi booting on my linux host machine.
v4l2-ctl -d /dev/video0 -i 2 # Tune card to composite 1 input
v4l2-ctl -d /dev/video0 -s pal-60 # Set input to UK pal-60
cat /dev/video0 | mplayer - # view stream in mplayer
What I saw was a steady boot up until registering the WiFi adaptor, where abouts progress stalled and the device appeared to hang. I'd read elsewhere of reports of conflicts between USB peripherals, so I yanked the keyboard receiver out, and immediately the Pi boot continued. Curious to know whether this was an irreconcilable issue, at the point of prompting for log-in I reinstated the keyboard USB dongle and surprisingly all seemed well.

Log in pi

The Debian Image comes with one preconfigured Super User account who's password is raspberry. We are going to change that post-haste. Log in with these credentials and proceed to configure accounts.
passwd pi # change the pi account's password
sudo su - root # use pi to switch user to root
passwd root # change the root account password
exit # drop out of root, back to pi account
sudo adduser {supply a user name} # add a new user to the system
sudo su - root # switch back to the root account
visudo # Add the new user to the list of super users (see below for more on visudo)
exit # drop out of root, back to pi account
exit # log out of pi
visudo is a text editor designed specifically for editing the sudoers list. That is, a list of users and their associated special privileges. We need to add our new user to this list and grant them the ability to run all commands normally executed by root, when prefixed with sudo. In Debian only root can run visudo. The editor is based on vi, a low level text editor that requires knowledge of special key strokes to do stuff. We simply need to scroll down (arrow key down) to the section as shown below (around line 18). You'll replace ian with your new username.
# User privilege specification
root    ALL=(ALL) ALL
suse    ALL=(ALL) ALL
pi      ALL=(ALL) ALL
ian     ALL=(ALL) ALL
Having made the change, save the edits by hitting ctrl-k x

Log in new user

You can now log in as the new user and finish off our pre play customizations. Lets set up passwordless SSH. This will enable us to connect to our Pi from other computers without the need to enter login details all the time. Accept defaults for all in the following.
cd # just to be sure we are top level home.
ssh-keygen # create a key pair, but just press enter when prompted for a passphrase
cd ~/.ssh # enter the .ssh directory to do more with your key.
ln id_rsa.pub authorized_keys # ssh expects the public key to be called authorized_keys
cd # go home.
We will need to know the IP address of our Pi (line in the next command is a pipe character e.g. shift back slash left of z on a UK keyboard)
ifcongfig | grep inet # its the dotted number left of the bottom line.
E.g.
ian@raspberrypi:~$ ifconfig |grep inet
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet addr:192.168.1.90  Bcast:192.168.1.255  Mask:255.255.255.0
Most modern routers automatically reserve an IP address when they issue to a new device. So I can be fairly sure everytime I boot Pi it will always get 192.168.1.90. However, there are two things we can do to make this safer. We can set up a static IP address by editing the network interface, or we can navigate to the webadmin page of the router and reserve the address for the PI. The latter is the easier, assuming you know how to log in to your router. I did, so that's what I've done. When you are reserving addresses you need to know the MAC address (hardware address, HWaddr) of the questionable device, as shown below:
ian@raspberrypi:~$ ifconfig |grep wlan0 |grep HWaddr
wlan0     Link encap:Ethernet  HWaddr 54:04:xx:df:xx:xx
Now head back to your host machine and grab the private half of your key-pair. To do a proper job, you should put this in .ssh of your local account. If you've not got one, make one with mkdir ~/.ssh, but don't do that until you've checked with ls ~/.ssh first. You should also add your Pi's IP address to your /etc/hosts file so that we don't need to type the IP address in every time we connect to it. The following assumes you are sudo on your main machine, otherwise su - root, or don't bother. Also, replace user with your new user account name.
sudo echo "www.xxx.yyy.zzz pi pi" >> /etc/hosts # add pi to local DNS
cd ~/.ssh # move back to your host .ssh directory
scp user@pi:~/.ssh/id_rsa pi_key # snatch the private key from your pi
cd # move back home
ssh -l user -i ~/.ssh/pi_key pi # test out your passwordless ssh
I'm too lazy to type that in each time, so I make an entry in ~/.ssh/config to simplify the process. Edit your ~/.ssh/config, or make a new one in your favourite text editor. Mine looks like this, note the bit about compression helps speed up transfers.
host pi
hostname pi
identityFile ~/.ssh/pi_key
compression yes
compressionLevel 6
Now I can connect to the Pi simply by typing ssh pi Which you should do because we need to be back in the Pi to set up VNC.

VNC at boot

VNC lets us connect to a Pi desktop environment from the comfort of our main machine. The Pi can be enjoyed without a dedicated keyboard, mouse and monitor. We call it working headless, though it doesn't really involve decapitation. Services that start at Boot time are controlled by the update-rc.d command. Essentially, we need to create a script that runs a vncserver before login. NB. replace XXX on lines 14/15 with your username The script below was originally posted at elinux, and retweeted to the Pi community by dktucson.
### BEGIN INIT INFO
# Provides: vncboot
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VNC Server at boot time
# Description: Start VNC Server at boot time.
### END INIT INFO

#! /bin/sh
# /etc/init.d/vncboot

USER=XXX
HOME=/home/XXX

export USER HOME

case "$1" in
start)
echo "Starting VNC Server"
#Insert your favoured settings for a VNC session
su - $USER -c "/usr/bin/vncserver :1 -geometry 900x640 -depth 16 -pixelformat rgb565 &" &
 ;;

stop)
echo "Stopping VNC Server"
/usr/bin/vncserver -kill :1
 ;;

*)
echo "Usage: /etc/init.d/vncboot {start|stop}"
exit 1
 ;;
esac

exit 0
First we need to update the pi package list, and install our vncserver program. To manage software on the Pi we need to use apt The Advanced Packaging Tool. Read all about it here.
apt-get update
apt-get install tightvncserver
Now we set up a password to gain access to the desktop.
vncpasswd user # replace user with the account name
Now fire up a text editor, copy and paste the boot script from above.
sudo nano /etc/init.d/vncboot
{ copy and paste}
{ ctrl-O, ctrl-X}
sudo update-rc.d vncboot defaults
That's it. You can reboot your pi and enjoy it from a far thanks to VNC. You'll need a vnc client on the remote machine. Assuming you've got one you can connect to the pi thus:
vncviewer pi:1
Here's my local machine ssh'd into pi and viewing the public key (left) and a VNC viewer displaying my blog post with a terminal showing the public key too.

Pi Time

I've had my Pi a couple of weeks, but there's not been enough time to really get it going.  Last night I decided I was going to set it up once and for all.  Here's what I had in mind:

Hardware
  1. Wireless network connection
    • Asus N13 Realtek Dongle (£16)
  2. Wireless keyboard and mouse
    • Logitech mk260  (£17)
  3. Single power source for USB hub & Pi
Software
  1. Debian Image (debian6-19-04-2012)
  2. Passwordless SSH on boot
  3. VNC server on boot
The previous week I'd had a 10 min go at getting the pi up and running, and was impressed at the capabilities of something so cheap.  But it was apparent that some effort would be needed to get the device achieving anything close to useful.  Mores the point, I'd had no success with the N10 and had fallen back to wired ethernet.


The Plan
There's nothing quite like research when it comes to setting up new hardware, especially kit as experimental as the Pi.  Here are the websites to whom I'm truly thankful for advice and instruction.
I found it necessary to mix in steps from each of the above and brew a bespoke install guide.   I'll explain more at the end, but suffice is to say - pay particular attention to code revision numbers and publication dates.  It really matters.

Setting up tutorial
Part A: pre switch on
You need a host machine to preconfigure your SD card.  If you've not got one, don't bother reading further.  Sell your Pi on ebay, and go for a pint instead. If on the other hand, you are up for the challenge read on. The first section deals with getting the pi to boot with wifi enabled. It borrows heavily from the pi startup guide and Tomasz Miklas posting on ctrl-alt-del.cc.
  1. Download debian6-19-04-2012 image. Get your image here http://www.raspberrypi.org/downloads
  2. Copy the image to an SD card.  In linux we dd, on Windows you'll do something else.  My SD card is /dev/sdc, and I'd changed directory to be in the same place as the image input file
  3. sudo dd if=debian6-19-04-2012.img of=/dev/sdc
    
    Being executed from the command line, it may appear as if nothing happens. Mine took around 4 min to complete.
  4. Sync the SD card before removing it to ensure data writing completes without error
  5. sudo sync
    
  6. Remove SD card, then reinsert in to the host machine. There's much more preparation to be done before getting anywhere near the Pi.
  7. On inserting the card into a Linux host, two new volumes will appear. One is the 79 Mb DOS boot disc, the other is the 2 Gb root volume. I have a 4 Gb SD card, so I need to resize the partitions on the new volumes to reclaim lost space. I did this in graphical parted (Gparted)· Note that the volumes must be unmounted before Parted can work on them. My linux automounts SD cards under /media using volume UUIDs as names for mount points.
    sudo umount /media/18c27e44-ad29-4264-9506-c93bb7083f47/
    sudo umount /media/95F5-0D7A/
    
    I fired up Gparted, selected /dev/sdc as the target volume and did two things
    1. Move swap to end of volume on right
    2. Resized Root to use maximum free space
    3. Finally remove & reinsert the SD card to remount mount it on the host machine for further file copying
  8. Download and copy over firmware updates and kernel modules. GitHub hosts the necessary files, so you'll need github core tools installed to carry out the next steps. Git Help at https://github.com/raspberrypi
  9. cd
    mkdir git_pi
    cd git_pi
    git clone git://github.com/raspberrypi/firmware.git
    cd firmware
    git checkout a8f8d24
    
    Key in these steps are ensuring that we use firmware previously shown to work - the checkout command specifies the code revision we will use. Big thumbs up to Tomasz Miklas.
  10. Copy all files from /firmware/boot and firmware/opt/vc to their respective places on the SD card. Note that on Linux if you copy in a file with the same name, the original file is replaced without warning.
    cd /media/95F5-0D7A/boot
    cp -r ~/git_pi/firmware/boot/* .
    rm -rf /media/18c27e44-ad29-4264-9506-c93bb7083f47/opt/vc
    cp -r ~/git_pi/firmware/opt/vc /media/18c27e44-ad29-4264-9506-c93bb7083f47/opt/
    rm -r /media/18c27e44-ad29-4264-9506-c93bb7083f47/lib/modules/3.1.9+ 
    cp -r ~/git_pi/firmware/lib/modules/3.1.9+ /media/18c27e44-ad29-4264-9506-c93bb7083f47/lib/modules/
    
  11. Now git clone firmware tools, as below, and copy over libstdc++.so.6.0.14
    cd ~/git_pi
    git clone git://github.com/raspberrypi/tools.git
    cd tools
    git checkout 3aba47b
    cp arm-bcm2708/linux-x86/arm-bcm2708-linux-gnueabi/sys-root/lib/libstdc++.so.6.0.14 \
    /media/18c27e44-ad29-4264-9506-c93bb7083f47/usr/lib/.
    
  12. Finally, copy over the wireless driver module
    cd ~/pi_git/
    wget http://www.electrictea.co.uk/rpi/8192cu.tar.gz
    gunzip -c 8192cu.tar.gz |tar -xf -
    cp 8192cu.ko /media/18c27e44-ad29-4264-9506-c93bb7083f47/lib/modules/3.1.9+/kernel/net/wireless/.
  13. Now we do a bit of configuration before firing up the pi. Set configuration for WPA2 (or whatever you need), load wireless module every time and make active at boot.
    nano /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/wpa_supplicant.conf
    
    Enter text as shown (replacing your SSID and passphrase)
    ctrl_interface=/var/run/wpa_supplicant
    network={
        ssid="_your_SSID_"
        scan_ssid=1
        proto=RSN
        key_mgmt=WPA-PSK
        pairwise=CCMP TKIP
        group=CCMP TKIP
        # to get encoded PSK run: wpa_passphrase 
        psk=YOUR KEY
    }
    
    Two things to note: 1) double quotes around SSID, 2) PSK is the output of wpa_passphrase _your_SSID
  14. Configure network interfaces
  15. nano /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/network/interfaces
    
    This is what I have ...
    auto lo
    
    iface lo inet loopback
    iface eth0 inet dhcp
    
    auto wlan0
    iface wlan0 inet dhcp
    pre-up wpa_supplicant -Dwext -i wlan0 -c /etc/wpa_supplicant.conf -B
    
  16. Disable loading of native wifi driver, ensure our wifi driver loads, even when dongle isn't present.
    echo '8192cu' >>  /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/modules
    echo 'blacklist rtl8192cu' >> /media/18c27e44-ad29-4264-9506-c93bb7083f47/etc/modprobe.d/blacklist.conf
    
  17. Enable ssh at boot
    cd /media/95F5-0D7A
    mv boot_enable_ssh.rc boot.rc 
That's it for pre-configuration. You can now remove your SD card from the host PC, insert it in to th Pi and power on.

Headless Pi powered from USB hub (white kindle cable), wireless dongle at back (under power lead) keyboard / mouse receiver disconnected for boot




Part B: Switch on 
Power on wasn't so straight forward. I found out by trial and error that the USB receiver for the keyboard / mouse conflicted with the WiFi Dongle, and needed to be disconnected at boot. Other than that, I was able to SSH in to the Pi within 2 min of turning on. In the next post I'll describe the elementary set up to get VNC at boot, create local accounts and set up passwordless SSH.