4 # SPDX-License-Identifier: BSD-2-Clause-FreeBSD
6 # Copyright 2004-2007 Colin Percival
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted providing that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
32 #### Usage function -- called from command-line handling code.
34 # Usage instructions. Options not listed:
35 # --debug -- don't filter output from utilities
36 # --no-stats -- don't show progress statistics while fetching files
39 usage: `basename $0` [options] command ... [path]
42 -b basedir -- Operate on a system mounted at basedir
44 -d workdir -- Store working files in workdir
45 (default: /var/db/freebsd-update/)
46 -f conffile -- Read configuration options from conffile
47 (default: /etc/freebsd-update.conf)
48 -F -- Force a fetch operation to proceed in the
49 case of an unfinished upgrade
50 -k KEY -- Trust an RSA key with SHA256 hash of KEY
51 -r release -- Target for upgrade (e.g., 11.1-RELEASE)
52 -s server -- Server from which to fetch updates
53 (default: update.FreeBSD.org)
54 -t address -- Mail output of cron command, if any, to address
56 --not-running-from-cron
57 -- Run without a tty, for use by automated tools
58 --currently-running release
59 -- Update as if currently running this release
61 fetch -- Fetch updates from server
62 cron -- Sleep rand(3600) seconds, fetch updates, and send an
63 email if updates were found
64 upgrade -- Fetch upgrades to FreeBSD version specified via -r option
65 install -- Install downloaded updates or upgrades
66 rollback -- Uninstall most recently installed updates
67 IDS -- Compare the system against an index of "known good" files.
72 #### Configuration processing functions
75 # Configuration options are set in the following order of priority:
76 # 1. Command line options
77 # 2. Configuration file options
79 # In addition, certain options (e.g., IgnorePaths) can be specified multiple
80 # times and (as long as these are all in the same place, e.g., inside the
81 # configuration file) they will accumulate. Finally, because the path to the
82 # configuration file can be specified at the command line, the entire command
83 # line must be processed before we start reading the configuration file.
85 # Sound like a mess? It is. Here's how we handle this:
86 # 1. Initialize CONFFILE and all the options to "".
87 # 2. Process the command line. Throw an error if a non-accumulating option
89 # 3. If CONFFILE is "", set CONFFILE to /etc/freebsd-update.conf .
90 # 4. For all the configuration options X, set X_saved to X.
91 # 5. Initialize all the options to "".
92 # 6. Read CONFFILE line by line, parsing options.
93 # 7. For each configuration option X, set X to X_saved iff X_saved is not "".
94 # 8. Repeat steps 4-7, except setting options to their default values at (6).
96 CONFIGOPTIONS="KEYPRINT WORKDIR SERVERNAME MAILTO ALLOWADD ALLOWDELETE
97 KEEPMODIFIEDMETADATA COMPONENTS IGNOREPATHS UPDATEIFUNMODIFIED
98 BASEDIR VERBOSELEVEL TARGETRELEASE STRICTCOMPONENTS MERGECHANGES
99 IDSIGNOREPATHS BACKUPKERNEL BACKUPKERNELDIR BACKUPKERNELSYMBOLFILES"
101 # Set all the configuration options to "".
103 for X in ${CONFIGOPTIONS}; do
108 # For each configuration option X, set X_saved to X.
110 for X in ${CONFIGOPTIONS}; do
111 eval ${X}_saved=\$${X}
115 # For each configuration option X, set X to X_saved if X_saved is not "".
117 for X in ${CONFIGOPTIONS}; do
119 if ! [ -z "${_}" ]; then
120 eval ${X}=\$${X}_saved
125 # Set the trusted keyprint.
127 if [ -z ${KEYPRINT} ]; then
134 # Set the working directory.
136 if [ -z ${WORKDIR} ]; then
143 # Set the name of the server (pool) from which to fetch updates
144 config_ServerName () {
145 if [ -z ${SERVERNAME} ]; then
152 # Set the address to which 'cron' output will be mailed.
154 if [ -z ${MAILTO} ]; then
161 # Set whether FreeBSD Update is allowed to add files (or directories, or
162 # symlinks) which did not previously exist.
164 if [ -z ${ALLOWADD} ]; then
181 # Set whether FreeBSD Update is allowed to remove files/directories/symlinks.
182 config_AllowDelete () {
183 if [ -z ${ALLOWDELETE} ]; then
200 # Set whether FreeBSD Update should keep existing inode ownership,
201 # permissions, and flags, in the event that they have been modified locally
203 config_KeepModifiedMetadata () {
204 if [ -z ${KEEPMODIFIEDMETADATA} ]; then
207 KEEPMODIFIEDMETADATA=yes
210 KEEPMODIFIEDMETADATA=no
221 # Add to the list of components which should be kept updated.
222 config_Components () {
224 if [ "$C" = "src" ]; then
225 if [ -e "${BASEDIR}/usr/src/COPYRIGHT" ]; then
226 COMPONENTS="${COMPONENTS} ${C}"
228 echo "src component not installed, skipped"
231 COMPONENTS="${COMPONENTS} ${C}"
236 # Add to the list of paths under which updates will be ignored.
237 config_IgnorePaths () {
239 IGNOREPATHS="${IGNOREPATHS} ${C}"
243 # Add to the list of paths which IDS should ignore.
244 config_IDSIgnorePaths () {
246 IDSIGNOREPATHS="${IDSIGNOREPATHS} ${C}"
250 # Add to the list of paths within which updates will be performed only if the
251 # file on disk has not been modified locally.
252 config_UpdateIfUnmodified () {
254 UPDATEIFUNMODIFIED="${UPDATEIFUNMODIFIED} ${C}"
258 # Add to the list of paths within which updates to text files will be merged
259 # instead of overwritten.
260 config_MergeChanges () {
262 MERGECHANGES="${MERGECHANGES} ${C}"
266 # Work on a FreeBSD installation mounted under $1
268 if [ -z ${BASEDIR} ]; then
275 # When fetching upgrades, should we assume the user wants exactly the
276 # components listed in COMPONENTS, rather than trying to guess based on
277 # what's currently installed?
278 config_StrictComponents () {
279 if [ -z ${STRICTCOMPONENTS} ]; then
296 # Upgrade to FreeBSD $1
297 config_TargetRelease () {
298 if [ -z ${TARGETRELEASE} ]; then
303 if echo ${TARGETRELEASE} | grep -qE '^[0-9.]+$'; then
304 TARGETRELEASE="${TARGETRELEASE}-RELEASE"
308 # Pretend current release is FreeBSD $1
309 config_SourceRelease () {
311 if echo ${UNAME_r} | grep -qE '^[0-9.]+$'; then
312 UNAME_r="${UNAME_r}-RELEASE"
317 # Define what happens to output of utilities
318 config_VerboseLevel () {
319 if [ -z ${VERBOSELEVEL} ]; then
321 [Dd][Ee][Bb][Uu][Gg])
324 [Nn][Oo][Ss][Tt][Aa][Tt][Ss])
327 [Ss][Tt][Aa][Tt][Ss])
339 config_BackupKernel () {
340 if [ -z ${BACKUPKERNEL} ]; then
357 config_BackupKernelDir () {
358 if [ -z ${BACKUPKERNELDIR} ]; then
360 echo "BackupKernelDir set to empty dir"
364 # We check for some paths which would be extremely odd
365 # to use, but which could cause a lot of problems if
368 /|/bin|/boot|/etc|/lib|/libexec|/sbin|/usr|/var)
369 echo "BackupKernelDir set to invalid path $1"
376 echo "BackupKernelDir ($1) is not an absolute path"
385 config_BackupKernelSymbolFiles () {
386 if [ -z ${BACKUPKERNELSYMBOLFILES} ]; then
389 BACKUPKERNELSYMBOLFILES=yes
392 BACKUPKERNELSYMBOLFILES=no
403 # Handle one line of configuration
405 if [ $# -eq 0 ]; then
414 #### Parameter handling functions.
416 # Initialize parameters to null, just in case they're
417 # set in the environment.
419 # Configration settings
422 # No configuration file set yet
425 # No commands specified yet
428 # Force fetch to proceed
434 # Fetched first in a chain of commands
438 # Parse the command line
440 while [ $# -gt 0 ]; do
442 # Location of configuration file
444 if [ $# -eq 1 ]; then usage; fi
445 if [ ! -z "${CONFFILE}" ]; then usage; fi
451 --not-running-from-cron)
456 config_SourceRelease $1 || usage
459 # Configuration file equivalents
461 if [ $# -eq 1 ]; then usage; fi; shift
462 config_BaseDir $1 || usage
465 if [ $# -eq 1 ]; then usage; fi; shift
466 config_WorkDir $1 || usage
469 if [ $# -eq 1 ]; then usage; fi; shift
470 config_KeyPrint $1 || usage
473 if [ $# -eq 1 ]; then usage; fi; shift
474 config_ServerName $1 || usage
477 if [ $# -eq 1 ]; then usage; fi; shift
478 config_TargetRelease $1 || usage
481 if [ $# -eq 1 ]; then usage; fi; shift
482 config_MailTo $1 || usage
485 if [ $# -eq 1 ]; then usage; fi; shift
486 config_VerboseLevel $1 || usage
489 # Aliases for "-v debug" and "-v nostats"
491 config_VerboseLevel debug || usage
494 config_VerboseLevel nostats || usage
498 cron | fetch | upgrade | install | rollback | IDS)
499 COMMANDS="${COMMANDS} $1"
502 # Anything else is an error
510 # Make sure we have at least one command
511 if [ -z "${COMMANDS}" ]; then
516 # Parse the configuration file
518 # If a configuration file was specified on the command line, check
519 # that it exists and is readable.
520 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
521 echo -n "File does not exist "
522 echo -n "or is not readable: "
527 # If a configuration file was not specified on the command line,
528 # use the default configuration file path. If that default does
529 # not exist, give up looking for any configuration.
530 if [ -z "${CONFFILE}" ]; then
531 CONFFILE="/etc/freebsd-update.conf"
532 if [ ! -r "${CONFFILE}" ]; then
537 # Save the configuration options specified on the command line, and
538 # clear all the options in preparation for reading the config file.
542 # Read the configuration file. Anything after the first '#' is
543 # ignored, and any blank lines are ignored.
547 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
548 if ! configline ${LINEX}; then
549 echo "Error processing configuration file, line $L:"
555 # Merge the settings read from the configuration file with those
556 # provided at the command line.
560 # Provide some default parameters
562 # Save any parameters already configured, and clear the slate
566 # Default configurations
567 config_WorkDir /var/db/freebsd-update
570 config_AllowDelete yes
571 config_KeepModifiedMetadata yes
573 config_VerboseLevel stats
574 config_StrictComponents no
575 config_BackupKernel yes
576 config_BackupKernelDir /boot/kernel.old
577 config_BackupKernelSymbolFiles no
579 # Merge these defaults into the earlier-configured settings
583 # Set utility output filtering options, based on ${VERBOSELEVEL}
584 fetch_setup_verboselevel () {
585 case ${VERBOSELEVEL} in
587 QUIETREDIR="/dev/stderr"
589 STATSREDIR="/dev/stderr"
597 STATSREDIR="/dev/null"
603 QUIETREDIR="/dev/null"
605 STATSREDIR="/dev/stdout"
613 # Perform sanity checks and set some final parameters
614 # in preparation for fetching files. Figure out which
615 # set of updates should be downloaded: If the user is
616 # running *-p[0-9]+, strip off the last part; if the
617 # user is running -SECURITY, call it -RELEASE. Chdir
618 # into the working directory.
619 fetchupgrade_check_params () {
620 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
623 "SERVERNAME must be given via command line or configuration file."
624 _KEYPRINT_z="Key must be given via -k option or configuration file."
625 _KEYPRINT_bad="Invalid key fingerprint: "
626 _WORKDIR_bad="Directory does not exist or is not writable: "
627 _WORKDIR_bad2="Directory is not on a persistent filesystem: "
629 if [ -z "${SERVERNAME}" ]; then
630 echo -n "`basename $0`: "
631 echo "${_SERVERNAME_z}"
634 if [ -z "${KEYPRINT}" ]; then
635 echo -n "`basename $0`: "
636 echo "${_KEYPRINT_z}"
639 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
640 echo -n "`basename $0`: "
641 echo -n "${_KEYPRINT_bad}"
645 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
646 echo -n "`basename $0`: "
647 echo -n "${_WORKDIR_bad}"
651 case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*)
652 echo -n "`basename $0`: "
653 echo -n "${_WORKDIR_bad2}"
659 cd ${WORKDIR} || exit 1
661 # Generate release number. The s/SECURITY/RELEASE/ bit exists
662 # to provide an upgrade path for FreeBSD Update 1.x users, since
663 # the kernels provided by FreeBSD Update 1.x are always labelled
666 sed -E 's,-p[0-9]+,,' |
667 sed -E 's,-SECURITY,-RELEASE,'`
669 FETCHDIR=${RELNUM}/${ARCH}
670 PATCHDIR=${RELNUM}/${ARCH}/bp
672 # Disallow upgrade from a version that is not a release
674 *-RELEASE | *-ALPHA* | *-BETA* | *-RC*)
677 echo -n "`basename $0`: "
679 Cannot upgrade from a version that is not a release
680 (including alpha, beta and release candidates)
681 using `basename $0`. Instead, FreeBSD can be directly
682 upgraded by source or upgraded to a RELEASE/RELENG version
683 prior to running `basename $0`.
684 Currently running: ${RELNUM}
690 # Figure out what directory contains the running kernel
691 BOOTFILE=`sysctl -n kern.bootfile`
692 KERNELDIR=${BOOTFILE%/kernel}
693 if ! [ -d ${KERNELDIR} ]; then
694 echo "Cannot identify running kernel"
698 # Figure out what kernel configuration is running. We start with
699 # the output of `uname -i`, and then make the following adjustments:
700 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
701 # file says "ident SMP-GENERIC", I don't know...
702 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
703 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
704 # we're running an SMP kernel. This mis-identification is a bug
705 # which was fixed in 6.2-STABLE.
707 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
710 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
711 if sysctl kern.version | grep -qE '/SMP$'; then
717 BSPATCH=/usr/bin/bspatch
719 PHTTPGET=/usr/libexec/phttpget
721 # Set up variables relating to VERBOSELEVEL
722 fetch_setup_verboselevel
724 # Construct a unique name from ${BASEDIR}
725 BDHASH=`echo ${BASEDIR} | sha256 -q`
728 # Perform sanity checks etc. before fetching updates.
729 fetch_check_params () {
730 fetchupgrade_check_params
732 if ! [ -z "${TARGETRELEASE}" ]; then
733 echo -n "`basename $0`: "
734 echo -n "-r option is meaningless with 'fetch' command. "
735 echo "(Did you mean 'upgrade' instead?)"
739 # Check that we have updates ready to install
740 if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then
741 echo "You have a partially completed upgrade pending"
742 echo "Run '$0 install' first."
743 echo "Run '$0 fetch -F' to proceed anyway."
748 # Perform sanity checks etc. before fetching upgrades.
749 upgrade_check_params () {
750 fetchupgrade_check_params
752 # Unless set otherwise, we're upgrading to the same kernel config.
753 NKERNCONF=${KERNCONF}
755 # We need TARGETRELEASE set
756 _TARGETRELEASE_z="Release target must be specified via -r option."
757 if [ -z "${TARGETRELEASE}" ]; then
758 echo -n "`basename $0`: "
759 echo "${_TARGETRELEASE_z}"
763 # The target release should be != the current release.
764 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
765 echo -n "`basename $0`: "
766 echo "Cannot upgrade from ${RELNUM} to itself"
770 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
771 if [ "${ALLOWADD}" = "no" ]; then
772 echo -n "`basename $0`: "
773 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
774 echo "when upgrading between releases."
777 if [ "${ALLOWDELETE}" = "no" ]; then
778 echo -n "`basename $0`: "
779 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
780 echo "when upgrading between releases."
784 # Set EDITOR to /usr/bin/vi if it isn't already set
785 : ${EDITOR:='/usr/bin/vi'}
788 # Perform sanity checks and set some final parameters in
789 # preparation for installing updates.
790 install_check_params () {
791 # Check that we are root. All sorts of things won't work otherwise.
792 if [ `id -u` != 0 ]; then
793 echo "You must be root to run this."
797 # Check that securelevel <= 0. Otherwise we can't update schg files.
798 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
799 echo "Updates cannot be installed when the system securelevel"
800 echo "is greater than zero."
804 # Check that we have a working directory
805 _WORKDIR_bad="Directory does not exist or is not writable: "
806 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
807 echo -n "`basename $0`: "
808 echo -n "${_WORKDIR_bad}"
812 cd ${WORKDIR} || exit 1
814 # Construct a unique name from ${BASEDIR}
815 BDHASH=`echo ${BASEDIR} | sha256 -q`
817 # Check that we have updates ready to install
818 if ! [ -L ${BDHASH}-install ]; then
819 echo "No updates are available to install."
820 if [ $ISFETCHED -eq 0 ]; then
821 echo "Run '$0 fetch' first."
826 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
827 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
828 echo "Update manifest is corrupt -- this should never happen."
829 echo "Re-run '$0 fetch'."
833 # Figure out what directory contains the running kernel
834 BOOTFILE=`sysctl -n kern.bootfile`
835 KERNELDIR=${BOOTFILE%/kernel}
836 if ! [ -d ${KERNELDIR} ]; then
837 echo "Cannot identify running kernel"
842 # Perform sanity checks and set some final parameters in
843 # preparation for UNinstalling updates.
844 rollback_check_params () {
845 # Check that we are root. All sorts of things won't work otherwise.
846 if [ `id -u` != 0 ]; then
847 echo "You must be root to run this."
851 # Check that we have a working directory
852 _WORKDIR_bad="Directory does not exist or is not writable: "
853 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
854 echo -n "`basename $0`: "
855 echo -n "${_WORKDIR_bad}"
859 cd ${WORKDIR} || exit 1
861 # Construct a unique name from ${BASEDIR}
862 BDHASH=`echo ${BASEDIR} | sha256 -q`
864 # Check that we have updates ready to rollback
865 if ! [ -L ${BDHASH}-rollback ]; then
866 echo "No rollback directory found."
869 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
870 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
871 echo "Update manifest is corrupt -- this should never happen."
876 # Perform sanity checks and set some final parameters
877 # in preparation for comparing the system against the
878 # published index. Figure out which index we should
879 # compare against: If the user is running *-p[0-9]+,
880 # strip off the last part; if the user is running
881 # -SECURITY, call it -RELEASE. Chdir into the working
883 IDS_check_params () {
884 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
887 "SERVERNAME must be given via command line or configuration file."
888 _KEYPRINT_z="Key must be given via -k option or configuration file."
889 _KEYPRINT_bad="Invalid key fingerprint: "
890 _WORKDIR_bad="Directory does not exist or is not writable: "
892 if [ -z "${SERVERNAME}" ]; then
893 echo -n "`basename $0`: "
894 echo "${_SERVERNAME_z}"
897 if [ -z "${KEYPRINT}" ]; then
898 echo -n "`basename $0`: "
899 echo "${_KEYPRINT_z}"
902 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
903 echo -n "`basename $0`: "
904 echo -n "${_KEYPRINT_bad}"
908 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
909 echo -n "`basename $0`: "
910 echo -n "${_WORKDIR_bad}"
914 cd ${WORKDIR} || exit 1
916 # Generate release number. The s/SECURITY/RELEASE/ bit exists
917 # to provide an upgrade path for FreeBSD Update 1.x users, since
918 # the kernels provided by FreeBSD Update 1.x are always labelled
921 sed -E 's,-p[0-9]+,,' |
922 sed -E 's,-SECURITY,-RELEASE,'`
924 FETCHDIR=${RELNUM}/${ARCH}
925 PATCHDIR=${RELNUM}/${ARCH}/bp
927 # Figure out what directory contains the running kernel
928 BOOTFILE=`sysctl -n kern.bootfile`
929 KERNELDIR=${BOOTFILE%/kernel}
930 if ! [ -d ${KERNELDIR} ]; then
931 echo "Cannot identify running kernel"
935 # Figure out what kernel configuration is running. We start with
936 # the output of `uname -i`, and then make the following adjustments:
937 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
938 # file says "ident SMP-GENERIC", I don't know...
939 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
940 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
941 # we're running an SMP kernel. This mis-identification is a bug
942 # which was fixed in 6.2-STABLE.
944 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
947 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
948 if sysctl kern.version | grep -qE '/SMP$'; then
955 PHTTPGET=/usr/libexec/phttpget
957 # Set up variables relating to VERBOSELEVEL
958 fetch_setup_verboselevel
961 #### Core functionality -- the actual work gets done here
963 # Use an SRV query to pick a server. If the SRV query doesn't provide
964 # a useful answer, use the server name specified by the user.
965 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
966 # from that; or if no servers are returned, use ${SERVERNAME}.
967 # This allows a user to specify "portsnap.freebsd.org" (in which case
968 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
969 # (in which case portsnap will use that particular server, since there
970 # won't be an SRV entry for that name).
972 # We ignore the Port field, since we are always going to use port 80.
974 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
975 # no mirrors are available for any reason.
976 fetch_pick_server_init () {
979 # Check that host(1) exists (i.e., that the system wasn't built with the
980 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
981 if ! which -s host; then
986 echo -n "Looking up ${SERVERNAME} mirrors... "
988 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
989 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
990 # "$name server selection ..."; we allow either format.
991 MLIST="_http._tcp.${SERVERNAME}"
992 host -t srv "${MLIST}" |
993 sed -nE "s/${MLIST} (has SRV record|server selection) //Ip" |
994 cut -f 1,2,4 -d ' ' |
996 sort > serverlist_full
998 # If no records, give up -- we'll just use the server name we were given.
999 if [ `wc -l < serverlist_full` -eq 0 ]; then
1004 # Report how many mirrors we found.
1005 echo `wc -l < serverlist_full` "mirrors found."
1007 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
1008 # is set, this will be used to generate the seed; otherwise, the seed
1010 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
1011 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
1015 RANDVALUE=`jot -r 1 0 999999999`
1019 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
1020 fetch_pick_server () {
1021 # Generate a list of not-yet-tried mirrors
1022 sort serverlist_tried |
1023 comm -23 serverlist_full - > serverlist
1025 # Have we run out of mirrors?
1026 if [ `wc -l < serverlist` -eq 0 ]; then
1028 No mirrors remaining, giving up.
1030 This may be because upgrading from this platform (${ARCH})
1031 or release (${RELNUM}) is unsupported by `basename $0`. Only
1032 platforms with Tier 1 support can be upgraded by `basename $0`.
1033 See https://www.freebsd.org/platforms/index.html for more info.
1035 If unsupported, FreeBSD must be upgraded by source.
1040 # Find the highest priority level (lowest numeric value).
1041 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
1043 # Add up the weights of the response lines at that priority level.
1048 SRV_W=`echo $X | cut -f 2 -d ' '`
1049 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
1054 # If all the weights are 0, pretend that they are all 1 instead.
1055 if [ ${SRV_WSUM} -eq 0 ]; then
1056 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
1062 # Pick a value between 0 and the sum of the weights - 1
1063 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
1065 # Read through the list of mirrors and set SERVERNAME. Write the line
1066 # corresponding to the mirror we selected into serverlist_tried so that
1067 # we won't try it again.
1071 SRV_W=`echo $X | cut -f 2 -d ' '`
1072 SRV_W=$(($SRV_W + $SRV_W_ADD))
1073 if [ $SRV_RND -lt $SRV_W ]; then
1074 SERVERNAME=`echo $X | cut -f 3 -d ' '`
1075 echo "$X" >> serverlist_tried
1078 SRV_RND=$(($SRV_RND - $SRV_W))
1085 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
1086 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
1087 fetch_make_patchlist () {
1088 grep -vE "^([0-9a-f]{64})\|\1$" |
1091 if [ -f "files/${Y}.gz" ] ||
1092 [ ! -f "files/${X}.gz" ]; then
1099 # Print user-friendly progress statistics
1104 if [ $(($LNC % 10)) = 0 ]; then
1106 elif [ $(($LNC % 2)) = 0 ]; then
1113 # Function for asking the user if everything is ok
1115 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1116 case "${CONTINUE}" in
1127 # Initialize the working directory
1130 touch tINDEX.present
1133 # Check that we have a public key with an appropriate hash, or
1134 # fetch the key if it doesn't exist. Returns 1 if the key has
1135 # not yet been fetched.
1137 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1141 echo -n "Fetching public key from ${SERVERNAME}... "
1143 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1144 2>${QUIETREDIR} || true
1145 if ! [ -r pub.ssl ]; then
1149 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1150 echo "key has incorrect hash."
1157 # Fetch metadata signature, aka "tag".
1159 echo -n "Fetching metadata signature "
1160 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1162 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1163 2>${QUIETREDIR} || true
1164 if ! [ -r latest.ssl ]; then
1169 openssl rsautl -pubin -inkey pub.ssl -verify \
1170 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1173 if ! [ `wc -l < tag.new` = 1 ] ||
1175 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1177 echo "invalid signature."
1183 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1184 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1185 EOLTIME=`cut -f 6 -d '|' < tag.new`
1188 # Sanity-check the patch number in a tag, to make sure that we're not
1189 # going to "update" backwards and to prevent replay attacks.
1190 fetch_tagsanity () {
1191 # Check that we're not going to move from -pX to -pY with Y < X.
1192 RELPX=`uname -r | sed -E 's,.*-,,'`
1193 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1194 RELPX=`echo ${RELPX} | cut -c 2-`
1198 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1200 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1201 echo " appear older than what"
1202 echo "we are currently running (`uname -r`)!"
1203 echo "Cowardly refusing to proceed any further."
1207 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1208 # it contains a patch number <= RELPATCHNUM, in order to protect
1209 # against rollback (replay) attacks.
1212 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1214 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1216 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1218 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1219 echo " are older than the"
1220 echo -n "most recently seen updates"
1221 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1222 echo "Cowardly refusing to proceed any further."
1228 # Fetch metadata index file
1229 fetch_metadata_index () {
1230 echo ${NDEBUG} "Fetching metadata index... "
1232 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1234 if ! [ -f ${TINDEXHASH} ]; then
1238 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1239 echo "update metadata index corrupt."
1245 # Print an error message about signed metadata being bogus.
1246 fetch_metadata_bogus () {
1248 echo "The update metadata$1 is correctly signed, but"
1249 echo "failed an integrity check."
1250 echo "Cowardly refusing to proceed any further."
1254 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1255 # with the lines not named in $@ from tINDEX.present (if that file exists).
1256 fetch_metadata_index_merge () {
1257 for METAFILE in $@; do
1258 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1260 fetch_metadata_bogus " index"
1264 grep -E "${METAFILE}\|" ${TINDEXHASH}
1266 sort > tINDEX.wanted
1268 if [ -f tINDEX.present ]; then
1269 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1270 sort -m - tINDEX.wanted > tINDEX.new
1273 mv tINDEX.wanted tINDEX.new
1277 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1278 # are added by future versions of the server, this won't cause problems,
1279 # since the only lines which appear in tINDEX.new are the ones which we
1280 # specifically grepped out of ${TINDEXHASH}.
1281 fetch_metadata_index_sanity () {
1282 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1283 fetch_metadata_bogus " index"
1288 # Sanity check the metadata file $1.
1289 fetch_metadata_sanity () {
1290 # Some aliases to save space later: ${P} is a character which can
1291 # appear in a path; ${M} is the four numeric metadata fields; and
1292 # ${H} is a sha256 hash.
1293 P="[-+./:=,%@_[~[:alnum:]]"
1294 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1297 # Check that the first four fields make sense.
1298 if gunzip -c < files/$1.gz |
1299 grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then
1300 fetch_metadata_bogus ""
1304 # Remove the first three fields.
1305 gunzip -c < files/$1.gz |
1306 cut -f 4- -d '|' > sanitycheck.tmp
1308 # Sanity check entries with type 'f'
1309 if grep -E '^f' sanitycheck.tmp |
1310 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1311 fetch_metadata_bogus ""
1315 # Sanity check entries with type 'd'
1316 if grep -E '^d' sanitycheck.tmp |
1317 grep -qvE "^d\|${M}\|\|\$"; then
1318 fetch_metadata_bogus ""
1322 # Sanity check entries with type 'L'
1323 if grep -E '^L' sanitycheck.tmp |
1324 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1325 fetch_metadata_bogus ""
1329 # Sanity check entries with type '-'
1330 if grep -E '^-' sanitycheck.tmp |
1331 grep -qvE "^-\|\|\|\|\|\|"; then
1332 fetch_metadata_bogus ""
1340 # Fetch the metadata index and metadata files listed in $@,
1341 # taking advantage of metadata patches where possible.
1343 fetch_metadata_index || return 1
1344 fetch_metadata_index_merge $@ || return 1
1345 fetch_metadata_index_sanity || return 1
1347 # Generate a list of wanted metadata patches
1348 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1349 fetch_make_patchlist > patchlist
1351 if [ -s patchlist ]; then
1352 # Attempt to fetch metadata patches
1353 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1354 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1355 tr '|' '-' < patchlist |
1356 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1357 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1358 2>${STATSREDIR} | fetch_progress
1361 # Attempt to apply metadata patches
1362 echo -n "Applying metadata patches... "
1363 tr '|' ' ' < patchlist |
1365 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1366 gunzip -c < ${X}-${Y}.gz > diff
1367 gunzip -c < files/${X}.gz > diff-OLD
1369 # Figure out which lines are being added and removed
1372 while read PREFIX; do
1373 look "${PREFIX}" diff-OLD
1376 grep -E '^\+' diff |
1377 cut -c 2- > diff-add
1379 # Generate the new file
1380 comm -23 diff-OLD diff-rm |
1381 sort - diff-add > diff-NEW
1383 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1384 mv diff-NEW files/${Y}
1387 mv diff-NEW ${Y}.bad
1389 rm -f ${X}-${Y}.gz diff
1390 rm -f diff-OLD diff-NEW diff-add diff-rm
1391 done 2>${QUIETREDIR}
1395 # Update metadata without patches
1396 cut -f 2 -d '|' < tINDEX.new |
1398 if [ ! -f "files/${Y}.gz" ]; then
1404 if [ -s filelist ]; then
1405 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1406 echo ${NDEBUG} "metadata files... "
1407 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1408 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1412 if ! [ -f ${Y}.gz ]; then
1416 if [ `gunzip -c < ${Y}.gz |
1417 ${SHA256} -q` = ${Y} ]; then
1418 mv ${Y}.gz files/${Y}.gz
1420 echo "metadata is corrupt."
1427 # Sanity-check the metadata files.
1428 cut -f 2 -d '|' tINDEX.new > filelist
1430 fetch_metadata_sanity ${X} || return 1
1433 # Remove files which are no longer needed
1434 cut -f 2 -d '|' tINDEX.present |
1436 cut -f 2 -d '|' tINDEX.new |
1438 comm -13 - oldfiles |
1439 lam -s "files/" - -s ".gz" |
1441 rm patchlist filelist oldfiles
1445 mv tINDEX.new tINDEX.present
1451 # Extract a subset of a downloaded metadata file containing only the parts
1452 # which are listed in COMPONENTS.
1453 fetch_filter_metadata_components () {
1454 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1455 gunzip -c < files/${METAHASH}.gz > $1.all
1457 # Fish out the lines belonging to components we care about.
1458 for C in ${COMPONENTS}; do
1459 look "`echo ${C} | tr '/' '|'`|" $1.all
1462 # Remove temporary file.
1466 # Generate a filtered version of the metadata file $1 from the downloaded
1467 # file, by fishing out the lines corresponding to components we're trying
1468 # to keep updated, and then removing lines corresponding to paths we want
1470 fetch_filter_metadata () {
1471 # Fish out the lines belonging to components we care about.
1472 fetch_filter_metadata_components $1
1474 # Canonicalize directory names by removing any trailing / in
1475 # order to avoid listing directories multiple times if they
1476 # belong to multiple components. Turning "/" into "" doesn't
1477 # matter, since we add a leading "/" when we use paths later.
1478 cut -f 3- -d '|' $1 |
1479 sed -e 's,/|d|,|d|,' |
1480 sed -e 's,/|-|,|-|,' |
1483 # Figure out which lines to ignore and remove them.
1484 for X in ${IGNOREPATHS}; do
1485 grep -E "^${X}" $1.tmp
1488 comm -13 - $1.tmp > $1
1490 # Remove temporary files.
1494 # Filter the metadata file $1 by adding lines with "/boot/$2"
1495 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1496 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1497 # the original lines which start with that.
1498 # Put another way: Deal with the fact that the FOO kernel is sometimes
1499 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1500 fetch_filter_kernel_names () {
1502 sed -e "s,/boot/$2,${KERNELDIR},g" |
1506 if ! [ -d /boot/$2 ]; then
1507 grep -v ^/boot/$2 $1 > $1.tmp
1512 # For all paths appearing in $1 or $3, inspect the system
1513 # and generate $2 describing what is currently installed.
1514 fetch_inspect_system () {
1518 # Tell the user why his disk is suddenly making lots of noise
1519 echo -n "Inspecting system... "
1521 # Generate list of files to inspect
1526 # Examine each file and output lines of the form
1527 # /path/to/file|type|device-inum|user|group|perm|flags|value
1528 # sorted by device and inode number.
1530 # If the symlink/file/directory does not exist, record this.
1531 if ! [ -e ${BASEDIR}/${F} ]; then
1535 if ! [ -r ${BASEDIR}/${F} ]; then
1536 echo "Cannot read file: ${BASEDIR}/${F}" \
1542 # Otherwise, output an index line.
1543 if [ -L ${BASEDIR}/${F} ]; then
1545 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1546 readlink ${BASEDIR}/${F};
1547 elif [ -f ${BASEDIR}/${F} ]; then
1549 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1550 sha256 -q ${BASEDIR}/${F};
1551 elif [ -d ${BASEDIR}/${F} ]; then
1553 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1555 echo "Unknown file type: ${BASEDIR}/${F}" \
1561 sort -k 3,3 -t '|' > $2.tmp
1564 # Check if an error occurred during system inspection
1565 if [ -f .err ]; then
1569 # Convert to the form
1570 # /path/to/file|type|user|group|perm|flags|value|hlink
1571 # by resolving identical device and inode numbers into hard links.
1572 cut -f 1,3 -d '|' $2.tmp |
1573 sort -k 1,1 -t '|' |
1574 sort -s -u -k 2,2 -t '|' |
1575 join -1 2 -2 3 -t '|' - $2.tmp |
1576 awk -F \| -v OFS=\| \
1578 if (($2 == $3) || ($4 == "-"))
1579 print $3,$4,$5,$6,$7,$8,$9,""
1581 print $3,$4,$5,$6,$7,$8,$9,$2
1586 # We're finished looking around
1590 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1591 # files which differ; generate $3 containing these paths and the old hashes.
1592 fetch_filter_mergechanges () {
1593 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1595 for X in ${MERGECHANGES}; do
1596 grep -E "^${X}" ${F}
1598 cut -f 1,2,7 -d '|' |
1602 # Any line in $2-values which doesn't appear in $1-values and is a
1603 # file means that we should list the path in $3.
1604 comm -13 $1-values $2-values |
1606 cut -f 1 -d '|' > $2-paths
1608 # For each path, pull out one (and only one!) entry from $1-values.
1609 # Note that we cannot distinguish which "old" version the user made
1610 # changes to; but hopefully any changes which occur due to security
1611 # updates will exist in both the "new" version and the version which
1612 # the user has installed, so the merging will still work.
1614 look "${X}|" $1-values |
1616 done < $2-paths > $3
1619 rm $1-values $2-values $2-paths
1622 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1623 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1624 # the paths are listed in $4. For entries in $2 marked "not present"
1625 # (aka. type -), remove lines from $[123] unless there is a corresponding
1627 fetch_filter_unmodified_notpresent () {
1628 # Figure out which lines of $1 and $3 correspond to bits which
1629 # should only be updated if they haven't changed, and fish out
1630 # the (path, type, value) tuples.
1631 # NOTE: We don't consider a file to be "modified" if it matches
1633 for X in ${UPDATEIFUNMODIFIED}; do
1637 cut -f 1,2,7 -d '|' |
1640 # Do the same for $2.
1641 for X in ${UPDATEIFUNMODIFIED}; do
1644 cut -f 1,2,7 -d '|' |
1647 # Any entry in $2-values which is not in $1-values corresponds to
1648 # a path which we need to remove from $1, $2, and $3, unless it
1649 # that path appears in $4.
1650 comm -13 $1-values $2-values |
1651 sort -t '|' -k 1,1 > mlines.tmp
1652 cut -f 1 -d '|' $4 |
1654 join -v 2 -t '|' - mlines.tmp |
1656 rm $1-values $2-values mlines.tmp
1658 # Any lines in $2 which are not in $1 AND are "not present" lines
1659 # also belong in mlines.
1661 cut -f 1,2,7 -d '|' |
1662 fgrep '|-|' >> mlines
1664 # Remove lines from $1, $2, and $3
1665 for X in $1 $2 $3; do
1666 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1667 cut -f 1 -d '|' < mlines |
1669 join -v 2 -t '|' - ${X}.tmp |
1674 # Store a list of the modified files, for future reference
1675 fgrep -v '|-|' mlines |
1676 cut -f 1 -d '|' > modifiedfiles
1680 # For each entry in $1 of type -, remove any corresponding
1681 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1682 # of type - from $1.
1683 fetch_filter_allowadd () {
1684 cut -f 1,2 -d '|' < $1 |
1686 cut -f 1 -d '|' > filesnotpresent
1688 if [ ${ALLOWADD} != "yes" ]; then
1690 join -v 1 -t '|' - filesnotpresent |
1696 join -v 1 -t '|' - filesnotpresent |
1702 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1703 # which don't correspond to entries in $2.
1704 fetch_filter_allowdelete () {
1705 # Produce a lists ${PATH}|${TYPE}
1707 cut -f 1-2 -d '|' < ${X} |
1708 sort -u > ${X}.nodes
1711 # Figure out which lines need to be removed from $1.
1712 if [ ${ALLOWDELETE} != "yes" ]; then
1713 comm -23 $1.nodes $2.nodes > $1.badnodes
1718 # Remove the relevant lines from $1
1721 done < $1.badnodes |
1722 comm -13 - $1 > $1.tmp
1725 rm $1.badnodes $1.nodes $2.nodes
1728 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1729 # with metadata not matching any entry in $1, replace the corresponding
1730 # line of $3 with one having the same metadata as the entry in $2.
1731 fetch_filter_modified_metadata () {
1732 # Fish out the metadata from $1 and $2
1734 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1737 # Find the metadata we need to keep
1738 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1739 comm -13 $1.metadata $2.metadata > keepmeta
1744 # Extract the lines which we need to remove from $3, and
1745 # construct the lines which we need to add to $3.
1749 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1750 look "${NODE}|" $3 >> $3.remove
1751 look "${NODE}|" $3 |
1753 lam -s "${LINE}|" - >> $3.add
1756 # Remove the specified lines and add the new lines.
1759 sort -u - $3.add > $3.tmp
1762 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1765 # Remove lines from $1 and $2 which are identical;
1766 # no need to update a file if it isn't changing.
1767 fetch_filter_uptodate () {
1768 comm -23 $1 $2 > $1.tmp
1769 comm -13 $1 $2 > $2.tmp
1775 # Fetch any "clean" old versions of files we need for merging changes.
1776 fetch_files_premerge () {
1777 # We only need to do anything if $1 is non-empty.
1779 # Tell the user what we're doing
1780 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1782 # List of files wanted
1785 sort -u > files.wanted
1787 # Only fetch the files we don't already have
1789 if [ ! -f "files/${Y}.gz" ]; then
1792 done < files.wanted > filelist
1794 # Actually fetch them
1795 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1796 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1799 # Make sure we got them all, and move them into /files/
1801 if ! [ -f ${Y}.gz ]; then
1805 if [ `gunzip -c < ${Y}.gz |
1806 ${SHA256} -q` = ${Y} ]; then
1807 mv ${Y}.gz files/${Y}.gz
1809 echo "${Y} has incorrect hash."
1816 rm filelist files.wanted
1820 # Prepare to fetch files: Generate a list of the files we need,
1821 # copy the unmodified files we have into /files/, and generate
1822 # a list of patches to download.
1823 fetch_files_prepare () {
1824 # Tell the user why his disk is suddenly making lots of noise
1825 echo -n "Preparing to download files... "
1827 # Reduce indices to ${PATH}|${HASH} pairs
1828 for X in $1 $2 $3; do
1829 cut -f 1,2,7 -d '|' < ${X} |
1835 # List of files wanted
1836 cut -f 2 -d '|' < $3.hashes |
1839 if ! [ -f files/${HASH}.gz ]; then
1844 # Generate a list of unmodified files
1845 comm -12 $1.hashes $2.hashes |
1846 sort -k 1,1 -t '|' > unmodified.files
1848 # Copy all files into /files/. We only need the unmodified files
1849 # for use in patching; but we'll want all of them if the user asks
1850 # to rollback the updates later.
1852 F=`echo "${LINE}" | cut -f 1 -d '|'`
1853 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1855 # Skip files we already have.
1856 if [ -f files/${HASH}.gz ]; then
1860 # Make sure the file hasn't changed.
1861 cp "${BASEDIR}/${F}" tmpfile
1862 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1864 echo "File changed while FreeBSD Update running: ${F}"
1868 # Place the file into storage.
1869 gzip -c < tmpfile > files/${HASH}.gz
1873 # Produce a list of patches to download
1874 sort -k 1,1 -t '|' $3.hashes |
1875 join -t '|' -o 2.2,1.2 - unmodified.files |
1876 fetch_make_patchlist > patchlist
1879 rm unmodified.files $1.hashes $2.hashes $3.hashes
1881 # We don't need the list of possible old files any more.
1884 # We're finished making noise
1890 # Attempt to fetch patches
1891 if [ -s patchlist ]; then
1892 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1893 echo ${NDEBUG} "patches.${DDSTATS}"
1894 tr '|' '-' < patchlist |
1895 lam -s "${PATCHDIR}/" - |
1896 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1897 2>${STATSREDIR} | fetch_progress
1900 # Attempt to apply patches
1901 echo -n "Applying patches... "
1902 tr '|' ' ' < patchlist |
1904 if [ ! -f "${X}-${Y}" ]; then continue; fi
1905 gunzip -c < files/${X}.gz > OLD
1907 bspatch OLD NEW ${X}-${Y}
1909 if [ `${SHA256} -q NEW` = ${Y} ]; then
1913 rm -f diff OLD NEW ${X}-${Y}
1914 done 2>${QUIETREDIR}
1918 # Download files which couldn't be generate via patching
1920 if [ ! -f "files/${Y}.gz" ]; then
1923 done < files.wanted > filelist
1925 if [ -s filelist ]; then
1926 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1927 echo ${NDEBUG} "files... "
1928 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1929 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1930 2>${STATSREDIR} | fetch_progress
1933 if ! [ -f ${Y}.gz ]; then
1937 if [ `gunzip -c < ${Y}.gz |
1938 ${SHA256} -q` = ${Y} ]; then
1939 mv ${Y}.gz files/${Y}.gz
1941 echo "${Y} has incorrect hash."
1949 rm files.wanted filelist patchlist
1952 # Create and populate install manifest directory; and report what updates
1954 fetch_create_manifest () {
1955 # If we have an existing install manifest, nuke it.
1956 if [ -L "${BDHASH}-install" ]; then
1957 rm -r ${BDHASH}-install/
1958 rm ${BDHASH}-install
1961 # Report to the user if any updates were avoided due to local changes
1962 if [ -s modifiedfiles ]; then
1963 cat - modifiedfiles <<- EOF | ${PAGER}
1964 The following files are affected by updates. No changes have
1965 been downloaded, however, because the files have been modified
1971 # If no files will be updated, tell the user and exit
1972 if ! [ -s INDEX-PRESENT ] &&
1973 ! [ -s INDEX-NEW ]; then
1974 rm INDEX-PRESENT INDEX-NEW
1976 echo -n "No updates needed to update system to "
1977 echo "${RELNUM}-p${RELPATCHNUM}."
1981 # Divide files into (a) removed files, (b) added files, and
1982 # (c) updated files.
1983 cut -f 1 -d '|' < INDEX-PRESENT |
1984 sort > INDEX-PRESENT.flist
1985 cut -f 1 -d '|' < INDEX-NEW |
1986 sort > INDEX-NEW.flist
1987 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1988 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
1989 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
1990 rm INDEX-PRESENT.flist INDEX-NEW.flist
1992 # Report removed files, if any
1993 if [ -s files.removed ]; then
1994 cat - files.removed <<- EOF | ${PAGER}
1995 The following files will be removed as part of updating to
1996 ${RELNUM}-p${RELPATCHNUM}:
2001 # Report added files, if any
2002 if [ -s files.added ]; then
2003 cat - files.added <<- EOF | ${PAGER}
2004 The following files will be added as part of updating to
2005 ${RELNUM}-p${RELPATCHNUM}:
2010 # Report updated files, if any
2011 if [ -s files.updated ]; then
2012 cat - files.updated <<- EOF | ${PAGER}
2013 The following files will be updated as part of updating to
2014 ${RELNUM}-p${RELPATCHNUM}:
2019 # Create a directory for the install manifest.
2020 MDIR=`mktemp -d install.XXXXXX` || return 1
2023 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
2024 mv INDEX-NEW ${MDIR}/INDEX-NEW
2026 # Link it into place
2027 ln -s ${MDIR} ${BDHASH}-install
2030 # Warn about any upcoming EoL
2032 # What's the current time?
2033 NOWTIME=`date "+%s"`
2035 # When did we last warn about the EoL date?
2036 if [ -f lasteolwarn ]; then
2037 LASTWARN=`cat lasteolwarn`
2039 LASTWARN=`expr ${NOWTIME} - 63072000`
2042 # If the EoL time is past, warn.
2043 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
2046 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
2047 Any security issues discovered after `date -r ${EOLTIME}`
2048 will not have been corrected.
2053 # Figure out how long it has been since we last warned about the
2054 # upcoming EoL, and how much longer we have left.
2055 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
2056 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
2058 # Don't warn if the EoL is more than 3 months away
2059 if [ ${TIMELEFT} -gt 7884000 ]; then
2063 # Don't warn if the time remaining is more than 3 times the time
2064 # since the last warning.
2065 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
2069 # Figure out what time units to use.
2070 if [ ${TIMELEFT} -lt 604800 ]; then
2073 elif [ ${TIMELEFT} -lt 2678400 ]; then
2081 # Compute the right number of units
2082 NUM=`expr ${TIMELEFT} / ${SIZE}`
2083 if [ ${NUM} != 1 ]; then
2090 WARNING: `uname -sr` is approaching its End-of-Life date.
2091 It is strongly recommended that you upgrade to a newer
2092 release within the next ${NUM} ${UNIT}.
2095 # Update the stored time of last warning
2096 echo ${NOWTIME} > lasteolwarn
2099 # Do the actual work involved in "fetch" / "cron".
2101 workdir_init || return 1
2103 # Prepare the mirror list.
2104 fetch_pick_server_init && fetch_pick_server
2106 # Try to fetch the public key until we run out of servers.
2107 while ! fetch_key; do
2108 fetch_pick_server || return 1
2111 # Try to fetch the metadata index signature ("tag") until we run
2112 # out of available servers; and sanity check the downloaded tag.
2113 while ! fetch_tag; do
2114 fetch_pick_server || return 1
2116 fetch_tagsanity || return 1
2118 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2119 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2121 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2122 # the lines which (a) belong to components we care about, and (b)
2123 # don't correspond to paths we're explicitly ignoring.
2124 fetch_filter_metadata INDEX-NEW || return 1
2125 fetch_filter_metadata INDEX-OLD || return 1
2127 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2128 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2129 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2131 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2132 # system and generate an INDEX-PRESENT file.
2133 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2135 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2136 # correspond to lines in INDEX-PRESENT with hashes not appearing
2137 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2138 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2139 # INDEX-OLD with type -.
2140 fetch_filter_unmodified_notpresent \
2141 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2143 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2144 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2145 # of type - from INDEX-PRESENT.
2146 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2148 # If ${ALLOWDELETE} != "yes", then remove any entries from
2149 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2150 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2152 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2153 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2154 # replace the corresponding line of INDEX-NEW with one having the
2155 # same metadata as the entry in INDEX-PRESENT.
2156 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2158 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2159 # no need to update a file if it isn't changing.
2160 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2162 # Prepare to fetch files: Generate a list of the files we need,
2163 # copy the unmodified files we have into /files/, and generate
2164 # a list of patches to download.
2165 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2168 fetch_files || return 1
2170 # Create and populate install manifest directory; and report what
2171 # updates are available.
2172 fetch_create_manifest || return 1
2174 # Warn about any upcoming EoL
2175 fetch_warn_eol || return 1
2178 # If StrictComponents is not "yes", generate a new components list
2179 # with only the components which appear to be installed.
2180 upgrade_guess_components () {
2181 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2182 # Generate filtered INDEX-ALL with only the components listed
2184 fetch_filter_metadata_components $1 || return 1
2186 # Tell the user why his disk is suddenly making lots of noise
2187 echo -n "Inspecting system... "
2189 # Look at the files on disk, and assume that a component is
2190 # supposed to be present if it is more than half-present.
2191 cut -f 1-3 -d '|' < INDEX-ALL |
2193 while read C S F; do
2194 if [ -e ${BASEDIR}/${F} ]; then
2201 sed -E 's,^ +,,' > compfreq
2202 grep ' = ' compfreq |
2204 sort -k 2,2 -t ' ' > compfreq.total
2205 grep ' + ' compfreq |
2207 sort -k 2,2 -t ' ' > compfreq.present
2208 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2209 while read S P T; do
2210 if [ ${T} -ne 0 -a ${P} -gt `expr ${T} / 2` ]; then
2214 cut -f 2 -d ' ' < compfreq.total > comp.total
2215 rm INDEX-ALL compfreq compfreq.total compfreq.present
2217 # We're done making noise.
2220 # Sometimes the kernel isn't installed where INDEX-ALL
2221 # thinks that it should be: In particular, it is often in
2222 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2223 # deal with this, if "kernel|X" is listed in comp.total
2224 # (i.e., is a component which would be upgraded if it is
2225 # found to be present) we will add it to comp.present.
2226 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2227 # not, we print a warning -- the user is running a kernel
2228 # which isn't part of the release.
2229 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2230 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2232 if grep -qE "^kernel\|" comp.total &&
2233 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2236 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2237 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2238 This kernel will not be updated: you MUST update the kernel manually
2239 before running "$0 install".
2243 # Re-sort the list of installed components and generate
2244 # the list of non-installed components.
2245 sort -u < comp.present > comp.present.tmp
2246 mv comp.present.tmp comp.present
2247 comm -13 comp.present comp.total > comp.absent
2249 # Ask the user to confirm that what we have is correct. To
2250 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2251 # subcomponents must be listed in the configuration file).
2253 echo -n "The following components of FreeBSD "
2254 echo "seem to be installed:"
2255 tr '|' '/' < comp.present |
2258 echo -n "The following components of FreeBSD "
2259 echo "do not seem to be installed:"
2260 tr '|' '/' < comp.absent |
2263 continuep || return 1
2266 # Suck the generated list of components into ${COMPONENTS}.
2267 # Note that comp.present.tmp is used due to issues with
2268 # pipelines and setting variables.
2270 tr '|' '/' < comp.present > comp.present.tmp
2272 COMPONENTS="${COMPONENTS} ${C}"
2273 done < comp.present.tmp
2275 # Delete temporary files
2276 rm comp.present comp.present.tmp comp.absent comp.total
2280 # If StrictComponents is not "yes", COMPONENTS contains an entry
2281 # corresponding to the currently running kernel, and said kernel
2282 # does not exist in the new release, add "kernel/generic" to the
2283 # list of components.
2284 upgrade_guess_new_kernel () {
2285 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2286 # Grab the unfiltered metadata file.
2287 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2288 gunzip -c < files/${METAHASH}.gz > $1.all
2290 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2291 # isn't in $1.all, we need to add kernel/generic.
2292 for C in ${COMPONENTS}; do
2293 if [ ${C} = "kernel/${KCOMP}" ] &&
2294 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2295 COMPONENTS="${COMPONENTS} kernel/generic"
2299 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2300 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2301 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2302 replaced with a "generic" kernel.
2304 continuep || return 1
2308 # Don't need this any more...
2313 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2314 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2315 upgrade_oldall_to_oldnew () {
2316 # For each ${F}|... which appears in INDEX-ALL but does not appear
2317 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2318 cut -f 1 -d '|' < $1 |
2320 cut -f 1 -d '|' < $2 |
2322 comm -13 $1.paths - |
2323 lam - -s "|-||||||" |
2327 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2328 comm -23 $1 $2 > $1.tmp
2331 # Remove lines from INDEX-ALL which have a file name not appearing
2332 # anywhere in INDEX-OLD (since these must be files which haven't
2333 # changed -- if they were new, there would be an entry of type "-").
2334 cut -f 1 -d '|' < $1 |
2336 sort -k 1,1 -t '|' < $2 |
2337 join -t '|' - $1.paths |
2342 # Rename INDEX-ALL to INDEX-NEW.
2346 # Helper for upgrade_merge: Return zero true iff the two files differ only
2347 # in the contents of their RCS tags.
2349 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2350 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2352 if [ $X = $Y ]; then
2359 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2360 # and update $3 to reflect the hashes of merged files.
2362 # We only need to do anything if $1 is non-empty.
2364 cut -f 1 -d '|' $1 |
2367 # Create staging area for merging files
2371 mkdir -p merge/old/${D}
2372 mkdir -p merge/${OLDRELNUM}/${D}
2373 mkdir -p merge/${RELNUM}/${D}
2374 mkdir -p merge/new/${D}
2379 # Currently installed file
2380 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2381 gunzip < files/${V}.gz > merge/old/${F}
2384 if look "${F}|" $1 | fgrep -q "|f|"; then
2385 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2386 gunzip < files/${V}.gz \
2387 > merge/${OLDRELNUM}/${F}
2391 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2392 fgrep -q "|f|"; then
2393 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2394 gunzip < files/${V}.gz \
2395 > merge/${RELNUM}/${F}
2399 # Attempt to automatically merge changes
2400 echo -n "Attempting to automatically merge "
2401 echo -n "changes in files..."
2404 # If the file doesn't exist in the new release,
2405 # the result of "merging changes" is having the file
2407 if ! [ -f merge/${RELNUM}/${F} ]; then
2411 # If the file didn't exist in the old release, we're
2412 # going to throw away the existing file and hope that
2413 # the version from the new release is what we want.
2414 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2415 cp merge/${RELNUM}/${F} merge/new/${F}
2419 # Some files need special treatment.
2421 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2422 # Don't merge these -- we're rebuild them
2423 # after updates are installed.
2424 cp merge/old/${F} merge/new/${F}
2427 if ! diff3 -E -m -L "current version" \
2428 -L "${OLDRELNUM}" -L "${RELNUM}" \
2430 merge/${OLDRELNUM}/${F} \
2431 merge/${RELNUM}/${F} \
2432 > merge/new/${F} 2>/dev/null; then
2433 echo ${F} >> failed.merges
2440 # Ask the user to handle any files which didn't merge.
2442 # If the installed file differs from the version in
2443 # the old release only due to RCS tag expansion
2444 # then just use the version in the new release.
2445 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2446 cp merge/${RELNUM}/${F} merge/new/${F}
2452 The following file could not be merged automatically: ${F}
2453 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2456 read dummy </dev/tty
2457 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2458 done < failed.merges
2461 # Ask the user to confirm that he likes how the result
2464 # Skip files which haven't changed except possibly
2465 # in their RCS tags.
2466 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2467 samef merge/old/${F} merge/new/${F}; then
2471 # Skip files where the installed file differs from
2472 # the old file only due to RCS tags.
2473 if [ -f merge/old/${F} ] &&
2474 [ -f merge/${OLDRELNUM}/${F} ] &&
2475 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2479 # Warn about files which are ceasing to exist.
2480 if ! [ -f merge/new/${F} ]; then
2483 The following file will be removed, as it no longer exists in
2484 FreeBSD ${RELNUM}: ${F}
2486 continuep < /dev/tty || return 1
2490 # Print changes for the user's approval.
2493 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2494 FreeBSD ${RELNUM} have been merged into ${F}:
2496 diff -U 5 -L "current version" -L "new version" \
2497 merge/old/${F} merge/new/${F} || true
2498 continuep < /dev/tty || return 1
2501 # Store merged files.
2503 if [ -f merge/new/${F} ]; then
2504 V=`${SHA256} -q merge/new/${F}`
2506 gzip -c < merge/new/${F} > files/${V}.gz
2509 done < $1-paths > newhashes
2511 # Pull lines out from $3 which need to be updated to
2512 # reflect merged files.
2515 done < $1-paths > $3-oldlines
2517 # Update lines to reflect merged files
2518 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2519 $3-oldlines newhashes > $3-newlines
2521 # Remove old lines from $3 and add new lines.
2524 sort - $3-newlines > $3.tmp
2528 rm $1-paths newhashes $3-oldlines $3-newlines
2532 # We're done with merging files.
2536 # Do the work involved in fetching upgrades to a new release
2538 workdir_init || return 1
2540 # Prepare the mirror list.
2541 fetch_pick_server_init && fetch_pick_server
2543 # Try to fetch the public key until we run out of servers.
2544 while ! fetch_key; do
2545 fetch_pick_server || return 1
2548 # Try to fetch the metadata index signature ("tag") until we run
2549 # out of available servers; and sanity check the downloaded tag.
2550 while ! fetch_tag; do
2551 fetch_pick_server || return 1
2553 fetch_tagsanity || return 1
2555 # Fetch the INDEX-OLD and INDEX-ALL.
2556 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2558 # If StrictComponents is not "yes", generate a new components list
2559 # with only the components which appear to be installed.
2560 upgrade_guess_components INDEX-ALL || return 1
2562 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2563 # the components we want and without anything marked as "Ignore".
2564 fetch_filter_metadata INDEX-OLD || return 1
2565 fetch_filter_metadata INDEX-ALL || return 1
2567 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2568 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2569 mv INDEX-OLD.tmp INDEX-OLD
2572 # Adjust variables for fetching files from the new release.
2574 RELNUM=${TARGETRELEASE}
2575 OLDFETCHDIR=${FETCHDIR}
2576 FETCHDIR=${RELNUM}/${ARCH}
2578 # Try to fetch the NEW metadata index signature ("tag") until we run
2579 # out of available servers; and sanity check the downloaded tag.
2580 while ! fetch_tag; do
2581 fetch_pick_server || return 1
2584 # Fetch the new INDEX-ALL.
2585 fetch_metadata INDEX-ALL || return 1
2587 # If StrictComponents is not "yes", COMPONENTS contains an entry
2588 # corresponding to the currently running kernel, and said kernel
2589 # does not exist in the new release, add "kernel/generic" to the
2590 # list of components.
2591 upgrade_guess_new_kernel INDEX-ALL || return 1
2593 # Filter INDEX-ALL to contain only the components we want and without
2594 # anything marked as "Ignore".
2595 fetch_filter_metadata INDEX-ALL || return 1
2597 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2598 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2599 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2601 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2602 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2603 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2605 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2606 # system and generate an INDEX-PRESENT file.
2607 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2609 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2610 # paths and hashes of old versions of files to merge.
2611 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2613 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2614 # correspond to lines in INDEX-PRESENT with hashes not appearing
2615 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2616 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2617 # INDEX-OLD with type -.
2618 fetch_filter_unmodified_notpresent \
2619 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2621 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2622 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2623 # of type - from INDEX-PRESENT.
2624 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2626 # If ${ALLOWDELETE} != "yes", then remove any entries from
2627 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2628 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2630 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2631 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2632 # replace the corresponding line of INDEX-NEW with one having the
2633 # same metadata as the entry in INDEX-PRESENT.
2634 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2636 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2637 # no need to update a file if it isn't changing.
2638 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2640 # Fetch "clean" files from the old release for merging changes.
2641 fetch_files_premerge tomerge-old
2643 # Prepare to fetch files: Generate a list of the files we need,
2644 # copy the unmodified files we have into /files/, and generate
2645 # a list of patches to download.
2646 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2648 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2649 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2650 fetch_files || return 1
2652 # Merge configuration file changes.
2653 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2655 # Create and populate install manifest directory; and report what
2656 # updates are available.
2657 fetch_create_manifest || return 1
2659 # Leave a note behind to tell the "install" command that the kernel
2660 # needs to be installed before the world.
2661 touch ${BDHASH}-install/kernelfirst
2663 # Remind the user that they need to run "freebsd-update install"
2664 # to install the downloaded bits, in case they didn't RTFM.
2665 echo "To install the downloaded upgrades, run \"$0 install\"."
2668 # Make sure that all the file hashes mentioned in $@ have corresponding
2669 # gzipped files stored in /files/.
2671 # Generate a list of hashes
2678 # Make sure all the hashes exist
2680 if ! [ -f files/${HASH}.gz ]; then
2681 echo -n "Update files missing -- "
2682 echo "this should never happen."
2683 echo "Re-run '$0 fetch'."
2692 # Remove the system immutable flag from files
2694 # Generate file list
2696 cut -f 1 -d '|' > filelist
2700 if ! [ -e ${BASEDIR}/${F} ]; then
2703 echo ${BASEDIR}/${F}
2705 done < filelist | xargs chflags noschg || return 1
2711 # Decide which directory name to use for kernel backups.
2712 backup_kernel_finddir () {
2715 # Pathname does not exist, so it is OK use that name
2716 # for backup directory.
2717 if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then
2721 # If directory do exist, we only use if it has our
2723 if [ -d $BASEDIR/$BACKUPKERNELDIR -a \
2724 -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then
2728 # We could not use current directory name, so add counter to
2729 # the end and try again.
2731 if [ $CNT -gt 9 ]; then
2732 echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)"
2735 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2736 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2740 # Backup the current kernel using hardlinks, if not disabled by user.
2741 # Since we delete all files in the directory used for previous backups
2742 # we create a marker file called ".freebsd-update" in the directory so
2743 # we can determine on the next run that the directory was created by
2744 # freebsd-update and we then do not accidentally remove user files in
2745 # the unlikely case that the user has created a directory with a
2748 # Only make kernel backup is so configured.
2749 if [ $BACKUPKERNEL != yes ]; then
2753 # Decide which directory name to use for kernel backups.
2754 backup_kernel_finddir
2756 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2757 # "not ours", backup_kernel_finddir would have exited, so
2758 # deleting the directory content is as safe as we can make it.
2759 if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then
2760 rm -fr $BASEDIR/$BACKUPKERNELDIR
2763 # Create directories for backup.
2764 mkdir -p $BASEDIR/$BACKUPKERNELDIR
2765 mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \
2766 mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null
2768 # Mark the directory as having been created by freebsd-update.
2769 touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update
2770 if [ $? -ne 0 ]; then
2771 echo "Could not create kernel backup directory"
2775 # Disable pathname expansion to be sure *.symbols is not
2779 # Use find to ignore symbol files, unless disabled by user.
2780 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2783 FINDFILTER="-a ! -name *.debug -a ! -name *.symbols"
2786 # Backup all the kernel files using hardlinks.
2787 (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \
2788 cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;)
2790 # Re-enable patchname expansion.
2795 install_from_index () {
2796 # First pass: Do everything apart from setting file flags. We
2797 # can't set flags yet, because schg inhibits hard linking.
2798 sort -k 1,1 -t '|' $1 |
2800 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2803 # Create a directory
2804 install -d -o ${OWNER} -g ${GROUP} \
2805 -m ${PERM} ${BASEDIR}/${FPATH}
2808 if [ -z "${LINK}" ]; then
2809 # Create a file, without setting flags.
2810 gunzip < files/${HASH}.gz > ${HASH}
2811 install -S -o ${OWNER} -g ${GROUP} \
2812 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2815 # Create a hard link.
2816 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2821 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2826 # Perform a second pass, adding file flags.
2828 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2829 if [ ${TYPE} = "f" ] &&
2830 ! [ ${FLAGS} = "0" ]; then
2831 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2836 # Remove files which we want to delete
2838 # Generate list of new files
2839 cut -f 1 -d '|' < $2 |
2842 # Generate subindex of old files we want to nuke
2843 sort -k 1,1 -t '|' $1 |
2844 join -t '|' -v 1 - newfiles |
2845 sort -r -k 1,1 -t '|' |
2847 tr '|' ' ' > killfiles
2849 # Remove the offending bits
2850 while read FPATH TYPE; do
2853 rmdir ${BASEDIR}/${FPATH}
2856 rm ${BASEDIR}/${FPATH}
2859 rm ${BASEDIR}/${FPATH}
2865 rm newfiles killfiles
2868 # Install new files, delete old files, and update linker.hints
2870 # If we haven't already dealt with the kernel, deal with it.
2871 if ! [ -f $1/kerneldone ]; then
2872 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2873 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2875 # Backup current kernel before installing a new one
2876 backup_kernel || return 1
2879 install_from_index INDEX-NEW || return 1
2881 # Remove files which need to be deleted
2882 install_delete INDEX-OLD INDEX-NEW || return 1
2884 # Update linker.hints if necessary
2885 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2886 kldxref -R ${BASEDIR}/boot/ 2>/dev/null
2889 # We've finished updating the kernel.
2892 # Do we need to ask for a reboot now?
2893 if [ -f $1/kernelfirst ] &&
2894 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2897 Kernel updates have been installed. Please reboot and run
2898 "$0 install" again to finish installing updates.
2904 # If we haven't already dealt with the world, deal with it.
2905 if ! [ -f $1/worlddone ]; then
2906 # Create any necessary directories first
2907 grep -vE '^/boot/' $1/INDEX-NEW |
2908 grep -E '^[^|]+\|d\|' > INDEX-NEW
2909 install_from_index INDEX-NEW || return 1
2911 # Install new runtime linker
2912 grep -vE '^/boot/' $1/INDEX-NEW |
2913 grep -vE '^[^|]+\|d\|' |
2914 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2915 install_from_index INDEX-NEW || return 1
2917 # Install new shared libraries next
2918 grep -vE '^/boot/' $1/INDEX-NEW |
2919 grep -vE '^[^|]+\|d\|' |
2920 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2921 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2922 install_from_index INDEX-NEW || return 1
2924 # Deal with everything else
2925 grep -vE '^/boot/' $1/INDEX-OLD |
2926 grep -vE '^[^|]+\|d\|' |
2927 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2928 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2929 grep -vE '^/boot/' $1/INDEX-NEW |
2930 grep -vE '^[^|]+\|d\|' |
2931 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2932 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2933 install_from_index INDEX-NEW || return 1
2934 install_delete INDEX-OLD INDEX-NEW || return 1
2936 # Rebuild generated pwd files.
2937 if [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/spwd.db ] ||
2938 [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/pwd.db ] ||
2939 [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/passwd ]; then
2940 pwd_mkdb -d ${BASEDIR}/etc -p ${BASEDIR}/etc/master.passwd
2943 # Rebuild /etc/login.conf.db if necessary.
2944 if [ ${BASEDIR}/etc/login.conf -nt ${BASEDIR}/etc/login.conf.db ]; then
2945 cap_mkdb ${BASEDIR}/etc/login.conf
2948 # Rebuild man page databases, if necessary.
2949 for D in /usr/share/man /usr/share/openssl/man; do
2950 if [ ! -d ${BASEDIR}/$D ]; then
2953 if [ -z "$(find ${BASEDIR}/$D -type f -newer ${BASEDIR}/$D/mandoc.db)" ]; then
2956 makewhatis ${BASEDIR}/$D
2959 # We've finished installing the world and deleting old files
2960 # which are not shared libraries.
2963 # Do we need to ask the user to portupgrade now?
2964 grep -vE '^/boot/' $1/INDEX-NEW |
2965 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2968 if grep -vE '^/boot/' $1/INDEX-OLD |
2969 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2972 join -v 1 - newfiles |
2976 Completing this upgrade requires removing old shared object files.
2977 Please rebuild all installed 3rd party software (e.g., programs
2978 installed from the ports tree) and then run "$0 install"
2979 again to finish installing updates.
2987 # Remove old shared libraries
2988 grep -vE '^/boot/' $1/INDEX-NEW |
2989 grep -vE '^[^|]+\|d\|' |
2990 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2991 grep -vE '^/boot/' $1/INDEX-OLD |
2992 grep -vE '^[^|]+\|d\|' |
2993 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2994 install_delete INDEX-OLD INDEX-NEW || return 1
2996 # Remove old directories
2997 grep -vE '^/boot/' $1/INDEX-NEW |
2998 grep -E '^[^|]+\|d\|' > INDEX-NEW
2999 grep -vE '^/boot/' $1/INDEX-OLD |
3000 grep -E '^[^|]+\|d\|' > INDEX-OLD
3001 install_delete INDEX-OLD INDEX-NEW || return 1
3003 # Remove temporary files
3004 rm INDEX-OLD INDEX-NEW
3007 # Rearrange bits to allow the installed updates to be rolled back
3008 install_setup_rollback () {
3009 # Remove the "reboot after installing kernel", "kernel updated", and
3010 # "finished installing the world" flags if present -- they are
3011 # irrelevant when rolling back updates.
3012 if [ -f ${BDHASH}-install/kernelfirst ]; then
3013 rm ${BDHASH}-install/kernelfirst
3014 rm ${BDHASH}-install/kerneldone
3016 if [ -f ${BDHASH}-install/worlddone ]; then
3017 rm ${BDHASH}-install/worlddone
3020 if [ -L ${BDHASH}-rollback ]; then
3021 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
3024 mv ${BDHASH}-install ${BDHASH}-rollback
3027 # Actually install updates
3029 echo -n "Installing updates..."
3031 # Make sure we have all the files we should have
3032 install_verify ${BDHASH}-install/INDEX-OLD \
3033 ${BDHASH}-install/INDEX-NEW || return 1
3035 # Remove system immutable flag from files
3036 install_unschg ${BDHASH}-install/INDEX-OLD \
3037 ${BDHASH}-install/INDEX-NEW || return 1
3039 # Install new files, delete old files, and update linker.hints
3040 install_files ${BDHASH}-install || return 1
3042 # Rearrange bits to allow the installed updates to be rolled back
3043 install_setup_rollback
3048 # Rearrange bits to allow the previous set of updates to be rolled back next.
3049 rollback_setup_rollback () {
3050 if [ -L ${BDHASH}-rollback/rollback ]; then
3051 mv ${BDHASH}-rollback/rollback rollback-tmp
3052 rm -r ${BDHASH}-rollback/
3053 rm ${BDHASH}-rollback
3054 mv rollback-tmp ${BDHASH}-rollback
3056 rm -r ${BDHASH}-rollback/
3057 rm ${BDHASH}-rollback
3061 # Install old files, delete new files, and update linker.hints
3063 # Install old shared library files which don't have the same path as
3064 # a new shared library file.
3065 grep -vE '^/boot/' $1/INDEX-NEW |
3066 grep -E '/lib/.*\.so\.[0-9]+\|' |
3068 sort > INDEX-NEW.libs.flist
3069 grep -vE '^/boot/' $1/INDEX-OLD |
3070 grep -E '/lib/.*\.so\.[0-9]+\|' |
3071 sort -k 1,1 -t '|' - |
3072 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
3073 install_from_index INDEX-OLD || return 1
3075 # Deal with files which are neither kernel nor shared library
3076 grep -vE '^/boot/' $1/INDEX-OLD |
3077 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3078 grep -vE '^/boot/' $1/INDEX-NEW |
3079 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3080 install_from_index INDEX-OLD || return 1
3081 install_delete INDEX-NEW INDEX-OLD || return 1
3083 # Install any old shared library files which we didn't install above.
3084 grep -vE '^/boot/' $1/INDEX-OLD |
3085 grep -E '/lib/.*\.so\.[0-9]+\|' |
3086 sort -k 1,1 -t '|' - |
3087 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
3088 install_from_index INDEX-OLD || return 1
3090 # Delete unneeded shared library files
3091 grep -vE '^/boot/' $1/INDEX-OLD |
3092 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3093 grep -vE '^/boot/' $1/INDEX-NEW |
3094 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3095 install_delete INDEX-NEW INDEX-OLD || return 1
3097 # Deal with kernel files
3098 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
3099 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3100 install_from_index INDEX-OLD || return 1
3101 install_delete INDEX-NEW INDEX-OLD || return 1
3102 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3103 kldxref -R /boot/ 2>/dev/null
3106 # Remove temporary files
3107 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3110 # Actually rollback updates
3112 echo -n "Uninstalling updates..."
3114 # If there are updates waiting to be installed, remove them; we
3115 # want the user to re-run 'fetch' after rolling back updates.
3116 if [ -L ${BDHASH}-install ]; then
3117 rm -r ${BDHASH}-install/
3118 rm ${BDHASH}-install
3121 # Make sure we have all the files we should have
3122 install_verify ${BDHASH}-rollback/INDEX-NEW \
3123 ${BDHASH}-rollback/INDEX-OLD || return 1
3125 # Remove system immutable flag from files
3126 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3127 ${BDHASH}-rollback/INDEX-OLD || return 1
3129 # Install old files, delete new files, and update linker.hints
3130 rollback_files ${BDHASH}-rollback || return 1
3132 # Remove the rollback directory and the symlink pointing to it; and
3133 # rearrange bits to allow the previous set of updates to be rolled
3135 rollback_setup_rollback
3140 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3142 # Get all the lines which mismatch in something other than file
3143 # flags. We ignore file flags because sysinstall doesn't seem to
3144 # set them when it installs FreeBSD; warning about these adds a
3145 # very large amount of noise.
3146 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3147 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3148 cut -f 1-5,7-8 -d '|' $2 |
3149 comm -13 $1.noflags - |
3150 fgrep -v '|-|||||' |
3151 sort -k 1,1 -t '|' |
3152 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3154 # Ignore files which match IDSIGNOREPATHS.
3155 for X in ${IDSIGNOREPATHS}; do
3156 grep -E "^${X}" INDEX-NOTMATCHING
3159 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3160 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3162 # Go through the lines and print warnings.
3164 while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do
3165 # Warn about different object types.
3166 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3167 echo -n "${FPATH} is a "
3169 f) echo -n "regular file, "
3171 d) echo -n "directory, "
3173 L) echo -n "symlink, "
3176 echo -n "but should be a "
3178 f) echo -n "regular file."
3180 d) echo -n "directory."
3182 L) echo -n "symlink."
3187 # Skip other tests, since they don't make sense if
3188 # we're comparing different object types.
3192 # Warn about different owners.
3193 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3194 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3195 echo "but should be owned by user id ${OWNER}."
3198 # Warn about different groups.
3199 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3200 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3201 echo "but should be owned by group id ${GROUP}."
3204 # Warn about different permissions. We do not warn about
3205 # different permissions on symlinks, since some archivers
3206 # don't extract symlink permissions correctly and they are
3208 if ! [ "${PERM}" = "${P_PERM}" ] &&
3209 ! [ "${TYPE}" = "L" ]; then
3210 echo -n "${FPATH} has ${P_PERM} permissions, "
3211 echo "but should have ${PERM} permissions."
3214 # Warn about different file hashes / symlink destinations.
3215 if ! [ "${HASH}" = "${P_HASH}" ]; then
3216 if [ "${TYPE}" = "L" ]; then
3217 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3218 echo "but should be a symlink to ${HASH}."
3220 if [ "${TYPE}" = "f" ]; then
3221 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3222 echo "but should have SHA256 hash ${HASH}."
3226 # We don't warn about different hard links, since some
3227 # some archivers break hard links, and as long as the
3228 # underlying data is correct they really don't matter.
3229 done < INDEX-NOTMATCHING
3232 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3235 # Do the work involved in comparing the system to a "known good" index
3237 workdir_init || return 1
3239 # Prepare the mirror list.
3240 fetch_pick_server_init && fetch_pick_server
3242 # Try to fetch the public key until we run out of servers.
3243 while ! fetch_key; do
3244 fetch_pick_server || return 1
3247 # Try to fetch the metadata index signature ("tag") until we run
3248 # out of available servers; and sanity check the downloaded tag.
3249 while ! fetch_tag; do
3250 fetch_pick_server || return 1
3252 fetch_tagsanity || return 1
3254 # Fetch INDEX-OLD and INDEX-ALL.
3255 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3257 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3258 # the components we want and without anything marked as "Ignore".
3259 fetch_filter_metadata INDEX-OLD || return 1
3260 fetch_filter_metadata INDEX-ALL || return 1
3262 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3263 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3264 mv INDEX-ALL.tmp INDEX-ALL
3267 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3268 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3270 # Inspect the system and generate an INDEX-PRESENT file.
3271 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3273 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3275 IDS_compare INDEX-ALL INDEX-PRESENT
3278 #### Main functions -- call parameter-handling and core functions
3280 # Using the command line, configuration file, and defaults,
3281 # set all the parameters which are needed later.
3289 # Fetch command. Make sure that we're being called
3290 # interactively, then run fetch_check_params and fetch_run
3292 if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then
3293 echo -n "`basename $0` fetch should not "
3294 echo "be run non-interactively."
3295 echo "Run `basename $0` cron instead."
3303 # Cron command. Make sure the parameters are sensible; wait
3304 # rand(3600) seconds; then fetch updates. While fetching updates,
3305 # send output to a temporary file; only print that file if the
3309 sleep `jot -r 1 0 3600`
3311 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3312 if ! fetch_run >> ${TMPFILE} ||
3313 ! grep -q "No updates needed" ${TMPFILE} ||
3314 [ ${VERBOSELEVEL} = "debug" ]; then
3315 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3321 # Fetch files for upgrading to a new release.
3323 upgrade_check_params
3324 upgrade_run || exit 1
3327 # Install downloaded updates.
3329 install_check_params
3330 install_run || exit 1
3333 # Rollback most recently installed updates.
3335 rollback_check_params
3336 rollback_run || exit 1
3339 # Compare system against a "known good" index.
3347 # Make sure we find utilities from the base system
3348 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3350 # Set a pager if the user doesn't
3351 if [ -z "$PAGER" ]; then
3355 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3359 for COMMAND in ${COMMANDS}; do