I have a few development jails dedicated to my work on FreshPorts. It’s been a hobby of mine since the late 1990s. The code I create gets packaged, ready to deploy onto the test, stage, and production hosts.
What I absolutely do not want to happen, and it’s happened recently, is for those packages to be installed on the development environments. Why? It installs to the same location as the working copy of my code.
You might think: well, just don’t install those packages.
Yes, that’s what I have been doing. Until an automated process did what I said, and not what I wanted.
All the code is still there. Nothing was lost, but to reverse the process involves work. Here is an example:
[dan@dev-ingress01:/usr/local/lib/perl5/site_perl/FreshPorts] $ ls -l total 1046 -rw-r--r-- 1 dan dan 376 May 6 2018 Makefile.PL -rw-r--r-- 1 dan dan 1254 May 6 2018 README.txt -rw-r--r-- 1 root wheel 860 May 6 2018 announcements.pm -rw-r--r-- 1 dan dan 860 Jun 10 2019 announcements.pm.pkgsave -rw-r--r-- 1 root wheel 6446 Jan 3 23:14 branches.pm -rw-r--r-- 1 dan dan 4467 Jun 10 2019 branches.pm.pkgsave -rw-r--r-- 1 root wheel 6460 May 6 2018 cache.pm -rw-r--r-- 1 dan dan 6460 Jun 10 2019 cache.pm.pkgsave -rw-r--r-- 1 root wheel 2824 May 6 2018 caching.pm -rw-r--r-- 1 dan dan 2824 Jun 10 2019 caching.pm.pkgsave -rw-r--r-- 1 root wheel 8113 Aug 1 2020 category.pm -rw-r--r-- 1 dan dan 7842 Jun 10 2019 category.pm.pkgsave -rw-r--r-- 1 root wheel 3652 Jul 25 2020 commit_log.pm -rw-r--r-- 1 dan dan 2827 Jun 10 2019 commit_log.pm.pkgsave -rw-r--r-- 1 root wheel 737 May 6 2018 commit_log_branches.pm -rw-r--r-- 1 dan dan 737 Jun 10 2019 commit_log_branches.pm.pkgsave -rw-r--r-- 1 root wheel 1748 May 6 2018 commit_log_element.pm -rw-r--r-- 1 dan dan 1748 Jun 10 2019 commit_log_element.pm.pkgsave -rw-r--r-- 1 root wheel 893 May 6 2018 commit_log_port_elements.pm -rw-r--r-- 1 dan dan 893 Jun 10 2019 commit_log_port_elements.pm.pkgsave -rw-r--r-- 1 root wheel 2217 Sep 5 2018 commit_log_ports.pm -rw-r--r-- 1 dan dan 2217 Jun 10 2019 commit_log_ports.pm.pkgsave -rw-r--r-- 1 root wheel 1344 May 6 2018 commit_log_ports_elements.pm -rw-r--r-- 1 dan dan 1344 Jun 10 2019 commit_log_ports_elements.pm.pkgsave ...
I wrote a small script to diff the results:
[dan@dev-ingress01:~/modules] $ cat ~/bin/pkgsave-diff #!/bin/sh cd ~/modules FILES=$(ls | grep -v pkgsave) for file in $FILES do if [ -f $file ] ; then echo -n $file if [ -f $file.pkgsave ] ; then diff -ruN $file $file.pkgsave fi fi done[dan@dev-ingress01:~/modules] $
To get remove the package:
[dan@dev-ingress01:~/tmp/p5-freshports-modules-git] $ sudo pkg delete p5-freshports-modules-git Checking integrity... done (0 conflicting) Deinstallation has been requested for the following 1 packages (of 0 packages in the universe): Installed packages to be REMOVED: p5-freshports-modules-git: 2.0.1 Number of packages to be removed: 1 Proceed with deinstalling packages? [y/N]: y [dev-ingress01.int.unixathome.org] [1/1] Deinstalling p5-freshports-modules-git-2.0.1... [dev-ingress01.int.unixathome.org] [1/1] Deleting files for p5-freshports-modules-git-2.0.1: 100% ==> You should manually remove the "freshports" user. ==> You should manually remove the "ingress" user. ==> You should manually remove the "freshports" group ==> You should manually remove the "ingress" group You may need to manually remove /usr/local/etc/freshports/config.pm if it is no longer needed.
And then pull back in my code, and remove the .pkgsave files.
[dan@dev-ingress01:~/modules] $ svn up Updating '.': Restored 'port.pm' Restored 'branches.pm' Restored 'package_flavors.pm' Restored 'port_dependencies.pm' Restored 'commit_log_branches.pm' Restored 'special_processing_files.pm' Restored 'vuxml_names.pm' Restored 'commit_log_element.pm' Restored 'database.pm' Restored 'db_utils.pm' Restored 'vuxml_packages.pm' Restored 'utilities.pm' ... Restored 'announcements.pm' Restored 'category.pm' Restored 'observer_commits.pm' At revision 5610. [dan@dev-ingress01:~/modules] $ rm *.pkgsave
Creating the fake package
bapt gave me the first idea: fake package. My first thoughts were of a whole FreeBSD package. It was manu who suggested a +MANIFEST file.
Here is how I created it. From an existing package file, I pulled out the contents.
[dan@dev-ingress01:~/modules] $ cd ~/tmp [dan@dev-ingress01:~/tmp] $ mkdir p5-freshports-modules-git [dan@dev-ingress01:~/tmp] $ cd p5-freshports-modules-git [dan@dev-ingress01:~/tmp/p5-freshports-modules-git] $ tar -xzf /var/cache/pkg/p5-freshports-modules-git-2.0.1.txz tar: Removing leading '/' from member names [dan@dev-ingress01:~/tmp/p5-freshports-modules-git] $ ls -l total 2 -rw-r--r-- 1 dan dan 1715 Jan 1 1970 +COMPACT_MANIFEST -rw-r--r-- 1 dan dan 12261 Jan 1 1970 +MANIFEST drwxr-xr-x 3 dan dan 3 Feb 16 14:31 usr
I copied & pasted the contents of the +MANIFEST and used an online JSON pretty print tool to get a reasonable format.
I placed the first few lines, all down to the deps”:{“ line, into a new file.
[dan@dev-ingress01:~] $ cat +MANIFEST-p5-freshports-modules-git { "name": "p5-freshports-modules-git", "origin": "dvl/p5-freshports-modules-git", "version": "9999..0.1", "comment": "For use by Dan Langille only", "maintainer": "dan@langille.org", "www": "http://www.FreshPorts.org/", "abi": "FreeBSD:12:amd64", "arch": "freebsd:12:x86:64", "prefix": "/usr/local", "flatsize": 368322, "licenselogic": "single", "desc": "A quick and easy way to load multiple ports with \na single command.\n\nWWW: http://www.FreshPorts.org/", } [dan@dev-ingress01:~] $
This is all you need. Perhaps some fields are optional, but I’m not optimizing this.
Notice that I have bumped version up high, so that pkg upgrade will never over write it.
To register this +MANIFEST, this command is used:
$ sudo pkg register -M ./+MANIFEST-p5-freshports-modules-git [dev-ingress01.int.unixathome.org] Installing p5-freshports-modules-git-9999..0.1...
For additional protection, the package can be locked.
$ sudo pkg lock p5-freshports-modules-git p5-freshports-modules-git-9999..0.1: lock this package? [y/N]: y Locking p5-freshports-modules-git-9999..0.1
The lock protects the package from “reinstallation, modification or deletion”