Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    custom_php_pre_deinstall_command, how to prevent package removal?

    Scheduled Pinned Locked Moved Development
    7 Posts 2 Posters 1.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cmcdonaldC
      cmcdonald Netgate Developer
      last edited by

      I know it's possible to run an arbitrary php function via custom_php_pre_deinstall_command

      Is it possible to actually prevent package removal by causing the deinstall to fail?

      Need help fast? https://www.netgate.com/support

      1 Reply Last reply Reply Quote 0
      • bmeeksB
        bmeeks
        last edited by

        I don't think so. But why would you want to do that anyway? Are you trying to have your package behave like some kind of malware ... ๐Ÿค”, and refuse to be removed even if the user wants it gone?

        cmcdonaldC 1 Reply Last reply Reply Quote 0
        • cmcdonaldC
          cmcdonald Netgate Developer @bmeeks
          last edited by cmcdonald

          @bmeeks I need to perform checks , otherwise removing the package can break things. I need to alert the user and block the removal...only if certain checks pass can the deinstall proceed.

          You'll find out soon enough the rationale behind this ๐Ÿ˜‰

          Need help fast? https://www.netgate.com/support

          bmeeksB 1 Reply Last reply Reply Quote 0
          • bmeeksB
            bmeeks @cmcdonald
            last edited by

            @rcmcdonald91 said in custom_php_pre_deinstall_command, how to prevent package removal?:

            @bmeeks I need to perform checks , otherwise removing the package can break things. I need to alert the user and block the removal...only if certain checks pass can the deinstall proceed.

            You'll find out soon enough the rationale behind this ๐Ÿ˜‰

            I don't think you can do that because the pfSense core code is going to call the pkg utility to remove your package when the user kicks that process off. During the removal, the core code calls the de-install hook you mentioned to give you chance to clean up temp directories and files, but I think no matter what you do at that point, the pkg utility is going to remove all of the PHP, binary and other pieces of your package specified in the package manifest.

            cmcdonaldC 1 Reply Last reply Reply Quote 0
            • cmcdonaldC
              cmcdonald Netgate Developer @bmeeks
              last edited by cmcdonald

              @bmeeks One solution that I have is to run pkg lock in my resync routine that will keep the package locked until a condition to unlock is satisfied. Only issue with this is during installation, the custom_php_resync_command is actually executed in a blocking state while pkg is still running, so any attempt at running pkg lock during install is messy.

              Is there any internal plumbing available in pfSense that I could use to check if resync command was executed during package install and otherwise?

              Because the package that I'm working on creates pseudointerfaces that could be assigned to pfSense interfaces, accidental removal of the package can put the firewall into a non-bootable state due to interface mismatch / reassignment issues.

              Need help fast? https://www.netgate.com/support

              1 Reply Last reply Reply Quote 0
              • bmeeksB
                bmeeks
                last edited by

                You would need to follow all the logic within the pfSense PHP files to see the course of events for package install, removal and sync. You can find them in /usr/local/www/. There are five of them, all beginning with pkg. They will, in turn, include a file from /etc/inc with additional subroutines in it.

                cmcdonaldC 1 Reply Last reply Reply Quote 1
                • cmcdonaldC
                  cmcdonald Netgate Developer @bmeeks
                  last edited by

                  Yea I'm not seeing any way to run code after pkg has released its lock on the database. Will keep thinking on it. Of course I can lock the package manually at some point later when pkg isn't also running an install, which might work.

                  Need help fast? https://www.netgate.com/support

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.