Archives for May, 2010

26
May

Fedora 13 Released Yesterday…

If you haven’t heard, Fedora 13 was released yesterday. I had the chance to sit down and play with it myself and found it quite easy and comfortable. I would recommend that anybody check it out.

By the way, I just finished verifying my Fedora 13 and MacBook Aluminum 5,1 guide last night as well, so if you have a MacBook, this guide ought to be helpful for you!

25
May

How To: Install VirtualBox 3.2 on Fedora 13

This is a step by step tutorial on how to get VirtualBox 3.2 up and running on Fedora 13. Specifically, this guide was written using the VirtualBox 3.2.0 (32-bit) version. It can be adapted to upcoming versions and different CPUs (64-bit). The folks at VirtualBox have made it easy to install for Fedora users and I’m going to show you how in a few easy steps. Right, open a terminal window and let’s get to it…
[Read more →]

24
May

Embedding Code in HTML Page

Here’s a method for embedding code in an HTML page using a quick and painless tool called code2html. code2html is available in most distribution repositories, so installing it is just a matter of calling your package manager like yum install code2html. After installing it, here’s an example of how to use it:

code2html -l plain -o html-nocolor myprogram.c > myprogram.c.html

OR

cat myprogram.c | code2html -l plain -o html-nocolor - > myprogram.c.html

When finished, you can then copy/paste the contents into another webpage. In my example, I chose to have a plain conversion and no colors so that I can use the <pre> tag to make my output look like I want it to.

Be sure to check out the code2html man page for plenty of other examples and usage information.

20
May

Prepping, Cleaning, and Compressing an Image

Here are some non-comprehensive tips for creating an image from a block device that runs an embedded Linux system (ie. SD Card, USB Drive, etc). Using these steps will help you prepare, clean, and compress an image to the smallest size possible. I used these recently to create a microSD card image for the company I work for (Technologic Systems) so we can upload them to an FTP server that customers have access to. It runs Debian Linux with and initrd and Busybox. I believe that BeagleBoard and other embedded system companies who produce single board computers (SBCs) also have a similar setup to this.

Steps on the Embedded System Itself:
Clear any history from within Busybox:

> .ash_profile

Boot to full Debian and clean up:

