1.\" $OpenBSD: mirroring-ports.7,v 1.18 2009/06/12 17:27:20 sthen Exp $ 2.\" 3.\" Copyright (c) 2000 Marc Espie 4.\" 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd $Mdocdate: June 12 2009 $ 28.Dt MIRRORING-PORTS 7 29.Os 30.Sh NAME 31.Nm mirroring-ports 32.Nd how to build a mirror for ports distfiles 33.Sh DESCRIPTION 34The 35.Nm OpenBSD Ports Collection 36offers some powerful tools to mirror software sources. 37The ports infrastructure provides a 38.Ar mirror-maker 39target that can be used to build a Makefile to facilitate mirroring 40distfiles. 41This target builds 42.Ic ${DISTDIR}/Makefile , 43which can be used on almost any Unix-like machine to mirror 44.Ox 45distfiles. 46Optionally, port dependencies may also be recorded in the Makefile, 47which greatly increases the execution time of 48.Ar mirror-maker . 49The variable 50.Ev RECURSIVE_FETCH_LIST 51can be set to 52.Sq \&Yes 53to request that this is done. 54.Pp 55A sample Makefile entry is formatted like this: 56.Bd -literal 57all:: audio/tracker/tracker-5.3 58\&.PHONY: audio/tracker/tracker-5.3 59audio/tracker/tracker-5.3: tracker-5.3.tgz 60 61tracker-5.3.tgz: $F 62 @MAINTAINER="espie@openbsd.org" \\ 63 SITES="ftp://ftp.uni-trier.de/pub/unix/audio/tracker/ " \\ 64 CIPHER="sha1" CKSUM="b0973d6a9c363caebd3a71547412f42b0681f323" \\ 65 exec ${FETCH} "$@" 66 67 68.Ed 69This Makefile is usually invoked by the user from the directory where 70they wish to mirror distfiles, with variables 71.Ev FETCH 72and 73.Ev F 74set on the command line, e.g., 75.Bd -literal -offset indent 76cd mirror && make -k -j 5 -f path_to_makefile FETCH=fetch_script 77.Ed 78.Pp 79Targets are set up so that each port is referenced by its full name, and 80retrieves all its distfiles. 81The 82.Ar all 83target can be used to retrieve all distfiles. 84Targets 85.Ar ftp 86and 87.Ar cdrom 88can be used to retrieve all distfiles necessary to build ftp and CD-ROM 89packages, respectively. 90Default is 91.Ar ftp 92plus 93.Ar cdrom . 94Actual fetching is usually invoked with a parallel-make option, so that 95several retrievals through ftp can proceed simultaneously. 96.Pp 97The 98.Ev F 99variable can be set to a dummy name, or a recent filename, to force 100re-fetching of anything which is older than the filename. 101Its intended use is to force re-fetching existing files, 102or to checksum all files. 103.Pp 104The 105.Ev ${FETCH} 106script should be supplied by the user, and will download and verify the 107archive file. 108It must obey the following variables: 109.Bl -tag -width DIST_SUBDIR 110.It Ev MAINTAINER 111Port maintainer, used to report errors, 112.It Ev ERROR 113Some ports problems can be detected while building the Makefile, in which 114case this variable will be set to a proper error message. 115.It Ev DIST_SUBDIR 116See 117.Xr ports 7 118for more details. 119The 120.Ev ${FETCH} 121script is responsible for creating this subdirectory and cd'ing to it 122before performing the actual fetch. 123.It Ev SITES 124A list of sites to try for fetching the distribution file. 125.It Ev CIPHER 126The checksumming utility to use for verifying the distribution file. 127It will normally be set to 128.Xr sha1 1 129unless you tinker with 130.Ev PREFERRED_CIPHER 131while building the mirroring Makefile. 132.It Ev CKSUM 133The corresponding checksum. 134If neither 135.Ev CIPHER 136nor 137.Ev CKSUM 138nor 139.Ev ERROR 140are set, the distribution file needs not be checked. 141.El 142.Pp 143A standard fetch strategy is to try all sites in order: whenever the 144distribution file is found, download it; verify the checksum; erase the 145file and try the next site if it doesn't match. 146.Pp 147Mirroring sites should update their master Makefile fairly often. 148Activities a proper mirror should offer (in order of decreasing importance): 149.Bl -tag -width XXXXXXXXX 150.It Mirror new files 151Use a proper fetch script to download missing files, 152.It Run Pa ${PORTSDIR}/infrastructure/fetch/link-checksums 153This script creates permanent hardlinks that preserve distfiles against 154checksum changes. 155.It Verify all checksums 156All checksums should be verified from time to time, and maintainers 157notified of persistent discrepancies, 158.It Check mastersites liveliness 159Use a tool such as 160.Sq mirror 161to check that the master sites haven't fallen 162off the Earth. 163Even though the first site in the site list is the 164most important site, good mirrors will scan all sites and report all 165problems, 166.It Remove old files 167To gain room this, the mirror should maintain a list of 168.Sq active 169files (easy enough, just provide a fetch script that just lists the 170file names), and remove files that are no longer active. 171Since 172.Ox 173releases happen every six months, this delay should be longer than that. 174.El 175Sample scripts are provided in the 176.Pa ${PORTSDIR}/infrastructure/fetch 177directory. 178.Sh FILES 179.Bl -tag -width XXXXXXXXX -compact 180.It Pa ${DISTDIR}/Makefile 181Main mirroring Makefile 182.It Pa ${PORTSDIR}/infrastructure/fetch/fetch-all 183Sample script usable to retrieve distfiles. 184.It Pa ${PORTSDIR}/infrastructure/fetch/check-all 185Sample script to check all distfiles checksums. 186.It Pa ${PORTSDIR}/infrastructure/fetch/link-checksums 187Populating checksums subdirectories with links, to guard against shifting 188checksums. 189.El 190.Sh SEE ALSO 191.Xr ports 7 192.Sh HISTORY 193This infrastructure was introduced for 194.Ox 2.7 195by Marc Espie, with feedback from Bob Beck, Todd Fries, Camiel Dobbelaar, 196and a few other people. 197.Sh CAVEATS 198Changing checksums is a recurring problem that is outside the direct 199control of the 200.Ox 201Project. 202Some software distributors change distribution files without 203warning, without changing the file name proper. 204Once the problem has been identified, the port maintainer should usually 205contact the software author to fix the problem, or, if the software author 206is unresponsive, the maintainer should use 207.Ev DIST_SUBDIR 208to provide some state to guard against shifting checksums. 209.Pp 210However, a more robust approach is also needed, so that ports users can 211depend on distfiles mirrors to carry what they need irrespective of those 212synchronization issues. 213The 214.Pa link-checksums 215script creates another access to the distfiles, indexed through the actual 216checksums that the files should match. 217Provided mirroring is run sufficiently often, together with 218.Pa link-checksums , 219two versions of the same distfile with respective checksums cksum1 and cksum2 220will be available under the names 221.Pa ${DISTFILES}/sha1/cksum1/distfile 222and 223.Pa ${DISTFILES}/sha1/cksum2/distfile . 224.Pp 225Starting revision 1.281, if 226.Ev REFETCH 227is set to true, 228.Pa bsd.port.mk 229will try to retrieve files under that naming scheme as a last resort. 230