#!/usr/bin/perl -W

#
# PROJECT
#          Hinode/EIS
# PURPOSE
#          Perl script which runs on EISCO. It backs up the current planning
#          database and then unpacks the timeline database that was made
#          remotely.
# CATEGORY
#          EIS Timeline Planning/Remote Planning
# WRITTEN
#          John Rainnie & David Brooks & David Williams (RPG)
# HISTORY
#          v0.1 JAR 28-Oct-2008
#

#use Date;
use Env qw(HOME SSW CMDPLN);

#########################################################################
#
# Run backup script
#
#########################################################################

system("/home/flare/slb/eisco/scripts/db_backup.sh");

#########################################################################
#
# Unpack CPT properties and incoming timeline_db
#
#########################################################################

print "Unpacking incoming tar file \n";
system("cd $HOME && tar xfz $HOME/eis_rp_tldb.tar.gz");

#########################################################################
#
# Move CPT properties file to $HOME directory
#
#########################################################################

print "Moving CPT properties file to home directory\n";
system("mv $HOME/eis_rp_tldb/eis_cpt_properties.txt $HOME/.");

#########################################################################
#
# Move timeline_db to /home/eisco/planning_db (live area)
#
#########################################################################

print "Transplanting timeline_db into live planning_db\n";
system("rm -rf /home/eisco/planning_db/timeline_db");
system("mv $HOME/eis_rp_tldb/timeline_db /home/eisco/planning_db/.");

# Ensures timeline database files are readable (mcrw and jar 23-06-2009)
# Prevents problems for the refomatter.
system("chmod 644 /home/eisco/planning_db/timeline_db/*");
system("chmod 755 /home/eisco/planning_db/timeline_db/*dbd");

#########################################################################
#
# THE END FOR NOW
#
print "Now run RPCT by command line version \n";
#########################################################################
#
