# Portmaster - understanding it better



## PacketMan (Nov 4, 2015)

I am reading the man page for portmaster a few times trying to get a through understanding of it. I realize 'it' will come to me over time. But in the meantime, is there another document I can read that will be more quicker understand what all the flags (and their combinations) really mean, and thus depending on what I am trying to do will determine what options I execute.

The forum has lots of posts where people say I am doing this and then others chime in and say should be doing it differently.  So I want to understand portmaster intimately, and while I think the man page is a great document, I want to read other stuff.

Any recommendations?

Thanks again,
Packet Man


----------



## protocelt (Nov 4, 2015)

Hi.

I can't say as I'm aware of any other actual documentation other than the man page for portmaster(8). You could read through the code as portmaster(8) is just a rather large sh(1) script. Instead of asking a general question though, it might be easier to ask more specific questions in the context of what your trying to accomplish as you go along and learn.

Regarding seeing conflicting information, as with all UNIX/UNIX-like operating systems, there are many times multiple ways to accomplish the same goal, so the posts your reading are not always conflicting but different paths to the same destination depending on the users goals and experience. If you get an answer to a question you don't understand or is confusing on the forums don't be afraid to say your confused or it doesn't make sense to you. Many times an experienced user will chime in and correct an incorrect answer and/or explain things in more detail.


----------



## rabfulton (Nov 4, 2015)

Is there plans for ports-mgmt/portmaster to support the new `pkg` system?


----------



## PacketMan (Nov 4, 2015)

Well why would I use the -a flag? Or why would I not use the -a flag?  Why would I use -a with -f if -f is going to do a force rebuild anyways?  Why would I use --update-if-newer; doesn't -a do the same? Doesn't -f -R do the same? Why would I want to use --always-fetch? Why would I -f (always rebuild) even if the port is already up to date? Why can't I use --update-if-newer on a single portmaster <port> command, even though its gonna call all the required dependencies into check.

I realize these questions are not really related to portmaster, but then again they are. If this is the recommended tool to get the job done, what better tool to provide more documentation around.

I have no issue asking question, you folks should already know that!  But I'm a bit older school too; stop, size up the situation, do some reading/learning, learn by fire, ask when necessary.

Even if I had an examples 'cookbook' to supplement the examples already provided.


----------



## kpa (Nov 4, 2015)

rabfulton said:


> Is there plans for portmaster to support the new `pkg` system?



It already does in a way that the packages created (also what gets installed when building ports) by it are pkg packages and the support for the older packages has been dropped. What is really missing is the support for creating a local package repository using ports-mgmt/portmaster so that you could use pkg-upgrade(8) with that local repository.


----------



## sidetone (Nov 4, 2015)

I'm sure you've looked at /usr/local/share/portmaster.rc.sample. My reasons for using less packages, is that sometimes it's been built differently than how it's done in ports, causing inconsistency then broken features when running the built program. Using packages for build-only-dependencies usually doesn't harm builds.

Maybe it depends if you want the newest port, or if you like fresh installations of the updated code. Minor dependencies change often, and rebuilds allow the programs to be built with those changed dependencies. Perhaps it depends on your method of keeping builds functioning the way you like.


----------



## wblock@ (Nov 4, 2015)

PacketMan said:


> Well why would I use the -a flag? Or why would I not use the -a flag?


Use -a when there are no further special instructions in /usr/ports/UPDATING.  And only use it after checking that file.  I don't know what --update-if-newer does, I never use it.

This is my attempt to document a "best practices" type of upgrading ports: Upgrading FreeBSD Ports.


----------



## PacketMan (Nov 4, 2015)

wblock@ said:


> Use -a when there are no further special instructions in /usr/ports/UPDATING.  And only use it after checking that file.  I don't know what --update-if-newer does, I never use it.
> 
> This is my attempt to document a "best practices" type of upgrading ports: Upgrading FreeBSD Ports.



