#!/usr/bin/perl

use strict;
use warnings;
use FindBin qw( $Bin );
use File::Copy qw( copy );
use Expect;
use File::Slurp qw( read_file );
use lib "$Bin/../software";
use Common qw( commands );

my @path = split /\//, $Bin;
my $pen_path = "";

if ($path[1] eq 'opt') {
  $pen_path = "/".$path[2]."/".$path[3];
}
elsif ($path[1] eq 'var') {
  $pen_path = "/".$path[3]."/".$path[4];
}
else {
  $pen_path = "/".$path[1]."/".$path[2];
}

commands();

my $is_i686 = `uname -a | grep i686`;
$is_i686 //= "";

&copy("$Bin/data/machine_calibrate", "/opt/bin/machine_calibrate");
system("chmod 755 /opt/bin/machine_calibrate");

&copy("$Bin/data/startup.sh", "/opt/bin/startup.sh");
system("chmod 755 /opt/bin/startup.sh");

if ($is_i686) {
  &copy("$Bin/data/touch_driver_i686", "/opt/bin/touch_driver");
}
else {
  &copy("$Bin/data/touch_driver", "/opt/bin/touch_driver");
}

system("chmod 755 /opt/bin/touch_driver");

system("touch /.configured");

system("reboot");

