Mail archive
alpine-devel

[alpine-devel] [PATCH 1/4] /testing - Initial APKBUILD for PSAD (Port Scan Attack Detector)

From: IT Offshore <developer_at_it-offshore.co.uk>
Date: Sun, 3 Nov 2013 19:29:38 +0000

This is now a single patch for PSAD.

BUILD adapted from Arch Linux https://aur.archlinux.org/packages/psad/

psad.initd = revised init script (using OpenRC builtins)

psad.post-install = creates & adds psad service to default run level
---
 testing/psad/APKBUILD          | 87 ++++++++++++++++++++++++++++++++++++++++++
 testing/psad/psad.confd        |  8 ++++
 testing/psad/psad.initd        | 55 ++++++++++++++++++++++++++
 testing/psad/psad.post-install |  7 ++++
 4 files changed, 157 insertions(+)
 create mode 100644 testing/psad/APKBUILD
 create mode 100644 testing/psad/psad.confd
 create mode 100644 testing/psad/psad.initd
 create mode 100644 testing/psad/psad.post-install
diff --git a/testing/psad/APKBUILD b/testing/psad/APKBUILD
new file mode 100644
index 0000000..58983f6
--- /dev/null
+++ b/testing/psad/APKBUILD
_at_@ -0,0 +1,87 @@
+# Contributor: IT Offshore <developer_at_it-offshore.co.uk>
+# Maintainer:
+pkgname=psad
+pkgver=2.2.1
+pkgrel=0
+pkgdesc="3 lightweight system daemons that analyze iptables log messages to detect port scans and other suspicious traffic"
+url="http://cipherdyne.org/psad/"
+arch="all"
+license="GPL"
+depends="perl iptables ip6tables ssmtp psmisc perl-bit-vector perl-date-calc perl-iptables-chainmgr perl-iptables-parse perl-net-ipv4addr perl-unix-syslog net-tools"
+install="$pkgname.post-install"
+subpackages="$pkgname-doc"
+source="http://cipherdyne.org/psad/download/$pkgname-nodeps-$pkgver.tar.gz
+	psad.initd
+	psad.confd
+	"
+
+_builddir="$srcdir"/$pkgname-$pkgver
+
+build() {
+	cd "$_builddir"
+
+	#Set the config dirs
+  sed -e "s|'/usr/sbin'|'$pkgdir/usr/sbin'|" \
+      -e "s|'/usr/bin'|'$pkgdir/usr/bin'|" \
+      -e "s|my \$mpath = \"/usr/share/man/man\$section\";|my \$mpath = \"$pkgdir/usr/share/man/man\$section\";|" \
+          ./install.pl -i
+       #/usr/sbin/psadwatchd set with last cmd
+  sed -e "s|/var/log/psad|$pkgdir&|" \
+      -e "s|/var/run/psad|$pkgdir&|" \
+      -e "s|/var/lib/psad|$pkgdir&|" \
+      -e "s|/usr/lib/psad|$pkgdir&|" \
+      -e "s|/etc/psad|$pkgdir&|" \
+      -e "s|/usr/bin/whois_psad|$pkgdir/usr/bin/whois|" \
+      -e "s|/usr/sbin/fwcheck_psad|$pkgdir&|" \
+      -e "s|/usr/sbin/kmsgsd|$pkgdir&|" \
+      -e "s|/usr/sbin/psad|$pkgdir&|" \
+        ./psad.conf -i
+
+	#Disable install of generic init script & setting numeric run level 
+  	START=$(sed -n '/if ($init_dir and &is_root()) {/=' ./install.pl)
+  	END=$(expr $START + 7)
+        #Busybox sed does not support +7d
+	sed -e ''$START','$END'd' ./install.pl -i
+}
+
+package() {
+	cd "$_builddir"
+
+	#hope that things work
+	mkdir -p $pkgdir/etc/psad \
+                 $pkgdir/usr/bin \
+                 $pkgdir/usr/sbin \
+                 $pkgdir/usr/share/man/man8 \
+                 $pkgdir/var/lib/psad \
+                 $pkgdir/var/log/psad \
+                 $pkgdir/var/run/psad 
+ 	ln -s /bin/busybox $pkgdir/usr/bin/whois 
+	./install.pl --runlevel 1  
+ 
+        #Set correct permissions
+ 	chmod -R o+r $pkgdir/etc/psad
+ 	chmod -R o+r $pkgdir/usr/sbin/*
+ 	chmod 0700 $pkgdir/var/lib/psad
+	#remove whois symbolic link
+	rm -rf $pkgdir/usr/bin/whois 
+
+ 	# Fix the config
+ 	sed -e "s|$pkgdir||" $pkgdir/etc/psad/psad.conf -i
+ 	sed -e "s|$pkgdir||" $pkgdir/var/log/psad/install.log -i
+
+	#install init script & config defaults
+	install -m755 -D "$srcdir"/$pkgname.initd \
+		"$pkgdir"/etc/init.d/$pkgname || return 1
+	install -m644 -D "$srcdir"/$pkgname.confd \
+		"$pkgdir"/etc/conf.d/$pkgname || return 1
+}
+
+md5sums="ee600d9b6b4b915b026370c9a3726b5f  psad-nodeps-2.2.1.tar.gz
+6e5ef9b0ddebf1a229da58b0f1918f89  psad.initd
+bc07efebb41cc23c4be129bbbacc874b  psad.confd"
+sha256sums="0422cdd1a37d4c8fcc1a4ce6e7c4a6974e58fdde82242f45b83eb6beb85708b5  psad-nodeps-2.2.1.tar.gz
+b38a3643f0b0c9ed338f1c3f1beea6114ba5b0a8cfb60097598066aa4e415c32  psad.initd
+74c72225fa37c367a458321b737050cacaf262f32b0cc13babc54468ff1988b9  psad.confd"
+sha512sums="9e3f475376c3c7b753e71676f5c9d639e9fffd93caf864faa130f8030e37f9a6c57ba59c9519d2bd8dde945f7ff7a014ca2a710bd4b7be9721ca7f13f879b970  psad-nodeps-2.2.1.tar.gz
+01fbb402032f8cff9d2c6be3a032c5ea446d4708ca4f56addebba84bbd1b70e69e4c94b31a3af2680bbf8633f854f1ed8ef78ac746450ff1848fdbc4c90bf44a  psad.initd
+a80666f59356cc6157a9f5dca132991d4f1e0afda8f673d602de2557219d5521bec9ae148330e98d9483175d14d96e4cc2ccd11541d8b187b0e47f44ba4ada54  psad.confd"
diff --git a/testing/psad/psad.confd b/testing/psad/psad.confd
new file mode 100644
index 0000000..27ce228
--- /dev/null
+++ b/testing/psad/psad.confd
_at_@ -0,0 +1,8 @@
+# Default settings for psad.
+
+# Add any options you would like to pass to the daemon when started
+# For example if you would like to add an override file for your setup, this
+# can be achived this way:
+#
+#     command_args="--Override-config /root/psad.override.conf"
+command_args=""
diff --git a/testing/psad/psad.initd b/testing/psad/psad.initd
new file mode 100644
index 0000000..3e12cf4
--- /dev/null
+++ b/testing/psad/psad.initd
_at_@ -0,0 +1,55 @@
+#!/sbin/runscript
+
+# This file is part of PSAD (Port Scan Attack Detector)
+# Adapted for Alpine Linux by IT Offshore <developer_at_it-offshore.co.uk>
+
+command="/usr/sbin/psad"
+pidfile="/var/run/psad/psad.pid"
+config_file="/etc/psad/psad.conf"
+
+depend() {
+	need net
+	need logger
+	after iptables
+}
+
+# allow override config_file location from conf.d
+: ${config_file:="/etc/psad/psad.conf"}
+
+check_config() {
+	[ -f "$config_file" ] || error "$config_file is missing"
+}
+
+start_pre() {
+	check_config || return 1
+	# make sure dir for pidfile exists. /var/run is tmpfs...
+	checkpath --directory ${pidfile%/*}
+}
+
+start() {
+    ebegin "Starting PSAD (Port Scan Attack Detector)"
+    start-stop-daemon --start $command --pidfile $pidfile
+    eend $?
+}
+
+stop()
+{
+	local pidfile
+	local piddir=/var/run/psad
+	local process_list="psadwatchd kmsgsd psad"
+
+	# Stop all 3 daemons with psad stopped last as it launches the other 2
+	for process in $process_list; do
+
+		pidfile="$piddir/$process.pid"
+		einfo "Stopping the $process process"
+		start-stop-daemon --stop $process --progress --pidfile $pidfile
+		eend $?
+
+	done
+}
+
+exit
+
+
+
diff --git a/testing/psad/psad.post-install b/testing/psad/psad.post-install
new file mode 100644
index 0000000..ab9647e
--- /dev/null
+++ b/testing/psad/psad.post-install
_at_@ -0,0 +1,7 @@
+#!/bin/sh
+
+# add & start psad service
+rc-update add psad default
+rc-service psad start
+exit 0
+
-- 
1.8.4.2
---
Unsubscribe:  alpine-devel+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-devel+help_at_lists.alpinelinux.org
---
Received on Sun Nov 03 2013 - 19:29:38 UTC