#!/bin/bash
#
# batch file to setup
#


################################################################################
#
# echo informations
#

echo
echo "    start <TSC Printer Driver> install......"

################################################################################
#
# check and execute uninstall shell script
#

if test -f /usr/local/share/tsc/printer/uninstall-driver
then
  echo "find"
  echo "    execute uninstall shell script now......"
  if !(/usr/local/share/tsc/printer/uninstall-driver)
  then
    echo "    uninstall old <Panasonic GDI Printer Driver> failed"
    echo "    install driver failed"
    echo
    exit 1
  fi
else
  echo "not find"
fi


################################################################################
#
# echo informations
#

echo "    start copy files......"

################################################################################
#
# set own, grp and permissions
#
chown -R root:root ./*
chmod 644  ./ppd/*.ppd
chmod 644  ./tscprintersetting.desktop
chmod 644  ./thermalprinterui.png
chmod 755  ./thermalprinterui
chmod 755  ./thermalprinterut
chmod 755  ./pstotspl
chmod 755  ./pstotspl2
chmod 755  ./uninstall-driver

################################################################################
#
# make install dir
#
mkdir -p /usr/share/cups/model/tsc/
chown -R root:root /usr/share/cups/model/tsc/
chmod -R 755 /usr/share/cups/model/tsc/

mkdir -p /usr/local/share/tsc/printer/
chown -R root:root /usr/local/share/tsc/printer/
chmod -R 755 /usr/local/share/tsc/printer/


################################################################################
#
# copy files
#

cp ./pstotspl /usr/lib/cups/filter/
cp ./pstotspl2 /usr/lib/cups/filter/

cp ./ppd/*.ppd /usr/share/cups/model/tsc/
cp ./thermalprinterui /usr/local/share/tsc/printer/
cp ./thermalprinterut /usr/local/share/tsc/printer/
cp ./thermalprinterui.png /usr/local/share/tsc/printer/
cp ./uninstall-driver /usr/local/share/tsc/printer/

chmod 4755 /usr/local/share/tsc/printer/thermalprinterut

if test -d /usr/share/applications/
then
  cp ./tscprintersetting.desktop /usr/share/applications/
fi


echo "    restart spooler - CUPS"
################################################################################
#
# restart 
#
if test -f /etc/init.d/cups
then
  /etc/init.d/cups restart
else
  if test -f /etc/init.d/cupsys
  then
    /etc/init.d/cupsys restart
  fi
fi

################################################################################
#
# echo informations
#

echo "    install driver completed"
echo

exit 0

