pgci / jobhelpers / wpti

#!/usr/bin/perl

use strict;
use warnings;

use File::Temp qw/tempdir/;
use Getopt::Std;


my $tmpdir = tempdir(CLEANUP => 1);

$ENV{PGHOST} = $tmpdir;
$ENV{PGPORT} = 54321;
$ENV{PGDATA} = $tmpdir."/pgdata";
$ENV{PGUSER} = 'postgres';

my $listen_addresses = '';
my $locale_opt = '';

my %opts;
getopts('CL', \%opts);
$listen_addresses = 'localhost' if $opts{L};
$locale_opt = '--locale=C' if $opts{C};

my $ret;

system "initdb -A trust -U postgres $locale_opt >/dev/null";
$ret = system 'pg_ctl', '-s', '-w', '-l', "$tmpdir/logfile", '-o', "--fsync=off -k $tmpdir --listen-addresses='$listen_addresses'", 'start';

if ($ret != 0) {
    system('cat', "$tmpdir/logfile");
    exit 88;
}

if (@ARGV) {
    $ret = system @ARGV;
} else {
    $ret = system $ENV{SHELL};
}

system 'pg_ctl', '-s', '-w', '-m', 'immediate', 'stop';

if ($ret == -1) {
    exit 254;
} elsif ($ret & 127) {
    exit 255;
} else {
    exit($ret >> 8);
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.