Okay, but section 23.2.3.2 doesn't say that, and IMHO it says after a major upgrade to do a portmaster -af.  Thanks for that link wblock I'll look into it soon.  Let me ask this question, lets say `portmaster -L --index-only| egrep '(ew|ort) version|total install'` tells me a whole bunch of ports need updating (but not all obviously), what should I do? And does what I should so depend on whether I did a minor or major OS release upgrade?


----------



## protocelt (Nov 4, 2015)

Pretty much. Unless a portmaster(8) flag is specified in /usr/ports/UPDATING, don't use any flags besides the -a flag when upgrading ports. The exception is the -f flag that can be used with the -a flag to rebuild every installed port which should be done after a major FreeBSD upgrade. wblock@ has a HOWTO on this procedure in Thread 51210. If you want to experiment, you can add the -n flag to the command for a dry run that will run through the command steps, but not change anything.


----------



## wblock@ (Nov 4, 2015)

PacketMan said:


> Okay, but section 23.2.3.2 doesn't say that, and IMHO it says after a major upgrade to do a portmaster -af.



-af is not the same as -a.  The -f means "rebuild the port even if it does not need to be rebuilt".  This is a short way to rebuild all ports, although it takes more time than the correct way.



> Thanks for that link wblock I'll look into it soon.  Let me ask this question, lets say `portmaster -L --index-only| egrep '(ew|ort) version|total install'` tells me a whole bunch of ports need updating (but not all obviously), what should I do?



Read that article first.  Then, as always (yes, always), check /usr/ports/UPDATING for any new steps that have been added since the last time you upgraded ports.  If they apply to your system, either because they are specific for a particular port you have installed or because they must be run on all systems, do them.  After completing those steps, check for ports that still need to be updated.  It is safe to use -a to upgrade those.



> And does what I should so depend on whether I did a minor or major OS release upgrade?



As far as ports are concerned, a minor version upgrade does not matter at all.  After a major version upgrade, all ports must be rebuilt.


----------



## PacketMan (Nov 4, 2015)

wblock@ said:


> -af is not the same as -a.  The -f means "rebuild the port even if it does not need to be rebuilt".



Right, I knew that. I guess what I was trying to say is I am reading that what you are saying is different than what the handbook says.  Thus an example I why I would like to learn intimately what the portmaster options, and their combinations do.


----------



## wblock@ (Nov 4, 2015)

The Handbook is only saying to use -af after a major version upgrade, definitely not routinely.

I have a script I use to update the ports tree and provide some convenient features.  Here is a new article about that: Update: Automating Ports Tree Updates.


----------



## PacketMan (Nov 5, 2015)

Righto thanks.  Let me ask about this scenario.    When a port is installed for the first time, or upgraded / forced reinstall a pkg is created and stored on the system right?  Now obviously after a major release update all ports should be reinstalled, even if there is no update available for at least some of the ports.  So, to save time, and simply be efficient, can I use portmaster options to (a) reuse previous pkg's for those ports that do not have updates and still complete 'force reinstall', and (b) download the new port code for those that do have updates?  The --packages, and --packages-build option comes to mind here.  If I can do this why would I not want to use the pkg code that was previously compiled from either a previous install, or previous update via portmaster.


----------



## wblock@ (Nov 5, 2015)

Packages that were built for the previous version of FreeBSD will not work anyway.  That is why things have to be rebuilt.  Or you can download packages that have been built for the newer version of FreeBSD.


----------



## PacketMan (Nov 7, 2015)

So when my force rebuild gets aborted due to an issue I fix the issue and them move on.  I was doing this locally on the box, but now am doing it remotely.  Normally I would copy/paste the whole restart list, but it looks like when I do it remotely the list is too large to paste the whole thing in. So I suppose I have two choices, paste in what it will take and then pick up the rest later and do that.

