#!/bin/bash -x

# Copyright (C) 2012 DECOIT GmbH <asterisk4ucs@decoit.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -e
set -u
set -x

STEM="$1"
INPUT="$2"
CLASS="$3"
SSHTARGET="$4"
SSHPATH="$5"
SSHCMD="$6"

mkdir $CLASS

sox -V3 $INPUT -r 8000 -c 1 $CLASS/$STEM.wav
sox -V3 $INPUT -r 8000 -c 1 $CLASS/$STEM.gsm

chmod 0755 $CLASS
chmod 0644 $CLASS/*

scp -Bqr $CLASS $SSHTARGET:$SSHPATH
ssh -oBatchMode=yes $SSHTARGET "$SSHCMD -rx 'moh reload'"

echo Done.

