RT#71525: welcome_msgnum / svc_acct_welcome_exclude deprecation [upgrade to export]
[freeside.git] / FS / bin / freeside-init-config
1 #!/usr/bin/perl -Tw
2
3 use strict;
4 use vars qw($opt_u $opt_f $opt_v);
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup checkeuid dbh);
7 use FS::CurrentUser;
8 use FS::Record qw(qsearch);
9 use FS::Conf;
10
11
12 die "Not running uid freeside!" unless checkeuid();
13
14 getopts("u:vf");
15 my $dir = shift or die &usage;
16
17 $FS::CurrentUser::upgrade_hack = 1;
18 $FS::UID::AutoCommit = 0;
19 $FS::UID::callback_hack = 1;
20 adminsuidsetup $opt_u; #$user;
21
22 $|=1;
23
24 if (!scalar(qsearch('conf', {})) || $opt_f) {
25   my $error = FS::Conf::init_config($dir);
26   if ($error) {
27     warn "CONFIGURATION INITIALIZATION FAILED\n";
28     dbh->rollback or die dbh->errstr;
29     die $error if $error;
30   }
31 }
32
33 warn "Freeside database initialized - committing transaction\n" if $opt_v;
34
35 dbh->commit or die dbh->errstr;
36 dbh->disconnect or die dbh->errstr;
37
38 warn "Configuration initialization committed successfully\n" if $opt_v;
39
40 sub usage {
41   die "Usage:\n  freeside-init-config [ -v ] [ -f ] directory\n"
42   # [ -u user ] for devel/multi-db installs
43 }
44
45 1;