# Is there a BEST way to update ports?



## ghostcorps (Sep 14, 2011)

Hi Guys

 I have been looking into ways to keep my system upto date and have gotten myself a bit turned around.

 To update my port tree I have this in my crontab:



```
portsnap -I cron update && pkg_version -vIL=
```

 Which sends me an email advising that there are ports to update. However I have found at least three ways to do the update, each of which seems to have their own pros and cons.


The best options I have found so far are:


```
portupgrade -aRrP
```


```
portmanager -u -l
```


```
portmaster -ay
```

Or this script:


```
#!/bin/sh
/usr/sbin/portsnap fetch update && \
/usr/local/sbin/portmaster -L --index-only | egrep '(ew|ort) version|total install'
```

Or this script: http://www.mebsd.com/freebsd-security-hardening/update-freebsd-with-portmaster.html

I know there are alot of opinions in the forum and portmaster looks to be the method of choice but is there any reason to think otherwise? I have run portmanager already, will it preclude using the portmaster next time?

Thanks


----------



## ghostcorps (Sep 14, 2011)

I'm going with This


----------



## vermaden (Sep 14, 2011)

ghostcorps said:
			
		

> I'm going with This



Then also try this one


----------



## nekoexmachina (Sep 14, 2011)

I'm updating once a long time with `rm -rf /var/db/pkg /usr/local && portmaster < pkg_list.txt`


----------



## ghostcorps (Sep 14, 2011)

vermaden said:
			
		

> Then also try this one



Wow!  That is a very detailed walkthrough  

What would be the advantage of your method over the one above?


----------



## wblock@ (Sep 14, 2011)

For the part of vermaden's post about updating applications, it's using packages.  Packages are just precompiled ports, off-the-rack "one size fits all" binaries.  Since they're already compiled, that step is skipped, saving time.  Differences between the FreeBSD package build cluster and the target system can cause problems.


----------



## ghostcorps (Sep 14, 2011)

wblock said:
			
		

> For the part of vermaden's post about updating applications, it's using packages.  Packages are just precompiled ports, off-the-rack "one size fits all" binaries.  Since they're already compiled, that step is skipped, saving time.  Differences between the FreeBSD package build cluster and the target system can cause problems.



So you are saying that using Packages as in Vermadens method is quicker but it can cause problems in systems that are not exactly standard?


----------



## wblock@ (Sep 14, 2011)

ghostcorps said:
			
		

> So you are saying that using Packages as in Vermadens method is quicker but it can cause problems in systems that are not exactly standard?



The package cluster machines build packages in a set environment.  Usually that will have the latest libraries and such.  Download one of those packages onto a machine that has older libraries, and it will complain.  That can cascade into a bunch of upgrades.

Ports don't have that particular problem, since they're built on the target machine.


----------



## vermaden (Sep 14, 2011)

@wblock

That is why I also use from time to time *ports-build* function from my howto to cope with such problems, so far, I haven't seen any of them, but the longer You would not update the base system, the bigger chance for hitting such problems, that is why I included information about updating the base system in the first part.

The only 'problem' are options that are (or not) compiled into the packages, for example like lack of TTF support in *conky* which I must rebuild (with *ports-build* function) every time the new version is fetched, but its harmless.

I found that way the least problematic and time consuming, pity we do not have _'stable ports tree'_ but that has been discussed many times that FreeBSD community does not currently have man power to do that.


----------



## ghostcorps (Sep 15, 2011)

Thanks guys 

 I think I will stick with the simpler method. It is a new build and is not 100% upto date. 

 Since I do like to tinker though, I think I should stick with the method that to me seems more straightforward and more forgiving to any hacks I may need to make in the future.

Thanks again 

Have a great day.


----------



## carlton_draught (Sep 15, 2011)

I use DutchDaemon's script, portupdater.sh. At the end, I read if there is anything relevant in /usr/ports/UPDATING (which that script prints out), and then:

`# portmaster -a`

Or as appropriate.


----------



## wblock@ (Sep 15, 2011)

ghostcorps said:
			
		

> ```
> portupgrade -aRrP
> ```



Forgot to mention this from post #1.  -arR, sometimes called "pirate mode", is equivalent to -a.


----------



## ghostcorps (Sep 15, 2011)

wblock said:
			
		

> Forgot to mention this from post #1.  -arR, sometimes called "pirate mode", is equivalent to -a.



hahaha  that's exactly how I would say it in my mind!   


carlton_draught: Dutchdemons script is very nice thankyou


----------



## ghostcorps (Sep 16, 2011)

Dumb question I know. But I haven't used crontab very often.

I have this in /etc/crontab


```
@daily                                  root    portupdater.sh cron
```

Is this correct? The script is in /usr/bin


----------



## jrm@ (Sep 16, 2011)

You might need to specify a PATH with something like:


```
PATH=/bin:/sbin:/usr/bin:/usr/sbin
```

or specify the whole path for the command, i.e., /usr/bin/portupdater.sh.


----------



## ghostcorps (Sep 16, 2011)

Thanks 

/etc/crontab already shows /usr/bin in the PATH. I originally had the script in / and specified the whole path, but I thought I should keep it neat and put the script where crontab expects it to be so I moved it.

Thanks again


----------



## carlton_draught (Sep 16, 2011)

One thing ghostcorps - I would recommend running that script manually as it asks for input from time to time, to delete various things as necessary. Unless DutchDaemon says otherwise, I would not put it in crontab.


----------



## ghostcorps (Sep 16, 2011)

Thanks for the followup Carlton,

 In the post you sent me to DutchDaemon advises that the script be run from /etc/crontab, but that it can be run manually without interaction using portupdater yes or portupdater now which allows the interactive options. 

I have confirmed that manually running portupdater cron does not require interaction either.


----------



## wblock@ (Sep 16, 2011)

One problem with automated updating of ports is that by the time you see the special procedures in /usr/ports/UPDATING, the system may already be broken.


----------



## ghostcorps (Sep 16, 2011)

wblock said:
			
		

> One problem with automated updating of ports is that by the time you see the special procedures in /usr/ports/UPDATING, the system may already be broken.



Thanks for the heads up,

I have been reading /usr/ports/UPDATING after running the script but before portmaster -a which I do manually. Is this still too late?



			
				DutchDaemon said:
			
		

> The script will only update/maintain the ports tree and show a summary, it will not update ports.


----------



## wblock@ (Sep 16, 2011)

ghostcorps said:
			
		

> Thanks for the heads up,
> 
> I have been reading /usr/ports/UPDATING after running the script but before portmaster -a which I do manually. Is this still too late?



No that, should be okay.


----------



## ghostcorps (Sep 16, 2011)

Cool   Thanks again

Now I just need to figure out why freebsd-update cron is isn't sending me mail and the update procedure is done.


----------



## DutchDaemon (Sep 16, 2011)

I'm just going to state this once again, as if I haven't done this often enough:

Leave /etc/crontab alone. 

It is the system's crontab and may be altered or overwritten in an OS upgrade. Put cron jobs for root (or any user) in their own personal crontab, which is available by running [cmd=]crontab -e[/cmd] as that particular user. Note that you will not need the 'user field' in that case, because the crontab is already personal.

crontab(5)


----------

