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 |
+ |
#### EDIT THESE: SCRAM Installation Values ################# |
23 |
+ |
$ENV{'SCRAM_VERSION'}='@SCRAM_VERSION@'; |
24 |
+ |
$ENV{'SCRAM_LOOKUPDB'}='@SCRAM_LOOKUPDB_DIR@/project.lookup'; |
25 |
+ |
################################################ |
26 |
+ |
if (exists $ENV{SCRAM_USERLOOKUPDB} && -f "$ENV{SCRAM_USERLOOKUPDB}") |
27 |
+ |
{ |
28 |
+ |
$ENV{'SCRAM_LOOKUPDB'}=$ENV{SCRAM_USERLOOKUPDB}; |
29 |
+ |
print "Using $ENV{SCRAM_USERLOOKUPDB} as the database.","\n", if ($ENV{SCRAM_DEBUG}); |
30 |
+ |
} |
31 |
+ |
#### Core settings #### |
32 |
+ |
$main::bold = ""; |
33 |
+ |
$main::normal = ""; |
34 |
+ |
$main::line = "-"x80; |
35 |
+ |
$main::lookupdb = ""; |
36 |
+ |
$main::error = ""; |
37 |
+ |
$main::good = ""; |
38 |
+ |
$main::prompt=""; |
39 |
+ |
$main::ORIG_ARGV=[]; |
40 |
+ |
push @$main::ORIG_ARGV,$ARGV; |
41 |
+ |
|
42 |
+ |
# Test whether the output from SCRAM is being redirected, or |
43 |
+ |
# not (prevents escape signals from being printed to STDOUT if |
44 |
+ |
# STDOUT is redirected to a file or piped): |
45 |
+ |
if ( -t STDIN && -t STDOUT && $^O !~ /MSWin32|cygwin/ ) |
46 |
+ |
{ |
47 |
+ |
$bold = "\033[1m"; |
48 |
+ |
$normal = "\033[0m"; |
49 |
+ |
$prompt = "\033[0;32;1m"; |
50 |
+ |
$fail = "\033[0;31;1m"; # Red |
51 |
+ |
$pass = "\033[0;33;1m"; # Yellow |
52 |
+ |
$good = $bold.$pass; # Status messages ([OK]) |
53 |
+ |
$error = $bold.$fail; # ([ERROR]) |
54 |
+ |
} |
55 |
+ |
|
56 |
+ |
# Start a SCRAM session: |
57 |
+ |
$scram = SCRAM::SCRAM->new(); |
58 |
+ |
|
59 |
+ |
# Getopt option variables: |
60 |
+ |
my %opts; |
61 |
+ |
my %options = |
62 |
+ |
("verbose\v=s" => sub { $ENV{SCRAM_VERBOSE} = $ENV{SCRAM_DEBUG} = 1; $scram->classverbosity($_[1]) }, |
63 |
+ |
"debug|d" => sub { $ENV{SCRAM_DEBUG} = 1; $scram->fullverbosity() }, |
64 |
+ |
"arch|a=s" => sub { $ENV{SCRAM_ARCH} = $_[1]; $scram->architecture($ENV{SCRAM_ARCH}) }, |
65 |
+ |
"noreturn|n" => sub { $opts{SCRAM_NORETURN} = 1 }, # Pause after returning (for download in NS) |
66 |
+ |
"force|f" => sub { $opts{SCRAM_FORCE} = 1 }, # A force flag for commands that might need it |
67 |
+ |
"help|h" => sub { $opts{SCRAM_HELP} = 1 } |
68 |
+ |
); |
69 |
+ |
|
70 |
+ |
# Get the options using Getopt: |
71 |
+ |
Getopt::Long::config qw(default no_ignore_case require_order bundling); |
72 |
+ |
|
73 |
+ |
if (! Getopt::Long::GetOptions(\%opts, %options)) |
74 |
+ |
{ |
75 |
+ |
$scram->scramfatal("Error parsing arguments. See \"scram help\" for usage info."); |
76 |
+ |
exit(1); |
77 |
+ |
} |
78 |
+ |
|
79 |
+ |
# Check for a valid command and execute it or show an error message: |
80 |
+ |
my $command=shift(@ARGV); |
81 |
+ |
|
82 |
+ |
# Handle help option: |
83 |
+ |
if ($opts{SCRAM_HELP} || ! $command) |
84 |
+ |
{ |
85 |
+ |
print $scram->usage(); |
86 |
+ |
exit(0); |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
# Now execute the desired command (the routine automatically |
90 |
+ |
# checks to make sure the command is valid): |
91 |
+ |
my $retval = $scram->execcommand($command,@ARGV); |
92 |
+ |
|
93 |
+ |
# Check to see if we have --noreturn set. If so, we may be running |
94 |
+ |
# as a helper application in a web browser: |
95 |
+ |
if ($opts{SCRAM_NORETURN}) |
96 |
+ |
{ |
97 |
+ |
print "\n"; |
98 |
+ |
my $dummy = <STDIN>; |
99 |
+ |
} |
100 |
+ |
|
101 |
+ |
exit($retval); |
102 |
+ |
#### End of SCRAM script #### |