So in Part One, we took an old external had drive, and added it as storage to a Raspberry Pi. In Part Two, we took that Raspberry Pi and shared the new folders on the local network. In this final tutorial, I’ll show what all of this has been for, and show you how to create your own Home Theater Raspberry Pi.
Category Archives: How To
How to Share a Folder on Raspberry Pi
In part one of our tutorial, we discussed how to mount an external hard drive or USB drive on to our Raspberry Pi (or any other Linux based) computer. In this tutorial we will discuss how to share folders from that computer to your local network. I am doing this so I can share the media files I have on my external hard drive, and access them from many places on my network, such as my laptop, my android phone, and my Raspberry Pi running XBMC. You can use this tutorial to share files in a similar way.
How to Mount USB Disks on Raspberry Pi
I’ve got a Raspberry Pi, and I’ve got an old external hard drive. So what can I do with them? I decided I was going to create a networked shared drive from them, so in this first tutorial, I will show you how to mount the drive on a Linux operating system. Doing this is easy, but can get a little tricky when you attach and remove drives on the fly.
Handling Shell Script Interrupts
If you do much shell scripting, then handling shell interrupts is something you should consider. As a user is interacting with your script, they may decide to interrupt it by typing Ctrl-C, for example. Typically this will interrupt your shell script execution, forcing it to exit.
Depending on what your shell script is doing, this could leave behind temporary files, or leave other files in a broken state. It would be useful if you could trap the interrupt, and handle it safely, before exiting the script.
This can be achieved on most shells using the ‘trap’ command. The trap command takes the following syntax:
trap [OPTIONS] [[ARG] SIGSPEC ... ]
The ARG is the command to be executed on signal delivery, while SIGSPEC is the name of the signal(s) to trap. Options include -h for help, -l to list signal names, or -p to print all defined signal handlers.
For example, to always return a ‘user aborted’ error code, the following line in your script could be used. Whatever value given to $exit_user_abort would be returned.
trap 'echo "`basename $0`: Ouch! User Aborted." 1>&2; exit $exit_user_abort' 1 2 15
The numbers 1, 2 and 15 at the end of this example define which interrupts we’re interested in trapping. These numbers correspond to different kinds of interrupts. A short list is given here, but you can use ‘trap -l’ for a complete list.
| Signal Number | Signal Name | Explanation |
|---|---|---|
| 0 | EXIT | exit command. Script has executed successfully. |
| 1 | HUP | Hang Up. The user session has disconnected. |
| 2 | INT | Interrupt. Ctrl-C (or other shell interrupt signal) has been given. |
| 3 | QUIT | Quit. Ctrl-\ (or other shell quit signal) has been given. |
| 6 | ABRT | Abort signal. |
| 15 | TERM | Terminate. Kill command has been issued against your script. |
If your trap runs several commands, it’s possibly neater to call a shell function than list the commands in-line, as above. For example:
trap funcname 1 2 15
funcname
# Function to handle interrupts
{
echo "`basename $0`: Ouch! User Aborted." 1>&2
exit $exit_user_abort
}
Ini files and Apache Commons Configuration
The project I’m currently working on uses a simplistic object store for persistence. The original authors, in their collective wisdom, decided that whenever something needed to be saved they would save it to a hashtable, and use Java serialization to save that to a file.
In a way I can see why they did. It’s a quick way of getting a simple to use object store. The project has been through several revisions since, but the data store stayed the same. It should have been replaced with something more robust a long time ago. I’ll explain more after the jump …
Automatically Unmount Network Shares on Ubuntu
I’ve mentioned before, how I mount shared drives in Ubuntu both at home and at work. While this is quite useful, it seems the default setup for Ubuntu stops the network interface before disconnecting these drives. This results in Ubuntu hanging for a while on shutdown while these drives time out. After the jump we describe how to solve this problem.
FARTing Around
I’ve recently become aware of Getting Things Done, and have been attempting to practice it for the last six weeks. In many ways, it is very similar to what I had been doing previously. You could call my method a lightweight GTD, and it’s based on the FART mnemonic.
For any item that crosses my desk, be it email, IM, memos, or stickies, I follow the same basic triage process. Four directives (File, Act, Redirect or Trash) are applied based on a few simple considerations. These are as follows:
- Do I need to refer to this item again?
If so, file it somewhere easily searchable such as a mail folder, content management system, Wiki, etc. Remove the item from your In-box to the file location. Continue to consider the other questions.
- Do I need to act on this?
If so, add a to-do to your to-do list. Prioritise and schedule work on the action using your to-do list. Remove the item from your In-box by Filing, Redirection, or Trashing.
- Am I the best person to work on this?
If not, redirect or delegate it to someone else. You may, if you feel you need to, add a reminder to your to-do list to follow up with the delegate.
- Trash it, you’re done.
By now, you’ve filed the item if necessary, decided to act on it, or delegated it. What other possible action can you now take? You have extracted all value from the item, so the only other option is to remove it from your In-box. If you have not done so already, or filed the item to a folder, move the item to the trash. You are now done with processing your incoming items. All that remains is to tackle your to-do list.
Repeat as necessary, and you will soon find that heap of email shrinking. In-box 0 is not an impossible goal. All you need to do, is think outside the In-box!
Pre-Merge Formatting
A problem with formatting code on a branch, is when you come to merge it back to the trunk, you end up having to work thorough lots of file changes which are really only formatting changes. The larger your project size, the more work this involves. I was faced with a similar task recently.
While editing file by file, I usually do the Ctrl-A Ctrl-Shift-F combo to ensure the file is formatted according to our corporate standards before saving any edits. Since much of the code I touched on the branch was formatted under a different standard, and I touched a lot of files while introducing log4j logging, the end result was heading for a hairy merge. What I really needed was a way to bulk format both the branch and the trunk versions of the code-base.
Luckily, I realised that that same formatter embedded in Eclipse can be used to bulk format Java source. Here’s how …
Howto: Pause a Shell Script
File this one under “Another Nifty script-let”. The problem this time is getting a shell script to pause for user input. What I needed was a way to make a script stop, saying “Hit a key to continue..”, wait for the user to hit a key, then continue the script execution. Here’s how:
Technical Marketing

Tag Cloud
It saddens me sometimes to see videos like this. While the rest of us chuckle, we fail to learn the lesson, that users don’t share our world view of software.
As a Software Engineer, I am too well aware of our industries penchant for technical terms. Yet the fact remains that you can use the internet without knowing what a “browser” is, just as well as you can drive a car without knowing what a “limited slip differential” is.








