-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 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 "Configuration initialized - commiting transaction\n" if $opt_v;
+$dbh->commit or die $dbh->errstr;
+$dbh->disconnect or die $dbh->errstr;
+warn "Configuration committed successfully\n" if $opt_v;