Saturday, April 24, 2010

Converting spaces in filenames

Execute this simple one liner to convert spaces to underscores (You can replace this with any character you wish

find . -name "* *" | while read file; do target=`echo "$file"|tr -s ' ' '_'`; mv "$file" "$target"; done

Tuesday, April 6, 2010

Accessing your Popcorn A-110 with SSH

If your a user of a Popcorn Hour A-110 device you may also want to gain root access to manipulate the folders, rename/delete folders/files etc... The lost goes on and on..

Anyway the steps to do this are outlined as follows:

  • Enable FTP on the A-110
  • Install NMT Community Installer (Windows & Mac support)
  • Install Dropbear utility
  • Download the public keys from the A-110
  • Connecting to the A-110
  • Locating the Hard-Disk
Enable FTP

On the A-110 in the setup under NMT applications you need to ensure that FTP service is running. If it is not running then start the service up.


To check the FTP service is up and running you can test this out as follows:


    ftp ftp://ftpuser:1234@[A-110 IP]


Install NMT Community Installer


Point your browser to http://www.nmtinstaller.com/ and download the version for your OS (Based on my experience with this application, the Windows version is much more usable). Using the Mac version requires an additional application to install. I am running Parallels Desktop on my Mac with Windows 7 environment to install and run the Installer. I have tried the Mac version but found it to be a little buggy from a visual perspective.

Installation of this application itself is relatively simple and does not require any complex questions.

When starting up the Installer you are required to answer a few question and the most critical question being the FTP configuration of your A-110.

Install Dropbear utility

Once the Installer is successfully up and running you are now in a position to install the Dropbear.
Installation of the Dropbear utility is no different to installing any other utility within the Installer. The step by step instructions are quite simple. Also during the process of the installation it will give you some tips on how to use the Dropbear (which I will explain next).

Download public keys

Once Dropbear is installed you can now go ahead and download the public key to connect. The public key is located in the FTP root folder. Download the [id_rsa_root.openssh] file to your local drive.

   ftp ftp://ftpuser:1234@[A-110 IP]/id_rsa_root.openssh

Connecting to the A-110

Connecting to the A-110 is as simple as using the following command

   ssh root@[A-110 IP] -i id_rsa_root.openssh

This will leave you with a prompt as follows:

   root@PCH-A110 /root#

From here you are free to navigate around and do as you please. Of course you should ensure you are familiar with a Linux filesystem as to not damage the running behaviour of the A-110

Locating the Hard-Drive

The location of the hard drive is at this mount point (If you had USB sticks, then they would be located at a similar mount point).

   /opt/sybhttpd/localhost.drives/HARD_DISK

Sunday, March 14, 2010

Uploading files to my Popcorn Hour

I was for some time using SCP to transfer files from my Mac to my Popcorn Hour media player until I discovered Curl. Curl or rather cURL is a utility for transferring files using various internet protocols using URL syntax.

For a one off transfer you can simply use

curl -T {file} -u {user}:{password} ftp://{ip address}{path}

For sending a complete folder I manage to find a useful script (batch_folder_upload.sh) and adapt it for my needs

#!/bin/sh 

Pwd=$(pwd)
fullDir=$Pwd/$1

echo $fullDir

if [ ! -d $fullDir ]
then
   echo "Could not find folder to upload from $fullDir"
   exit -1
fi

for file in $1/* ; do
 echo "Uploading $file to /Upload/$1"
 curl --globoff --ftp-create-dirs -T $file -u ftpuser:1234 ftp://192.168.1.9/Upload/$1/
done

I have included the --globoff argument as curl does not like the use of [ or ] in the filename. Apparantly there is a fix coming for this issue.

Simply invoke the script

   $ ./batch_upload

Format your code blocks for blogging

Here is a nice link I found for converting code blocks to be viewed in a more readable way.

Formatting Code blocks for pasting into blog posts

Adding image borders and EXIF tagging

I found a web blog from Frederico Maggi who posted a nice tutorial for batch editing image files to add a border with some Exif data.

The work by Frederico was a great start and I took his work and made a few treaks. The major change I made was to the ~/bin/lr_borderscript. I felt that the border size was too small and that the text was too small. I also adapted the script to perform a rename using the convert utility

#!/bin/sh
#File: ~/bin/lr_border
 
year=$($HOME/bin/exiv_year $1)
data=$($HOME/bin/exiv_data $1)
 
name="Carl Wainwright © "
 
if [ -n "$year" ]
then
name=$name" "$year
fi

inname=`convert $1 -format "%t" info:` 
echo "Processing $inname"

outname=${inname}_mod.jpg
#convert $1 -resize 50% $outname
convert $1 $outname

echo "Writing to $outname"
 
mogrify -gravity North -border 5x5 -bordercolor black $outname
mogrify -gravity North -border 1x1 -bordercolor grey $outname
mogrify -gravity North -border 60x60 -bordercolor black $outname
 
if [ -n "$data" ]
then
mogrify -pointsize 30 -fill white -gravity SouthEast -annotate +25+6 "$name" -gravity SouthWest -annotate +25+6 "$data" $outname
else
mogrify -pointsize 30 -fill white -gravity SouthEast -annotate +25+6 "$name" $outname
fi

I also modified the exiv_data script to match the Exif data for my Konica Minolta 7D.


#!/bin/sh
#File: $HOME/bin/exiv_data
time=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.Photo\.ExposureTime" | awk '{print $2}')
focal=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.FocalLength " | awk '{print $2}')
aperture=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.Photo\.FNumber" | awk '{print $2}')
iso=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.ISOSpeedRatings" | awk '{print $2}')
 
if [ -n "$time" -a -n "$focal" -a -n "$aperture" -a -n "$iso" ]
then
echo $focal"mm, "$time" @ "$aperture" (ISO "$iso")"
fi

Executing the above script can be done as follows 

ls *.JPG | while read file; do ~/bin/lr_borderscript_new $file; done

Start of a new Adventure

First post of my blogging adventure...

First stop to collect some of my recent scripts and command lines to get things going..