1 |
muzaffar |
1.1.2.1 |
#!/usr/bin/env perl
|
2 |
|
|
|
3 |
|
|
BEGIN
|
4 |
|
|
{
|
5 |
|
|
use File::Basename;
|
6 |
|
|
use Cwd;
|
7 |
|
|
my $installdir=dirname($0);
|
8 |
|
|
if ($installdir!~/^\//)
|
9 |
|
|
{
|
10 |
|
|
$installdir=getcwd()."/${installdir}";
|
11 |
|
|
}
|
12 |
|
|
$installdir=dirname($installdir);
|
13 |
|
|
$ENV{'SCRAM_TOOL_HOME'}="${installdir}/src";
|
14 |
|
|
$ENV{'SCRAM'}=$0;
|
15 |
|
|
unshift @INC,"$installdir", "${installdir}/src";
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
use SCRAM::SCRAM_SITE;
|
19 |
|
|
use SCRAM::SCRAM;
|
20 |
|
|
use Getopt::Long ();
|
21 |
|
|
|
22 |
muzaffar |
1.1.2.2 |
#### EDIT THESE: SCRAM Installation Values #################
|
23 |
|
|
$ENV{'SCRAM_VERSION'}='@SCRAM_VERSION@';
|
24 |
|
|
$ENV{'SCRAM_LOOKUPDB'}='@SCRAM_LOOKUPDB_DIR@/project.lookup';
|
25 |
muzaffar |
1.1.2.1 |
#### Core settings ####
|
26 |
|
|
$main::bold = "";
|
27 |
|
|
$main::normal = "";
|
28 |
|
|
$main::line = "-"x80;
|
29 |
|
|
$main::lookupdb = "";
|
30 |
|
|
$main::error = "";
|
31 |
|
|
$main::good = "";
|
32 |
|
|
$main::prompt="";
|
33 |
|
|
$main::ORIG_ARGV=[];
|
34 |
muzaffar |
1.1.2.3 |
push @$main::ORIG_ARGV,@ARGV;
|
35 |
muzaffar |
1.1.2.3.2.1 |
$|=1;
|
36 |
muzaffar |
1.1.2.1 |
|
37 |
|
|
# Test whether the output from SCRAM is being redirected, or
|
38 |
|
|
# not (prevents escape signals from being printed to STDOUT if
|
39 |
|
|
# STDOUT is redirected to a file or piped):
|
40 |
|
|
if ( -t STDIN && -t STDOUT && $^O !~ /MSWin32|cygwin/ )
|
41 |
|
|
{
|
42 |
|
|
$bold = "\033[1m";
|
43 |
|
|
$normal = "\033[0m";
|
44 |
|
|
$prompt = "\033[0;32;1m";
|
45 |
|
|
$fail = "\033[0;31;1m"; # Red
|
46 |
|
|
$pass = "\033[0;33;1m"; # Yellow
|
47 |
|
|
$good = $bold.$pass; # Status messages ([OK])
|
48 |
|
|
$error = $bold.$fail; # ([ERROR])
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
# Start a SCRAM session:
|
52 |
|
|
$scram = SCRAM::SCRAM->new();
|
53 |
|
|
|
54 |
|
|
# Getopt option variables:
|
55 |
|
|
my %opts;
|
56 |
|
|
my %options =
|
57 |
muzaffar |
1.1.2.3.2.1 |
("verbose|v=s" => sub { $ENV{SCRAM_VERBOSE} = $ENV{SCRAM_DEBUG} = 1; $scram->classverbosity($_[1]) },
|
58 |
muzaffar |
1.1.2.1 |
"debug|d" => sub { $ENV{SCRAM_DEBUG} = 1; $scram->fullverbosity() },
|
59 |
muzaffar |
1.1.2.3.2.1 |
"arch|a=s" => sub { $opts{SCRAM_ARCH} = $_[1] },
|
60 |
|
|
"noreturn|n" => sub { $opts{SCRAM_NORETURN} = 1 }, # Pause after returning (for download in NS)
|
61 |
|
|
"force|f" => sub { $opts{SCRAM_FORCE} = 1 }, # A force flag for commands that might need it
|
62 |
muzaffar |
1.1.2.1 |
"help|h" => sub { $opts{SCRAM_HELP} = 1 }
|
63 |
|
|
);
|
64 |
|
|
|
65 |
|
|
# Get the options using Getopt:
|
66 |
|
|
Getopt::Long::config qw(default no_ignore_case require_order bundling);
|
67 |
|
|
|
68 |
|
|
if (! Getopt::Long::GetOptions(\%opts, %options))
|
69 |
|
|
{
|
70 |
|
|
$scram->scramfatal("Error parsing arguments. See \"scram help\" for usage info.");
|
71 |
|
|
exit(1);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
# Check for a valid command and execute it or show an error message:
|
75 |
|
|
my $command=shift(@ARGV);
|
76 |
|
|
|
77 |
|
|
# Handle help option:
|
78 |
|
|
if ($opts{SCRAM_HELP} || ! $command)
|
79 |
|
|
{
|
80 |
|
|
print $scram->usage();
|
81 |
|
|
exit(0);
|
82 |
|
|
}
|
83 |
|
|
|
84 |
muzaffar |
1.1.2.3.2.1 |
#FIXME: Assuming the each SCRAM_ARCH has its own SCRAM-DB
|
85 |
|
|
if ($opts{SCRAM_ARCH})
|
86 |
|
|
{
|
87 |
|
|
my $newarch=$opts{SCRAM_ARCH};
|
88 |
|
|
my $oldarch = $scram->architecture();
|
89 |
|
|
if ($oldarch ne $newarch)
|
90 |
|
|
{
|
91 |
|
|
$ENV{SCRAM_ARCH} = $newarch;
|
92 |
|
|
$scram->architecture($newarch);
|
93 |
|
|
my $db=$ENV{'SCRAM_LOOKUPDB'};
|
94 |
|
|
$db=~s/\/$oldarch(\/.+|)$/\/$newarch$1/;
|
95 |
|
|
if (-f $db) {$ENV{'SCRAM_LOOKUPDB'} = $db; }
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
if (exists $ENV{SCRAM_USERLOOKUPDB} && -f "$ENV{SCRAM_USERLOOKUPDB}")
|
99 |
|
|
{
|
100 |
|
|
$ENV{'SCRAM_LOOKUPDB'} = $ENV{SCRAM_USERLOOKUPDB};
|
101 |
|
|
print "Using $ENV{SCRAM_USERLOOKUPDB} as the database.","\n", if ($ENV{SCRAM_DEBUG});
|
102 |
|
|
}
|
103 |
|
|
$scram->init ($opts{SCRAM_FORCE});
|
104 |
|
|
|
105 |
muzaffar |
1.1.2.1 |
# Now execute the desired command (the routine automatically
|
106 |
|
|
# checks to make sure the command is valid):
|
107 |
|
|
my $retval = $scram->execcommand($command,@ARGV);
|
108 |
|
|
|
109 |
|
|
# Check to see if we have --noreturn set. If so, we may be running
|
110 |
|
|
# as a helper application in a web browser:
|
111 |
|
|
if ($opts{SCRAM_NORETURN})
|
112 |
|
|
{
|
113 |
|
|
print "\n";
|
114 |
|
|
my $dummy = <STDIN>;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
exit($retval);
|
118 |
|
|
#### End of SCRAM script ####
|