#!/bin/sh
set -e

# WSJT expects to write configuration files in the current directory,
# which also needs to contain CALL3.TXT and TSKY.DAT before starting.
# If those don't currently exist, create them first.

RUNDIR=$HOME/.wsjt

if [ ! -d $RUNDIR ]; then
	mkdir $RUNDIR
fi

if [ ! -f $RUNDIR/CALL3.TXT ]; then
	zcat /usr/share/wsjt/CALL3.TXT.gz > $RUNDIR/CALL3.TXT
fi
if [ ! -f $RUNDIR/TSKY.DAT ]; then
	zcat /usr/share/wsjt/TSKY.DAT.gz > $RUNDIR/TSKY.DAT
fi
if [ ! -f $RUNDIR/wsjtrc ]; then
	cp /usr/share/wsjt/wsjtrc $RUNDIR
fi
if [ ! -d $RUNDIR/RxWav ]; then
	mkdir $RUNDIR/RxWav
	ln -s /usr/share/doc/wsjt/examples $RUNDIR/RxWav/Samples
fi
if [ ! -f $RUNDIR/wsjt.xbm ]; then
	cp /usr/share/wsjt/wsjt.xbm $RUNDIR
fi

# WSJT needs to now run from $HOME/.wsjt with PYTHONPATH updated
# to find the shared library

cd $RUNDIR
env PYTHONPATH=/usr/lib/wsjt python /usr/share/wsjt/wsjt.py

