summaryrefslogtreecommitdiff
path: root/FS/bin/freeside-init-config
blob: fe4729c40ec011b4854381342064df52208959d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/perl -Tw

use strict;
use vars qw($opt_u $opt_f $opt_v);
use Getopt::Std;
use FS::UID qw(adminsuidsetup checkeuid dbh);
use FS::CurrentUser;
use FS::Record qw(qsearch);
use FS::Conf;


die "Not running uid freeside!" unless checkeuid();

getopts("u:vf");
my $dir = shift or die &usage;

$FS::CurrentUser::upgrade_hack = 1;
$FS::UID::AutoCommit = 0;
$FS::UID::callback_hack = 1;
adminsuidsetup $opt_u; #$user;

$|=1;

if (!scalar(qsearch('conf', {})) || $opt_f) {
  my $error = FS::Conf::init_config($dir);
  if ($error) {
    warn "CONFIGURATION INITIALIZATION FAILED\n";
    dbh->rollback or die dbh->errstr;
    die $error if $error;
  }
}

warn "Freeside database initialized - committing transaction\n" if $opt_v;

dbh->commit or die dbh->errstr;
dbh->disconnect or die dbh->errstr;

warn "Configuration initialization committed successfully\n" if $opt_v;

sub usage {
  die "Usage:\n  freeside-init-config [ -v ] [ -f ] directory\n"
  # [ -u user ] for devel/multi-db installs
}

1;