Atum Tenório

Sobre as coisas que para aí andam e nos caem à frente.

sábado, março 14, 2009

tech: Olympus LS 10 and Linux

script para transferir ficheiros wav de um Olympus LS 10 adicionando a data de geração ao nome do ficheiro.

script to transfer wav files from an Olympus LS 10, adding the creation date to the file name


#!/bin/bash
# transfer_ls10.sh
# writen by rreis@aero.ist.utl.pt 2009.03.14
# Under the GPL v2
#
# Mount a Olympus LX 10 device, copy all wav files to a directory
# adding creation date to their names
#
# Usage:
#
# ./transfer_ls10.sh
#
# Before usage edit
# savedir=< dir under where files will be saved >
#
# As usual, use at your own risk. For me it works without problem
# your system can be diferent. This is open source, check the code,
# improve it, return it back to the rest
#
# Happy recordings!
#
##################################################################

# mount device

device=$1
checkfile="$device/olyml_tb.dat"
savedir=/home/fuji/audio/recordings
ls10dirprefx="dss_fld"
tmplisting="/tmp/$$tmp"

if [[ -z "$device" ]]; then
echo
echo "WARNING: Specify mount point"
echo
exit -1
fi

# check if it is Olympus LS 10

mount $device

echo "Checking for $checkfile"

if [ ! -e "$checkfile" ]; then
echo
echo "WARNING: It doesn't looks like the Olympus LS 10!"
echo "WARNING: $checkfile not present"
echo "WARNING: ls result"
echo
ls $device
echo
umount $device
exit -1
fi

echo "Device OK. Looks like an Olympus LS 10"

# create dir for saving the transfered files
# if dir already exists don't complain

date=`date +"%Y.%m.%d"`
savedir="$savedir/ls10_$date"
mkdir -p $savedir

# build copy script header

echo "#!/bin/bash" > $tmplisting
echo " " >> $tmplisting
chmod 700 $tmplisting

# get file times and new names
echo "Compiling files on device"
slist="a b c d"
for fld in $slist; do

dr="$device/$ls10dirprefx"$fld

find $dr -name "*.wav" -prune \
-printf "cp -a $dr/%f $savedir/%TY.%Tm.%Td-%TH:%TM.%f \n" \
>> $tmplisting

done

echo "Copying files"
/./$tmplisting

echo "Cleaning up"
rm $tmplisting
cd
umount $device
echo "End"

exit 0