| 1 | use ExtUtils::MakeMaker; |
| 2 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
| 3 | # the contents of the Makefile that is written. |
| 4 | |
| 5 | use strict; |
| 6 | |
| 7 | my @ALLOWED_ARGS = ('INSTALLDIRS','DESTDIR','PREFIX','RSCDIR','REPORTDIR','CGIDIR','CONFDIR','PIDDIR','STATDIR','APACHECONF','MANDIR','DOCDIR','SYSTEMDDIR','RETENTION', 'BINDIR'); |
| 8 | |
| 9 | # Parse command line arguments and store them as environment variables |
| 10 | while ($_ = shift) { |
| 11 | my ($k,$v) = split(/=/, $_, 2); |
| 12 | if (grep(/^$k$/, @ALLOWED_ARGS)) { |
| 13 | $ENV{$k} = $v; |
| 14 | } |
| 15 | } |
| 16 | $ENV{DESTDIR} =~ s/\/$//; |
| 17 | |
| 18 | # Perform some checks |
| 19 | if (exists $ENV{INSTALLDIRS} && $ENV{INSTALLDIRS} !~ /^(site|vendor)$/) { |
| 20 | die "ERROR: INSTALLDIRS value must be 'site' or 'vendor'.\n"; |
| 21 | } |
| 22 | |
| 23 | # Default install path |
| 24 | my $DESTDIR = $ENV{DESTDIR} || ''; |
| 25 | my $PREFIX = $ENV{PREFIX} || '/usr/local'; |
| 26 | my $INSTALLDIRS = $ENV{INSTALLDIRS} || 'site'; |
| 27 | my $CONFDIR = $ENV{CONFDIR} || "$DESTDIR$PREFIX/etc"; |
| 28 | my $CONFDIR_SRVC = $ENV{CONFDIR} || "$PREFIX/etc"; |
| 29 | if ($INSTALLDIRS eq 'vendor') { |
| 30 | $PREFIX = $ENV{PREFIX} || '/usr'; |
| 31 | $CONFDIR = $ENV{CONFDIR} || "$DESTDIR/etc"; |
| 32 | $CONFDIR_SRVC = $ENV{CONFDIR} || "/etc"; |
| 33 | } |
| 34 | my $BINDIR = $ENV{BINDIR} || "$DESTDIR$PREFIX/bin"; |
| 35 | my $PIDDIR = $ENV{PIDDIR} || "$DESTDIR/var/run/postgresql"; |
| 36 | my $STATDIR = $ENV{STATDIR} || "$DESTDIR/var/lib/pgcluu/data"; |
| 37 | my $REPORTDIR = $ENV{REPORTDIR} || "$DESTDIR/var/lib/pgcluu/report"; |
| 38 | my $RSCDIR = $ENV{RSCDIR} || "$DESTDIR$PREFIX/share/pgcluu"; |
| 39 | my $CGIDIR = $ENV{CGIDIR} || "$DESTDIR$PREFIX/lib/cgi-bin"; |
| 40 | my $APACHECONF = $ENV{APACHECONF} || "$CONFDIR/apache2/conf-available"; |
| 41 | my $MANDIR = $ENV{MANDIR} || "$DESTDIR$PREFIX/share/man"; |
| 42 | my $DOCDIR = $ENV{DOCDIR} || "$DESTDIR$PREFIX/share/doc"; |
| 43 | my $SYSTEMDDIR = $ENV{SYSTEMDDIR} || "$DESTDIR/lib/systemd/system"; |
| 44 | my $RETENTION = $ENV{RETENTION} || 30; |
| 45 | my $STATDIR_SRVC = $ENV{STATDIR} || "/var/lib/pgcluu/data"; |
| 46 | my $REPORTDIR_SRVC = $ENV{REPORTDIR} || "/var/lib/pgcluu/report"; |
| 47 | my $PIDDIR_SRVC = $ENV{PIDDIR} || "/var/run/postgresql"; |
| 48 | my $BINDIR_SRVC = $ENV{BINDIR} || "$PREFIX/bin"; |
| 49 | |
| 50 | # Try to detect RPM specific directory installation |
| 51 | my $RPM_LIKE = 0; |
| 52 | if ($SYSTEMDDIR eq '/usr/lib/systemd/system' && ! -d '/usr/lib/systemd/system') { |
| 53 | $SYSTEMDDIR = $ENV{SYSTEMDDIR} || '/lib/systemd/system'; |
| 54 | } |
| 55 | |
| 56 | # Setup ok. generating sendmailanalyzer.conf config file |
| 57 | unless(open(OUTCFG, ">pgcluu.conf")) { |
| 58 | print "\nError: can't write config file pgcluu.conf, $!\n"; |
| 59 | exit 0; |
| 60 | } |
| 61 | |
| 62 | print OUTCFG qq{ |
| 63 | #----------------------------------------------------------------------------- |
| 64 | # Configuration file for pgCluu scripts. Most of the directives are used by |
| 65 | # the CGI script execpt those starting by STATS_COLLECTD_ or STATS_REPORT_ |
| 66 | #----------------------------------------------------------------------------- |
| 67 | |
| 68 | # Defined the base URL where resources files are stored |
| 69 | # Resources files are css and javascript files. |
| 70 | # Default is to automatically set the relative path. |
| 71 | RSC_BASE /pgcluu/rsc/ |
| 72 | |
| 73 | # Path to the main pgCluu data directory. This path |
| 74 | # must be readable by the user running your httpd server. |
| 75 | INPUT_DIR $STATDIR_SRVC |
| 76 | |
| 77 | # Space or comma separated list of database that must be reported. |
| 78 | # Value can be any valid perl regexp |
| 79 | #INCLUDE_DB [^p].* |
| 80 | |
| 81 | # Space or comma separated list of table that must be reported. |
| 82 | # Value can be any valid perl regexp |
| 83 | #INCLUDE_TB tmp.* |
| 84 | |
| 85 | # Space or comma separated list of network device that must be reported. |
| 86 | # Value can be any valid perl regexp |
| 87 | #INCLUDE_IFACE lo |
| 88 | |
| 89 | # Space or comma separated list of disk device that must be reported. |
| 90 | # Value can be any valid perl regexp |
| 91 | #INCLUDE_DEV sda |
| 92 | |
| 93 | # By default pgcluu look at mm/dd/yy format in header line of sar file. |
| 94 | # When enabled pgcluu will look at dd/mm/yy format. |
| 95 | REVERT_DATE 0 |
| 96 | |
| 97 | # Max number of days in a graph. Using default pgcluu_collectd 1 minute |
| 98 | # interval each, daily graph will have 1440 points. Having too much data |
| 99 | # to render is not a good point for performances with the current code. |
| 100 | # The user can set is own graph period, we are limit it to the first seven |
| 101 | # days of the selected period. This mean a maximum of 10080 points for one |
| 102 | # week, this seems a safe limit. Feel free to increase or reduce the limit |
| 103 | # following the server and client resources. |
| 104 | MAX_RENDERED_DAYS 7 |
| 105 | |
| 106 | # Retention limit in the statistics directory expressed in number of days. |
| 107 | # This directive is only used by pgcluu_collectd in incremental mode. Only |
| 108 | # the last number of days will be preserved, obsolete directories will be |
| 109 | # removed. It can be used to preserved disk space. Default store 30 days. |
| 110 | STATS_COLLECTD_RETENTION $RETENTION |
| 111 | |
| 112 | # Retention limit in the report directory (static html) expressed in number |
| 113 | # of days. This directive is only used by pgcluu in incremental mode. Only |
| 114 | # the last number of days will be preserved, obsolete directories will be |
| 115 | # removed. It can be used to preserved disk space. Default store 30 days. |
| 116 | STATS_REPORT_RETENTION $RETENTION |
| 117 | |
| 118 | # This directive must be enabled in CGI mode. In this case pgcluu must be |
| 119 | # run periodically at least each 5 minutes to build and update cached stats. |
| 120 | STATS_REPORT_CACHING 0 |
| 121 | |
| 122 | # Directory where the pgCluu reports must be saved |
| 123 | STATS_REPORT_OUTDIR $REPORTDIR_SRVC |
| 124 | }; |
| 125 | close(OUTCFG); |
| 126 | |
| 127 | unless(open(INST, ">install_all.sh")) { |
| 128 | print "\nError: can't write post install file install_all.sh, $!\n"; |
| 129 | exit 0; |
| 130 | } |
| 131 | print INST qq{#!/bin/sh |
| 132 | if [ ! -d "$DESTDIR/bin" ]; then |
| 133 | mkdir -p $DESTDIR/bin |
| 134 | fi |
| 135 | if [ ! -d "$CONFDIR" ]; then |
| 136 | mkdir -p $CONFDIR |
| 137 | fi |
| 138 | if [ ! -d "$RSCDIR/rsc" ]; then |
| 139 | mkdir -p $RSCDIR/rsc |
| 140 | fi |
| 141 | if [ ! -d "$MANDIR/man1" ]; then |
| 142 | mkdir -p $MANDIR/man1 |
| 143 | fi |
| 144 | if [ ! -d "$DOCDIR/pgcluu" ]; then |
| 145 | mkdir -p $DOCDIR/pgcluu |
| 146 | fi |
| 147 | if [ ! -d "$DOCDIR/pgcluu/examples" ]; then |
| 148 | mkdir -p $DOCDIR/pgcluu/examples |
| 149 | fi |
| 150 | if [ ! -d "$CGIDIR" ]; then |
| 151 | mkdir -p $CGIDIR |
| 152 | fi |
| 153 | if [ ! -d "$APACHECONF" ]; then |
| 154 | mkdir -p $APACHECONF |
| 155 | fi |
| 156 | if [ ! -d "$SYSTEMDDIR" ]; then |
| 157 | mkdir -p $SYSTEMDDIR |
| 158 | fi |
| 159 | if [ ! -d "$STATDIR" ]; then |
| 160 | mkdir -p $STATDIR |
| 161 | chown postgres: $STATDIR |
| 162 | fi |
| 163 | if [ ! -d "$REPORTDIR" ]; then |
| 164 | mkdir -p $REPORTDIR |
| 165 | chown postgres: $REPORTDIR |
| 166 | fi |
| 167 | if [ ! -d "$PIDDIR" ]; then |
| 168 | mkdir -p $PIDDIR |
| 169 | chown postgres: $PIDDIR |
| 170 | fi |
| 171 | |
| 172 | # Do not override existing Apache configuration file |
| 173 | if [ ! -f "$APACHECONF/pgcluu.conf" ]; then |
| 174 | echo " |
| 175 | Alias /pgcluu $RSCDIR/ |
| 176 | <Directory $RSCDIR/> |
| 177 | Options FollowSymLinks MultiViews |
| 178 | AllowOverride None |
| 179 | Require local |
| 180 | #Require ip 192.1.168.0/24 |
| 181 | </Directory>" > $APACHECONF/pgcluu.conf |
| 182 | fi |
| 183 | |
| 184 | install -m 755 pgcluu_collectd $DESTDIR/bin/ |
| 185 | install -m 755 pgcluu $DESTDIR/bin/ |
| 186 | install -m 755 cgi-bin/pgcluu.cgi $CGIDIR/ |
| 187 | install -m 644 cgi-bin/rsc/* $RSCDIR/rsc/ |
| 188 | install -m 644 LICENSE $DOCDIR/pgcluu/ |
| 189 | install -m 644 README $DOCDIR/pgcluu/ |
| 190 | install -m 644 ChangeLog $DOCDIR/pgcluu/changelog |
| 191 | install -m 644 pgcluu_collectd.service $DOCDIR/pgcluu/examples/ |
| 192 | install -m 644 pgcluu.service $DOCDIR/pgcluu/examples/ |
| 193 | install -m 644 pgcluu.timer $DOCDIR/pgcluu/examples/ |
| 194 | install -m 644 pgcluu.conf $DOCDIR/pgcluu/examples/pgcluu.conf.dist |
| 195 | # Do not override existing configuration file |
| 196 | if [ ! -f "$CONFDIR/pgcluu.conf" ]; then |
| 197 | install -m 644 pgcluu.conf $CONFDIR/pgcluu.conf |
| 198 | fi |
| 199 | gzip -f $DOCDIR/pgcluu/changelog |
| 200 | if [ ! -e "$MANDIR/man1/pgcluu.1p.gz" ]; then |
| 201 | gzip -f $MANDIR/man1/pgcluu.1p |
| 202 | fi |
| 203 | install -m 644 pgcluu_collectd.service $SYSTEMDDIR/ |
| 204 | install -m 644 pgcluu.service $SYSTEMDDIR/ |
| 205 | install -m 644 pgcluu.timer $SYSTEMDDIR/ |
| 206 | if [ ! -e "/etc/apache2/conf-enabled/pgcluu.conf" ]; then |
| 207 | cd /etc/apache2/conf-enabled/ |
| 208 | ln -s ../conf-available/pgcluu.conf pgcluu.conf |
| 209 | fi |
| 210 | cd $MANDIR/man1/ |
| 211 | ln -s pgcluu.1p.gz pgcluu_collectd.1p.gz |
| 212 | }; |
| 213 | close(INST); |
| 214 | `chmod 755 install_all.sh`; |
| 215 | |
| 216 | `perl -p -i -e 's#my \\\$CONFIG_FILE .*#my \\\$CONFIG_FILE = "$CONFDIR_SRVC/pgcluu.conf";#' cgi-bin/pgcluu.cgi pgcluu_collectd pgcluu`; |
| 217 | `perl -p -i -e 's#my \\\$PIDFILE .*=.*#my \\\$PIDFILE = "$PIDDIR_SRVC/pgcluu_collectd.pid";#' pgcluu_collectd`; |
| 218 | `perl -p -i -e 's#/var/lib/pgcluu/data#$STATDIR_SRVC#' pgcluu.service pgcluu_collectd.service`; |
| 219 | `perl -p -i -e 's#/var/lib/pgcluu/report#$REPORTDIR_SRVC#' pgcluu.service`; |
| 220 | `perl -p -i -e 's#/usr/bin#$BINDIR_SRVC#' pgcluu.service pgcluu_collectd.service`; |
| 221 | `perl -p -i -e 's#/var/run/postgresql#$PIDDIR_SRVC#' pgcluu_collectd.service`; |
| 222 | |
| 223 | my %merge_compat = (); |
| 224 | if ($ExtUtils::MakeMaker::VERSION >= 6.46) { |
| 225 | %merge_compat = ( |
| 226 | 'META_MERGE' => { |
| 227 | resources => { |
| 228 | homepage => 'http://pgcluu.darold.net/', |
| 229 | repository => { |
| 230 | type => 'git', |
| 231 | git => '[email protected]:darold/pgcluu.git', |
| 232 | web => 'http://pgcluu.darold.net/', |
| 233 | }, |
| 234 | }, |
| 235 | } |
| 236 | ); |
| 237 | } |
| 238 | |
| 239 | WriteMakefile( |
| 240 | 'DISTNAME' => 'pgcluu', |
| 241 | 'NAME' => 'pgCluu', |
| 242 | 'VERSION_FROM' => 'pgcluu', |
| 243 | 'dist' => { |
| 244 | 'COMPRESS'=>'gzip -9f', 'SUFFIX' => 'gz', |
| 245 | 'ZIP'=>'/usr/bin/zip','ZIPFLAGS'=>'-rl' |
| 246 | }, |
| 247 | 'AUTHOR' => 'Gilles Darold ([email protected])', |
| 248 | 'ABSTRACT' => 'pgCluu - PostgreSQL performances auditing tool', |
| 249 | 'EXE_FILES' => [ qw(pgcluu pgcluu_collectd) ], |
| 250 | 'MAN1PODS' => { 'doc/pgCluu.pod' => 'blib/man1/pgcluu.1p' }, |
| 251 | 'DESTDIR' => $ENV{DESTDIR}, |
| 252 | 'INSTALLDIRS' => $ENV{INSTALLDIRS}, |
| 253 | 'clean' => {FILES => "install_all.sh"}, |
| 254 | %merge_compat |
| 255 | ); |
| 256 | |
| 257 | sub MY::install { |
| 258 | my $self = shift; |
| 259 | |
| 260 | my $string = $self->MM::install; |
| 261 | $string =~ s/(pure_install\s+)(.*)/$1 install_all $2/; |
| 262 | |
| 263 | return $string; |
| 264 | } |
| 265 | |
| 266 | sub MY::postamble { |
| 267 | my $postamble = <<'END'; |
| 268 | install_all: install_all.sh |
| 269 | sh install_all.sh |
| 270 | END |
| 271 | return $postamble; |
| 272 | } |
| 273 | |
| 274 | if (!$ENV{QUIET}) { |
| 275 | print "Done...\n\n"; |
| 276 | print "Now type 'make && make install'\n\n"; |
| 277 | } |
| 278 |