#! /bin/sh
#
# Simple startup script for syscomp CGR 101
# (C) 2009,2010 jw@suse.de, Novell Inc.
# Distributable under GPLv2 or GPLv3.
#
# 2009-04-28, jw - initial draft
# 2010-08-26, jw - moved port.cfg inside ~/.syscomp-cgr dir

dir=/usr/lib/syscomp/CGR101-1.14
# test -d $dir || dir=$HOME/src/syscomp/CGR101V110

def_port=/dev/ttyUSB0
cfg_dir=$HOME/.syscomp-cgr
port_cfg=$cfg_dir/port.cfg
mkdir -p $cfg_dir

if [ ! -f $port_cfg ]; then
  echo "Writing default port $def_port to $port_cfg"
  echo $def_port > $port_cfg
fi

if [ -f $port_cfg ]; then
  # test the port
  port=$(cat $port_cfg)
  if [ -e $port ]; then
    test -r $port -a -w $port || (echo "$port: no r/w permission, try sudo -E $0"; sleep 2)
  else
    echo ""
    echo "$port: not found, check connection??"
    echo ""
    sleep 2;
  fi
fi
 
exec wish $dir/main.tcl
