- Timestamp:
- Sep 1, 2016, 2:39:37 PM (10 years ago)
- File:
-
- 1 edited
-
trunk/Nebulous-Server/bin/neb-initdb (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Nebulous-Server/bin/neb-initdb
r18386 r39668 18 18 19 19 my ($db, $dbhost, $dbuser, $dbpass); 20 21 $db = $ENV{'NEB_DB'} unless $db; 22 $dbhost = $ENV{'NEB_DBHOST'} || 'localhost'; 23 $dbuser = $ENV{'NEB_USER'} unless $dbuser; 24 $dbpass = $ENV{'NEB_PASS'} unless $dbpass; 20 my ($trap, $actually_do_it); 21 # Removed default options using environment variables because it's too dangerous. 25 22 26 23 GetOptions( … … 29 26 'user=s' => \$dbuser, 30 27 'pass=s' => \$dbpass, 28 'yes_i_know_what_im_doing' => \$trap, 29 'yes_i_know_what_im_doing_really=s' => \$actually_do_it, 31 30 ) || pod2usage( 2 ); 32 31 33 32 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 34 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 ) 35 unless $db && $dbuser && $dbpass; 33 pod2usage( -msg => "Required options: --db --user --pass --host", -exitval => 2 ) 34 unless $db && $dbuser && $dbpass && $dbhost; 35 pod2usage( -msg => "Aborting due to mistake in options. Check code.", -exitval => 2) if ($trap); 36 pod2usage( -msg => "Aborting due to mistake in options. Check code.", -exitval => 2) unless (defined($actually_do_it)); 37 if ($actually_do_it ne 'this_is_intentionally_difficult') { 38 pod2usage( -msg => "Aborting due to mistake in options. Check code.", -exitval => 2); 39 } 36 40 37 41 my $dbh = DBI->connect( … … 48 52 my $sql = Nebulous::Server::SQL->new(); 49 53 50 print "Dropping any existing tables..."; 54 print "Not dropping any existing tables because that's dangerous..."; 55 # 56 #foreach my $statement (@{ $sql->get_db_clear }) { 57 # $dbh->do( $statement ); 58 #} 51 59 52 foreach my $statement (@{ $sql->get_db_clear }) { 53 $dbh->do( $statement ); 54 } 55 56 print " OK\nCreating new tables..."; 60 print " OK!\nCreating new tables..."; 57 61 58 62 foreach my $statement (@{ $sql->get_db_schema }) { 59 $dbh->do( $statement ); 63 eval { 64 $dbh->do( $statement ); 65 }; 66 if ($@) { 67 die "Error received: $@\n"; 68 } 60 69 } 61 70 … … 72 81 =head1 SYNOPSIS 73 82 74 neb-initdb [--db <database>] [--user <username>] [--pass <password>] 83 neb-initdb [--db <database>] [--user <username>] [--pass <password>] [--host <dbhost>] 75 84 76 85 =head1 DESCRIPTION … … 78 87 This program initialize a database for use by L<Nebulous::Server> by creating 79 88 the appropriate set of tables. Any pre-existing tables with conflicting names 80 are first removed. 89 are first removed. This help file intentionally does not tell you how to make 90 the program actually work. 81 91 82 92 =head1 OPTIONS … … 84 94 =over 4 85 95 86 =item * --db |-d<database>96 =item * --db <database> 87 97 88 98 Name of database (C<namespace>) to create tables in. 89 99 90 Optional if the appropriate environment variable is set.91 100 92 =item * --user |-u<username>101 =item * --user <username> 93 102 94 103 Username to authenticate with. 95 104 96 Optional if the appropriate environment variable is set.97 105 98 =item * --pass |-p<password>106 =item * --pass <password> 99 107 100 108 Password to authenticate with. 101 109 102 Optional if the appropriate environment variable is set. 110 =item * --host <dbhost> 111 112 Host to generate the database tables on. 103 113 104 114 =back … … 106 116 =head1 ENVIRONMENT 107 117 108 These environment variables may be used in place of the specified command line 109 options. All command line option will override the corresponding environment 110 value. 111 112 =over 4 113 114 =item * C<NEB_DB> 115 116 Equivalent to --db|-d 117 118 =item * C<NEB_USER> 119 120 Equivalent to --user|-u 121 122 =item * C<NEB_PASS> 123 124 Equivalent to --pass|-p 125 126 =back 127 128 =head1 CREDITS 129 130 Just me, myself, and I. 118 No environment variables interact with this program. 131 119 132 120 =head1 SUPPORT … … 134 122 Please contact the author directly via e-mail. 135 123 136 =head1 AUTHOR137 138 Joshua Hoblitt <jhoblitt@cpan.org>139 140 124 =head1 COPYRIGHT 141 125 142 Copyright (C) 2005-20 07 Joshua Hoblitt. All rights reserved.126 Copyright (C) 2005-2016 IPP. All rights reserved. 143 127 144 128 This program is free software; you can redistribute it and/or modify it under
Note:
See TracChangeset
for help on using the changeset viewer.