Or I simply restart the whole process using the -a -f and -R flags.  (I am also using -B -D -G --no-confirm).  Am I correct in thinking that `portmaster` will scan through the whole list again, notice that a bunch of ports have the install flag set and thus skip over them? That is what it mostly looks like, but I am not 100% sure that it doesn't re-do some ports already rebuilt.


----------



## wblock@ (Nov 7, 2015)

PacketMan said:


> So when my force rebuild gets aborted due to an issue I fix the issue and them move on. I was doing this locally on the box, but now am doing it remotely. Normally I would copy/paste the whole restart list, but it looks like when I do it remotely the list is too large to paste the whole thing in. So I suppose I have two choices, paste in what it will take and then pick up the rest later and do that.


That can cause problems, because the output is sorted by port name, but `portmaster` sorts and builds them in dependency order.

I'd suggest running it with something like script(1) so that when it fails, the list of ports remaining to be built can be copied from the log file.  If I were working on ports-mgmt/portmaster (and I'm not, sh is a terrible programming language), I'd have it save that output to a log file.  Maybe that is what -H does.


----------



## PacketMan (Nov 7, 2015)

Thanks wblock@.  What about my 2nd option?  Just restarting the whole process using the -a -f and -R flags? Am I correct in thinking that portmaster will scan through the whole list again, notice that a bunch of ports have the install flag set and thus skip over them?


----------



## wblock@ (Nov 8, 2015)

I would expect -af to force the rebuilding of all ports.


----------



## PacketMan (Nov 8, 2015)

So when I initially run `portmaster -a -f` I get asked if I want to clear previous install flags. So let's say I say yes the first time around, and lets say 40% of the rebuild is done when something goes wrong and I get an abort.  Assuming I have address the issue to cause the abort, can I use the -a -f -R to force rebuild only the remaining (60%) ports that have not already been rebuilt? Doesn't the -R cause portmaster to skip over the previous 40% of the ports because they have already been rebuilt, thus their install flag is set to yes?


----------



## protocelt (Nov 8, 2015)

Using the -a and -f flags will override the -R flag.


----------



## freethread (Nov 8, 2015)

wblock@ said:


> That can cause problems, because the output is sorted by port name, but `portmaster` sorts and builds them in dependency order.
> 
> I'd suggest running it with something like script(1) so that when it fails, the list of ports remaining to be built can be copied from the log file.  If I were working on ports-mgmt/portmaster (and I'm not, sh is a terrible programming language), I'd have it save that output to a log file. Maybe that is what -H does.



About the -H option. I use it regularly (not on command line, in the global options file /usr/local/etc/portmaster.rc, the option is HIDE_BUILD). The option tells portmaster to create the log file for each port in directory /tmp. The name of the log file has the form (here for ports-mgmt/pkg):

```
port_log-74463-pkg.oHy5fQ6A
```
where `74463` is the portmaster instance PID that execute the installation/upgrading and `pkg` the name of the package. The file will be deleted if no errors, otherwise you can view it for errors (and delete it).


----------



## PacketMan (Nov 8, 2015)

protocelt said:


> Using the -a and -f flags will override the -R flag.



Are ya sure?

Where in the man page do I read that?  I am referring to this:

"*-R* used with the *-r* or *-f* options to skip ports updated on a previous
run. When used with *-r* it will also prevent the rebuild of the par-
ent port if it, and all of its dependencies are up to date."


----------



## ANOKNUSA (Nov 8, 2015)

kpa said:


> What is really missing is the support for creating a local package repository using ports-mgmt/portmaster so that you could use pkg-upgrade(8) with that local repository.



That's what ports-mgmt/poudriere is for, though.

The most useful Portmaster feature I can think of that's currently broken is `--packages-build`, which fetches and installs build dependency packages rather than building their ports. Some ports depend on other, much larger ports to build, but not run. Building the latest version of GCC or Clang or LLVM often takes longer than building the port for which it is needed, and leaving build dependencies installed is hardly optimal since leaving them around prevents the use of `pkg autoremove` to remove totally unneeded packages. You could use pkg-set(8) to switch them to explicitly installed packages, but then you'd just have to rebuild them eventually anyway.

