X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-setup;h=9b16d78cb31273fc387c36765ea9df24f1652c26;hb=71af306c68c2733bd478d40d949e1cb49bf5eac4;hp=2ba717cb35416fb91925ef86509dc96e3dc31207;hpb=9bc0e873966642f415795525f8a2a57381afb080;p=freeside.git diff --git a/FS/bin/freeside-setup b/FS/bin/freeside-setup index 2ba717cb3..9b16d78cb 100755 --- a/FS/bin/freeside-setup +++ b/FS/bin/freeside-setup @@ -4,32 +4,35 @@ BEGIN { $FS::Schema::setup_hack = 1; } use strict; -use vars qw($opt_s $opt_d $opt_v); +use vars qw($opt_u $opt_d $opt_v); use Getopt::Std; use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); use FS::CurrentUser; use FS::Schema qw( dbdef_dist reload_dbdef ); -use FS::Record; +use FS::Record qw( qsearch ); #use FS::raddb; use FS::Setup qw(create_initial_data); +use FS::Conf; die "Not running uid freeside!" unless checkeuid(); #my %attrib2db = # map { lc($FS::raddb::attrib{$_}) => $_ } keys %FS::raddb::attrib; -getopts("svd:"); -#my $user = shift or die &usage; -getsecrets(); #$user); +getopts("u:vd:"); +my $config_dir = shift || 'conf' ; +$config_dir =~ /^([\w.:=]+)$/ + or die "unacceptable configuration directory name"; +$config_dir = $1; + +getsecrets($opt_u); #needs to match FS::Record -my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; +my($dbdef_file) = "%%%FREESIDE_CONF%%%/dbdef.". datasrc; ### -#print "\nEnter the maximum username length: "; -#my($username_len)=&getvalue; -my $username_len = 32; #usernamemax config file +my $username_len = 32; #print "\n\n", <save($dbdef_file); @@ -87,13 +90,14 @@ $dbdef->save($dbdef_file); ### $FS::CurrentUser::upgrade_hack = 1; -my $dbh = adminsuidsetup; #$user; +$FS::UID::callback_hack = 1; +my $dbh = adminsuidsetup $opt_u; #$user; +$FS::UID::callback_hack = 0; #create tables $|=1; foreach my $statement ( $dbdef->sql($dbh) ) { - warn $statement if $statement =~ /TABLE cdr/; $dbh->do( $statement ) or die "CREATE error: ". $dbh->errstr. "\ndoing statement: $statement"; } @@ -104,6 +108,33 @@ dbdef_create($dbh, $dbdef_file); delete $FS::Schema::dbdef_cache{$dbdef_file}; #force an actual reload reload_dbdef($dbdef_file); +warn "Freeside schema initialized - commiting transaction\n" if $opt_v; + +$dbh->commit or die $dbh->errstr; +$dbh->disconnect or die $dbh->errstr; + +warn "Database schema committed successfully\n" if $opt_v; + +warn "Initializing freeside configuration\n" if $opt_v; +$FS::UID::callback_hack = 1; +$dbh = adminsuidsetup $opt_u; +$FS::UID::callback_hack = 0; +if (!scalar(qsearch('conf', {}))) { + my $error = FS::Conf::init_config($config_dir); + if ($error) { + $dbh->rollback or die $dbh->errstr; + die $error; + } +} + +warn "Freeside configuration initialized - commiting transaction\n" if $opt_v; + +$dbh->commit or die $dbh->errstr; +$dbh->disconnect or die $dbh->errstr; + +warn "Freeside configuration committed successfully\n" if $opt_v; + +$dbh = adminsuidsetup $opt_u; create_initial_data('domain' => $opt_d); warn "Freeside database initialized - commiting transaction\n" if $opt_v; @@ -120,8 +151,10 @@ sub dbdef_create { # reverse engineer the schema from the DB and save to file } sub usage { - die "Usage:\n freeside-setup -d domain.name [ -v ] user\n"; + die "Usage:\n freeside-setup -d domain.name [ -v ] [ config/dir ]\n" + # [ -u user ] for devel/multi-db installs } 1; +