#!/bin/bash

cd /dev
if [ -e ttyUSB0 ]
then
   cd /usr/local/pressnet/etc
     if [ -e record ]
     then
        /etc/init.d/crond stop
        a=$(sed -n '1p' record)
        if [ $a = 0 ]
        then
           /etc/init.d/crond restart
           exit
        else
           sed -ie '1d' record
           echo 0 >> record
           /usr/local/pressnet/bin/pnsd stop
           sleep 10
           /usr/local/pressnet/bin/pnsd start
           /usr/local/pressnet/bin/pnc_restart
           /etc/init.d/crond restart
              if [ -e restart ]
              then
                  c=$(sed -n '1p' restart)
                      if [ $c = 1 ]
                      then
                        sed -ie '1d' restart
                        echo 0 >> restart
                      else
                         exit
                      fi
              else
                   exit
              fi
         fi
     fi
else
   cd /usr/local/pressnet/etc
   if [ -e restart ]
   then
        b=$(sed -n '1p' restart)
        if [ $b = 0 ]
        then
           /usr/local/pressnet/bin/pnsd stop
           sleep 10
           /usr/local/pressnet/bin/pnsd start
           /usr/local/pressnet/bin/pnc_restart
           sed -ie '1d' restart
           echo 1 >> restart
        else
           exit
        fi
    else
        exit
   fi
fi