PacketMan: that's the use of the `-a` *and* `-f` flags, not *or*. `portmaster -af` installs updates while rebuilding any ports that either depend upon or are dependencies of the upgraded ports.


----------



## protocelt (Nov 8, 2015)

PacketMan said:


> Are ya sure?


Yes.


PacketMan said:


> Where in the man page do I read that?  I am referring to this:
> 
> "*-R* used with the *-r* or *-f* options to skip ports updated on a previous
> run. When used with *-r* it will also prevent the rebuild of the par-
> ent port if it, and all of its dependencies are up to date."


  Both the -a and -f flags together rebuild every installed port regardless of there being and update available or being a dependency of another port. If there is an update, the port is updated as well. If a port was just rebuilt from a previous portmaster(8) run, running `# portmaster -af` again will rebuild it anyway as that's what you've told portmaster(8) to do (force a rebuild of every single installed port).


----------



## PacketMan (Nov 9, 2015)

Righto protocelt, thanks again.

Two last questions, for now:

How can I use portmaster to find installed ports that are not needed, and deinstall/clean them.
How can I use portmaster to find the path to a port that is needed to install say for example library file?

Maybe portmaster is not the tool for this?  I know for #2 a lot of time the port will document the dependencies and include the path, but sometimes during an abort this is not so obvious. How do I easily find the path/port wihtout asking on this forum all the time? I tried using ports-mgmt/psearch but that did not work for me. Is there another thread on here I should be reading?

As for #1 I just want to do regular maintenance and prune out any ports, libraries, etc, that are not needed. I'm guessing the answer is there would be multiple commands, and there is another thread that covers that? Been reading the handbook, and one of my older published FreeBSD books, but thought I ask the friendly folks here.


----------



## SirDice (Nov 9, 2015)

PacketMan said:


> How can I use portmaster to find installed ports that are not needed, and deinstall/clean them.


Use pkg-autoremove(8).



> How can I use portmaster to find the path to a port that is needed to install say for example library file?



`pkg info -W /usr/local/bin/perl` for example. Finding it in a port is going to be tricky. Although ports have a pkg-plist not all of them have it in a file, some ports generate the list dynamically.

Keep in mind ports-mgmt/portmaster is a tool to build ports, once a port is installed it's a package and those are handled by pkg(8).


----------



## sidetone (Nov 9, 2015)

I use `portmaster -s` to trim unused packages. Adding the `-y` or `-t` argument, is supposed to make it answer yes without user intervention. The without prompting options work some of the time, it's either a bug that comes and goes, or a setting in /usr/local/etc/portmaster.rc has to be made.

For finding ports, there's also ports-mgmt/portsearch and ports-mgmt/portfind


----------



## kpa (Nov 9, 2015)

sidetone said:


> I use `portmaster -s` to trim unused packages.



There is very little gain in using portmaster(8) for that since it uses pkg(8) behind the scenes for the actual operation. I think it just calls `pkg autoremove` now.


----------



## PacketMan (Nov 22, 2015)

Allow me to ask this question.  First my understanding:  installing a port using make(1) causes a package to be built, with the options I specified. Compiling a port takes wayyyyyy longer.  When doing updates, often there will be ports that are current up to date and thus do not need to be rebuilt. So my question is: what portmaster(8) flag option allows the packages to remain on the system, and be reused?

How would/could the --packages, and --packages-build help me achieve this?


----------



## protocelt (Nov 22, 2015)

When using portmaster(8), you don't reuse packages. If a port has no update available, it will not be rebuilt unless a dependency of it has changed and the port has to be rebuilt against the updated dependency. The port has to be rebuilt in this case and you can't use current package as it's built against the old dependency.


----------

