Annotation of wikisrc/tutorials/pkgsrc/pkg_comp_pkg_chk.mdwn, revision 1.4

1.1       imil        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 usecases 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. Well 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 misakes.
                      8: 
                      9: Let's install *pkg_comp*
                     10: 
                     11:        # cd /usr/pkgsrc/pkgtools/pkg_comp
                     12:        # make install clean
                     13: 
                     14: Once done, we will create the *chroot*ed environment:
                     15: 
                     16:        # mkdir -p /home/pkg_comp
                     17:        # cd /home/pkg_comp
                     18:        # pkg_comp -C test.conf maketemplate
                     19: 
                     20: This will create a template file, which will be used to build our fake NetBSD system, but first, we'll have to setup some informations. Using your favourite editor, change the following variables to suit your needs:
                     21: 
                     22: * DESTDIR, where the *chroot* will be built
                     23: * DISTRIBDIR, where pkg_comp fill find your NetBSD binaries sets
                     24: * SETS_X11 may be set to "no" if you do not intend to use the X Window system
                     25: 
                     26: This is my *pkg_comp* configuration:
1.2       imil       27: 
1.1       imil       28:        ...
                     29:        DESTDIR="/home/pkg_comp/test"
                     30:        DISTRIBDIR="/home/pkg_comp/dist/NetBSD-5.0.1"
                     31:        SETS_X11="no"
                     32:        ...
                     33: 
                     34: 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.
                     35: 
                     36: We can now build the *chroot* using the following command:
                     37: 
1.4     ! wiki       38:        # pkg_comp -C test.conf makeroot
1.1       imil       39: 
                     40: From now on, we can enter our *chroot* using the *chroot* target:
                     41: 
1.4     ! wiki       42:        # pkg_comp -C test.conf chroot
1.1       imil       43:        PKG_COMP ==> Mounting sandboxed filesystems
                     44:        PKG_COMP ==> Entering sandbox `/home/pkg_comp/test'
                     45:        pkg_comp:test.conf# exit
                     46:        PKG_COMP ==> Unmounting sandboxed filesystems
                     47: 
                     48: A very simple method to build a package in the *chroot* is to use the *build* target:
1.4     ! wiki       49:        # pkg_comp -C test.conf build pkgtools/pkgfind
1.1       imil       50: 
                     51: But as we want to keep a good control on our packages freshness and build method, we will use another tool: *pkg_chk*.
                     52: 
                     53: ### pkg_chk
                     54: 
                     55: *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.
                     56: 
                     57: 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*:
                     58: 
                     59:        /usr/src on /var/chroot/pkg_comp/default/usr/src type null (read-only, local)
                     60:        /usr/pkgsrc on /var/chroot/pkg_comp/default/usr/pkgsrc type null (read-only, local)
                     61:        /usr/pkgsrc/distfiles on /var/chroot/pkg_comp/default/pkg_comp/distfiles type null (local)
                     62:        /usr/pkgsrc/packages on /var/chroot/pkg_comp/default/pkg_comp/packages type null (local)
                     63: 
                     64: 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.
                     65: 
                     66:        # pkg_chk -g
                     67: 
                     68: This command will generate an initial pkgchk.conf file based upon the packages installed on the host machine.
                     69: 
                     70: Now, enter the *chroot* as we must configure its *etc/mk.conf* file:
                     71: 
                     72:        # no X11
                     73:        MKX11=no
                     74:        # clean dependencies when the "clean" target is called
                     75:        CLEANDEPENDS=yes
                     76:        # everybody likes vim
                     77:        ACCEPTABLE_LICENSES+=vim-license
                     78:        # we want to build packages fo every software
1.3       imil       79:        DEPENDS_TARGET=package-install
                     80:        UPDATE_TARGET=package-install
1.1       imil       81: 
1.4     ! wiki       82: Everything is now ready. *pkg_chk* has many options, but we will keep its use very simple.
1.1       imil       83: 
                     84: To see what operations are going to take place without actually doing anything, use the following switches:
                     85: 
                     86:        pkg_comp:test.conf# pkg_chk -uan
                     87: 
                     88: When ready, call *pkg_chk* this way:
                     89: 
                     90:        pkg_comp:test.conf# pkg_chk -ua
                     91: 
                     92: Depending on how many packages you must generate, this operation could be a rather long one.
                     93: 
                     94: 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*:
                     95: 
                     96:        # pkg_chk -uab
                     97: 
                     98: As *pkg_chk manpage* says:
                     99: 
                    100:        -b      Use binary packages.  If -s is not set this allows pkg_chk to
                    101:                run without PKGSRCDIR.
                    102: 
1.4     ! wiki      103: Here we are! massive upgrade, no harm, no pain.
1.1       imil      104: 
                    105: ### Upgrading more than one machine with pkgin
                    106: 
                    107: 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.
                    108: 
                    109: 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*:
                    110: 
                    111:        ...
                    112:        dir-listing.activate = "enable"
                    113:        ...
                    114:        $HTTP["host"] == "pkgsrc.home.imil.net" {
                    115:                server.document-root = "/usr/pkgsrc/packages"
                    116:        }
                    117:        ...
                    118: 
                    119: In this directory, create a *pkg_summary.bz2* file, where all packages, dependencies and descriptions will be available:
                    120: 
                    121:        # cd /usr/pkgsrc/packages/All
                    122:        # pkg_info -X * | bzip2 > pkg_summary.bz2
                    123: 
                    124: Then, on the machine to be upgraded, install *pkgin* :
                    125: 
                    126:        # pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/5.0/databases/sqlite3-3.6.17.tgz
                    127:        # pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/amd64/5.0/pkgtools/pkgin-0.2.5.tgz
                    128: 
                    129: And put your own repository in */usr/pkg/etc/pkgin/repositories.conf*:
                    130: 
                    131:        http://pkgsrc.home.imil.net/All
                    132: 
                    133: Update *pkgin*'s database:
                    134: 
                    135:        # pkgin up
                    136: 
                    137: And upgrade your packages:
                    138: 
                    139:        # pkgin full-upgrade
                    140: 
                    141: There you go !

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