File:  [NetBSD Developer Wiki] / wikisrc / tutorials / pkgsrc / pkg_comp_pkg_chk.mdwn
Revision 1.7: download - view: text, annotated - select for diffs
Thu Feb 23 23:30:51 2017 UTC (3 years, 3 months ago) by jmmv
Branches: MAIN
CVS tags: HEAD
Link to the pkg_comp 2.x tutorials and leave the pkg_comp 1.x instructions
as they currently are.

    1: ## Keeping packages up-to-date with pkg_comp and pkg_chk
    2: 
    3: *Pkgsrc* is a fantastic package management framework, but when it comes to upgrades, some use cases may lead to an unstable situation. Also, if by any chance you have 2 or more NetBSD machines to keep up-to-date, upgrading each one separately could be risky and a real waste of time. We'll see how to flawlessly keep your packages up-to-date with minimal risks.
    4: 
    5: ### pkg_comp
    6: 
    7: Under *pkgsrc/pkgtools* you will find a great utility called *pkg_comp*. This script permits to handle packages manipulation in a *chroot*ed environment, thus keeping your real packages safe from any mistakes.
    8: 
    9: For *pkg_comp* 2.x, located under *pkgsrc/pkgtools/pkg_comp*, follow these tutorials:
   10: 
   11: * [Introducing pkg_comp 2.0 (and sandboxctl 1.0)](http://julio.meroh.net/2017/02/introducing-pkg_comp-2.0.html)
   12: * [Keeping NetBSD up-to-date with pkg_comp 2.0](http://julio.meroh.net/2017/02/pkg_comp-2.0-tutorial-netbsd.html)
   13: * [Easy pkgsrc on macOS with pkg_comp 2.0](http://julio.meroh.net/2017/02/pkg_comp-2.0-tutorial-macos.html)
   14: 
   15: For *pkg_comp* 1.x, located under *pkgsrc/pkgtools/pkg_comp1*, continue reading this page.
   16: 
   17: Let's install *pkg_comp 1.x*:
   18: 
   19: 	# cd /usr/pkgsrc/pkgtools/pkg_comp1
   20: 	# make install clean
   21: 
   22: Once done, we will create the *chroot*ed environment:
   23: 
   24: 	# mkdir -p /home/pkg_comp
   25: 	# cd /home/pkg_comp
   26: 	# pkg_comp -C test.conf maketemplate
   27: 
   28: This will create a template file, which will be used to build our fake NetBSD system, but first, we'll have to set up some information. Using your favourite editor, change the following variables to suit your needs:
   29: 
   30: * DESTDIR, where the *chroot* will be built
   31: * DISTRIBDIR, where pkg_comp will find your NetBSD binary sets
   32: * SETS_X11 may be set to "no" if you do not intend to use the X Window system
   33: 
   34: This is my *pkg_comp* configuration:
   35: 
   36: 	...
   37: 	DESTDIR="/home/pkg_comp/test"
   38: 	DISTRIBDIR="/home/pkg_comp/dist/NetBSD-5.0.1"
   39: 	SETS_X11="no"
   40: 	...
   41: 
   42: If you don't yet have NetBSD's binary sets, download them from your favourite mirror and put them in */home/pkg_comp/dist/NetBSD-5.0.1/binary/sets*. Also note that NetBSD's source directory (*/usr/src* in most cases) must exist.
   43: 
   44: We can now build the *chroot* using the following command:
   45: 
   46: 	# pkg_comp -C test.conf makeroot
   47: 
   48: From now on, we can enter our *chroot* using the *chroot* target:
   49: 
   50: 	# pkg_comp -C test.conf chroot
   51: 	PKG_COMP ==> Mounting sandboxed filesystems
   52: 	PKG_COMP ==> Entering sandbox `/home/pkg_comp/test'
   53: 	pkg_comp:test.conf# exit
   54: 	PKG_COMP ==> Unmounting sandboxed filesystems
   55: 
   56: A very simple method to build a package in the *chroot* is to use the *build* target:
   57: 	# pkg_comp -C test.conf build pkgtools/pkgfind
   58: 
   59: But as we want to keep a good control on our packages freshness and build method, we will use another tool: *pkg_chk*.
   60: 
   61: ### pkg_chk
   62: 
   63: *pkg_chk* is another tool available under *pkgsrc/pkgtools*. This script reads the content of the *pkgsrc/pkgchk.conf* file and checks if every listed package is up to date. You will have to install *pkg_chk* on the *chroot* as well as in the host.
   64: 
   65: Let's create a */usr/pkgsrc/pkgchk.conf* file. Please note this must be done **outside** of the chroot, *pkg_comp* uses *pkgsrc*'s directory to read content, but it *mount*s it as a read only partition. Here's an output of the *mount* command inside of the *chroot*:
   66: 
   67: 	/usr/src on /var/chroot/pkg_comp/default/usr/src type null (read-only, local)
   68: 	/usr/pkgsrc on /var/chroot/pkg_comp/default/usr/pkgsrc type null (read-only, local)
   69: 	/usr/pkgsrc/distfiles on /var/chroot/pkg_comp/default/pkg_comp/distfiles type null (local)
   70: 	/usr/pkgsrc/packages on /var/chroot/pkg_comp/default/pkg_comp/packages type null (local)
   71: 
   72: As you can see, generated packages will be written to */usr/pkgsrc/packages* and we are allowed to *fetch distfiles* to */usr/pkgsrc/distfiles*, but */usr/pkgsrc* and */usr/src* are not writables.
   73: 
   74: 	# pkg_chk -g
   75: 
   76: This command will generate an initial pkgchk.conf file based upon the packages installed on the host machine.
   77: 
   78: Now, enter the *chroot* as we must configure its *etc/mk.conf* file:
   79: 
   80: 	# no X11
   81: 	MKX11=no
   82: 	# clean dependencies when the "clean" target is called
   83: 	CLEANDEPENDS=yes
   84: 	# everybody likes vim
   85: 	ACCEPTABLE_LICENSES+=vim-license
   86: 	# we want to build packages fo every software
   87: 	DEPENDS_TARGET=package-install
   88: 	UPDATE_TARGET=package-install
   89: 
   90: Everything is now ready. *pkg_chk* has many options, but we will keep its use very simple.
   91: 
   92: To see what operations are going to take place without actually doing anything, use the following switches:
   93: 
   94: 	pkg_comp:test.conf# pkg_chk -uan
   95: 
   96: When ready, call *pkg_chk* this way:
   97: 
   98: 	pkg_comp:test.conf# pkg_chk -ua
   99: 
  100: Depending on how many packages you must generate, this operation could be a rather long one.
  101: 
  102: Once the packages creation is finished, you may logout from *pkg_comp* and update your host's packages using binaries created by *pkg_comp*'s *pkg_chk*:
  103: 
  104: 	# pkg_chk -uab
  105: 
  106: As *pkg_chk manpage* says:
  107: 
  108: 	-b	Use binary packages.  If -s is not set this allows pkg_chk to
  109: 		run without PKGSRCDIR.
  110: 
  111: Here we are! massive upgrade, no harm, no pain.
  112: 
  113: ### Upgrading more than one machine with pkgin
  114: 
  115: A convenient method to upgrade more than one machine is to use *pkgtools/pkgin*, a remote package installation and upgrade utility being able to handle packages dependencies.
  116: 
  117: In the machine hosting binary packages, install an HTTP or FTP server being able to access the directory where your binary packages are located. For example, using *www/lighttpd*:
  118: 
  119: 	...
  120: 	dir-listing.activate = "enable"
  121: 	...
  122: 	$HTTP["host"] == "pkgsrc.home.imil.net" {
  123:         	server.document-root = "/usr/pkgsrc/packages"
  124: 	}
  125: 	...
  126: 
  127: In this directory, create a *pkg_summary.bz2* file, where all packages, dependencies and descriptions will be available:
  128: 
  129: 	# cd /usr/pkgsrc/packages/All
  130: 	# pkg_info -X * | bzip2 > pkg_summary.bz2
  131: 
  132: Then, on the machine to be upgraded, install *pkgin* :
  133: 
  134: 	# pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/5.0/databases/sqlite3-3.6.17.tgz
  135: 	# pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/5.0/pkgtools/pkgin-0.2.5.tgz
  136: 
  137: And put your own repository in */usr/pkg/etc/pkgin/repositories.conf*:
  138: 
  139: 	http://pkgsrc.home.imil.net/All
  140: 
  141: Update *pkgin*'s database:
  142: 
  143: 	# pkgin up
  144: 
  145: And upgrade your packages:
  146: 
  147: 	# pkgin full-upgrade
  148: 
  149: There you go !

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb