# pkg upgrade



## balanga (May 30, 2021)

How does pkg-upgrade() know which pkgs need to be upgraded?


----------



## cmoerz (May 30, 2021)

It downloads current version numbers from remote repository and compares it to the version details that are stored on your machine. `pkg` basically uses a sqlite database at /var/db/pkg/local.sqlite for that purpose.
If you let us know what parts in particular you're interested in, I might be able to point out further details (i.e. version comparison, package meta data etc.).


----------



## balanga (May 30, 2021)

I'm basically interested in manually putting together my own local pkg repo, but am unclear as to whether pkgs with different ABI's need their own repositories. I guess some pkgs will work with different releases of FreeBSD and some won't. Sorry if this sounds hazy but I'm only just beginning to marvel at the depths of the pkg management system of FreeBSD and how everything works together.

Can you tell me what info packagesite.yaml provides?


----------



## jmos (May 30, 2021)

balanga said:


> I'm basically interested in manually putting together my own local pkg repo, but am unclear as to whether pkgs with different ABI's need their own repositories. I guess some pkgs will work with different releases of FreeBSD and some won't.


They may/can be used on different systems if the Makefile f.e. makes use of "NO_BUILD" or "NO_ARCH", but: The dependencies of ports can change on newer versions (or maintainers temper), so they will differ over the time; Expect problems if you're putting together old packages and newer build packages (even if the portversion doesn't differ) - you may ran into false dependencies, even if pkg says everything's fine. It's no good idea to carry old packages from outdated FreeBSD versions to newer installations. It may work, but mustn't, so: Use packages built for FreeBSD 12 for FreeBSD 12, and packages built for FreeBSD 13 for FreeBSD 13. But do not mix them. There's nothing in the package repositories which can evaluate this.
And: There's a reason why your pkg command complained your package repository. https://forums.freebsd.org/threads/pkg-repo.80322/#post-512594


balanga said:


> Can you tell me what info packagesite.yaml provides?


That file can be read. You're using Midnight Commander, so just enter your repositories packagesite.txz file, move to the (only) included file packagesite.yaml, and press [F3].


----------



## balanga (May 30, 2021)

jmos said:


> That file can be read. You're using Midnight Commander, so just enter your repositories packagesite.txz file, move to the (only) included file packagesite.yaml, and press [F3].



Thanks, I can view the file I just wondered where I could find a record layout for the lines.


----------



## jmos (May 30, 2021)

balanga said:


> Thanks, I can view the file I just wondered where I could find a record layout for the lines.




```
{"keyword1":"value","keyword2":"value", …}
{"keyword1":"value","keyword2":"value", …}
…
```

So your YAML file contains just a list with a simple associative array: Every node ("package") is in braces, and for every node there's a list of keywords (like "name", "version" etc.) and its value (like "firefox", "89.0_1,2", etc.). Which keywords it uses you can read; Note that a value can contain another, new array with other key/values (so in this case f.e. "deps" - the dependencies). So its nested (a "multidimensional, associative array").

It's no fun to build the package meta file by yourself; While it looks quite simple I'm sure you will have to invest some days to program your alternative "pkg repo" command - even if your already firm in handling multidimensional, associative arrays, writing export files (escapes / special chars), handling data structures etc. Anyway, (nearly) all you need to write that file you'll get by just using `pkg info` in (afair three) different ways (once for all packages, twice for every package).


----------



## cmoerz (May 30, 2021)

Those yaml files aren't actually yaml but JSON files. See also this thread for reference:








						Solved - parsing packagesite.yaml
					

I'm trying to parse packagesite.yaml for reasons and I'm looking for coding help please.  I keep running into encoding issues. I've tried:  latin-1 ascii utf-8 ISO-8859-1  So far, I am unable to parse all of the file.  My proof-of-concept script is:  #!/usr/local/bin/python  import yaml import...




					forums.freebsd.org
				




The content structure should be relatively self-explanatory if you use a parser for JSON, just like jmos pointed out. Some additional details may also be gleaned from pkg-repo():


> _packagesite.txz_ similarly contains    at least one file _packagesite.yaml_,
> which is a    YAML document listing selected metadata    for each of the    pack-
> ages in the repository.  This is the key file containing the working data
> used by pkg(8) and    includes the run-time dependencies for each package,
> ...


----------



## balanga (May 30, 2021)

cmoerz said:


> Those yaml files aren't actually yaml but JSON files.



I don't actually know what JSON files are although I hear the term all the time...

I think I have an aversion to the name because it reminds me of someone called JASON who diddled me out of a lot of money once.... but hey-ho...


----------



## Alain De Vos (May 30, 2021)

Json looks like this,

```
[
   {
      "Naam":"JSON",
      "Type":"Gegevensuitwisselingsformaat",
      "isProgrammeertaal":false,
      "Zie ook":[
         "XML",
         "ASN.1"
      ]
   },
   {
      "Naam":"JavaScript",
      "Type":"Programmeertaal",
      "isProgrammeertaal":true,
      "Jaar":1995
   }
]
```


----------



## tingo (May 30, 2021)

It is easy enough to figure out both JSON and YAML if one is interested.


----------

