[packaging] Fix: Linux installers (migration/update/removal)

This commit is contained in:
Alexandr Stelnykovych 2025-03-25 14:30:46 +00:00
parent 6b958fd93d
commit f08a36f5ff
3 changed files with 119 additions and 20 deletions

View file

@ -1,45 +1,72 @@
#!/bin/bash #!/bin/bash
chmod +x /usr/lib/portmaster/portmaster-core echo "[ ] Post-Install script [arg1='$1' arg2='$2']"
# echo "[ ] Stopping old service (if exists)"
# Fix selinux permissions for portmaster-core if we have semanage
# available.
#
if command -V semanage >/dev/null 2>&1; then
semanage fcontext -a -t bin_t -s system_u $(realpath /usr/lib)'/portmaster/portmaster-core' || :
restorecon -R /usr/lib/portmaster/portmaster-core 2>/dev/null >&2 || :
fi
# Migration from v1
OLD_INSTALLATION_DIR="/opt/safing/portmaster"
MIGRATED_FILE_FLAG="$OLD_INSTALLATION_DIR/migrated.txt"
if [ -d "$OLD_INSTALLATION_DIR" ]; then
if [ ! -e "$MIGRATED_FILE_FLAG" ]; then
echo "Starting migration form v1"
# Becoause the service file need to change path, first the links to the old service needs to be removed.
systemctl stop portmaster.service systemctl stop portmaster.service
systemctl disable portmaster.service systemctl disable portmaster.service
#
# Migration from v1
#
OLD_INSTALLATION_DIR="/opt/safing/portmaster"
MIGRATED_FILE_FLAG="$OLD_INSTALLATION_DIR/migrated.txt"
if [ -d "$OLD_INSTALLATION_DIR" ]; then
if [ ! -e "$MIGRATED_FILE_FLAG" ]; then
echo "[ ] Starting migration form v1 ..."
# Because the service file need to change path, first the links to the old service needs to be removed.
echo "[ ] V1 migration: Removing old service"
rm /etc/systemd/system/portmaster.service # new V2 service registered at "/usr/lib/systemd/system/portmaster.service"
# Migrate config # Migrate config
echo "[ ] V1 migration: Copying V1 configuration"
cp -r $OLD_INSTALLATION_DIR/databases /var/lib/portmaster cp -r $OLD_INSTALLATION_DIR/databases /var/lib/portmaster
cp -r $OLD_INSTALLATION_DIR/config.json /var/lib/portmaster/config.json cp -r $OLD_INSTALLATION_DIR/config.json /var/lib/portmaster/config.json
# Remove shortcut # Remove shortcut
echo "[ ] V1 migration: Removing V1 shortcuts"
rm /etc/xdg/autostart/portmaster_notifier.desktop rm /etc/xdg/autostart/portmaster_notifier.desktop
rm /usr/share/applications/portmaster_notifier.desktop rm /usr/share/applications/portmaster_notifier.desktop
# Remove V1 files (except configuration)
# (keeping V1 configuration for a smooth downgrade, if needed)
echo "[ ] V1 migration: Removing V1 files"
rm -fr $OLD_INSTALLATION_DIR/exec
rm -fr $OLD_INSTALLATION_DIR/logs
rm -fr $OLD_INSTALLATION_DIR/updates
rm -fr $OLD_INSTALLATION_DIR/databases/cache
rm -fr $OLD_INSTALLATION_DIR/databases/icons
rm -fr $OLD_INSTALLATION_DIR/databases/history.db
for file in $OLD_INSTALLATION_DIR/*; do
if [ -f "$file" ] && [ "$(basename "$file")" != "config.json" ]; then
rm "$file"
fi
done
touch $MIGRATED_FILE_FLAG touch $MIGRATED_FILE_FLAG
echo "Migration complete" echo "[ ] Migration complete"
fi fi
fi fi
#
# Fix selinux permissions for portmaster-core if we have semanage available.
#
if command -V semanage >/dev/null 2>&1; then
echo "[ ] Fixing SELinux permissions"
semanage fcontext -a -t bin_t -s system_u $(realpath /usr/lib)'/portmaster/portmaster-core' || :
restorecon -R /usr/lib/portmaster/portmaster-core 2>/dev/null >&2 || :
fi
echo "[ ] Initializing binary files"
mv /usr/bin/portmaster /usr/lib/portmaster/portmaster mv /usr/bin/portmaster /usr/lib/portmaster/portmaster
ln -s /usr/lib/portmaster/portmaster /usr/bin/portmaster ln -s /usr/lib/portmaster/portmaster /usr/bin/portmaster
chmod +x /usr/lib/portmaster/portmaster-core
echo "[ ] Enabling service"
systemctl daemon-reload systemctl daemon-reload
systemctl enable portmaster.service systemctl enable portmaster.service
echo "Please reboot your system" echo "[ ] Done. Please reboot your system"

View file

@ -1,10 +1,35 @@
#!/bin/bash #!/bin/bash
echo "[ ] Post-Remove script [arg1='$1' arg2='$2']"
# DEB argument on upgrade - 'upgrade'; RPM - '1'
if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then
echo "[ ] Post-Remove script: This is an upgrade."
exit 0
fi
# #
# Remove selinux permissions for portmaster-core if we have semanage # Remove selinux permissions for portmaster-core if we have semanage available.
# available.
# #
if command -V semanage >/dev/null 2>&1; then if command -V semanage >/dev/null 2>&1; then
echo "[ ] Removing SELinux permissions"
semanage fcontext --delete $(realpath /usr/lib)'/portmaster/portmaster-core' || : semanage fcontext --delete $(realpath /usr/lib)'/portmaster/portmaster-core' || :
restorecon -R /usr/lib/portmaster/portmaster-core 2>/dev/null >&2 || : restorecon -R /usr/lib/portmaster/portmaster-core 2>/dev/null >&2 || :
fi fi
echo "[ ] Stopping and disabling service"
systemctl stop portmaster.service
systemctl disable portmaster.service
echo "[ ] Removing files"
# Remove binaries folder
sudo rm -fr /usr/lib/portmaster
# Remove data folder
sudo rm -fr /var/lib/portmaster
# remove V1 migration flag (if exists)
MIGRATED_FILE_FLAG="/opt/safing/portmaster/migrated.txt"
if [ -e "$MIGRATED_FILE_FLAG" ]; then
echo "[ ] Removing V1 migration flag"
rm "$MIGRATED_FILE_FLAG"
fi

47
packaging/linux/readme.md Normal file
View file

@ -0,0 +1,47 @@
# Installation scripts order
Execution order of installation scripts (`preInstallScript, preRemoveScript, postInstallScript, postRemoveScript`) is different for DEB and RPM packages.
**NOTE!** 'remove' scripts is using from old version!
## DEB scripts order
Useful link: https://wiki.debian.org/MaintainerScripts
```
DEB (apt) Install v2.2.2:
[*] Before install (2.2.2 : deb : install)
[*] After install (2.2.2 : deb : configure)
DEB (apt) Upgrade v1.1.1 -> v2.2.2:
[*] Before remove (1.1.1 : deb : upgrade)
[*] Before install (2.2.2 : deb : upgrade)
[*] After remove (1.1.1 : deb : upgrade)
[*] After install (2.2.2 : deb : configure)
DEB (apt) Remove:
[*] Before remove (1.1.1 : deb : remove)
[*] After remove (1.1.1 : deb : remove)
```
## RPM scripts order
Useful link: https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/
When scriptlets are called, they will be supplied with an argument.
This argument, accessed via $1 (for shell scripts) is the number of packages of this name
which will be left on the system when the action completes.
```
RPM (dnf) install:
[*] Before install (2.2.2 : rpm : 1)
[*] After install (2.2.2 : rpm : 1)
RPM (dnf) upgrade:
[*] Before install (2.2.2 : rpm : 2)
[*] After install (2.2.2 : rpm : 2)
[*] Before remove (1.1.1 : rpm : 1)
[*] After remove (1.1.1 : rpm : 1)
RPM (dnf) remove:
[*] Before remove (2.2.2 : rpm : 0)
[*] After remove (2.2.2 : rpm : 0)
```