#!/bin/sh
set -e

KUMATUXVERSION=1.0

echo "PAY ATTENTION NOW:"
echo "N900 lacks bash, therefore standard stuff like getopts doesn't work in scripts,"
echo "therefore you MUST run kumatux-setup.sh with the following syntax:"
echo "kumatux-setup.sh <absolute path to kumatux-setup.sh> <path to kumatux root> <path to kumatux links>"
echo "where:
      kumatux root refers to the directory which will hold special numeric links to
      kumatux links. These root links will be appended to PATH etc.;
      kumatux links refer to the links, that will be created for each program's files,
      in a kumatux centralized links' repository;
      For a proper way of installing kumatux on a bash enabled system check kumatux-setup.sh"
KUMATUXSETUPBIN=`dirname $1`/bin
KUMATUXSETUPROOT=$2
KUMATUXSETUPLINKS=$3

touch /home/user/.profile
## Record the paths in users profile
if [ "`grep "^export KUMATUXBIN" ~/.profile`" ]
then
    sed -i '/^export KUMATUXBIN/d' ~/.profile
fi
echo "export KUMATUXBIN=$KUMATUXSETUPBIN" >> ~/.profile

if [ "`grep "^export KUMATUXLINKS" ~/.profile`" ]
then
    sed -i '/^export KUMATUXLINKS/d' ~/.profile
fi
echo "export KUMATUXLINKS=$KUMATUXSETUPLINKS" >> ~/.profile

if [ "`grep "^export KUMATUXROOT" ~/.profile`" ]
then
    sed -i '/^export KUMATUXROOT/d' ~/.profile
fi
echo "export KUMATUXROOT=$KUMATUXSETUPROOT" >> ~/.profile

if [ "`grep "optexport" ~/.profile`" ]
then
    sed -i '/optexport/d' ~/.profile
fi
echo '. $KUMATUXBIN/optexport' >> ~/.profile

KUMATUXSETUPBIN=$KUMATUXSETUPBIN KUMATUXSETUPROOT=$KUMATUXSETUPROOT KUMATUXSETUPLINKS=$KUMATUXSETUPLINKS $KUMATUXSETUPBIN/setup.sh/directories.sh
KUMATUXSETUPBIN=$KUMATUXSETUPBIN KUMATUXSETUPROOT=$KUMATUXSETUPROOT KUMATUXSETUPLINKS=$KUMATUXSETUPLINKS $KUMATUXSETUPBIN/setup.sh/etc.sh
