A rubyist stranded on Martha’s Vineyard

How to install Doom on the Raspberry Pi

May 20, 2013
Raspberry Pi running Doom II

My kids were intrigued by what I was doing as I followed this SparkFun tutorial on how to install Doom on the Raspberry Pi, they were making questions and seem so motivated that I asked if they wanted to do it themselves, they accepted right away.

Although the instructions are good, they are a little outdated and some steps can be simplified. I decided to improve them and post them here.

List of hardware

  • Raspberry Pi model B
  • SanDisk SDHC 16 GB class 4 memory (all the software requires less than 2 GB)
  • Logitech K120 USB keyboard
  • USB micro cable
  • USB mouse
  • Ethernet cable

In case of problems with the peripherals, there's a list of compatible hardware and a separate list for the SD cards.

There's also a quick start guide with instructions on how to connect all the components.

Download Arch Linux ARM image

Download the Arch Linux ARM image from the Raspberry Pi website (scroll down to the Arch Linux ARM section).

I wasn't able to get the .zip file with the direct download and had to get a BitTorrent client from here. Once installed, just click the archlinux-hf-2013-02-11.zip.torrent link on the browser and it will open the BitTorrent client for you. The file is 200 MB and it took 8 minutes to download with my connection.

Write Linux image to SD card

These are instructions for the Mac, for other operating systems look here

These commands and actions need to be performed from an account that has administrator privileges.

(Optional) Verify if the the hash key is the same, in the terminal run this command and compare the long sequence of characters against the SHA-1 field below the link you just clicked (at the time of writing this post it was 1d2508908e7d8c899f4a5284e855cb27c17645dc)

$ shasum ~/Downloads/archlinux-hf-2013-02-11.zip

Extract the image:

$ unzip ~/Downloads/archlinux-hf-2013-02-11.zip

this will create file called archlinux-hf-2013-02-11.img in the current directory

From the terminal run df -h you'll get something like this:

Filesystem      Size   Used  Avail Capacity Mounted on
/dev/disk0s2   698Gi   89Gi  609Gi    13%   /
devfs          186Ki  186Ki    0Bi   100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%   /net
map auto_home    0Bi    0Bi    0Bi   100%   /home

Insert the SD card, run df -h again and look for the new device that wasn't listed last time. Record the device name of the filesystem's partition, in my case it was /dev/disk2s1

Filesystem      Size   Used  Avail Capacity Mounted on
/dev/disk0s2   698Gi   89Gi  609Gi    13%   /
devfs          186Ki  186Ki    0Bi   100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%   /net
map auto_home    0Bi    0Bi    0Bi   100%   /home
/dev/disk2s1    15Gi  2.3Mi   15Gi     1%   /Volumes/NO NAME

Unmount the partition so that you will be allowed to overwrite the disk, you need to enter your password

$ sudo diskutil unmount /dev/disk2s1

Using the device name of the partition work out the raw device name for the entire disk, by omitting the final “s1” and replacing “disk” with “rdisk” (this is very important: you will lose all data on the hard drive on your computer if you get the wrong device name). Make sure the device name is the name of the whole SD card as described above, not just a partition of it (for example, rdisk2, not rdisk2s1. Similarly you might have another SD drive name/number like rdisk2 or rdisk4, etc. – recheck by using the df -h command both before and after you insert your SD card reader into your Mac if you have any doubts!):

In our case, the partition is /dev/disk2s1 then the device is /dev/rdisk2

