Skip to content

Instantly share code, notes, and snippets.

@hemantborole
Created October 1, 2009 21:24
Show Gist options
  • Save hemantborole/199252 to your computer and use it in GitHub Desktop.
Save hemantborole/199252 to your computer and use it in GitHub Desktop.
#!/bin/bash
BASE_DIR="/mnt/grammars"
curl="curl --retry 3 --silent --show-error --fail"
instance_data_url=http://169.254.169.254/latest/user-data
# Starting an instance
# ec2-run-instance --user-data-file "http://s3_url"
# export GRAMMAR_URL=""
# export AM_URL=""
user_data_file=$(tempfile --prefix ec2 --suffix .user-data --mode 700)
if [ ! -z $1 ]; then
cp $1 $user_data_file;
else
$curl -o $user_data_file $instance_data_url 2>&1
fi
## user data requests some, none or all of the grammars to be
## s3 gotten into the watson instance.
## user data format e.g
## AM=(mixt20.mmf.tgz mixt10.mmf) ## note 2 am are requested
## LM=chacha.2.4gm.lm ## note grammar may or may not be compressed.
. $user_data_file
## s3get the respective grammar file,
## check if it gzip and if ye then uncompress it.
## add other compression formats in a switch case statement.
function get_and_uncompress() {
m=$1
m_elem=$2
WATSON_S3='/ypcsrd-watson/grammars'
s3get $WATSON_S3/${m}/${m_elem} ${m_elem}
isgz=`file ${m_elem}|awk -F":" '$2 ~ /gzip/ { print "gzip"}'`
if [ ! -z $isgz ]
then
tar zxvf ${m_elem}
fi
}
## if one or more acoustic model is requested.
if [ ! -z $AM ]
then
cd $BASE_DIR/am/
for am_elem in ${AM[@]}
do
get_and_uncompress 'am' $am_elem
done
fi
## if one or more language model is requested.
if [ ! -z $LM ]
then
cd $BASE_DIR/lm/
for lm_elem in ${LM[@]}
do
get_and_uncompress 'lm' $lm_elem
done
fi
## if one or more natural lm is requested.
if [ ! -z $NLM ]
then
cd $BASE_DIR/nlm/
for nlm_elem in ${NLM[@]}
do
get_and_uncompress 'nlm' $nlm_elem
done
fi
## if one or more tts data file is requested.
if [ ! -z $TTS ]
then
cd $BASE_DIR/tts/
for tts_elem in ${TTS[@]}
do
get_and_uncompress 'tts' $tts_elem
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment