Skip to content

Commit

Permalink
log file handling out of installer.pl
Browse files Browse the repository at this point in the history
- inlined into RPM spec with %ghost directive
- extracted into a new installer.pl postint option for Debian
So that installer.pl will still be an option for people installing from
source.

additional minor cleanups
- documented debian's .postint and .postrm
- aligned debian's .postint and .postrm whitepace's to project's guidelines
- removed invalid documentation in installer.pl
  • Loading branch information
obilodeau committed Jun 18, 2012
1 parent fefab3c commit 776f514
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 51 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Olivier Bilodeau
Fabrice Durand
Francois Gaudreault
Francis Lachapelle
Derek Wuelfrath

Translators
Expand Down
14 changes: 13 additions & 1 deletion addons/packages/packetfence.spec
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Source: http://www.packetfence.org/downloads/PacketFence/src/%{name}-%{version}.
Source: http://www.packetfence.org/downloads/PacketFence/src/%{name}-%{version}-%{rev}.tar.gz
%endif

# Log related globals
%global logfiles packetfence.log snmptrapd.log access_log error_log admin_access_log admin_error_log admin_debug_log pfdetect pfmon pfredirect
%global logdir /usr/local/pf/logs

BuildRequires: gettext, httpd, rpm-macros-rpmforge
BuildRequires: perl(Parse::RecDescent)
# Required to build documentation
Expand Down Expand Up @@ -259,7 +263,7 @@ fop -c docs/fonts/fop-config.xml -xml docs/docbook/pf-devel-guide.xml \
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/html/admin/mrtg
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/html/admin/scan/results
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/html/admin/traplog
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/logs
%{__install} -d $RPM_BUILD_ROOT%logdir
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/var/conf
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/var/dhcpd
%{__install} -d $RPM_BUILD_ROOT/usr/local/pf/var/named
Expand Down Expand Up @@ -328,6 +332,10 @@ cp -r NEWS $RPM_BUILD_ROOT/usr/local/pf/
cp -r README $RPM_BUILD_ROOT/usr/local/pf/
cp -r README.network-devices $RPM_BUILD_ROOT/usr/local/pf/
cp -r UPGRADE $RPM_BUILD_ROOT/usr/local/pf/
# logfiles
for LOG in %logfiles; do
touch $RPM_BUILD_ROOT%logdir/$LOG
done

#start create symlinks
curdir=`pwd`
Expand Down Expand Up @@ -690,6 +698,10 @@ fi
%config(noreplace) /usr/local/pf/lib/pf/vlan/custom.pm
%config(noreplace) /usr/local/pf/lib/pf/web/custom.pm
%dir /usr/local/pf/logs
# logfiles
for LOG in %logfiles; do
%ghost %logdir/$LOG
done
%doc /usr/local/pf/NEWS
%doc /usr/local/pf/README
%doc /usr/local/pf/README.network-devices
Expand Down
48 changes: 31 additions & 17 deletions debian/packetfence.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,35 @@ set -e

case "$1" in
configure)
export PACKETFENCE=/usr/local/pf
export PERL5LIB=/usr/local/pf/lib
perl -w -e "use strict; use warnings; use Parse::RecDescent; use lib \"./lib\"; use pf::pfcmd::pfcmd; Parse::RecDescent->Precompile(\$grammar, \"pfcmd_pregrammar\");"
mv pfcmd_pregrammar.pm $PACKETFENCE/lib/pf/pfcmd/
if [ ! -e "$PACKETFENCE/db/pf-schema.sql" ]; then
cd $PACKETFENCE/db
VERSIONSQL=$(ls pf-schema-* |sort -r | head -1)
ln -s $VERSIONSQL ./pf-schema.sql
fi
sed -i "1i\suhosin.session.encrypt=Off\n" /etc/php5/apache2/php.ini
for i in `find /etc/freeradius/ -name *.pf`;do mv $i `dirname $i`/`basename $i .pf`; done
for service in snort apache2 snmptrapfmt bind9 freeradius isc-dhcp-server
do
update-rc.d $service remove > /dev/null 2>&1
done
update-rc.d packetfence defaults . || exit 0
update-rc.d configurator start 02 2 3 4 5 . stop 20 0 1 6 . || exit 0
export PACKETFENCE=/usr/local/pf
export PERL5LIB=/usr/local/pf/lib

# creating emtpy log files
$PACKETFENCE/installer.pl postinst $PACKETFENCE

# compile grammar
perl -w -e "use strict; use warnings; use Parse::RecDescent; use lib \"./lib\"; use pf::pfcmd::pfcmd; Parse::RecDescent->Precompile(\$grammar, \"pfcmd_pregrammar\");"
mv pfcmd_pregrammar.pm $PACKETFENCE/lib/pf/pfcmd/

# link to latest SQL schema
if [ ! -e "$PACKETFENCE/db/pf-schema.sql" ]; then
cd $PACKETFENCE/db
VERSIONSQL=$(ls pf-schema-* |sort -r | head -1)
ln -s $VERSIONSQL ./pf-schema.sql
fi

# we are not compatible with suhosin session encryption
sed -i "1i\suhosin.session.encrypt=Off\n" /etc/php5/apache2/php.ini

# backup of original files in freeradius
for i in `find /etc/freeradius/ -name *.pf`;do mv $i `dirname $i`/`basename $i .pf`; done

# managing services
for service in snort apache2 snmptrapfmt bind9 freeradius isc-dhcp-server; do
update-rc.d $service remove > /dev/null 2>&1
done
update-rc.d packetfence defaults . || exit 0
update-rc.d configurator start 02 2 3 4 5 . stop 20 0 1 6 . || exit 0
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand All @@ -54,3 +66,5 @@ esac
#DEBHELPER#

exit 0
# vim: set shiftwidth=4:
# vim: set expandtab:
20 changes: 12 additions & 8 deletions debian/packetfence.postrm
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ case "$1" in
;;

remove)
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/radiusd.conf.orig /etc/freeradius/radiusd.conf
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/eap.conf.orig /etc/freeradius/eap.conf
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/users.orig /etc/freeradius/users
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/perl.orig /etc/freeradius/modules/perl
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/sql.conf.orig /etc/freeradius/sql.conf
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/radiusd.conf.orig /etc/freeradius/radiusd.conf
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/eap.conf.orig /etc/freeradius/eap.conf
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/users.orig /etc/freeradius/users
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/perl.orig /etc/freeradius/modules/perl
dpkg-divert --package packetfence --remove --rename --divert /etc/freeradius/sql.conf.orig /etc/freeradius/sql.conf
;;
purge)
update-rc.d packetfence remove >/dev/null || exit 0
update-rc.d configurator remove >/dev/null || exit 0
# removing init scripts
update-rc.d packetfence remove >/dev/null || exit 0
update-rc.d configurator remove >/dev/null || exit 0
# purging all files
rm -fr /usr/local/pf
;;
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
Expand All @@ -47,3 +49,5 @@ esac
#DEBHELPER#

exit 0
# vim: set shiftwidth=4:
# vim: set expandtab:
86 changes: 61 additions & 25 deletions installer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,39 @@ =head1 USAGE
cd /usr/local/pf && ./installer.pl
Then answer the questions ...
=head1 SYNOPSIS
installer.pl [postinst PATH]
=head1 DESCRIPTION
installer.pl will help you with the following tasks:
installer.pl without any options will help you with the following tasks:
=over
=item * creation of the C<pf> user
=item * creation of the database and database user
=item * installation of Perl module dependencies
=item * installation of JPGraph
=item * update of DHCP fingerprints to latest version
=item * update of OUI prefixes to the latest version
=item * downloading snort rules
=item * compilation of pfcmd grammar
=item * compilation of message catalogue (i18n)
=item * creation of a self-signed SSL certificate
=item * creation of the empty directories required and not in source tarball
=item * permissions and ownerships of files in F</usr/local/pf>
=back
=item * account creation for the Web Admin GUI
installer.pl postinst:
=item * installation of the PHP Pear Log package
=over
=item * permissions and ownerships of files in F</usr/local/pf>
=item * creation of empty log files required for PacketFence operation
=back
Expand Down Expand Up @@ -77,6 +79,12 @@ =head1 DEPENDENCIES
my $install_dir = $FindBin::Bin;
my $conf_dir = "$install_dir/conf";

if ($ARGV[0] eq 'postint') {
die 'You must specify destination path' if (!defined($ARGV[1]));
installer::postint($ARGV[1]);
exit;
}

# check if user is root
die("You must be root to run the installer!\n") if ( $< != 0 );

Expand Down Expand Up @@ -399,21 +407,10 @@ =head1 DEPENDENCIES
}

print "Creating required directories (you can safely ignore 'already exists' notices)\n";
`mkdir -p $install_dir/conf/ssl $install_dir/conf/users $install_dir/html/admin/mrtg $install_dir/html/admin/traplog $install_dir/html/admin/scan/results $install_dir/logs $install_dir/var/conf $install_dir/var/dhcpd $install_dir/var/named $install_dir/var/run $install_dir/var/rrd $install_dir/var/session $install_dir/var/webadmin_cache`;
installer::create_empty_directories($install_dir);

# TODO: au démarrage de PF, créer les logs si les fichiers n'existent pas
# et supprimer cette section
print "Creating empty log files\n";
`touch $install_dir/logs/packetfence.log`;
`touch $install_dir/logs/snmptrapd.log`;
`touch $install_dir/logs/access_log`;
`touch $install_dir/logs/error_log`;
`touch $install_dir/logs/admin_access_log`;
`touch $install_dir/logs/admin_error_log`;
`touch $install_dir/logs/admin_debug_log`;
`touch $install_dir/logs/pfdetect`;
`touch $install_dir/logs/pfmon`;
`touch $install_dir/logs/pfredirect`;
installer::create_empty_log_files($install_dir);

print "Setting permissions\n";
print " Chowning $install_dir pf:pf\n";
Expand All @@ -424,6 +421,7 @@ =head1 DEPENDENCIES
`chmod 6755 $file`;
}

# TODO change that
print
"Installation is complete\n** Please run $install_dir/configurator.pl before starting PacketFence **\n\n\n";

Expand Down Expand Up @@ -474,6 +472,44 @@ sub supported_os {
return (0);
}

package installer;

sub create_empty_directories {
my ($root_dir) = @_;
`mkdir -p $root_dir/conf/ssl $root_dir/conf/users $root_dir/html/admin/mrtg $root_dir/html/admin/traplog $root_dir/html/admin/scan/results $root_dir/logs $root_dir/var/conf $root_dir/var/dhcpd $root_dir/var/named $root_dir/var/run $root_dir/var/rrd $root_dir/var/session $root_dir/var/webadmin_cache`;
}

sub postinst {
my ($root_dir) = @_;
create_empty_log_files($root_dir);
}

=item create_empty_log_files
Create log files in a way that PacketFence will start. Files must exist and
be owned by pf:pf.
If the files already exists they won't be re-created or deleted.
=cut
sub create_empty_log_files {
my ($root_dir) = @_;
my @logfiles = qw(
packetfence.log
snmptrapd.log
access_log error_log
admin_access_log admin_error_log admin_debug_log
pfdetect pfmon pfredirect
);
print "Creating log files if they don't already exist\n";
foreach my $file (@logfiles) {
print "...$file\n";
`touch $root_dir/logs/$file`;
}
print "Setting log file ownership\n";
`chown -R pf:pf $root_dir/logs`;
}

=head1 SEE ALSO
L<configurator.pl>
Expand Down

0 comments on commit 776f514

Please sign in to comment.