In the terminal write the image to the card with this command, using the raw disk device name from above (read carefully the above step, to be sure you use the correct rdisk# here!):

$ sudo dd bs=1m if=./archlinux-hf-2013-02-11.img of=/dev/rdisk2

This command will take around 4 minutes and will not feedback any information until there is an error or it is finished, in my case this is what I got back:

1850+0 records in
1850+0 records out
1939865600 bytes transferred in 229.546995 secs (8450843 bytes/sec)

Before taking the card out you must eject it with this command:

$ sudo diskutil eject /dev/rdisk2

Put the SD card into the Raspberry Pi. Connect your display, keyboard, mouse, ethernet cables to the Pi. Lastly, connect power through the micro USB cable. The Pi should boot up Arch Linux ARM and get to the log-in screen.

Log in with login: root and password: root

Important

If at any time you want to cut the power to the Pi you must first shut it down. This is the command to do it:

$ shutdown -h now

System configuration

Login as root.

Change root password:

$ passwd

Edit the locale.gen file. All you need to know about the nano editor is here

$ nano /etc/locale.gen

Search for this line and make sure it's uncommented, i.e. there's no leading #

en_US.UTF-8 UTF-8

Generate locales:

locale-gen

To define your local timezone, find your region or country under this directory:

$ ls /usr/share/zoneinfo

Then find the file that best represents where you live inside that region, in my case:

$ ls /usr/share/zoneinfo/America

Using the full path create a symbolic link:

$ ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime

When the system displays the date, it should contain the correct timezone:

$ date
Sun May 18 13:25:46 EST 2013

Using nano make sure the file /etc/locale.conf contains these 2 lines:

LANG=en_US.UTF-8
LC_COLLATE=C

Define the name for your RPi:

$ nano /etc/hostname

Change alarmpi to doom or any name containing only lower case letters and numbers.

Modify /etc/hosts, look for the line 127.0.0.1 localhost.localdomain localhost

$ nano /etc/hosts

Add at the end of that line the same name you used under /etc/hostnanme:

127.0.0.1 localhost.localdomain localhost doom

Full system update

Verify that your Pi is connected to the Internet through the Ethernet port and login as root. If you forget to connect it's better to reboot with shutdown -r now and login again.

The package manager in Arch Linux is called pacman, perform a full system update by issuing this command (note this is a capital S).

$ pacman -Syyu

Once you provide confirmation, it will take several minutes (20 in my case) to download and install the software. Once complete, run this to verify the update was successful:

$ pacman -Syu

It should report nothing to do.

Install sudo and create a user account

The sudo command allows regular users to perform operations that require root priviledges. Install sudo:

$ pacman -Sy sudo

Allow users to run sudo:

$ EDITOR=nano visudo

Uncomment (take away the #) from the line that says: %wheel ALL=(ALL) ALL. Save and exit.

Create a regular user login (change mary for the desired user name, and assign it a password:

$ useradd -m -g users -G audio,lp,optical,storage,video,wheel,games,power,scanner -s /bin/bash mary
$ passwd mary

Reboot Pi:

$ shutdown -r now

Log back in with the user and password you just created.

Install sound drivers

Login as the newly created user.

Install Advanced Linux Sound Architecture (Alsa), required for sound:

$ sudo pacman -Sy alsa-firmware alsa-utils

The Pi has 2 audio outputs: HDMI and analog. If you have an HDMI monitor without sound capabilities, but have old fashioned speakers connected to the analog port, the audio won't work. This forces the Pi to use the analog output and sets volume to maximum:

$ amixer cset name='PCM Playback Route' 1
$ amixer cset name='PCM Playback Volume' 100%

To test the audio execute this command. It will play a “beach” sound that alternates between the left and right speakers.

$ speaker-test -c 2

If you have trouble setting the audio this article can help.

Important

Remember that you must shutdown before cutting power to the Pi, because you're logged in as a regular user you must run the command using sudo: 'sudo shutdown -h now

Install video drivers

Install Xorg, pre-requisite for GUI apps

$ sudo pacman -Sy xorg-server xorg-xinit xorg-utils xorg-server-utils

Install Xorg framebuffer video driver:

$ sudo pacman -Sy xf86-video-fbdev

Install Openbox and Xterm

Install Openbox and configuration utilities

$ sudo pacman -Sy openbox obconf obmenu lxappearance

Make initial configuration files for your Openbox user:

$ mkdir -p ~/.config/openbox
$ cp /etc/xdg/openbox/menu.xml ~/.config/openbox
$ cp /etc/xdg/openbox/rc.xml ~/.config/openbox

Create/Modify user's .xinitrc file

$ nano ~/.xinitrc

Add the following line to this file:

exec dbus-launch openbox-session

Before starting Openbox for the first time, let's install a terminal:

$ sudo pacman -Sy xterm

Check to see if Openbox works now:

$ startx

This is the graphical interface. All you see is an empty screen with a gray background. Right-click and a menu will pop-up. Select Terminals and then Xterm. This will open the same terminal you've been using, but inside a window.

If you want to exit the GUI select Log Out from the pop-up menu.

Desktop background

In the terminal window we just opened type the following command, it will install feh, an image viewer.

$ sudo pacman -Sy feh

Make a directory for your background, then go to it:

$ mkdir ~/wallpapers
$ cd ~/wallpapers

Find a wallpaper on the net then download with wget:

$ wget http://carreno.me/pi_wallpaper.jpg

Set your wallpaper (make sure to change destination to actual username and filename):

$ feh --bg-scale /home/mary/wallpapers/pi_wallpaper.jpg

To make your desktop load when starting Openbox, modify file autostart:

$ nano ~/.config/openbox/autostart

Add line:

$ sh ~/.fehbg &

Install programming environment

Install the base development package so you can compile C programs:

$ sudo pacman -Sy base-devel

This installs gcc and make plus other useful tools you may need for development.

Install Python 3 (python) or Python 2.7 (python2)

$ sudo pacman -Sy python python2

Install DOOM

Install chocolate-doom. Chocolate-doom is a shareware port for running DOOM game files (.wad files).

$ sudo pacman -Sy chocolate-doom

Get shareware wad file for playing DOOM demo (you can also use your full game .wad files if you own the game, I tested the Doom II wad file and it works fine):

$ cd /usr/share/doom
$ sudo wget http://www.jbserver.com/downloads/games/doom/misc/shareware/doom1.wad.zip

Unzip the file, but first install the zip/unzip utilities:

$ sudo pacman -Sy zip unzip
$ sudo unzip doom1.wad.zip

Run DOOM!!!!

$ chocolate-doom -iwad /usr/share/doom/DOOM1.WAD -window

Forget the -window if you want full screen but it will run slower. The smaller the window, the less math the GPU has to do.

References

How to test login from multiple IP addresses in Rails

July 10, 2012

At the request of a customer, I had to implement sending a notification email every time the application detects two active sessions for the same user from different IP addresses. I could not find a good example on how to test this functionality, so I decided to write a post showing my solution.

I created integration test test/integration/multiple_ip_test.rb. I my opinion, Rails integration tests are underutilized, this makes difficult to find sample code that goes beyond the basic cases.

require 'test_helper'

@@default_ip = "127.0.0.1"

class ActionController::Request
  def remote_ip
    @@default_ip
  end
end

class MultipleIpTest < ActionDispatch::IntegrationTest
  fixtures :all

  test "send email notification if login from different ip address" do
    post_via_redirect login_path,
                      :user => {:username => "john", :password => "test"}
    assert_equal "/users/john", path

    reset!
    @@default_ip = "200.1.1.1"
    post_via_redirect login_path,
                      :user => {:username => "john", :password => "test"}
    assert_equal "/users/john", path
    assert_equal 1, ActionMailer::Base.deliveries.size
  end
end

Integration tests look a lot like functional tests, but there are some differences. You cannot use @request to change the origin IP address. This is why I had to open the ActionController::Request class and redefine the remote_ip method.

Because the response to post_via_redirect is always 200, instead of using assert_response :redirect I use the URL to verify the user has logged in successfully.

The call to reset! is necessary to start a new session.

For an introduction on integration tests, check the Rails Guides on testing, unfortunately they do not mention the reset! method.

Basics of the New Massachusetts Data Privacy Regulation

August 20, 2010
Padlock Image

Last week I gave a lightning talk on this topic at Boston Ruby Group. There was nothing new in the technical part of my presentation; everyone in the audience was a professional developer and was already following good security practices.

However, I was impressed by the number of people who were not aware that now it's not only good practice; it's the law. And if you don't do it, you're subject to penalties.

I decided to write this short post with the highlights in order to help spread the word. You can get the full presentation from SlideShare. I also provide several links below to get more information and resources to help your small business become compliant.

Name

The official name of the regulation is 201 CMR 17.00: Standards for the Protection of Personal Information of Residents of the Commonwealth

When

The regulation became effective March 1, 2010

Who

Any individual, company, or organization, that stores personal information of residents of the Commonwealth of Massachusetts must comply

What is Personal Information?

Person's first name (or initial) and last name and anyone of these:

  • Social Security number
  • Driver’s license number
  • Account number: credit card, bank account, etc.

Administrative Requirements

The regulation requires one to maintain a comprehensive written information security program (WISP). This document must analyze the risks to security and describe how they'll be prevented. Some of its elements are:

  • Designate one person to be in charge of security
  • Security policies
  • Restrictions upon access to personal information
  • Keeping audit trails
  • Overseeing service providers

Technical Requirements

The most important are:

  • Firewalls, anti-virus, keeping software updated
  • User authentication: passwords or biometrics
  • Access control (permission is granted when needed only)
  • Encryption is mandatory for:
    • Email containing personal information
    • Wireless networks
    • VPN for remote access
    • Laptops and other portable devices

My Recommendations

The simplest way to comply with the regulations is not maintaining any personal information (PI) at all. However, this is rarely the case. If you own a business with 2 employees and keep their Social Security numbers, you must comply.

It's easy to use web-based services to do payroll, this way the PI won't be saved in your computer, but with your service provider. Keep paper records in a locked file cabinet inside a secure office. You still need the WISP though (see link to sample below).

If You Need Encryption

The encryption requirement is what has created more problems among small businesses, because they don't have the expertise to implement the technology.

The easiest way to comply is again: don't do it. If you need to send documents containing personal information to your customers, use fax, FedEx, even first class is compliant. And don't save personal information in your laptop, this way there's no need to encrypt it.

Encryption technology has been around for a long time and it's free if you use open source software, like GPG for email and TrueCrypt for encrypting laptops.

The problem with GPG is that it's complicated for non-technical users, especially the part that involves handling the cryptographic keys.

There are several products that provide easy to use solutions to send and receive secure messages with your customers. I like to recommend the one I developed: Solid Secure. There's no software to install. It's very easy to use because it works just like Gmail or Yahoo Mail. But as the owner of your business, you control who becomes a user.

Resources and Additional Information

Disclaimer: I am not a lawyer and this is not legal advice

My Second Week at Anything Goes Lab

August 09, 2010

Post about the 1st week.

Starting a session at Anything Goes Lab

Starting a session

If there were a single lesson I would take from these 2 weeks it would be: don't be afraid of failure. We all know this, but putting it in practice is not easy. Fear has kept me from doing many things. How did I learn this time? I heard very smart people telling stories about their failures, and they were not embarrassed; they even laughed about it.

The most convincing was having Bill Warner telling how a New York editor rejected his book. Some of his ideas were inspired by Wayne Dyer's The Power of Intention and he gave him credit for it. The editor's answer was pretty close to if I wanted to read Wayne Dyer I'd buy a book by Wayne Dyer.

As a team, we also had our own dose of failure. Scott Kirsner, a writer for the Boston Globe, came to visit. When he compared us to Curves, I don't think he meant it as a compliment.

We invited 2 guests to have lunch and talk; they were Eric Peters and Desh Deshpande. Eric was CTO and technical co-founder of Avid Technology. It was interesting to hear how Eric and Bill created the co-flow that made Avid successful.

What is Co-Flow?

All of us have multiple intentions, and because we're humans, there aren't two people with the same intentions. It's like our DNA.

A company on the other hand, has only one intention - the vision of the original founder, what he wanted to achieve with the idea. Because it is unique, it's called the primary intention. The goal of a startup is then, to build an invention to achieve the primary intention. We say that the primary intention flows through the invention.

Launchpad 1A at the Liberty Bar

At the Liberty Bar

But the founder is not alone; there are co-founders and employees, all with intentions of their own. There's co-flow when the members of the team not only follow the primary intention, but also add-up to it. They amplify it. This is the most powerful concept in building a company from the heart.

It's essential to identify the primary intention very clearly and communicate it to every member of the company. This was one of the main goals during our first week at Anything Goes Lab.

Eric Peter's task was to create the technology to allow movie editors to use a computer. It was the 80's. They were still cutting celluloid to do their work. Bill asked Eric to create the hardware and software to display movies at 15 frames per second. Defining the target display refresh rate was a tricky decision. Make the number too low and the editors won't like the product or will buy a competitor. Make it too high and you'll run into technical difficulties, need more resources, and delay the release.

Eric accepted the requirement without arguing. Didn't say anything either when Bill asked is it ready? - which I assume happened countless times. He knew his people (the editors) better than Bill. He knew 15 wasn't enough to convince them to switch. When he got back to Bill with a working solution, it was capable of displaying 30 frames/second.

This is a good example of co-flow at work. It's also proof of the exceptional abilities of Eric Peters as an engineer. It gave Avid a huge advantage over the competition, today its yearly sales are over $600 million.

Desh Deshpande

Desh (co-founder of Cascade Systems and Sycamore Networks) shared some of his stories as an entrepreneur. We have an audio recording of this session.

He agreed with most of our ideas when we discussed the principles of building a startup from the heart. He thinks using your head is an obstacle especially in the beginning. If you use your head you might never start a company. The first steps are irrational and come from the heart. But when things have started, the head can be useful too, for instance, recognizing that some approach you've been trying doesn't work. Follow your heart; use your head.

Among the teachings Desh shared with us, was one that made a big impression on me - something I already knew. But the clarity and conviction he used struck me: identify the good people early and never miss an opportunity to work with them.

Working on the board at Anything Goes Lab
Working on the board

Deliverables

Some of you might be wondering what goal we achieved; what concrete deliverables we completed in these two weeks, I know it, because we asked ourselves the same question the last few days. We took the boards and put everything in a wiki. You're welcome to take a look and make comments. There are 26 of us, with our stories, our people, intentions, beliefs and inventions.

We've already started working on our startups and intend to be in touch and help each other through this journey. Who knows - in 5 years, if we're lucky, someone else will invite us to talk to a group of young entrepreneurs, tell them our story and how it all started at Anything Goes Lab.

Post about the 1st week.