Skip to content

Commit a2f707d

Browse files
committed
First version of basic script.
Combines the Text::Template and Config::General perl modules to iterate over a folder of templates, fill them in with info from the stanzas.cfg file.
1 parent 60efd13 commit a2f707d

7 files changed

+94
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
ezproxy-collaborate.cfg
2+
stanzas.cfg
3+
stanza.cfg

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ Ezproxy Collaborate is a community-shared git archive of EzProxy database stanza
55

66
##Requirements
77

8-
# Perl installed
9-
## With module Text::Template (install via `cpan Text::Template` or some other method)
8+
# Perl installed (list of required modules below, can use cpan tool to install)
9+
## Text::Template
10+
## Config::General
11+
## File::Spec (should be part of most installs)
1012
# EzProxy Installed
1113

1214
## How it works

bin/generate-configs.pl

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+

ezproxy-collaborate.cfg.skel

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
##### Script settings
2+
CONFIG_DIR = /usr/local/ezproxy/conf.d
3+
TEMPLATE_DIR = templates
4+
TEMPLATE_CONFIG = stanzas.cfg

stanzas.cfg.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Books24x7>
2+
SiteIdentifier = FakeSiteIdentifier
3+
TokenKey = Your Selected Key
4+
TokenSignatureKey = FakeSigKey
5+
</Books24x7>

templates/AccessibleArchives.template

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
T Accessible Archives
2+
U http://www.accessible.com/
3+
HJ www.accessible.com
4+
DJ accessible.com
5+
6+

templates/Books24x7.template

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Title Book24x7.com
2+
URL http://library.books24x7.com/library.asp?
3+
Books24x7Site {$SiteIdentifier}
4+
TokenKey {$TokenKey}
5+
TokenSignatureKey {$TokenSignatureKey}
6+
DJ books24x7.com

0 commit comments

Comments
 (0)