install-eg.sh: SSL setup
[sitka/sitka-tools.git] / deployment / access_pathmap.pl
CommitLineData
bcd49ef3
LW
1#!/usr/bin/perl
2use strict;
3use warnings;
4use Config::Simple;
5use Getopt::Long;
6
161504e3 7my ($help, $config_file, $component, $srcpath);
bcd49ef3
LW
8
9GetOptions(
1c47dbca
LW
10 'help' => \$help, # show help message and exit
11 'config=s' => \$config_file, # INI file for path mappings
12 'component=s' => \$component, # The component to grab the source paths for
161504e3 13 'srcpath=s' => \$srcpath # The source path to grap the destination path for
bcd49ef3
LW
14);
15
16if ($help) {
17 print <<"HELP";
18
19OPTIONS:
20 --help
21 Show help message and exit.
22 --config
23 Location of INI file for path mappings.
24 --component
c6a6221d
LW
25 The component of the INI file for which you want the paths.
26 If you do not specify a component value then all components
27 (sections) in the INI file are returned.
bcd49ef3
LW
28 --srcpath
29 The source path to return the destination path for
30
31HELP
32 exit;
33}
34
35# load config
36die "No config file specified\n" unless ($config_file);
37die "Config file does not exist\n" unless (-r $config_file and -s $config_file);
1c47dbca 38
bcd49ef3
LW
39my $cfg = new Config::Simple($config_file);
40
41if (!$component) {
42 my @components = ();
43 #pull out components from INI file
44 open my $fh, '<', $config_file;
45 while (<$fh>) {
46 chomp;
47 if ($_ =~ /^\[[^]]+\]$/) {
c6a6221d
LW
48 $_ =~ s/^\[//;
49 $_ =~ s/\]$//;
50 #we use newlines because spaces seem to be valid within an INI file section.
51 #I am not sure if newlines are also valid because I could not find anything
52 #defining the INI section syntax, but I imagine using a newline within an INI
53 #file section declartion is not done very often if it is valid syntax.
54 print "$_\n";
bcd49ef3
LW
55 }
56 }
bcd49ef3 57} elsif (!$srcpath) {
e3bb1226 58 foreach my $key (keys %{$cfg->get_block($component)}) {
c6a6221d
LW
59 #again we use newlines because spaces can be used within directory names. I belive
60 #it is possible to use a newline in a directory name, but someone would have to be
61 #trying really hard to make things break if they started doing that with the Evergreen
62 #source.
bcd49ef3
LW
63 print $key . "\n";
64 }
65} else {
2385238b
LW
66 while (!defined $cfg->get_block($component)->{$srcpath}) {
67 $srcpath =~ s/\/[^\/]*$//;
68 if ($srcpath !~ '/') {
69 last;
70 }
71 }
72
73 if (defined $cfg->get_block($component)->{$srcpath}) {
74 print $cfg->get_block($component)->{$srcpath};
75 }
bcd49ef3
LW
76}
77