Commit | Line | Data |
e3bf7a69 |
1 | #!/usr/bin/env perl |
2 | |
3 | use lib 'lib'; |
4 | use feature 'say'; |
5 | use strict; |
6 | use warnings; |
7 | use Text::Tradition::Directory; |
8 | |
9 | binmode STDOUT, ':utf8'; |
10 | binmode STDERR, ':utf8'; |
11 | eval { no warnings; binmode $DB::OUT, ':utf8'; $DB::deep = 1000 }; |
12 | |
13 | my %VARS = ( |
14 | DBTYPE => 'mysql', |
15 | DBHOST => '127.0.0.1', |
16 | DBPORT => '3006', |
17 | DBNAME => 'idpresult', |
18 | DSN => undef, |
19 | DBUSER => undef, |
20 | DBPASS => undef, |
21 | ); |
22 | |
23 | if( -f "/etc/graphcalc.conf" ) { |
24 | # Read the variables in from here. |
25 | open( GCCONF, "/etc/graphcalc.conf" ) |
26 | or die "Could not open configuration file /etc/graphcalc.conf"; |
27 | while(<GCCONF>) { |
28 | chomp; |
29 | s/^\s+//; |
30 | my( $name, $val ) = split( /\s*\=\s*/, $_ ); |
31 | if( exists $VARS{$name} ) { |
32 | $VARS{$name} = $val; |
33 | } |
34 | } |
35 | close GCCONF; |
36 | } |
37 | unless( $VARS{DSN} ) { |
38 | $VARS{DSN} = sprintf( "dbi:%s:dbname=%s;host=%s;port=%s", |
39 | $VARS{DBTYPE}, $VARS{DBNAME}, $VARS{DBHOST}, $VARS{DBPORT} ); |
40 | } |
41 | |
42 | my $dirargs = { create => 1 }; |
43 | $dirargs->{user} = $VARS{DBUSER} if $VARS{DBUSER}; |
44 | $dirargs->{password} = $VARS{DBPASS} if $VARS{DBPASS}; |
45 | my $dir = Text::Tradition::Directory->new( |
46 | 'dsn' => $VARS{DSN}, 'extra_args' => $dirargs ); |
47 | my $scope = $dir->new_scope(); |
48 | |
49 | say "Initialized database at " . $VARS{DSN}; |