# Does the package manager handle upgrades?



## ScottSalley (Aug 30, 2010)

Is it possible to install version 1.0 of a package and then install version 2.0 and have scripts (included with the package) handle any upgrade tasks?

I haven't seen this documented anywhere, so I'm guessing 'no' but I'm hoping 'yes'.

[The company I work for has several versions of our product and I'm working on our cross-Unix installer that needs to detect any previous versions, back up/convert configurations, uninstall old packages and then drop in new ones.]


----------



## SirDice (Aug 30, 2010)

If you're talking about ports/packages both ports-mgmt/portmaster and ports-mgmt/portupgrade are able to handle upgrades.


----------



## phoenix (Aug 30, 2010)

The FreeBSD binary package spec includes pre-install and a post-install script hooks.

You can write a shell script to check for previous versions, backup the config files, call the pkg_delete on the existing version, etc and set it as the pre-install script.

Then write another shell script to take the old configuration data, convert it to the new form, and install the new config files, and use it as the post-install script.  And do any cleanup from previous versions here as well.

IOW, the tools and hooks are there, but it's up to you to write the code to make it work for your package.  

Reading through the man pages for pkg_create(), pkg_add() and pkg_delete() should be enough to get you going.  The Porter's Handbook may be useful as well.


----------



## SirDice (Aug 31, 2010)

In all honesty, I don't think a package by itself should take care of upgrading. It's usually just a matter of pkg_delete and pkg_add. Just make sure the pkg_delete doesn't remove any customized configs and pkg_add shouldn't overwrite existing ones.


----------



## dieselnutjob (Oct 15, 2010)

My netbsd box has a [cmd=]pkg_add -u packagename[/cmd] facility. Is there an equivalent for FreeBSD? I had a look at portupgrade but it seems to require ports to be installed which isn't quite what you want if you are using packages.


----------



## jb_fvwm2 (Oct 15, 2010)

```
pkg_add -r pkgname
```
 or 
	
	



```
ncftp ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8-stable/www
```
 ... 8 if running v8, for instance, and you can "get" the package if it exists  then pkg_add it directly, once downloaded. (requires ncftp3 port installed, and www for browsers, lang for languages, audio for audio ports etc).  You need its dependencies installed first. But in freebsd there is an advantage to using more than just packages unless one is REALLY short of disk space. (say, a 4g drive).


----------



## dieselnutjob (Oct 15, 2010)

What does this mean?

```
pkg_add -r apache
Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/apache.tbz... Done.
pkg_add: package 'apache-1.3.41_1' [b]or its older version already installed[/b]
```


----------



## SirDice (Oct 15, 2010)

dieselnutjob said:
			
		

> what does this mean?


It's already installed (or an older version of apache 1.3.x).


----------



## dieselnutjob (Oct 15, 2010)

But if I am trying to upgrade a package to a newer version (because the old one has a security problem) won't that _always_ be true?


----------



## SirDice (Oct 15, 2010)

You will need to remove the old one first. See pkg_delete(1).


----------



## DutchDaemon (Oct 15, 2010)

Since no one mentioned sysutils/bsdadminscripts (which contains a pkg_upgrade script), I will. I will also mention this, dieselnutjob.


----------



## phoenix (Oct 15, 2010)

And, both ports-mgmt/portupgrade and ports-mgmt/portmaster include --packages and --packages-only options, which will upgrade installed software using binary packages instead of compiling the ports.


----------



## dieselnutjob (Oct 16, 2010)

I had a look at pkg_upgrade in sysutils/bsdadminscripts and on the face of it, it seems like it might be the most suitable tool for someone that has built a system purely from binary packages.

However I have run into some problems.

On running it I get this:-

```
# ./usr/local/sbin/pkg_upgrade -an
cd: can't cd to /usr/ports
cd: can't cd to /usr/ports
fetch: ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8-release/INDEX: File unavailable (e.g., file not found, no access)
```

I guess I can just create /usr/ports but it seems like it might be a bug that the script writer has assumed that directories will be there that might not be. I guess I'll file a bug report about that.

I can't figure out where the script has picked up the "packages-8-release" from.  This directory doesn't exist on ftp.freebsd.org but "packages-8.0-release" does and would be correct for my system.  Can anyone tell me how I configure this?

In the pkg_upgrade script I found this

```
# Get some environment variables from uma. This includes PACKAGESITE,
# TMPDIR and PKG_INDEX.
eval "$(uma env $pid)"
```
and I am guessing that it's the PACKAGESITE that is wrong but I haven't yet figured out what "environment variables from uma" means and how to fix it.

Thanks, DNJ


----------



## dieselnutjob (Oct 16, 2010)

This solved the PACKAGESITE issue
`# echo "PACKAGESITE=ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/All" >> .profile`
`# echo "export PACKAGESITE" >> .profile`
Then logout of root and back in again

I still get errors if I run the pkg_upgrade in a jail though

```
# mkdir /usr/ports
# pkg_upgrade -an
fstat: /dev/mem: No such file or directory
fstat: /dev/mem: No such file or directory
/var/db/uma/FTPINDEX                          100% of   16 MB  247 kBps 00m00s
/usr/local/sbin/pkg_upgrade: cannot create /dev/tty: No such file or directory
/usr/local/sbin/pkg_upgrade: cannot create /dev/tty: No such file or directory
/usr/local/sbin/pkg_upgrade: cannot create /dev/tty: No such file or directory
```
So has it worked or not?


----------

