#!/bin/sh

SAYYA=edt1023.sayya.org
CLE=cle.linux.org.tw
nosee=noseeing.tar.gz
cd
[ -d tmp ] || mkdir tmp
cd tmp
rm -f $nosee

wget http://$SAYYA/gcin/$nosee > /dev/null 2>&1
if [ $? != 0 ]; then
  wget http://$CLE/~edt1023/gcin/$nosee > /dev/null 2>&1
fi
if [ ! -f $nosee ]; then
  echo "file $nosee was not downloaded"
  exit 1
fi

tar xvfz $nosee
if [ $? != 0 ]; then
  echo "tar error, maybe the file $nosee is not complete"
  exit 1
fi
id=`id -u`
if [ $id = 0 ]; then
  echo "root user, install to system"
  for i in /usr/share/gcin/table /usr/local/share/gcin/table
  do
    [ -d $i ] && cp -p noseeing.gtab $i && echo "  install to $i"
  done
  for i in /usr/share/gcin/scripts /usr/local/share/gcin/scripts
  do
    [ -d $i ] && install -m 0755 noseeadd.rb $i && echo "  install to $i"
  done
else
  mv noseeing.gtab ~/.gcin
  install -m 0755 noseeadd.rb ~/.gcin
fi
echo "*******************************"
echo "Installation completed. Press ctrl-alt-9 to activate boshiamy"
