forgotton freeside-setup bits of mysql locking workaround
[freeside.git] / FS / bin / freeside-setup
index bce5a0a..9b16d78 100755 (executable)
@@ -9,9 +9,10 @@ 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();
 
@@ -27,13 +28,11 @@ $config_dir = $1;
 getsecrets($opt_u);
 
 #needs to match FS::Record
-my($dbdef_file) = "/usr/local/etc/newtest/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", <<END, ":";
 #Freeside tracks the RADIUS User-Name, check attribute Password and
@@ -80,7 +79,7 @@ my $username_len = 32; #usernamemax config file
 # create a dbdef object from the old data structure
 ###
 
-my $dbdef = dbdef_dist;
+my $dbdef = dbdef_dist(datasrc);
 
 #important
 $dbdef->save($dbdef_file);
@@ -99,7 +98,6 @@ $FS::UID::callback_hack = 0;
 $|=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";
 }
@@ -117,11 +115,24 @@ $dbh->disconnect or die $dbh->errstr;
 
 warn "Database schema committed successfully\n" if $opt_v;
 
-my $init_config = "freeside-init-config";
-$init_config .= " -v" if $opt_v;
-$init_config .= " -u $opt_u" if $opt_u;
-$init_config .= " $config_dir";
-system "$init_config" ;
+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);