#!/usr/bin/env bash
# Script by Todd Allis, 29 Sep 2010
# Special thanks to PreCentral and WebOS homebrewers!
# This script will read token values from text files in the current
# directory and output them in an XML file to be pasted into a
# castle.xml file for use in reprogramming a Palm Pre / Palm Pre Plus.
# See http://forums.precentral.net/palm-pre-tips-information-resources/259077-pre-plus-sprint-step-step-conversion-guide.html
# for more details.
# First, let's define all of the tokens we'll use.
tokenlist='ProdSN ModemSN BATToRSP BATToCH DMSVRoNONCE DMSVRoAUTHPW DMCLoNONCE DMCLoAUTHPW DMCLoAUTHNAME DMCARRIER DMMODEL WIFIoADDR BToADDR PalmSN PRODoID PN'
# Next check to make sure each file is in the directory.
# A simple flag
filenotfound=n
for t in $tokenlist;
do
if [ ! -e "./"$t ]
then
echo "Error: $t not found in current directory."
filenotfound=y
fi
done
# If the flag was set even once, there's at least one file missing. Quit.
if [ $filenotfound == y ];
then
echo " "
echo "Error: One or more files not found in current directory. Did you copy the tokens over? Are you in the directory with the tokens?"
exit 1
fi
# Output the XML headers first. I put the big block of space on its own line.
echo '<Section name="tokens" type="token" size="4KB">'
echo -n ' '
echo '<Val name="installer" value="trenchcoat"/>'
# Now to grab and output each variable. I used an array keyed to the filename
# / variable name like: token[ProdSN], token[ModemSN], etc.
for t in $tokenlist;
do
token[$t]=`cat ./$t`
echo -n ' '
echo '<Val name="'$t'" action="overwrite" value="'${token[$t]}'"/>'
done
# Lastly, output the XML footer.
echo ' </Section>'