|
| 1 | +#!/usr/bin/env perl |
| 2 | + |
| 3 | +use strict ; |
| 4 | +use warnings ; |
| 5 | + |
| 6 | +use Text::Template ; |
| 7 | +use Config::General ; |
| 8 | +use File::Spec ; |
| 9 | + |
| 10 | + |
| 11 | +######################################## |
| 12 | +## Start config setup |
| 13 | + |
| 14 | +my $conf = Config::General->new('ezproxy-collaborate.cfg'); |
| 15 | +my %config = $conf->getall ; |
| 16 | + |
| 17 | +## End of config setup |
| 18 | + |
| 19 | +######################################## |
| 20 | +## Start stanza config setup |
| 21 | + |
| 22 | +# first go approach will be to have all the stanza configurations in |
| 23 | +# one file and the templates in separate files. |
| 24 | +# |
| 25 | +# might change to have a config directory w/ skeleton files |
| 26 | + |
| 27 | + |
| 28 | +my $stanzas_conf = Config::General->new('stanzas.cfg'); |
| 29 | +my $stanzas_config_ref = { $stanzas_conf->getall } ; |
| 30 | + |
| 31 | +## End of stanza setup |
| 32 | + |
| 33 | +opendir(my $template_dir, $config{TEMPLATE_DIR}) or die "Can't open template directory ( $config{TEMPLATE_DIR} ) $!" ; |
| 34 | + |
| 35 | +FILE: while( my $filepath = readdir( $template_dir ) ) { |
| 36 | + |
| 37 | + if( $filepath !~ /\.template$/) { |
| 38 | + next FILE ; |
| 39 | + } |
| 40 | + |
| 41 | + my $id = $filepath ; |
| 42 | + $id =~ s/\.template// ; |
| 43 | + |
| 44 | + # Setup the template |
| 45 | + my $template_filepath |
| 46 | + = File::Spec->catfile( $config{ TEMPLATE_DIR }, |
| 47 | + $filepath ) ; |
| 48 | + my $template |
| 49 | + = Text::Template->new( TYPE => 'FILE', |
| 50 | + SOURCE => $template_filepath ) ; |
| 51 | + |
| 52 | + my $text = $template->fill_in( HASH => $stanzas_config_ref->{ $id } ) ; |
| 53 | + |
| 54 | + |
| 55 | + # Setup the output file |
| 56 | + my $target_filepath_init = $filepath ; |
| 57 | + $target_filepath_init =~ s/\.template$/.stanza/ ; |
| 58 | + |
| 59 | + my $target_filepath = File::Spec->catfile($config{CONFIG_DIR}, |
| 60 | + $id . '.stanza') ; |
| 61 | + |
| 62 | + open my $target_fh, '>', $target_filepath or die "Couldn't open $target_filepath for writing $! " ; |
| 63 | + |
| 64 | + print $target_fh $text ; |
| 65 | + |
| 66 | +} |
| 67 | + |
0 commit comments