forked from eprints/eprints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepadmin
executable file
·3267 lines (2621 loc) · 77.4 KB
/
epadmin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
use FindBin;
use lib "$FindBin::Bin/../perl_lib";
######################################################################
#
#
######################################################################
=pod
=for Pod2Wiki
=head1 NAME
B<epadmin> - EPrints repository admin tool
=head1 SYNOPSIS
B<epadmin> I<command> I<repository_id> [B<options>]
Where I<command> is one of:
=over 4
=item cleanup_cachemaps
=item config_core
=item config_db
=item create
=item create_db
=item create_tables
=item create_user
=item erase_data
=item erase_eprints
=item erase_fulltext_index
=item help
=item profile
=item rebuild_triples
=item recommit
=item reorder
=item redo_mime_type
=item redo_thumbnails
=item refresh_abstracts
=item refresh_views
=item rehash
=item reindex
=item reload
=item remove_field
=item set_developer_mode
=item test
=item unit_tests
=item update
=item update_dry_run
=item upgrade
=back
Type I<epadmin help> for further help.
=head1 ARGUMENTS
=over 8
=item B<epadmin> create
START HERE! This option will walk you through the tasks needed to create your repository.
=item B<epadmin> test I<repository_id>
A null operation which just checks your configuration files are OK and that you can connect to the database. If no I<repository_id> is specified loads each repository in turn. Use --verbose to generate more information.
=item B<epadmin> cleanup_cachemaps I<repository_id>
Drop any orphaned cache tables.
=item B<epadmin> config_core I<repository_id>
Set hostname, contact email and repository name.
=item B<epadmin> config_db I<repository_id>
Set database connection properties and, optionally, to create database and database user.
=item B<epadmin> create_db I<repository_id>
Create a database and database user with the current settings.
=item B<epadmin> create_tables I<repository_id>
Create the database tables.
=item B<epadmin> create_user I<repository_id>
Create a new user. You need to do this to create your first admin account.
=item B<epadmin> erase_fulltext_index I<repository_id>
This erases all the .words and .indexcodes cache files from your repository, forcing the indexer to rerun the tools used to extract full text from your documents.
This is useful if you only setup the fulltext indexing after your repository is already live, or if you discover there has been a problem.
=item B<epadmin> rebuild_triples I<repository_id> [I<dataset_id> [I<item_id> I<item_id> ...]]
Queue all the records to have their RDF triple cache rebuilt. This may tie-up the indexer for some time on a large repository. Do this if you have made changes to the way RDF triples are produced from an EPrint.
=item B<epadmin> recommit I<repository_id> I<dataset_id> [I<eprint_id> I<eprint_id> ...]
Recommit all the records in the given dataset. What this does is cause the automatic values to be re-calculated. If a list of eprint_ids is given then just recommit those.
=item B<epadmin> reindex I<repository_id> I<dataset_id> [I<eprint_id> I<eprint_id> ...]
Schedule the dataset for reindexing. The indexer will do the actual indexing and it may take some time. This only schedules the reindexing. If a list of eprint_ids is given then just reindex those.
=item B<epadmin> reorder I<repository_id> I<dataset_id> [I<eprint_id> I<eprint_id> ...]
Regenerate the order values for the dataset. If a list of eprint_ids is given then just recalculate ordervalues for those.
=item B<epadmin> rehash I<repository_id> [I<document_id>]
Recalculate the hashes of the files in this document and write it to a probity log file. If a document id is given then just generate the hash for that document.
=item B<epadmin> reload I<repository_id>
Cause the web server to reload the repository configuration.
=item B<epadmin> set_developer_mode I<repository_id> <on|off>
While set to on developer mode causes the web server to reload the repository configuration on every page request. This makes development much quicker but must not be left switched on in a production environment since it increases server load dramatically.
=item B<epadmin> refresh_views I<repository_id>
Tell the webserver that all views pages must be regenerated. The webserver will update them next time they are requested. Also causes config to be reloaded.
=item B<epadmin> refresh_abstracts I<repository_id>
Tell the webserver that all abstract summary pages must be regenerated. The webserver will update them next , but won't update them again unless something on the EPrint changes or you re-run refresh abstracts. Also causes config to be reloaded.
=item B<epadmin> redo_mime_type I<repository_id> dataset [ objectid, ... ]
Re-run the file format identification. Dataset may be one of 'document' or
'file'. If 'document' only re-does the identification of the main files in
documents.
=item B<epadmin> redo_thumbnails I<repository_id> [ I<eprintid>, ... ]
Regenerate all the thumbnail and image-preview files and any other things which
are triggered if the document file changed. Optionally supply a list of eprint
ids to re-generate thumbnails for.
=item B<epadmin> erase_data I<repository_id>
Erases and recreates the database. Removes all documents and files. Does not touch the configuration files.
=item B<epadmin> erase_eprints I<repository_id>
Erases all the documents and eprints (including their files). Recreates the eprint and document tables. Leaves configuration files and the users and subjects tables alone.
=item B<epadmin> unit_tests
Run unit tests, printing the results to STDOUT. If everything passed will exit
with a return code of 0.
=item B<epadmin> profile I<test>
Run a performance profile of I<test> using L<Devel::NYTProf>.
=item B<epadmin> remove_field I<repository_id> I<dataset> I<field_id>
Remove the database entries for the given field, can not be undone!
=item B<epadmin> update I<repository_id>
This will add tables and columns to your SQL database to bring it in-line with your current configuration. It will not remove data. Use with caution on a live database. Database backup is recommended before use on live systems.
=item B<epadmin> update_dry_run I<repository_id>
This will tell you which tables and columns will be added to your SQL database to bring it in-line with your current configuration. As update does not remove any data it will not tell you about any tables or columns that are in your database but not in your current configuration.
=item B<epadmin> upgrade I<repository_id>
After upgrading EPrints, use this to update the database tables. It will advise any other tasks that are required.
=item B<epadmin> --help
=back
=head1 OPTIONS
=over 8
=item B<--help>
Print a brief help message and exit.
=item B<--man>
Print the full manual page and then exit.
=item B<--quiet>
This option does not do anything.
=item B<--verbose>
Explain in detail what is going on. May be repeated for greater effect.
=item B<--force>
Be more forceful (don't ask for confirmation).
=item B<--version>
Output version information and exit.
=back
=cut
#cjg Does not use noise levels
use EPrints;
use Sys::Hostname;
use DBI;
use Data::Dumper;
use File::Path;
use strict;
use Getopt::Long;
use Pod::Usage;
my $verbose = 0;
my $quiet = 0;
my $help = 0;
my $man = 0;
my $version = 0;
my $force = 0;
Getopt::Long::Configure("permute");
GetOptions(
'help|?' => \$help,
'man' => \$man,
'version' => \$version,
'verbose+' => \$verbose,
'silent' => \$quiet,
'quiet' => \$quiet,
'force' => \$force,
) || pod2usage( 2 );
EPrints::Utils::cmd_version( "epadmin" ) if $version;
pod2usage( 1 ) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
pod2usage( 2 ) if( scalar @ARGV == 0 );
# Set STDOUT to auto flush (without needing a \n)
$|=1;
my $noise = 1;
$noise = 0 if( $quiet );
$noise = 1+$verbose if( $verbose );
my $REGEXP_HOSTNAME_MIDDLE = '[a-z0-9-]+(\.[a-z0-9-]+)*';
my $REGEXP_HOSTNAME = '^'.$REGEXP_HOSTNAME_MIDDLE.'$';
my $REGEXP_EMAIL = '^[^@]+@'.$REGEXP_HOSTNAME_MIDDLE.'$';
my $REGEXP_HOSTNAME_FULL = '^[a-z0-9-]+(\.[a-z0-9-]+)*$';
my $REGEXP_VARNAME = '^[a-zA-Z][_A-Za-z0-9]*$';
my $REGEXP_NUMBER = '^[0-9]+$';
my $REGEXP_YESNO = '^(yes|no)$';
my $REGEXP_ANY = '^.*$';
my @PASSWORD_CHARS = ( 'a'..'z','A'..'Z','0'..'9' );
my $eprints = EPrints->new();
my $action = shift @ARGV;
if( $action eq "create" ) { create(); }
elsif( $action eq "test" ) { test( @ARGV ); }
elsif( $action eq "unit_tests" ) { unit_tests( @ARGV ); }
elsif( $action eq "profile" ) { profile( @ARGV ); }
else
{
my $repoid = shift @ARGV;
pod2usage(1) unless defined $repoid;
if( $action eq "cleanup_cachemaps" ) { cleanup_cachemaps( $repoid ); }
elsif( $action eq "config_core" ) { config_core( &repository($repoid) ); }
elsif( $action eq "config_db" ) { config_db( $repoid ); }
elsif( $action eq "database_type_info" ) { database_type_info( $repoid ); }
elsif( $action eq "create_db" ) { create_db( $repoid ); }
elsif( $action eq "create_user" ) { create_user( $repoid, @ARGV ); }
elsif( $action eq "create_tables" ) { create_tables( $repoid ); }
elsif( $action eq "erase_data" ) { erase_data( $repoid ); }
elsif( $action eq "erase_eprints" ) { erase_eprints( $repoid ); }
elsif( $action eq "erase_fulltext_index" ) { erase_fulltext_index( $repoid ); }
elsif( $action eq "reload" ) { reload( $repoid ); }
elsif( $action eq "refresh_abstracts" ) { refresh_abstracts( $repoid ); }
elsif( $action eq "refresh_views" ) { refresh_views( $repoid ); }
elsif( $action eq "redo_mime_type" ) { redo_mime_type( $repoid, @ARGV ); }
elsif( $action eq "redo_thumbnails" ) { redo_thumbnails( $repoid, @ARGV ); }
elsif( $action eq "set_developer_mode" ) { set_developer_mode( $repoid, @ARGV ); }
elsif( $action eq "upgrade" ) { upgrade( $repoid ); }
elsif( $action eq "update_database_structure" ) { update_database_structure( $repoid ); }
elsif( $action eq "update" ) { update_database_structure( $repoid ); }
elsif( $action eq "update_dry_run" ) { update_database_structure( $repoid, 1 ); }
elsif( $action eq "upgrade_mysql_charset" ) { upgrade_mysql_charset( $repoid ); }
elsif( $action eq "rebuild_triples" ) { rebuild_triples( $repoid, @ARGV ); }
elsif( $action eq "recommit" )
{
my $datasetid = shift @ARGV;
pod2usage(1) unless defined $datasetid;
recommit( $repoid, $datasetid, @ARGV );
}
elsif( $action eq "reindex" )
{
my $datasetid = shift @ARGV;
pod2usage(1) unless defined $datasetid;
reindex( $repoid, $datasetid, @ARGV );
}
elsif( $action eq "reorder" )
{
my $datasetid = shift @ARGV;
pod2usage(1) unless defined $datasetid;
reorder( $repoid, $datasetid, @ARGV );
}
elsif( $action eq "rehash" ) { rehash( $repoid, @ARGV ); }
elsif( $action eq "upgrade_add_files" ) { upgrade_add_files( $repoid, @ARGV ) }
elsif( $action eq "remove_field" ) { remove_field( $repoid, @ARGV ); }
else { pod2usage( 1 ); }
}
exit;
sub repository
{
my( $repoid, %opts ) = @_;
return $repoid if ref($repoid) && $repoid->isa( "EPrints::Repository" );
my $repo = $eprints->repository( $repoid, noise => $noise, %opts );
if( !defined $repo )
{
print STDERR "Failed to load repository: $repoid\n";
exit 1;
}
return $repo;
}
sub create
{
pod2usage( 2 ) if( scalar @ARGV != 0 );
my $system = EPrints::System->new;
print <<END;
Create an EPrint Repository
Please select an ID for the repository, which will be used to create a directory
and identify the repository. Lower case letters and numbers, may not start with
a number. examples: "lemurprints" or "test3"
END
if( scalar EPrints::Config::get_repository_ids() )
{
print "Existing repositories:\n";
print join( ", ", EPrints::Config::get_repository_ids() )."\n\n";
}
my $repoid = EPrints::Utils::get_input( $REGEXP_VARNAME, 'Archive ID' );
my $repodir = EPrints::Config::get( "base_path" )."/archives/".$repoid;
my $loaded_config = EPrints::Config::get_repository_config( $repoid );
my $exists = ( defined $loaded_config );
if( $exists )
{
print "A repository with that ID already exist.\n";
exit;
}
unless( -e $repodir )
{
print "We need to create $repodir, doing it now...\n";
unless( $system->mkdir( $repodir ) )
{
print "Problem creating directory\n\n";
exit;
}
}
unless( -d $repodir )
{
print "$repodir MUST be a directory.\n\n";
}
print "\nCreating initial files:\n";
&install(
$system,
EPrints::Config::get( "base_path" )."/lib/defaultcfg",
$repodir."/cfg" );
foreach( "cgi", "var", "html", "documents", "documents/disk0" )
{
$system->mkdir( "$repodir/$_" );
}
print <<END;
Ok. I've created the initial config files and directory structure.
I've also created a "disk0" directory under documents/ if you want
your full texts to be stored on a different partition then remove
the disk0, and create a symbolic link to the directory you wish to
store the full texts in. Additional links may be placed here to be
used when the first is full.
END
print "\n";
EPrints::Config::init(); # rescan repositories
my $config_core = EPrints::Utils::get_input( $REGEXP_YESNO, "Configure vital settings?", "yes" );
if( $config_core eq "yes" )
{
config_core( $repoid );
}
else
{
print "OK, but you'll need to edit 10_core.pl by hand in that case.\n";
}
print "\n";
my $config_db = EPrints::Utils::get_input( $REGEXP_YESNO, "Configure database?", "yes" );
if( $config_db eq "yes" )
{
config_db( $repoid );
}
else
{
print "OK, but you'll need to edit database.pl by hand in that case, and make sure the database exists.\n";
}
print "\n";
my $create_user = EPrints::Utils::get_input( $REGEXP_YESNO, "Create an initial user?", "yes" );
if( $create_user eq "yes" )
{
create_user( $repoid );
}
else
{
print "OK, but you will not be able to log into the website. You can always run 'epadmin create_user $repoid' later.\n"
}
# cjg: Register with website!
my $ok;
$ok = EPrints::Utils::get_input( $REGEXP_YESNO, "Do you want to build the static web pages?", "yes" );
if( $ok eq "yes" )
{
run_script( $repoid, "generate_static", "--verbose", $repoid );
}
$ok = EPrints::Utils::get_input( $REGEXP_YESNO, "Do you want to import the LOC subjects?", "yes" );
if( $ok eq "yes" )
{
run_script( $repoid, "import_subjects", "--verbose", "--force", $repoid );
}
$ok = EPrints::Utils::get_input( $REGEXP_YESNO, "Do you want to update the apache config files? (you still need to add the 'Include' line)", "yes" );
if( $ok eq "yes" )
{
run_script( $repoid, "generate_apacheconf", "--verbose" );
}
my $base_path = EPrints::Config::get( "base_path" );
print <<END;
--------------------------------------------------------------------------
That seemed to more or less work...
--------------------------------------------------------------------------
Now make any required changes to the cfg files.
Note that changing the metadata configuration may require the database
tables to be regenerated. epadmin erase_data will regenerate the
eprints and documents tables only. erase_data will regenerate everything.
(nb. these also do erase the contents of the tables, and any uploaded
files).
Make sure that your main apache config file contains the line:
Include $base_path/cfg/apache.conf
Then stop and start your webserver:
Often:
/etc/rc.d/init.d/httpd stop
/etc/rc.d/init.d/httpd start
(or maybe /usr/local/apache/bin/apachectl stop & start)
And then try connecting to your repository.
--------------------------------------------------------------------------
Don't forget to register your repository at http://roar.eprints.org/
END
exit;
}
# don't be fooled. This isn't the same as the install() in
# eprints-install
sub install
{
my($system, $dir, $dest) = @_;
print "Installing: $dest\n";
$system->mkdir( $dest );
opendir(my $dh, $dir) or die("Unable to install directory: $dir");
while(my $fn = readdir($dh))
{
next if $fn =~ m/^\./;
if( -d "$dir/$fn" )
{
install($system, "$dir/$fn", "$dest/$fn");
}
elsif( -f "$dir/$fn" )
{
EPrints::Utils::copy( "$dir/$fn", "$dest/$fn" );
$system->chown_for_eprints( "$dest/$fn" );
}
}
closedir($dh);
}
sub run_script
{
my( $repoid, $script, @opts ) = @_;
my $dir = EPrints::Config::get( "bin_path" );
Carp::croak "Fatal! bin_path not defined"
if !defined $dir;
my $path = "$dir/$script";
Carp::croak "Fatal! Wanted to execute $path, but it doesn't exist"
if !-e $path;
system( 'perl', $path, @opts );
}
sub cleanup_cachemaps
{
my( $repoid ) = @_;
my $repo = &repository( $repoid );
if( $force )
{
$repo->dataset( "cachemap" )->search->map(sub {
$_[2]->remove;
$repo->log( "Removed ".$_[2]->id );
});
}
my $c = $repo->database->drop_orphan_cache_tables;
if( $c == 0 )
{
$repo->log( "No orphaned cache tables found" );
}
}
sub config_core
{
my( $repo ) = @_;
my $repoid = ref($repo) ? $repo->get_id : $repo;
print "Core configuration for $repoid\n\n";
my %config = ();
$config{port} = 80;
$config{host} = undef;
$config{archiveroot} = "archives/".$repoid;
$config{aliases} = [];
$config{securehost} = undef;
$config{secureport} = 443;
$config{http_root} = "";
$config{adminemail} = undef;
$config{archive_name} = "Test Repository";
if( ref($repo) )
{
for(qw( port host aliases securehost secureport adminemail http_root ))
{
$config{$_} = $repo->config( $_ );
}
$config{archive_name} = $repo->phrase( "archive_name" );
}
print <<END;
Please enter the fully qualified hostname of the repository.
For a production system we recommend against using the real hostname of the
machine.
Example: $repoid.footle.ac.uk
END
HOSTNAME:
$config{host} = EPrints::Utils::get_input( $REGEXP_HOSTNAME_FULL, 'Hostname', $config{host} );
if( $config{host} eq "localhost" || $config{host} =~ /^\d{1,3}(.\d{1,3}){3}$/ )
{
print "Warning! Some browsers don't support setting cookies on 'localhost' or IP-addresses, please provide a different hostname.\n";
undef $config{host};
goto HOSTNAME;
}
print <<END;
Please enter the port of the webserver. This is probably 80, but you may wish
to run apache on a different port if you are experimenting.
END
$config{port} = EPrints::Utils::get_input( $REGEXP_NUMBER, 'Webserver Port', $config{port} );
# calculate example aliases
my $realhostname = hostname();
if( $realhostname !~ m/\./ )
{
# No dots in the actual hostname! Lets try and got the
# domain from resolv.conf
my $domain = "";
if( open( RESOLV, "/etc/resolv.conf" ) && 0)
{
while( <RESOLV> )
{
if( m/^search\s+([^\s]+)/ )
{
$domain = $1;
last;
}
}
close RESOLV;
}
$domain = "mydomain.com" if( $domain eq "" );
$realhostname.=".".$domain;
}
my @example_aliases = ();
push @example_aliases,$realhostname;
$realhostname=~m/^(([^\.]*)\.[^\.]*)(\.|$)?/;
push @example_aliases,$1 if( $3 eq ".");
push @example_aliases,$2;
$config{host}=~m/^(([^\.]*)\.[^\.]*)(\.|$)?/;
push @example_aliases,$1 if( $3 eq "." );
push @example_aliases,$2;
print <<END;
Please enter all the aliases which could reach the repository, and indicate if
you would like EPrints to write a Redirect Rule to redirect requests to this
alias to the correct URL.
END
if( scalar @{$config{aliases}}==0 )
{
print "Some suggestions:\n";
foreach( @example_aliases )
{
print $_."\n";
}
}
print <<END;
Enter a single hash (#) when you're done.
END
my @aliases = @{$config{aliases}};
$config{aliases} = [];
for(;;)
{
my $default = shift @aliases;
my $alias = EPrints::Utils::get_input( '^('.$REGEXP_HOSTNAME_MIDDLE.'|#)$', 'Alias (enter # when done)',
(defined $default ? $default->{name} : '#' ) );
last if( $alias eq "#" );
my $aliasrecord = {};
$aliasrecord->{name} = $alias;
$aliasrecord->{redirect} =
EPrints::Utils::get_input(
$REGEXP_YESNO,
"Redirect $alias to $config{host}",
(defined $default && $default->{redirect} ne 'yes' ? 'no' : 'yes' ) );
push @{$config{aliases}},$aliasrecord;
print "\n";
}
print <<END;
Please enter the path part of the repository's base URL. This should probably
be '/'.
END
$config{http_root} .= "/" if defined $config{http_root};
$config{http_root} = EPrints::Utils::get_input( '.*', 'Path', $config{http_root} );
$config{http_root} =~ s! ^/? !/!x;
$config{http_root} =~ s! /$ !!x;
$config{http_root} = undef if $config{http_root} eq "";
print <<END;
If you will use https for your user pages (including login) enter the https hostname
here, or leave blank when using http only.
END
$config{securehost} = EPrints::Utils::get_input( "^\$|$REGEXP_HOSTNAME_FULL", 'HTTPS Hostname', $config{securehost}||"" );
if( $config{securehost} )
{
print <<END;
Please enter the port of your secure (https) server. This is probably 443.
END
$config{secureport} = EPrints::Utils::get_input( $REGEXP_NUMBER, 'Secure Webserver Port', $config{secureport} );
}
#print <<END;
#
#Language Configuration
#
#Please enter the primary language and other supported languages for the
#repository. Supporting other languages represents a serious commitment to
#translate all the phrases and templates etc. into each of these other
#languages.
#
#Available languages: (please use the ID to refer to them)
#END
#my @langs = EPrints::Config::get_supported_languages();
#foreach( @langs )
#{
# my $title = utf8("");
# $title->utf8( "".EPrints::Config::lang_title( $_ ) );
# print $_." - ".($title->latin1)."\n";
#}
#print <<END;
#
#If you plan to add support for another language, you will need to edit the
#languages.xml file to indicate that this language is supported, and create
#the relevant phrase and template files.
#
#END
print "\n";
print "\n";
$config{adminemail} = EPrints::Utils::get_input( $REGEXP_EMAIL, 'Administrator Email', $config{adminemail} );
print <<END;
Enter the name of the repository in the default language. If you wish to enter
other titles for other languages or enter non ascii characters then you may
enter something as a placeholder and edit the XML config file which this
script generates.
END
$config{archive_name} = EPrints::Utils::get_input( '^.+$', 'Archive Name', $config{archive_name} );
# Write files?
print "\n";
my $config_core = EPrints::Utils::get_input( $REGEXP_YESNO, "Write these core settings?", "yes" );
if( $config_core eq "no" )
{
print "\nOK. Not writing after all.\n";
return;
}
# Write files!
my $repodir = EPrints::Config::get( "base_path" )."/archives/".$repoid;
my $aemailfile = "$repodir/cfg/cfg.d/adminemail.pl";
open( AEMAIL, ">$aemailfile" ) || die "Could not write to $aemailfile: $!";
print AEMAIL Data::Dumper->Dump(
[
$config{adminemail},
],
[qw/
$c->{adminemail}
/]
);
close AEMAIL;
print "Wrote $aemailfile\n";
my $corefile = "$repodir/cfg/cfg.d/10_core.pl";
open( CORE, ">$corefile" ) || die "Could not write to $corefile: $!";
print CORE <<EOF;
# This file was created by bin/epadmin
# You can regenerate this file by doing ./bin/epadmin config_core $repoid
EOF
print CORE Data::Dumper->Dump(
[
$config{host},
$config{port},
$config{aliases},
$config{securehost},
$config{secureport},
$config{http_root},
],
[qw/
$c->{host}
$c->{port}
$c->{aliases}
$c->{securehost}
$c->{secureport}
$c->{http_root}
/]
);
close CORE;
print "Wrote $corefile\n";
my $anamefile = "$repodir/cfg/lang/en/phrases/archive_name.xml";
open( ANAME, ">$anamefile" ) || die "Could not write to $anamefile: $!";
print ANAME <<END;
<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?>
<!DOCTYPE phrases SYSTEM "entities.dtd">
<epp:phrases xmlns="http://www.w3.org/1999/xhtml"
xmlns:epp="http://eprints.org/ep3/phrase">
<epp:phrase id="archive_name">$config{archive_name}</epp:phrase>
</epp:phrases>
END
close( ANAME );
print "Wrote $anamefile\n";
}
sub config_db
{
my( $repoid ) = @_;
my %config = ();
$config{dbname} = $repoid;
$config{dbhost} = "localhost";
$config{dbport} = undef;
$config{dbsock} = undef;
$config{dbuser} = $repoid;
$config{dbpass} = undef;
$config{dbengine} = "MyISAM";
print "\nConfiguring Database for: $repoid\n";
$config{dbname} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'Database Name', $config{dbname} );
$config{dbhost} = EPrints::Utils::get_input( $REGEXP_HOSTNAME, 'MySQL Host', $config{dbhost} );
print "\nYou probably don't need to set socket and port (unless you do!?).\n";
$config{dbport} = "#" if( !defined $config{dbport} );
$config{dbport} = EPrints::Utils::get_input( '^[0-9]+|#$', 'MySQL Port (# for no setting)', $config{dbport} );
$config{dbport} = undef if( $config{dbport} eq "#" );
$config{dbsock} = "#" if( !defined $config{dbsock} );
# can't remember what is a legal mysql socket... cjg
$config{dbsock} = EPrints::Utils::get_input( '^.*$', 'MySQL Socket (# for no setting)', $config{dbsock} );
$config{dbsock} = undef if( $config{dbsock} eq "#" );
my $defaultpass = $config{dbpass};
if( !defined $config{dbpass} || $config{dbpass} eq "" )
{
$defaultpass = "";
srand;
for( 1..8 )
{
$defaultpass .= $PASSWORD_CHARS[int rand scalar @PASSWORD_CHARS];
}
}
$config{dbuser} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'Database User', $config{dbuser} );
$config{dbpass} = EPrints::Utils::get_input_hidden( $REGEXP_VARNAME, 'Database Password', $defaultpass );
$config{dbengine} = EPrints::Utils::get_input( $REGEXP_VARNAME, 'Database Engine', $config{dbengine} );
print "\n";
my $config_db = EPrints::Utils::get_input( $REGEXP_YESNO, "Write these database settings?", "yes" );
if( $config_db eq "no" )
{
print "\nOK. Not writing after all.\n";
return;
}
my $repodir = EPrints::Config::get( "base_path" )."/archives/".$repoid;
my $dbfile = "$repodir/cfg/cfg.d/database.pl";
open( DBCONF, ">$dbfile" ) || die "Could not write to $dbfile: $!";
print DBCONF Data::Dumper->Dump(
[
$config{dbname},
$config{dbhost},
$config{dbport},
$config{dbsock},
$config{dbuser},
$config{dbpass},
$config{dbengine},
],
[qw/
$c->{dbname}
$c->{dbhost}
$c->{dbport}
$c->{dbsock}
$c->{dbuser}
$c->{dbpass}
$c->{dbengine}
/]
);
close DBCONF;
print "Wrote $dbfile\n";
print <<END;
EPrints can create the database, and grant the correct permissions.
END
my $makedb = EPrints::Utils::get_input( $REGEXP_YESNO, "Create database \"$config{dbname}\"", "yes" );
if( $makedb eq "yes" )
{
create_db( $repoid );
}
else
{
print "\nWell, OK. But you'll need to do it yourself then.\n";
}
}
my $mysql_root_password;
# subroutine so that it can cache if we do several operations
sub get_mysql_root_password
{
return $mysql_root_password if( defined $mysql_root_password );
#cjg hide password from display?
print <<END;
Ok, I'll need to connect to the mysql database as root. What is the root
password?
END
$mysql_root_password = EPrints::Utils::get_input_hidden( '^.*$', "MySQL Root Password" );
return $mysql_root_password;
}
sub root_dbh
{
my( $repoid, $dbname ) = @_;
my $repo = &repository( $repoid, db_connect => 0 );
if( !defined $dbname )
{
$dbname = $repo->config( "dbname" );