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: Linux
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
}
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:
How to change date formats on Ubuntu
In order to change the system date format on Ubuntu, you need to know a little about where the date format is coming from. Regional settings, such as date and time formats, as well as language, sort order, etc. are specified in files called locales. A locale contains the rules specifying how dates and times are formatted, amongst other settings.
Home Network Hard Drives.
I decided to splash out on a Home Network Hard Drive this weekend. It was a spur of the moment decision to go with the Iomega drive, as I didn’t spend much time researching options online, as I normally would do.
I plan on using the drive primarily for backups of my music, photo and other data collections. Since I bought my girlfriend a digital camera, she’s also needed extra drive space for storing photos, etc.
The software that ships with the drive, in a word, sucked. It looks and works like it was knocked out by a hungover engineer, the morning after the Office Christmas Party. Usability sucked, though it was functional, and I had the Windows XP laptop configured to connect to the drive as a network share. The drive also sports a web based administration tool, which is also functional though suffers from the same usability issues as the desktop client driver.
While the box notes the drives support for Linux, there is very little mention of it in the help or on the support section of the Iomega site. When you search for Linux, you end up redirected to the Mac OSX instructions. Come on Iomega, it’s obvious the drive is based on Samba, so your not entirely unfamiliar with Linux. It won’t take a lot to document how to mount the drive on Linux, and include it in your documentation set.
Connecting the Ubuntu desktop to the drive involved installing smbfs support using:
sudo apt-get install smbfs
Then adding the following line to /etc/fstab and issuing a “mount -a” command as root.
//192.168.1.103/PUBLIC /media/public cifs auto,uid=1000,gid=1000,umask=000,user 0 0
That is assuming you remain with defaults. As usernames and passwords can be changed through the web based administration tool, the connection string above would have to be modified in line. The IP may differ for your setup also.
Since then, I have registered with Iomega, to recieve notifications of software updates. I’ve updated the drives firmware, which forced an upgrade of the Windows client driver. It still sucks, from a usability standpoint, but at least it sucks a little less.
Once mounted under either Windows or Ubuntu, use of the drive is like any other. Though I have had some system freezes on Ubuntu when transferring large file sets, with large volumes of data. I have yet to diagnose the cause of this issue.
How To Install GlassFish on Windows
1. Download GlassFish
Download the installation jar for GlassFish. I went with GlassFish V2, since this is the latest stable release, though I think this technique will work with any version listed on the download page.
2. Install it
The GlassFish V2 Installation instructions show how to install it once download is complete. The problem with the GlassFish installer is that it does not register as a service with Windows, so once you log out, the GlassFish instance will terminate.
3. Register as a Service.
There are a few ways of doing this. The Hard Way, or my favourite the Easy Way. Once the service is registered, GlassFish will continue to run once you log out, and can be controlled through the Services applet from Control Panel, though continued use of asadmin is recommended.
Alternatively, use Ubuntu, where you can install GlassFish as easy as:
sudo apt-get install glassfish
Ubuntu wins again :-)
Ubuntu Printing
Problem: Printing from Ubuntu to the departmental printer results in the first page printing, followed by a blank page, no subsequent pages are printed. Printing a test page results in a second blank page also.
Solution: … Continue reading
Serial Port Jiggery-Pokery
How to enable and disable serial ports on Ubuntu
Today, I had to fix a bug in some software I’m working on. The details of the bug aren’t that important, apart from the fact that the bug only became apparent when the software was run on a system with one or less serial ports.
Since I’m debugging on Ubuntu, and I have two serial ports (/dev/ttyS0 and /dev/ttyS1), I needed to find a way to temporarily disable one. This is how I achieved it.





