2007-12-30

Managing JPG and CR2 files

My latest toy is a Canon Digital Rebel XTi, which has the option of shooting in JPG and RAW, or both. I don't have a lot of use for RAW (CR2 on the XTi) images right now, but I might someday. And with space as cheap as it is, I set the camera to shoot in both. They both end up in the same directory, but only the JPGs show up in GQView on Xubuntu. So, I go through and delete the JPG version of what I don't want -- CR2s don't show up in the file browser. I mean, it would be easy to go through by hand and delete CR2s if an associated JPG does not exist. But here in the land of over-engineering, we create a script to do it!

I think this would be a lot easier in bash, but I don't know bash scripting. So... quick and dirty? Yea, PHP is my language of choice.

#!/usr/bin/php
function sysout($message) {
fwrite(STDOUT, $message);
}
$cr2Extension = ".CR2";
$jpgExtension = ".JPG";

if ($argc < 1) {
sysout("No directory specified, exiting.\n");
exit(-1);
}
$directory = $argv[1];
if (!is_dir($directory)) {
sysout("`$directory` is not a directory, exiting.\n");
exit(-1);
}

sysout("Working directory: $directory\n");
sysout("Removing CR2 files if JPG does not exist...\n");
$files = scandir($directory);

$count = 0;
foreach ($files as $file) {
if (strripos($file, $cr2Extension) > -1) {
sysout("Found CR2: $file\n");
$jpg = $directory . substr($file, 0, strripos($file, ".")) . $jpgExtension;
if (!is_file($jpg)) {
sysout("Deleting: $directory$file\n");
unlink($directory . $file);
$count++;
}
}
}
sysout("Process ended successfully. $count files deleted.\n");
exit(0);
?>
If anyone wants to enlighten me to the 5 line bash or Python solution, by all means. This is easily adapted to Nikon style cameras by changing $cr2Extension to something else.

2007-12-25

Echoing to system files in Ubuntu through sudo

As I was setting up the TrackPoint on my Z60t, I came across a problem:

sudo echo -n 1 > /sys/devices/platform/i8042/serio1/serio2/press_to_select
bash: /sys/devices/platform/i8042/serio1/serio2/press_to_select: Permission denied

I found an old message board post that said:
That's because bash tries to redirect the output of 'sudo echo' to the
/sys/... file, but since bash runs without elevated privileges, it
cannot do so.
His solution was:

echo -n 1| sudo tee /sys/devices/platform/i8042/serio1/serio2/press_to_select

Which worked like a charm. I've never run across the problem of having to echo something to a file that didn't needed root permissions to be edited. It makes sense, but it took me a couple of minutes to figure out, so I thought I'd post it in case anyone else comes across this problem. Also, `tee` may turn out to be a useful program: it reads from stdin and writes to stdout and files.

Unfortunately, I got kind of distracted, and my TrackPoint still doesn't work.

2007-12-16

LaCie Ethernet Big Disk and Linux

With graduation impending, I wanted to get as much out of college as possible -- that is, of media from the local network. I bought a LaCie Ethernet Big Disk because of it's capacity (1 TB), it's accessibility (both USB 2.0 and Gigabit Ethernet), and the name of LaCie (I seemed to remember them being good from back in my hardware days. To boot, they claim "full Linux Support" (see link to their product page).

As soon as I got it, I tried the USB connection and got:

[ 5565.628000] usb 5-3: new high speed USB device using ehci_hcd and address 5
[ 5565.764000] usb 5-3: configuration #1 chosen from 2 choices
[ 5565.764000] eth1: register 'cdc_ether' at usb-0000:00:1d.7-3, CDC Ethernet Device, 00:d0:4b:9d:82:e4

I didn't really want to bother with understanding that, so I got the MAC registered on the network, mounted it with cifs, and went to town.

Flash forward to two weeks later: I'm at my parents house with no sort of network to speak of, am bored, and want to start accessing all of the goodies on my Ethernet Big Disk. I started poking around in Wireshark to see what was going on over eth1; here is the dump file. Some things I noticed:

  • The first thing I got from it was: `BROWSER Host Announcement GADGET, Workstation, Server, Print Queue Server, Xenix Server, NT Workstation, NT Server, Potential Browser`, so it remembers the hostname I set on it (Gadget). It broadcasted that from 10.208.75.100, so I figured that would be it's IP address. Tried connecting to it... no dice.

  • The next thing I got were some malformed ARP broadcast packets from LaCieGro_9d:82:e4 (00:d0:4b:9d:82:e4). That matches the MAC address on the real Ethernet port, so I suppose that makes sense.



Anyway, 10.208.75.100 seems to be the magic keyword to find out more about using this device in Linux. In the meantime, I'm going to post resources I found that have been useful:



The Storage Review site turned up two interesting bits of information I didn't know about the device:
Connect hidden page [https://IP_LACIE/ssh_controlF.cgi

User: root
Pass: storage [or defaulf of your LaCie]


I'm going to try these addresses in Windows (the SSH Control could be particularly useful -- I was using a Metasploit attack on the ProFTPd 1.30 server on board to root the box. This may be easier!)

Update:
I couldn't get the ssh_controlF.cgi page to work, nor the root/storage account. Interestingly enough, I don't have permission to STOR or MKDIR from my admin account when I FTP into it.

I did get connectivity working in Linux! From Windows, I went to the admin site for the drive and changed the IP address to 192.168.0.100 (192.168.2.* is my other network), and gave myself a static IP of 192.168.0.99 on that interface. Then, from Linux, the drive showed up as eth1, so I set eth1 to 192.168.0.99 as well, and was able to successfully mount it over CIFS. I think had I just gave myself a static IP for eth1 from the first place, it would have worked (maybe LaCie could put this on their support page?)