Files
2021-11-02 16:21:07 +01:00

179 lines
7.1 KiB
Plaintext

post_install() {
log() {
echo "$@"
}
#
# Prepares systemd support by creating a symlink for the .service file
# and enabling/disabling certain features of our .service unit based on
# the available systemd version.
#
installSystemdSupport() {
local changed="False"
if command -V systemctl >/dev/null 2>&1; then
local systemd_version="$(systemctl --version | head -1 | sed -n 's/systemd \([0-9]*\).*/\1/p')"
# not all distros have migrated /lib to /usr/lib yet but all that
# have provide a symlink from /lib -> /usr/lib so we just prefix with
# /lib here.
ln -s /opt/safing/portmaster/portmaster.service /lib/systemd/system/portmaster.service 2>/dev/null >&2 ||:
# rhel/centos8 does not yet have ProtectKernelLogs available
if [ "${systemd_version}" -lt 244 ]; then
sed -i "s/^ProtectKernelLogs/#ProtectKernelLogs/g" /opt/safing/portmaster/portmaster.service ||:
changed="True"
fi
# SystemCallFilter groups are added in 231 so make sure we comment it out
if [ "${systemd_version}" -lt 231 ]; then
sed -i "s/^SystemCall/#SystemCall/g" /opt/safing/portmaster/portmaster.service ||:
changed="True"
fi
if [ "${changed}" = "True" ] && [ "$1" = "upgrade" ]; then
systemctl daemon-reload ||:
fi
log "Configuring portmaster.service to launch at boot"
systemctl enable portmaster.service ||:
fi
}
#
# install .desktop files, either using desktop-file-install when available
# or by just copying the files into /usr/share/applications.
#
if command -V desktop-file-install >/dev/null 2>&1; then
desktop-file-install /opt/safing/portmaster/portmaster.desktop ||:
desktop-file-install /opt/safing/portmaster/portmaster_notifier.desktop ||:
elif [ -d /usr/share/applications ]; then
cp /opt/safing/portmaster/portmaster.desktop /usr/share/applications 2>/dev/null ||:
cp /opt/safing/portmaster/portmaster_notifier.desktop /usr/share/applications 2>/dev/null ||:
fi
installSystemdSupport
#
# Fix selinux permissions for portmaster-start
#
if command -V getenforce >/dev/null 2>&1; then
chcon -t bin_t /opt/safing/portmaster/portmaster-start
fi
#
# Prepare the installation directory tree
#
/opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster clean-structure
#
# Finally, trigger downloading modules. As this requires internet access
# it is more likely to fail and is thus the last thing we do.
#
if [ "${skip_downloads}" = "True" ]; then
log "Downloading of Portmaster modules skipped!"
log "Please run '/opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster update' manually.\n"
return
fi
log "Downloading portmaster modules. This may take a while ..."
/opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster update --update-agent "${download_agent}" 2>/dev/null >/dev/null || (
log "Failed to download modules"
log "Please run '/opt/safing/portmaster/portmaster-start --data /opt/safing/portmaster update' manually.\n"
)
}
post_upgrade() {
log() {
echo "$@"
}
#
# Prepares systemd support by creating a symlink for the .service file
# and enabling/disabling certain features of our .service unit based on
# the available systemd version.
#
installSystemdSupport() {
local changed="False"
if command -V systemctl >/dev/null 2>&1; then
local systemd_version="$(systemctl --version | head -1 | sed -n 's/systemd \([0-9]*\).*/\1/p')"
# not all distros have migrated /lib to /usr/lib yet but all that
# have provide a symlink from /lib -> /usr/lib so we just prefix with
# /lib here.
ln -s /opt/safing/portmaster/portmaster.service /lib/systemd/system/portmaster.service 2>/dev/null >&2 ||:
# rhel/centos8 does not yet have ProtectKernelLogs available
if [ "${systemd_version}" -lt 244 ]; then
sed -i "s/^ProtectKernelLogs/#ProtectKernelLogs/g" /opt/safing/portmaster/portmaster.service ||:
changed="True"
fi
# SystemCallFilter groups are added in 231 so make sure we comment it out
if [ "${systemd_version}" -lt 231 ]; then
sed -i "s/^SystemCall/#SystemCall/g" /opt/safing/portmaster/portmaster.service ||:
changed="True"
fi
if [ "${changed}" = "True" ] && [ "$1" = "upgrade" ]; then
systemctl daemon-reload ||:
fi
log "Configuring portmaster.service to launch at boot"
systemctl enable portmaster.service ||:
fi
}
#
# As of 0.4.0 portmaster-control has been renamed to portmaster-start
# and is not placed in /usr/bin anymore. Unfortunately, the postrm script
# of the old installer does not get rid of portmaster-control so we should
# take care during an upgrade.
#
rm /usr/bin/portmaster-control 2>/dev/null >&2 ||:
#
# If there's already a /var/lib/portmaster installation we're going to move
# configs and databases and remove the complete directory
# The preinstall.sh already checked that /var/lib/portmaster/updates MUST NOT
# exist so we should be safe to touch the databases here.
#
if [ -d /var/lib/portmaster ]; then
if [ ! -d /opt/safing/portmaster/config.json ]; then
log "Migrating from previous installation at /var/lib/portmaster to /opt/safing/portmaster ..."
mv /var/lib/portmaster/databases /opt/safing/portmaster/databases ||:
mv /var/lib/portmaster/config.json /opt/safing/portmaster/config.json ||:
fi
log "Removing previous installation directory at /var/lib/portmaster"
rm -r /var/lib/portmaster 2>/dev/null >&2 ||:
fi
}
pre_remove() {
log() {
echo "$@"
}
# stop the portmaster service and disable it if it's enabled.
if command -V systemctl >/dev/null 2>&1; then
if (systemctl -q is-active portmaster.service); then
log "Stopping portmaster.service"
systemctl stop portmaster.service ||:
fi
if (systemctl -q is-enabled portmaster.service); then
log "Disabling portmaster.service to launch at boot"
systemctl disable portmaster.service ||:
fi
fi
}
post_remove() {
log() {
echo "$@"
}
rm -rf /opt/safing/portmaster/updates ||:
# file is marked as a ghost on RPM system so it might have
# been automatically deleted by the package manager.
rm /lib/systemd/system/portmaster.service 2>/dev/null >&2 ||:
rm /usr/share/applications/portmaster.desktop 2>/dev/null >&2 ||:
rm /usr/share/applications/portmaster_notifier.desktop 2>/dev/null >&2 ||:
if [ "$1" = "purge" ]; then
rm -rf /opt/safing/portmaster ||:
fi
}