apt-get autoremove
apt-get clean
rm -rf /var/log/*/*

Now, clear any history in Debian and shutdown:

> .bash_history; history -c; shutdown -h now

Steps on the Linux PC:
Mount SD card on another Linux box (assumes /dev/sdb) and “zero out” all available partitions. In this example, there are four, one is raw kernel image so it is left alone:

mount /dev/sdb1 /mnt/tmp; cd /mnt/tmp
dd if=/dev/zero of=zerofill; rm -rf zerofill
umount /dev/sdb1

mount /dev/sdb3 /mnt/tmp; cd /mnt/tmp
dd if=/dev/zero of=zerofill; rm -rf zerofill
umount /dev/sdb3

mount /dev/sdb4 /mnt/tmp; cd /mnt/tmp
dd if=/dev/zero of=zerofill; rm -rf zerofill
umount /dev/sdb4

Now, create the .dd image and compress it:

dd if=/dev/sdb of=theImage.dd
bzip2 --best theImage.dd

Using the steps above, I was able to compress a 2GB SD image down to ~800MB (zeros compress very well)! And, since I took the time to clear out the history and logs, the user who downloads and uses the image will have a nice, clean image to work from. You could take it another step further and reduce the size of your kernel modules using my other guide:
Command to Reduce File Size of Installed Kernel Modules

18
May

How Unique is Your Web Browser?

It turns out that your web browser might be unique enough that it can be tracked. Take a break and check out this webpage:
https://panopticlick.eff.org/

17
May

Picup: A Keyword Scanning Script to Synchronize or Upload Photos to an Online Gallery

Picup is a script that scans for photos that match a specified keyword and then uploads it to a gallery on a remote server. Although this script serves a specific purpose to myself, I believe it will be very handy for others to use as well. There is only one dependency: rsync and sh, meaning it will run on just about any UNIX system like Linux or Mac OSX.

Download picup
(Right-Click and “Save Link As…”)

I’ve included two options for getting your photos uploaded to a website: 1.) directly upload the photos that have been found that match the keyword and 2.) synchronize all the photos (even the untagged photos) to a general location on the server and then have the cream of the crop (photos marked with keyword) displayed in another location on the server such as a gallery. The picup script works quite well with photo gallery websites like ZenPhoto where a database is not necessary and photos can be directly uploaded to an album folder such as /public_html/zenphoto/albums/.

There are many other options available as well that can be easily configured. These are all documented in the configuration file called picup_config which is automatically generated and populated with examples when the script is ran for the first time.

Here’s an example run to give you a better idea of what the script actually does:

$ picup
Searching for pictures marked with "favorites" in:
/MyFiles/Pictures/2010/05 - May/
This might take a while depending on the amount of files in directory...
2010/05 - May/My Pictures in May/IMG_0001.jpg
2010/05 - May/My Pictures in May/IMG_0002.jpg
2010/05 - May/My Pictures in May/IMG_0003.jpg
Please VERIFY the steps that are ABOUT TO BE EXECUTED!
This script is about to synchronize the directory
   /MyFiles/Pictures/
with the remote site
   username@domainname.com:/home/username/public_html/pictures
with the options of
   -avzh -e ssh --numeric-ids -i --delete-after --exclude-from=/MyFiles/Pictures/excludes
which will appear on the server as
   /home/username/public_html/pictures/2010/05 - May/My Pictures in May/IMG_0001.jpg
When finished, the following command will ran on the server
   ln -s "/home/username/public_html/pictures/2010/05 - May/My Pictures in May/IMG_0001.jpg" "/home/username/public_html/gallery/albums/2010/05 - May/My Pictures in May/IMG_0001.jpg"

Do you wish to continue? <yes,no> yes
building file list ... done
<rsync output snipped>

Uploading and executing script on server...
server_exec                                   100% 1071     1.1KB/s   00:00
Finished uploading your pictures.  Enjoy!
$

I hope you find some use in this script. One of the goals that I was working hard for was to make this as easy as possible to use as well as keep the script speedy in execution. If you have questions, please let me know. I’d like to know if this gets any attention in the ZenPhoto community or elsewhere.

Also, if you’ve seen my old embarrassment of the picup script , I believe this to be a massive improvement.

13
May

Yet Another Quick Serial Read c Program

Here’s yet another quick example of a serial capture c program that I came across while at work the other day. I just figured I would share…

int main(int argc, char * argv[]){
while(1){
FILE *fp;

fp = fopen("/proc/bus/usb/001/003", "r");

char buff[100];
while(fscanf(fp, "%s", buff) != EOF){
printf("%sn", buff);
}
fclose(fp);
}
return 0;
}
12
May

Grab Raw Keyboard Input from Event Device Node (/dev/input/event)

The following is a quick c program that will capture raw keyboard data from the event device node such as /dev/input/event1. Simply compile and run with the specific device node as an argument. ie. ./keyboard_key_capture /dev/input/event1.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <dirent.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <termios.h>
#include <signal.h>

void handler (int sig)
{
  printf ("nexiting...(%d)n", sig);
  exit (0);
}

void perror_exit (char *error)
{
  perror (error);
  handler (9);
}

int main (int argc, char *argv[])
{
  struct input_event ev[64];
  int fd, rd, value, size = sizeof (struct input_event);
  char name[256] = "Unknown";
  char *device = NULL;

  //Setup check
  if (argv[1] == NULL){
      printf("Please specify (on the command line) the path to the dev event interface devicen");
      exit (0);
    }

  if ((getuid ()) != 0)
    printf ("You are not root! This may not work...n");

  if (argc > 1)
    device = argv[1];

  //Open Device
  if ((fd = open (device, O_RDONLY)) == -1)
    printf ("%s is not a vaild device.n", device);

  //Print Device Name
  ioctl (fd, EVIOCGNAME (sizeof (name)), name);
  printf ("Reading From : %s (%s)n", device, name);

  while (1){
      if ((rd = read (fd, ev, size * 64)) < size)
          perror_exit ("read()");      

      value = ev[0].value;

      if (value != ' ' && ev[1].value == 1 && ev[1].type == 1){ // Only read the key press event
	   printf ("Code[%d]n", (ev[1].code));
      }
  }

  return 0;
}

Here is an example output from running the above command. Notice that Code[] is printed before the key that was pressed.

# ./keyb_key_cap_x86 /dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd
Reading From : /dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd (Dell Dell USB Keyboard)
Code[30]
aCode[48]
bCode[46]
cCode[32]
dCode[18]
eCode[33]
fCode[34]
gCode[35]
hCode[23]
iCode[36]
jCode[37]
kCode[38]
lCode[50]
mCode[49]
nCode[24]
oCode[25]
pCode[16]
qCode[19]
rCode[31]
sCode[20]
tCode[22]
uCode[47]
vCode[17]
wCode[45]
xCode[21]
yCode[44]
zCode[2]
1Code[3]
2Code[4]
3Code[5]
4Code[6]
5Code[7]
6Code[8]
7Code[9]
8Code[10]
9Code[11]
0

This is only an example program that I picked up from work. I hope it will be of use to somebody out there so it can quickly help you get started with your project.

11
May

Fixing ‘rm: cannot remove’ or ‘rm: cannot lstat’ Error Messages

If you happen to come across an error message such as the following, chances are that your filesystem has become corrupted somehow and all it really needs is some good ‘ol T.L.C. with fsck -f.

rm: cannot lstat `filename': Permission denied
rm: cannot remove `filename': Stale NFS file handle
10
May

Echo or Cat Multiple Lines or Paragraph of Text from within a Shell Script

If you find yourself needing to echo out multiple lines to the console, or even to another file, then you’ll want to use the following method which is much cleaner and much more efficient. It’s very useful in creating another document, script, or file without having to use echo for each line.

#!/bin/sh

cat > new_file << EOF
This will be line one
This will be line two
This will be line three
   This will be line four indented
Notice the absence of spaces on the next line
EOF

cat new_file

Basically, what the above script will do is use cat to write the following lines up to a delimiter, in this case EOF, to a file called new_file. The most important thing to keep in mind is that for this to work, there cannot be any spaces before the delimiter. The output of running this script looks like:

This will be line one
This will be line two
This will be line three
   This will be line four indented
Notice the absence of spaces on the next line

Naturally, this method will also work in the terminal command line and is not restricted to only shell scripts.

Next Page »