source: main/trunk/gs-release-builder/envi/bin/envi.pl@ 36212

Last change on this file since 36212 was 36212, checked in by kjdon, 2 years ago

a new repository for greenstone release build system files

File size: 3.3 KB
Line 
1#!/usr/bin/perl -w
2
3use strict;
4use File::Spec::Functions qw(rel2abs);
5use File::Basename;
6use Getopt::Long;
7
8#unset the environment
9BEGIN {
10 if ( $^O eq "MSWin32" && exists $ENV{'HOMEDRIVE'} && exists $ENV{'HOMEPATH'} ) {
11 $ENV{'HOME'} = $ENV{'HOMEDRIVE'} . $ENV{'HOMEPATH'};
12 } elsif ( $^O eq "MSWin32" ) {
13 $ENV{'HOME'} = "";
14 } else {
15 foreach my $key (keys %ENV) {
16 #if ( $^O eq "MSWin32" && $key !~ "^(HOME|USERNAME|USERPROFILE|COMMONPROGRAMFILES|APPDATA|PROGRAMFILES|LOCALAPPDATA|HOMEPATH|USERDOMAIN|PROGRAMDATA|SYSTEMDRIVE|SYSTEMROOT|WINDIR|VS71COMNTOOLS|NUMBER_OF_PROCESSORS|OS|PATHEXT|PROCESSOR_ARCHITECTURE|PROCESSOR_LEVEL|PROCESSOR_REVISION|TEMP|TMP|PATH)\$" ) {
17 # delete($ENV{$key});
18 #} elsif ( $key !~ "^(USER|HOME)\$" ) {
19 if ( $key !~ "^(USER|HOME)\$" ) {
20 delete($ENV{$key});
21 }
22 }
23 }
24}
25
26#options and arguments
27our $envi_verbose = 2; # set to 0 for no verboseness
28my $action = "";
29
30#figure out envi home
31$ENV{'ENVI_HOME'}=dirname(dirname(rel2abs($0)));
32
33#import utility functions
34do "$ENV{'ENVI_HOME'}/lib/util.pl";
35
36#parse options
37Getopt::Long::Configure('require_order'); #don't read options after the first argument
38GetOptions (
39 'v|verbose' => \$envi_verbose
40 );
41
42#parse arguments
43if ( @ARGV > 0 ) {
44 $action = $ARGV[0];
45 shift(@ARGV);
46}
47
48#show options / arguments
49envi_message( "verbose: '$envi_verbose'" );
50envi_message( "action: $action");
51
52#set the environment
53if ( -f "$ENV{'ENVI_HOME'}/etc/environment.pl" ) {
54 envi_message( "Sourcing system environment" );
55 do "$ENV{'ENVI_HOME'}/etc/environment.pl";
56}
57
58if ( -f "$ENV{'HOME'}/.envi/environment.pl" ) {
59 envi_message( "Sourcing user environment");
60 do "$ENV{'HOME'}/.envi/environment.pl";
61}
62
63#if no argument given, run default
64if ( "$action" eq "" ) {
65 print "------------------------------------------------------------\n";
66 print "EnvI Version 1.0\n";
67 print "Installed at: $ENV{'ENVI_HOME'}\n";
68 print "Run 'envi tasks' for a list of tasks\n";
69 print "Run 'envi TASKNAME' to run task with task with name TASKNAME\n";
70 print "------------------------------------------------------------\n";
71
72#if 'tasks' given as argument, show all available tasks
73} elsif ( "$action" eq "tasks" ) {
74 list_tasks();
75
76#if 'playlists' given as argument, show all available playlists
77} elsif ( "$action" eq "playlists" ) {
78 list_playlists();
79
80#if 'home' given as argument, show envi home
81} elsif ( "$action" eq "home" ) {
82 print "$ENV{'ENVI_HOME'}\n";
83
84#if 'env' given as argument, show or use the envi environment
85} elsif ( "$action" eq "env" ) {
86
87 # - run something in the envi environment
88 if ( exists $ARGV[0] ) {
89 my $command = $ARGV[0] . " ";
90 shift(@ARGV);
91 for my $a ( @ARGV ) {
92 $command .= " \"$a\"";
93 }
94 system( $command );
95
96 # - show task environment
97 } else {
98 foreach my $key (keys %ENV) {
99 print "$key=$ENV{$key}\n";
100 }
101 }
102
103#if default specified explicitly, run it
104} elsif ( "$action" eq "default" ) {
105 run_default_tasks();
106
107#if other argument given, run the specified task or playlist
108} else {
109
110 #if an existent playlist was specified, run it
111 if ( playlist_exists($action) ) {
112 run_playlist($action);
113
114 #if an existent task was specified, run it
115 } elsif ( task_exists($action) ) {
116 run_task( $action );
117
118 #otherwise, report no such task
119 } else {
120 print "no such task, playlist or option as '$action'\n"
121 }
122
123}
124
125
Note: See TracBrowser for help on using the repository browser.