#!/bin/sh
# script to load/save all the vars in speakup
#  Copyright (C) 2008 Steve Holmes
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#   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, see <http://www.gnu.org/licenses/>.
# speakupconf save or speakupconf load
# if root saves in /etc/speakup/<synth> else in $HOME/.speakup/<synth>
if [ $UID -eq "0" ]; then
  SAVEDIR="/etc/speakup"
else
  SAVEDIR="$HOME/.speakup"
fi
if [ ! -d /sys/module/speakup/parameters ]; then
  echo "no directory /sys/module/speakup/parameters"
  exit 0
fi
SYNTH=`cat /sys/module/speakup/parameters/synth`
case "$1" in
*save)
  if [ ! -d $SAVEDIR ] ; then
    echo creating $SAVEDIR
    mkdir $SAVEDIR
  fi
  if [ ! -d $SAVEDIR/$SYNTH ] ; then
    echo creating $SAVEDIR/$SYNTH
    mkdir $SAVEDIR/$SYNTH
  fi
  cd /sys/module/speakup/parameters
  SAVELIST=`    find . -perm -600 |sed 's/..//' |fgrep -v synth`
  for f in $SAVELIST; do
    cp $f $SAVEDIR/$SYNTH/$f
  done
;;
*load)
  if [ ! -d $SAVEDIR ] ; then
    echo no directory $SAVEDIR
    exit 1
  fi
  if [ ! -d $SAVEDIR/$SYNTH ] ; then
    echo no directory $SAVEDIR/$SYNTH
    exit 1
  fi
  cd $SAVEDIR/$SYNTH
  for f in *; do
    if [ -w /sys/module/speakup/parameters/$f ]; then
      cat $f >/sys/module/speakup/parameters/$f
    fi
  done
;;
*)
  echo "usage: speakupconf load/save"
  exit 1
;;
esac
