Creating a Debian package that does not remove directories after it's purged












2















I'm trying to create a Debian package that doesn't delete an empty directory after it's purged. Specifically, I'm creating my own package containing some CA certificates I trust.



I'm following Debian's suggested method of installing the certificates to /usr/local/share/ca-certificates. The problem I'm running in to is that the ca-certificates package creates /usr/local/share/ca-certificates when it's installed and I'd like that directory to stick around when my package is purged.



My goal is to install my trust chain into /usr/local/share/ca-certificates/mychain but when my Debian package is removed I want dpkg to not remove /usr/local/share/ca-certificates if it's empty since the ca-certificates package explicitly created that directory.



I searched around for a definitive answer but all I managed to find were long forum posts and e-mail threads.










share|improve this question



























    2















    I'm trying to create a Debian package that doesn't delete an empty directory after it's purged. Specifically, I'm creating my own package containing some CA certificates I trust.



    I'm following Debian's suggested method of installing the certificates to /usr/local/share/ca-certificates. The problem I'm running in to is that the ca-certificates package creates /usr/local/share/ca-certificates when it's installed and I'd like that directory to stick around when my package is purged.



    My goal is to install my trust chain into /usr/local/share/ca-certificates/mychain but when my Debian package is removed I want dpkg to not remove /usr/local/share/ca-certificates if it's empty since the ca-certificates package explicitly created that directory.



    I searched around for a definitive answer but all I managed to find were long forum posts and e-mail threads.










    share|improve this question

























      2












      2








      2








      I'm trying to create a Debian package that doesn't delete an empty directory after it's purged. Specifically, I'm creating my own package containing some CA certificates I trust.



      I'm following Debian's suggested method of installing the certificates to /usr/local/share/ca-certificates. The problem I'm running in to is that the ca-certificates package creates /usr/local/share/ca-certificates when it's installed and I'd like that directory to stick around when my package is purged.



      My goal is to install my trust chain into /usr/local/share/ca-certificates/mychain but when my Debian package is removed I want dpkg to not remove /usr/local/share/ca-certificates if it's empty since the ca-certificates package explicitly created that directory.



      I searched around for a definitive answer but all I managed to find were long forum posts and e-mail threads.










      share|improve this question














      I'm trying to create a Debian package that doesn't delete an empty directory after it's purged. Specifically, I'm creating my own package containing some CA certificates I trust.



      I'm following Debian's suggested method of installing the certificates to /usr/local/share/ca-certificates. The problem I'm running in to is that the ca-certificates package creates /usr/local/share/ca-certificates when it's installed and I'd like that directory to stick around when my package is purged.



      My goal is to install my trust chain into /usr/local/share/ca-certificates/mychain but when my Debian package is removed I want dpkg to not remove /usr/local/share/ca-certificates if it's empty since the ca-certificates package explicitly created that directory.



      I searched around for a definitive answer but all I managed to find were long forum posts and e-mail threads.







      linux debian packaging dpkg






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 7 '13 at 20:26









      livingstaccatolivingstaccato

      705517




      705517






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Add postrm script:



          #!/bin/sh

          set -e

          case "$1" in
          purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
          # Recreate the /usr/local/share/ca-certificates directory, since we are
          # ignoring Debian Policy by intentionally installing here. Removal of
          # ca-certificates-local removes this directory if empty.
          if [ ! -e /usr/local/share/ca-certificates ]; then
          if mkdir /usr/local/share/ca-certificates 2>/dev/null; then
          chown root:staff /usr/local/share/ca-certificates
          chmod 2775 /usr/local/share/ca-certificates
          fi
          fi
          ;;

          *)
          echo "postrm called with unknown argument `$1'" >&2
          exit 1
          ;;
          esac

          #DEBHELPER#

          exit 0


          This code is from ca-certificates-local:




          This is an example stub source package that includes a dummy CA
          certificate in the local/ directory. Remove the dummy certificate, copy
          your trusted local root CA (in PEM format with the filename ending in
          ".crt") to the local/ directory, edit files in the debian/ directory as
          desired, and build your custom package.




          See README, Steps to build your custom local root CA package from this example



          So, the quick way to create and install such packages:



          git clone git://anonscm.debian.org/collab-maint/ca-certificates.git ~/ca-certificates
          cd ~/ca-certificates/examples/ca-certificates-local/
          rm local/Local_Root_CA.crt
          cp <path-to-your-cert> local/
          # edit debian/control: change package-name, description, etc
          # install build dependencies: http://unix.stackexchange.com/questions/177505/how-to-install-parse-build-dependencies-from-debian-control/211319#211319
          dpkg-buildpackage
          dpkg -i ../<package-name-version>.deb





          share|improve this answer

































            1














            Install to a different local path and write a postinst script to create the directory in /usr/local and copy the files there.



            As you can imagine, this probably violates both the letter and the spirit of the Debian policy. But it's your network, your rules, your users (and their easily discoverable workarounds).



            For better usability, you could mark these files as conffiles so that at least they will be removed if you purge the package, but stay if you merely uninstall it.



            Bottom line, files dpkg doesn't know about, it cannot remove.






            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "106"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f64099%2fcreating-a-debian-package-that-does-not-remove-directories-after-its-purged%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Add postrm script:



              #!/bin/sh

              set -e

              case "$1" in
              purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
              # Recreate the /usr/local/share/ca-certificates directory, since we are
              # ignoring Debian Policy by intentionally installing here. Removal of
              # ca-certificates-local removes this directory if empty.
              if [ ! -e /usr/local/share/ca-certificates ]; then
              if mkdir /usr/local/share/ca-certificates 2>/dev/null; then
              chown root:staff /usr/local/share/ca-certificates
              chmod 2775 /usr/local/share/ca-certificates
              fi
              fi
              ;;

              *)
              echo "postrm called with unknown argument `$1'" >&2
              exit 1
              ;;
              esac

              #DEBHELPER#

              exit 0


              This code is from ca-certificates-local:




              This is an example stub source package that includes a dummy CA
              certificate in the local/ directory. Remove the dummy certificate, copy
              your trusted local root CA (in PEM format with the filename ending in
              ".crt") to the local/ directory, edit files in the debian/ directory as
              desired, and build your custom package.




              See README, Steps to build your custom local root CA package from this example



              So, the quick way to create and install such packages:



              git clone git://anonscm.debian.org/collab-maint/ca-certificates.git ~/ca-certificates
              cd ~/ca-certificates/examples/ca-certificates-local/
              rm local/Local_Root_CA.crt
              cp <path-to-your-cert> local/
              # edit debian/control: change package-name, description, etc
              # install build dependencies: http://unix.stackexchange.com/questions/177505/how-to-install-parse-build-dependencies-from-debian-control/211319#211319
              dpkg-buildpackage
              dpkg -i ../<package-name-version>.deb





              share|improve this answer






























                1














                Add postrm script:



                #!/bin/sh

                set -e

                case "$1" in
                purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
                # Recreate the /usr/local/share/ca-certificates directory, since we are
                # ignoring Debian Policy by intentionally installing here. Removal of
                # ca-certificates-local removes this directory if empty.
                if [ ! -e /usr/local/share/ca-certificates ]; then
                if mkdir /usr/local/share/ca-certificates 2>/dev/null; then
                chown root:staff /usr/local/share/ca-certificates
                chmod 2775 /usr/local/share/ca-certificates
                fi
                fi
                ;;

                *)
                echo "postrm called with unknown argument `$1'" >&2
                exit 1
                ;;
                esac

                #DEBHELPER#

                exit 0


                This code is from ca-certificates-local:




                This is an example stub source package that includes a dummy CA
                certificate in the local/ directory. Remove the dummy certificate, copy
                your trusted local root CA (in PEM format with the filename ending in
                ".crt") to the local/ directory, edit files in the debian/ directory as
                desired, and build your custom package.




                See README, Steps to build your custom local root CA package from this example



                So, the quick way to create and install such packages:



                git clone git://anonscm.debian.org/collab-maint/ca-certificates.git ~/ca-certificates
                cd ~/ca-certificates/examples/ca-certificates-local/
                rm local/Local_Root_CA.crt
                cp <path-to-your-cert> local/
                # edit debian/control: change package-name, description, etc
                # install build dependencies: http://unix.stackexchange.com/questions/177505/how-to-install-parse-build-dependencies-from-debian-control/211319#211319
                dpkg-buildpackage
                dpkg -i ../<package-name-version>.deb





                share|improve this answer




























                  1












                  1








                  1







                  Add postrm script:



                  #!/bin/sh

                  set -e

                  case "$1" in
                  purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
                  # Recreate the /usr/local/share/ca-certificates directory, since we are
                  # ignoring Debian Policy by intentionally installing here. Removal of
                  # ca-certificates-local removes this directory if empty.
                  if [ ! -e /usr/local/share/ca-certificates ]; then
                  if mkdir /usr/local/share/ca-certificates 2>/dev/null; then
                  chown root:staff /usr/local/share/ca-certificates
                  chmod 2775 /usr/local/share/ca-certificates
                  fi
                  fi
                  ;;

                  *)
                  echo "postrm called with unknown argument `$1'" >&2
                  exit 1
                  ;;
                  esac

                  #DEBHELPER#

                  exit 0


                  This code is from ca-certificates-local:




                  This is an example stub source package that includes a dummy CA
                  certificate in the local/ directory. Remove the dummy certificate, copy
                  your trusted local root CA (in PEM format with the filename ending in
                  ".crt") to the local/ directory, edit files in the debian/ directory as
                  desired, and build your custom package.




                  See README, Steps to build your custom local root CA package from this example



                  So, the quick way to create and install such packages:



                  git clone git://anonscm.debian.org/collab-maint/ca-certificates.git ~/ca-certificates
                  cd ~/ca-certificates/examples/ca-certificates-local/
                  rm local/Local_Root_CA.crt
                  cp <path-to-your-cert> local/
                  # edit debian/control: change package-name, description, etc
                  # install build dependencies: http://unix.stackexchange.com/questions/177505/how-to-install-parse-build-dependencies-from-debian-control/211319#211319
                  dpkg-buildpackage
                  dpkg -i ../<package-name-version>.deb





                  share|improve this answer















                  Add postrm script:



                  #!/bin/sh

                  set -e

                  case "$1" in
                  purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
                  # Recreate the /usr/local/share/ca-certificates directory, since we are
                  # ignoring Debian Policy by intentionally installing here. Removal of
                  # ca-certificates-local removes this directory if empty.
                  if [ ! -e /usr/local/share/ca-certificates ]; then
                  if mkdir /usr/local/share/ca-certificates 2>/dev/null; then
                  chown root:staff /usr/local/share/ca-certificates
                  chmod 2775 /usr/local/share/ca-certificates
                  fi
                  fi
                  ;;

                  *)
                  echo "postrm called with unknown argument `$1'" >&2
                  exit 1
                  ;;
                  esac

                  #DEBHELPER#

                  exit 0


                  This code is from ca-certificates-local:




                  This is an example stub source package that includes a dummy CA
                  certificate in the local/ directory. Remove the dummy certificate, copy
                  your trusted local root CA (in PEM format with the filename ending in
                  ".crt") to the local/ directory, edit files in the debian/ directory as
                  desired, and build your custom package.




                  See README, Steps to build your custom local root CA package from this example



                  So, the quick way to create and install such packages:



                  git clone git://anonscm.debian.org/collab-maint/ca-certificates.git ~/ca-certificates
                  cd ~/ca-certificates/examples/ca-certificates-local/
                  rm local/Local_Root_CA.crt
                  cp <path-to-your-cert> local/
                  # edit debian/control: change package-name, description, etc
                  # install build dependencies: http://unix.stackexchange.com/questions/177505/how-to-install-parse-build-dependencies-from-debian-control/211319#211319
                  dpkg-buildpackage
                  dpkg -i ../<package-name-version>.deb






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 25 at 12:11









                  Stephen Kitt

                  170k24382458




                  170k24382458










                  answered Jul 11 '15 at 17:15









                  Evgeny VereshchaginEvgeny Vereshchagin

                  3,28242236




                  3,28242236

























                      1














                      Install to a different local path and write a postinst script to create the directory in /usr/local and copy the files there.



                      As you can imagine, this probably violates both the letter and the spirit of the Debian policy. But it's your network, your rules, your users (and their easily discoverable workarounds).



                      For better usability, you could mark these files as conffiles so that at least they will be removed if you purge the package, but stay if you merely uninstall it.



                      Bottom line, files dpkg doesn't know about, it cannot remove.






                      share|improve this answer






























                        1














                        Install to a different local path and write a postinst script to create the directory in /usr/local and copy the files there.



                        As you can imagine, this probably violates both the letter and the spirit of the Debian policy. But it's your network, your rules, your users (and their easily discoverable workarounds).



                        For better usability, you could mark these files as conffiles so that at least they will be removed if you purge the package, but stay if you merely uninstall it.



                        Bottom line, files dpkg doesn't know about, it cannot remove.






                        share|improve this answer




























                          1












                          1








                          1







                          Install to a different local path and write a postinst script to create the directory in /usr/local and copy the files there.



                          As you can imagine, this probably violates both the letter and the spirit of the Debian policy. But it's your network, your rules, your users (and their easily discoverable workarounds).



                          For better usability, you could mark these files as conffiles so that at least they will be removed if you purge the package, but stay if you merely uninstall it.



                          Bottom line, files dpkg doesn't know about, it cannot remove.






                          share|improve this answer















                          Install to a different local path and write a postinst script to create the directory in /usr/local and copy the files there.



                          As you can imagine, this probably violates both the letter and the spirit of the Debian policy. But it's your network, your rules, your users (and their easily discoverable workarounds).



                          For better usability, you could mark these files as conffiles so that at least they will be removed if you purge the package, but stay if you merely uninstall it.



                          Bottom line, files dpkg doesn't know about, it cannot remove.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Feb 7 '13 at 21:34

























                          answered Feb 7 '13 at 21:29









                          tripleeetripleee

                          4,97411728




                          4,97411728






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Unix & Linux Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f64099%2fcreating-a-debian-package-that-does-not-remove-directories-after-its-purged%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to make a Squid Proxy server?

                              第一次世界大戦

                              Touch on Surface Book