Skip to content

Commit

Permalink
package: Add Debian postinst script (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyscot committed Dec 10, 2024
1 parent 4ee2dc8 commit 7e53da9
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ assets = [
[ "LICENSE", "usr/share/doc/qcp/", "644" ],
# gzip -9n < CHANGELOG.md > misc/changelog.gz
[ "misc/changelog.gz", "usr/share/doc/qcp/", "644" ],
[ "misc/20-qcp.conf", "etc/sysctl.d/", "644" ],
[ "misc/20-qcp.conf", "etc/sysctl.d/", "644" ], # this is automatically recognised as a conffile
[ "misc/qcp.1", "usr/share/man/man1/", "644" ],
]
maintainer-scripts="debian"
depends = "$auto,debconf"
12 changes: 12 additions & 0 deletions debian/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

set -e

if [ -e /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
db_version 2.0
db_capb
db_settitle qcp/title
fi

# We cannot meaningfully preconfigure as postinst checks the filesystem at runtime.
74 changes: 74 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/sh

set -e

# By Debian policy, packages must not ask unnecessary questions.
#
# Therefore, we examine the persistent sysctl directories to see
# if there are any mentions of the sysctls we want to set.
# If not, we presume that the system has no special requirements
# (this is expected to be the general case).

SYSCTL_FILE=20-qcp.conf
SYSCTL_PATH=/etc/sysctl.d/${SYSCTL_FILE}

. /usr/share/debconf/confmodule
db_version 2.0
db_capb
db_settitle qcp/title

#when testing this script, this line resets the db:
#db_fset qcp/sysctl_clash seen false

check_for_clashing_sysctls() {
for DIR in /etc/sysctl.d /usr/lib/sysctl.d; do
if grep -qcr -e net.core.rmem_max -e net.core.wmem_max --exclude "*${SYSCTL_FILE}*" ${DIR}; then
return 0
fi
done
return 1
}

activate_our_sysctls() {
sysctl -w -p ${SYSCTL_PATH}
}

disable_our_file() {
if [ -e ${SYSCTL_PATH} ]; then
mv -f ${SYSCTL_PATH} ${SYSCTL_PATH}.disabled
fi
}

try_to_enable_our_file() {
if [ -e ${SYSCTL_PATH}.disabled ]; then
mv -f ${SYSCTL_PATH}.disabled ${SYSCTL_PATH}
fi
}

alert_sysadmin() {
db_input high qcp/sysctl_clash || true
db_go || true

db_get qcp/sysctl_clash || true
case "$RET" in
"install and activate now")
try_to_enable_our_file
activate_our_sysctls
;;
"install but do NOT activate")
try_to_enable_our_file
# do nothing
;;
"do not install")
# they don't want it, OK
disable_our_file
;;
esac
}

if check_for_clashing_sysctls; then
alert_sysadmin
else
# No clashes; proceed quietly.
activate_our_sysctls
fi
20 changes: 20 additions & 0 deletions debian/postrm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

set -e

if [ -e /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
db_version 2

case "$1" in
purge)
# Remove my changes to the db.
if [ -e /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
db_version 2
db_purge
fi
;;
esac

fi
16 changes: 16 additions & 0 deletions debian/templates
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Template: qcp/title
Type: title
Description: qcp sysctl files

Template: qcp/sysctl_clash
Type: select
Choices: install and activate now, install but do NOT activate, do not install
Default: install and activate now
Description: Install sysctl files for qcp?
qcp has detected a possible sysctl clash!
.
qcp would like to install sysctl files to configure the kernel for good performance.
.
The sysctls used by qcp are: net.core.rmem_max net.core.wmem_max
.
sysctl config files may be found in: /etc/sysctl.d /usr/lib/sysctl.d

0 comments on commit 7e53da9

Please sign in to comment.