Commit 7218f144 authored by Christoph Berg's avatar Christoph Berg

Fix package checks for RedHat, and install logrotate config

parent 535e5764
......@@ -29,7 +29,7 @@ our @EXPORT = qw/error user_cluster_map get_cluster_port set_cluster_port
get_version_clusters next_free_port cluster_exists install_file
change_ugid config_bool get_db_encoding get_db_locales get_cluster_locales
get_cluster_databases read_cluster_conf_file read_pg_hba/;
our @EXPORT_OK = qw/$confroot $binroot quote_conf_value read_conf_file get_conf_value
our @EXPORT_OK = qw/$confroot $binroot $rpm quote_conf_value read_conf_file get_conf_value
set_conf_value set_conffile_value disable_conffile_value disable_conf_value
replace_conf_value cluster_data_directory get_file_device read_pidfile
check_pidfile_running/;
......@@ -52,6 +52,8 @@ if ($ENV{'PGSYSCONFDIR'}) {
my $mapfile = "$common_confdir/user_clusters";
our $binroot = "/usr/lib/postgresql/";
#redhat# $binroot = "/usr/pgsql-";
our $rpm = 0;
#redhat# $rpm = 1;
my $defaultport = 5432;
{
......
......@@ -76,33 +76,43 @@ sed -i -e 's/#redhat# //' \
%{buildroot}/usr/bin/pg_config \
%{buildroot}/usr/bin/pg_virtualenv \
%{buildroot}/usr/share/postgresql-common/PgCommon.pm \
%{buildroot}/usr/share/postgresql-common/init.d-functions \
%{buildroot}/usr/share/postgresql-common/testsuite
%{buildroot}/usr/share/postgresql-common/init.d-functions
# install init script
mkdir -p %{buildroot}/etc/init.d
mkdir -p %{buildroot}/etc/init.d %{buildroot}/etc/logrotate.d
cp debian/postgresql-common.postgresql.init %{buildroot}/etc/init.d/postgresql
#cp debian/postgresql-common.postinst %{buildroot}/usr/share/postgresql-common
cp rpm/init-functions-compat %{buildroot}/usr/share/postgresql-common
# ssl defaults to 'off' here because we don't have pregenerated snakeoil certs
sed -e 's/__SSL__/off/' createcluster.conf > %{buildroot}/etc/postgresql-common/createcluster.conf
cp debian/logrotate.template %{buildroot}/etc/logrotate.d/postgresql-common
%files -n postgresql-common -f files-postgresql-common
%attr(0755, root, root) %config /etc/init.d/postgresql
#%attr(0755, root, root) /usr/share/postgresql-common/postgresql-common.postinst
/usr/share/postgresql-common/init-functions-compat
%config /etc/postgresql-common/createcluster.conf
%config /etc/logrotate.d/postgresql-common
%files -n postgresql-client-common -f files-postgresql-client-common
%files -n postgresql-server-dev-all -f files-postgresql-server-dev-all
#%post
%post
## RedHat's adduser is different, create the user here
#if ! getent passwd postgres > /dev/null; then
# adduser --system --home /var/lib/postgresql --no-create-home \
# --shell /bin/bash --comment "PostgreSQL administrator" postgres
#fi
#sh -x /usr/share/postgresql-common/postgresql-common.postinst "configure"
version_lt () {
newest=$( ( echo $1; echo $2 ) | sort -V | tail -n1)
[ "$1" != "$newest" ]
}
lrversion=$(rpm --queryformat '%{VERSION}' -q logrotate)
if version_lt $lrversion 3.8; then
echo "Adjusting /etc/logrotate.d/postgresql-common for logrotate version $lrversion"
sed -i -e '/ su /d' /etc/logrotate.d/postgresql-common || :
fi
%post -n postgresql-client-common -f postgresql-client-common.post
......
......@@ -6,10 +6,26 @@ use lib 't';
use TestLib;
use POSIX qw/setlocale LC_ALL LC_MESSAGES/;
use Test::More tests => 12 + ($#MAJORS+1)*7;
use Test::More tests => $PgCommon::rpm ? (7*@MAJORS) : (12 + 7*@MAJORS);
note "PostgreSQL versions installed: @MAJORS\n";
if ($PgCommon::rpm) {
foreach my $v (@MAJORS) {
my $vv = $v;
$vv =~ s/\.//;
ok ((rpm_installed "postgresql$vv"), "postgresql$vv installed");
ok ((rpm_installed "postgresql$vv-libs"), "postgresql$vv-libs installed");
ok ((rpm_installed "postgresql$vv-server"), "postgresql$vv-server installed");
ok ((rpm_installed "postgresql$vv-contrib"), "postgresql$vv-contrib installed");
ok ((rpm_installed "postgresql$vv-plperl"), "postgresql$vv-plperl installed");
ok ((rpm_installed "postgresql$vv-plpython"), "postgresql$vv-plpython installed");
ok ((rpm_installed "postgresql$vv-pltcl"), "postgresql$vv-pltcl installed");
}
exit;
}
foreach my $v (@MAJORS) {
ok ((deb_installed "postgresql-$v"), "postgresql-$v installed");
ok ((deb_installed "postgresql-plpython-$v"), "postgresql-plpython-$v installed");
......
......@@ -4,13 +4,13 @@ use strict;
use lib 't';
use TestLib;
#FIXME: use Dpkg::Version;
use PgCommon qw/$binroot/;
use Test::More tests => (@MAJORS) * 4 + 1;
# Debian/Ubuntu packages are linked against libedit. If your psql binaries are
# linked against libreadline, set PG_READLINE=1 when running this testsuite.
$ENV{PG_READLINE} = 1 if ($PgCommon::rpm);
my ($want_lib, $avoid_lib) = $ENV{PG_READLINE} ? qw(libreadline libedit) : qw(libedit libreadline);
foreach my $v (@MAJORS) {
......@@ -20,8 +20,8 @@ foreach my $v (@MAJORS) {
"psql is not linked against $avoid_lib");
}
my $lrversion = `dpkg-query -f '\${Version}' --show logrotate`;
my $is_logrotate_38 = ($lrversion >= '3.8');
my $lrversion = package_version ('logrotate');
my $is_logrotate_38 = version_ge ($lrversion, '3.8');
note "logrotate version $lrversion is " . ($is_logrotate_38 ? 'greater' : 'smaller') . " than 3.8";
my $f = "/etc/logrotate.d/postgresql-common";
open F, $f;
......
......@@ -20,8 +20,8 @@ use Test::More;
our $VERSION = 1.00;
our @ISA = ('Exporter');
our @EXPORT = qw/ps ok_dir exec_as deb_installed is_program_out
like_program_out unlike_program_out pidof pid_env check_clean
our @EXPORT = qw/ps ok_dir exec_as deb_installed rpm_installed package_version
version_ge is_program_out like_program_out unlike_program_out pidof pid_env check_clean
@ALL_MAJORS @MAJORS $delay/;
use lib '/usr/share/postgresql-common';
......@@ -57,6 +57,42 @@ sub deb_installed {
return $result;
}
# Return whether a given rpm is installed.
# Arguments: <rpm name>
sub rpm_installed {
open (RPM, "rpm -qa $_[0] 2>/dev/null|") or die "call rpm: $!";
my $out = <RPM>; # returns void or the package name
close RPM;
return ($out =~ /./);
}
# Return a package version
# Arguments: <package>
sub package_version {
my $package = shift;
if ($PgCommon::rpm) {
return `rpm --queryformat '%{VERSION}' -q $package`;
} else {
my $version = `dpkg-query -f '\${Version}' --show $package`;
chomp $version;
return $version;
}
}
# Return whether a version is greater or equal to another one
# Arguments: <ver1> <ver2>
sub version_ge {
my ($v1, $v2) = @_;
use IPC::Open2;
open2(\*CHLD_OUT, \*CHLD_IN, 'sort', '-Vr');
print CHLD_IN "$v1\n";
print CHLD_IN "$v2\n";
close CHLD_IN;
my $v_ge = <CHLD_OUT>;
chomp $v_ge;
return $v_ge eq $v1;
}
# Return the user, group, and command line of running processes for the given
# program.
sub ps {
......
......@@ -140,7 +140,6 @@ ifconfig lo up || true
unset TMPDIR
unset LC_ALL
export LANG=en_US.utf8
#redhat# export PG_READLINE=1
# set variables which cause taint check errors
export IFS=' '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment