#!/bin/bash
if [ -d /usr/local/share/codesys ]; then
BASEPATH=/usr/local/share/codesys
else
BASEPATH=$(pwd)/scripts
fi
# check if file exists, before we call CODESYS with it
if [ ! -f ${BASEPATH}/${1}.py ]; then
echo "error: script '${BASEPATH}/${1}.py' not found."
exit -1
fi
# get first CODESYS profile and start the script with it
profile=$(basename "$(ls -1 ~/.wine.cds/drive_c/CODESYS/CODESYS/Profiles/*.profile | head -n 1 | sed 's,.profile,,')")
export WINEPREFIX=~/.wine.cds
wine-development ~/.wine.cds/drive_c/CODESYS/CODESYS/Common/CODESYS.exe --culture=en --profile="'"${profile}"'" --runscript="z:${BASEPATH}/${1}.py" --noUI