IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 39668 for trunk


Ignore:
Timestamp:
Sep 1, 2016, 2:39:37 PM (10 years ago)
Author:
watersc1
Message:

New, improved, safer, and more difficult to run neb-initdb.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous-Server/bin/neb-initdb

    r18386 r39668  
    1818
    1919my ($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;
     20my ($trap, $actually_do_it);
     21# Removed default options using environment variables because it's too dangerous.
    2522
    2623GetOptions(
     
    2926    'user=s'    => \$dbuser,
    3027    'pass=s'    => \$dbpass,
     28    'yes_i_know_what_im_doing'  => \$trap,
     29    'yes_i_know_what_im_doing_really=s' => \$actually_do_it,
    3130) || pod2usage( 2 );
    3231
    3332pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    34 pod2usage( -msg => "Required options: --db --user --pass", -exitval => 2 )
    35     unless $db && $dbuser && $dbpass;
     33pod2usage( -msg => "Required options: --db --user --pass --host", -exitval => 2 )
     34    unless $db && $dbuser && $dbpass && $dbhost;
     35pod2usage( -msg => "Aborting due to mistake in options.  Check code.", -exitval => 2) if ($trap);
     36pod2usage( -msg => "Aborting due to mistake in options.  Check code.", -exitval => 2) unless (defined($actually_do_it));
     37if ($actually_do_it ne 'this_is_intentionally_difficult') {
     38    pod2usage( -msg => "Aborting due to mistake in options.  Check code.", -exitval => 2);
     39}
    3640
    3741my $dbh = DBI->connect(
     
    4852my $sql = Nebulous::Server::SQL->new();
    4953
    50 print "Dropping any existing tables...";
     54print "Not dropping any existing tables because that's dangerous...";
     55#
     56#foreach my $statement (@{ $sql->get_db_clear }) {
     57#    $dbh->do( $statement );
     58#}
    5159
    52 foreach my $statement (@{ $sql->get_db_clear }) {
    53     $dbh->do( $statement );
    54 }
    55 
    56 print " OK\nCreating new tables...";
     60print " OK!\nCreating new tables...";
    5761
    5862foreach 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    }
    6069}
    6170
     
    7281=head1 SYNOPSIS
    7382
    74     neb-initdb [--db <database>] [--user <username>] [--pass <password>]
     83    neb-initdb [--db <database>] [--user <username>] [--pass <password>] [--host <dbhost>]
    7584
    7685=head1 DESCRIPTION
     
    7887This program initialize a database for use by L<Nebulous::Server> by creating
    7988the appropriate set of tables.  Any pre-existing tables with conflicting names
    80 are first removed.
     89are first removed.  This help file intentionally does not tell you how to make
     90the program actually work.
    8191
    8292=head1 OPTIONS
     
    8494=over 4
    8595
    86 =item * --db|-d <database>
     96=item * --db <database>
    8797
    8898Name of database (C<namespace>) to create tables in.
    8999
    90 Optional if the appropriate environment variable is set.
    91100
    92 =item * --user|-u <username>
     101=item * --user <username>
    93102
    94103Username to authenticate with.
    95104
    96 Optional if the appropriate environment variable is set.
    97105
    98 =item * --pass|-p <password>
     106=item * --pass <password>
    99107
    100108Password to authenticate with.
    101109
    102 Optional if the appropriate environment variable is set.
     110=item * --host <dbhost>
     111
     112Host to generate the database tables on.
    103113
    104114=back
     
    106116=head1 ENVIRONMENT
    107117
    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.
     118No environment variables interact with this program.
    131119
    132120=head1 SUPPORT
     
    134122Please contact the author directly via e-mail.
    135123
    136 =head1 AUTHOR
    137 
    138 Joshua Hoblitt <jhoblitt@cpan.org>
    139 
    140124=head1 COPYRIGHT
    141125
    142 Copyright (C) 2005-2007  Joshua Hoblitt.  All rights reserved.
     126Copyright (C) 2005-2016  IPP.  All rights reserved.
    143127
    144128This program is free software; you can redistribute it and/or modify it under
Note: See TracChangeset for help on using the changeset viewer.