-STDOUT->autoflush(1);
-
-# calculate build number
-$build = $main::version;
-
-if (opendir(DIR, "$main::root/perl")) {
- my @d = readdir(DIR);
- closedir(DIR);
- foreach my $fn (@d) {
- if ($fn =~ /^cluster\.pl$/ || $fn =~ /\.pm$/) {
- my $f = new IO::File "$main::root/perl/$fn" or next;
- while (<$f>) {
- if (/^#\s+\$Id:\s+[\w\._]+,v\s+(\d+\.\d+)/ ) {
- $build += $1;
- last;
+
+
+sub setup_start
+{
+
+ #############################################################
+ #
+ # The start of the main line of code
+ #
+ #############################################################
+
+ $starttime = $systime = time;
+ $systime_days = int ($systime / 86400);
+ $systime_daystart = $systime_days * 86400;
+ $lang = 'en' unless $lang;
+
+ unless ($DB::VERSION) {
+ $SIG{INT} = $SIG{TERM} = \&cease;
+ }
+
+ # open the debug file, set various FHs to be unbuffered
+ dbginit(undef, $broadcast_debug ? \&DXCommandmode::broadcast_debug : undef);
+ foreach (@debug) {
+ dbgadd($_);
+ }
+ STDOUT->autoflush(1);
+
+ # log our path
+ dbg "Perl path: " . join(':', @INC);
+
+ # try to load the database
+ if (DXSql::init($dsn)) {
+ $dbh = DXSql->new($dsn);
+ $dbh = $dbh->connect($dsn, $dbuser, $dbpass) if $dbh;
+ }
+
+ # try to load Encode and Git
+ {
+ local $^W = 0;
+ my $w = $SIG{__DIE__};
+ $SIG{__DIE__} = 'IGNORE';
+ eval { require Encode; };
+ unless ($@) {
+ import Encode;
+ $can_encode = 1;
+ }
+ $gitbranch = 'none';
+ $gitversion = 'none';
+ eval { require Git; };
+ unless ($@) {
+ import Git;
+
+ # determine the real version number
+ my $repo = Git->repository(Directory => "$root/.git");
+ if ($repo) {
+ my $desc = $repo->command_oneline(['describe', '--long'], STDERR => 0);
+ if ($desc) {
+ my ($v, $s, $b, $g) = $desc =~ /^([\d.]+)(?:\.(\d+))?-(\d+)-g([0-9a-f]+)/;
+ $s ||= '';
+ dbg("Git: $desc") if isdbg('git');
+ dbg("Git: V=$v S=$s B=$b g=$g") if isdbg('git');
+ $version = $v;
+ $build = $b || 0;
+ $gitversion = "$g\[r]";
+ }
+ my @branch = $repo->command([qw{branch}], STDERR=>0);
+ for (@branch) {
+ my ($star, $b) = split /\s+/;
+ if ($star eq '*') {
+ $gitbranch = $b;
+ last;
+ }