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 updatesready -- Check if there are fetched updates ready to install
66 install -- Install downloaded updates or upgrades
67 rollback -- Uninstall most recently installed updates
68 IDS -- Compare the system against an index of "known good" files
69 showconfig -- Show configuration
74 #### Configuration processing functions
77 # Configuration options are set in the following order of priority:
78 # 1. Command line options
79 # 2. Configuration file options
81 # In addition, certain options (e.g., IgnorePaths) can be specified multiple
82 # times and (as long as these are all in the same place, e.g., inside the
83 # configuration file) they will accumulate. Finally, because the path to the
84 # configuration file can be specified at the command line, the entire command
85 # line must be processed before we start reading the configuration file.
87 # Sound like a mess? It is. Here's how we handle this:
88 # 1. Initialize CONFFILE and all the options to "".
89 # 2. Process the command line. Throw an error if a non-accumulating option
91 # 3. If CONFFILE is "", set CONFFILE to /etc/freebsd-update.conf .
92 # 4. For all the configuration options X, set X_saved to X.
93 # 5. Initialize all the options to "".
94 # 6. Read CONFFILE line by line, parsing options.
95 # 7. For each configuration option X, set X to X_saved iff X_saved is not "".
96 # 8. Repeat steps 4-7, except setting options to their default values at (6).
98 CONFIGOPTIONS="KEYPRINT WORKDIR SERVERNAME MAILTO ALLOWADD ALLOWDELETE
99 KEEPMODIFIEDMETADATA COMPONENTS IGNOREPATHS UPDATEIFUNMODIFIED
100 BASEDIR VERBOSELEVEL TARGETRELEASE STRICTCOMPONENTS MERGECHANGES
101 IDSIGNOREPATHS BACKUPKERNEL BACKUPKERNELDIR BACKUPKERNELSYMBOLFILES"
103 # Set all the configuration options to "".
105 for X in ${CONFIGOPTIONS}; do
110 # For each configuration option X, set X_saved to X.
112 for X in ${CONFIGOPTIONS}; do
113 eval ${X}_saved=\$${X}
117 # For each configuration option X, set X to X_saved if X_saved is not "".
119 for X in ${CONFIGOPTIONS}; do
121 if ! [ -z "${_}" ]; then
122 eval ${X}=\$${X}_saved
127 # Set the trusted keyprint.
129 if [ -z ${KEYPRINT} ]; then
136 # Set the working directory.
138 if [ -z ${WORKDIR} ]; then
145 # Set the name of the server (pool) from which to fetch updates
146 config_ServerName () {
147 if [ -z ${SERVERNAME} ]; then
154 # Set the address to which 'cron' output will be mailed.
156 if [ -z ${MAILTO} ]; then
163 # Set whether FreeBSD Update is allowed to add files (or directories, or
164 # symlinks) which did not previously exist.
166 if [ -z ${ALLOWADD} ]; then
183 # Set whether FreeBSD Update is allowed to remove files/directories/symlinks.
184 config_AllowDelete () {
185 if [ -z ${ALLOWDELETE} ]; then
202 # Set whether FreeBSD Update should keep existing inode ownership,
203 # permissions, and flags, in the event that they have been modified locally
205 config_KeepModifiedMetadata () {
206 if [ -z ${KEEPMODIFIEDMETADATA} ]; then
209 KEEPMODIFIEDMETADATA=yes
212 KEEPMODIFIEDMETADATA=no
223 # Add to the list of components which should be kept updated.
224 config_Components () {
226 COMPONENTS="${COMPONENTS} ${C}"
230 # Remove src component from list if it isn't installed
231 finalize_components_config () {
234 if [ "$C" = "src" ]; then
235 if [ -e "${BASEDIR}/usr/src/COPYRIGHT" ]; then
236 COMPONENTS="${COMPONENTS} ${C}"
238 echo "src component not installed, skipped"
241 COMPONENTS="${COMPONENTS} ${C}"
246 # Add to the list of paths under which updates will be ignored.
247 config_IgnorePaths () {
249 IGNOREPATHS="${IGNOREPATHS} ${C}"
253 # Add to the list of paths which IDS should ignore.
254 config_IDSIgnorePaths () {
256 IDSIGNOREPATHS="${IDSIGNOREPATHS} ${C}"
260 # Add to the list of paths within which updates will be performed only if the
261 # file on disk has not been modified locally.
262 config_UpdateIfUnmodified () {
264 UPDATEIFUNMODIFIED="${UPDATEIFUNMODIFIED} ${C}"
268 # Add to the list of paths within which updates to text files will be merged
269 # instead of overwritten.
270 config_MergeChanges () {
272 MERGECHANGES="${MERGECHANGES} ${C}"
276 # Work on a FreeBSD installation mounted under $1
278 if [ -z ${BASEDIR} ]; then
285 # When fetching upgrades, should we assume the user wants exactly the
286 # components listed in COMPONENTS, rather than trying to guess based on
287 # what's currently installed?
288 config_StrictComponents () {
289 if [ -z ${STRICTCOMPONENTS} ]; then
306 # Upgrade to FreeBSD $1
307 config_TargetRelease () {
308 if [ -z ${TARGETRELEASE} ]; then
313 if echo ${TARGETRELEASE} | grep -qE '^[0-9.]+$'; then
314 TARGETRELEASE="${TARGETRELEASE}-RELEASE"
318 # Pretend current release is FreeBSD $1
319 config_SourceRelease () {
321 if echo ${UNAME_r} | grep -qE '^[0-9.]+$'; then
322 UNAME_r="${UNAME_r}-RELEASE"
327 # Define what happens to output of utilities
328 config_VerboseLevel () {
329 if [ -z ${VERBOSELEVEL} ]; then
331 [Dd][Ee][Bb][Uu][Gg])
334 [Nn][Oo][Ss][Tt][Aa][Tt][Ss])
337 [Ss][Tt][Aa][Tt][Ss])
349 config_BackupKernel () {
350 if [ -z ${BACKUPKERNEL} ]; then
367 config_BackupKernelDir () {
368 if [ -z ${BACKUPKERNELDIR} ]; then
370 echo "BackupKernelDir set to empty dir"
374 # We check for some paths which would be extremely odd
375 # to use, but which could cause a lot of problems if
378 /|/bin|/boot|/etc|/lib|/libexec|/sbin|/usr|/var)
379 echo "BackupKernelDir set to invalid path $1"
386 echo "BackupKernelDir ($1) is not an absolute path"
395 config_BackupKernelSymbolFiles () {
396 if [ -z ${BACKUPKERNELSYMBOLFILES} ]; then
399 BACKUPKERNELSYMBOLFILES=yes
402 BACKUPKERNELSYMBOLFILES=no
413 # Handle one line of configuration
415 if [ $# -eq 0 ]; then
424 #### Parameter handling functions.
426 # Initialize parameters to null, just in case they're
427 # set in the environment.
429 # Configration settings
432 # No configuration file set yet
435 # No commands specified yet
438 # Force fetch to proceed
444 # Fetched first in a chain of commands
448 # Parse the command line
450 while [ $# -gt 0 ]; do
452 # Location of configuration file
454 if [ $# -eq 1 ]; then usage; fi
455 if [ ! -z "${CONFFILE}" ]; then usage; fi
461 --not-running-from-cron)
466 config_SourceRelease $1 || usage
469 # Configuration file equivalents
471 if [ $# -eq 1 ]; then usage; fi; shift
472 config_BaseDir $1 || usage
475 if [ $# -eq 1 ]; then usage; fi; shift
476 config_WorkDir $1 || usage
479 if [ $# -eq 1 ]; then usage; fi; shift
480 config_KeyPrint $1 || usage
483 if [ $# -eq 1 ]; then usage; fi; shift
484 config_ServerName $1 || usage
487 if [ $# -eq 1 ]; then usage; fi; shift
488 config_TargetRelease $1 || usage
491 if [ $# -eq 1 ]; then usage; fi; shift
492 config_MailTo $1 || usage
495 if [ $# -eq 1 ]; then usage; fi; shift
496 config_VerboseLevel $1 || usage
499 # Aliases for "-v debug" and "-v nostats"
501 config_VerboseLevel debug || usage
504 config_VerboseLevel nostats || usage
508 cron | fetch | upgrade | updatesready | install | rollback |\
510 COMMANDS="${COMMANDS} $1"
513 # Anything else is an error
521 # Make sure we have at least one command
522 if [ -z "${COMMANDS}" ]; then
527 # Parse the configuration file
529 # If a configuration file was specified on the command line, check
530 # that it exists and is readable.
531 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
532 echo -n "File does not exist "
533 echo -n "or is not readable: "
538 # If a configuration file was not specified on the command line,
539 # use the default configuration file path. If that default does
540 # not exist, give up looking for any configuration.
541 if [ -z "${CONFFILE}" ]; then
542 CONFFILE="/etc/freebsd-update.conf"
543 if [ ! -r "${CONFFILE}" ]; then
548 # Save the configuration options specified on the command line, and
549 # clear all the options in preparation for reading the config file.
553 # Read the configuration file. Anything after the first '#' is
554 # ignored, and any blank lines are ignored.
558 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
559 if ! configline ${LINEX}; then
560 echo "Error processing configuration file, line $L:"
566 # Merge the settings read from the configuration file with those
567 # provided at the command line.
571 # Provide some default parameters
573 # Save any parameters already configured, and clear the slate
577 # Default configurations
578 config_WorkDir /var/db/freebsd-update
581 config_AllowDelete yes
582 config_KeepModifiedMetadata yes
584 config_VerboseLevel stats
585 config_StrictComponents no
586 config_BackupKernel yes
587 config_BackupKernelDir /boot/kernel.old
588 config_BackupKernelSymbolFiles no
590 # Merge these defaults into the earlier-configured settings
594 # Set utility output filtering options, based on ${VERBOSELEVEL}
595 fetch_setup_verboselevel () {
596 case ${VERBOSELEVEL} in
598 QUIETREDIR="/dev/stderr"
600 STATSREDIR="/dev/stderr"
608 STATSREDIR="/dev/null"
614 QUIETREDIR="/dev/null"
616 STATSREDIR="/dev/stdout"
624 # Perform sanity checks and set some final parameters
625 # in preparation for fetching files. Figure out which
626 # set of updates should be downloaded: If the user is
627 # running *-p[0-9]+, strip off the last part; if the
628 # user is running -SECURITY, call it -RELEASE. Chdir
629 # into the working directory.
630 fetchupgrade_check_params () {
631 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
634 "SERVERNAME must be given via command line or configuration file."
635 _KEYPRINT_z="Key must be given via -k option or configuration file."
636 _KEYPRINT_bad="Invalid key fingerprint: "
637 _WORKDIR_bad="Directory does not exist or is not writable: "
638 _WORKDIR_bad2="Directory is not on a persistent filesystem: "
640 if [ -z "${SERVERNAME}" ]; then
641 echo -n "`basename $0`: "
642 echo "${_SERVERNAME_z}"
645 if [ -z "${KEYPRINT}" ]; then
646 echo -n "`basename $0`: "
647 echo "${_KEYPRINT_z}"
650 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
651 echo -n "`basename $0`: "
652 echo -n "${_KEYPRINT_bad}"
656 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
657 echo -n "`basename $0`: "
658 echo -n "${_WORKDIR_bad}"
662 case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*)
663 echo -n "`basename $0`: "
664 echo -n "${_WORKDIR_bad2}"
670 cd ${WORKDIR} || exit 1
672 # Generate release number. The s/SECURITY/RELEASE/ bit exists
673 # to provide an upgrade path for FreeBSD Update 1.x users, since
674 # the kernels provided by FreeBSD Update 1.x are always labelled
677 sed -E 's,-p[0-9]+,,' |
678 sed -E 's,-SECURITY,-RELEASE,'`
680 FETCHDIR=${RELNUM}/${ARCH}
681 PATCHDIR=${RELNUM}/${ARCH}/bp
683 # Disallow upgrade from a version that is not a release
685 *-RELEASE | *-ALPHA* | *-BETA* | *-RC*)
688 echo -n "`basename $0`: "
690 Cannot upgrade from a version that is not a release
691 (including alpha, beta and release candidates)
692 using `basename $0`. Instead, FreeBSD can be directly
693 upgraded by source or upgraded to a RELEASE/RELENG version
694 prior to running `basename $0`.
695 Currently running: ${RELNUM}
701 # Figure out what directory contains the running kernel
702 BOOTFILE=`sysctl -n kern.bootfile`
703 KERNELDIR=${BOOTFILE%/kernel}
704 if ! [ -d ${KERNELDIR} ]; then
705 echo "Cannot identify running kernel"
709 # Figure out what kernel configuration is running. We start with
710 # the output of `uname -i`, and then make the following adjustments:
711 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
712 # file says "ident SMP-GENERIC", I don't know...
713 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
714 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
715 # we're running an SMP kernel. This mis-identification is a bug
716 # which was fixed in 6.2-STABLE.
718 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
721 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
722 if sysctl kern.version | grep -qE '/SMP$'; then
728 BSPATCH=/usr/bin/bspatch
730 PHTTPGET=/usr/libexec/phttpget
732 # Set up variables relating to VERBOSELEVEL
733 fetch_setup_verboselevel
735 # Construct a unique name from ${BASEDIR}
736 BDHASH=`echo ${BASEDIR} | sha256 -q`
739 # Perform sanity checks etc. before fetching updates.
740 fetch_check_params () {
741 fetchupgrade_check_params
743 if ! [ -z "${TARGETRELEASE}" ]; then
744 echo -n "`basename $0`: "
745 echo -n "-r option is meaningless with 'fetch' command. "
746 echo "(Did you mean 'upgrade' instead?)"
750 # Check that we have updates ready to install
751 if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then
752 echo "You have a partially completed upgrade pending"
753 echo "Run '$0 install' first."
754 echo "Run '$0 fetch -F' to proceed anyway."
759 # Perform sanity checks etc. before fetching upgrades.
760 upgrade_check_params () {
761 fetchupgrade_check_params
763 # Unless set otherwise, we're upgrading to the same kernel config.
764 NKERNCONF=${KERNCONF}
766 # We need TARGETRELEASE set
767 _TARGETRELEASE_z="Release target must be specified via -r option."
768 if [ -z "${TARGETRELEASE}" ]; then
769 echo -n "`basename $0`: "
770 echo "${_TARGETRELEASE_z}"
774 # The target release should be != the current release.
775 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
776 echo -n "`basename $0`: "
777 echo "Cannot upgrade from ${RELNUM} to itself"
781 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
782 if [ "${ALLOWADD}" = "no" ]; then
783 echo -n "`basename $0`: "
784 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
785 echo "when upgrading between releases."
788 if [ "${ALLOWDELETE}" = "no" ]; then
789 echo -n "`basename $0`: "
790 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
791 echo "when upgrading between releases."
795 # Set EDITOR to /usr/bin/vi if it isn't already set
796 : ${EDITOR:='/usr/bin/vi'}
799 # Perform sanity checks and set some final parameters in
800 # preparation for installing updates.
801 install_check_params () {
802 # Check that we are root. All sorts of things won't work otherwise.
803 if [ `id -u` != 0 ]; then
804 echo "You must be root to run this."
808 # Check that securelevel <= 0. Otherwise we can't update schg files.
809 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
810 echo "Updates cannot be installed when the system securelevel"
811 echo "is greater than zero."
815 # Check that we have a working directory
816 _WORKDIR_bad="Directory does not exist or is not writable: "
817 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
818 echo -n "`basename $0`: "
819 echo -n "${_WORKDIR_bad}"
823 cd ${WORKDIR} || exit 1
825 # Construct a unique name from ${BASEDIR}
826 BDHASH=`echo ${BASEDIR} | sha256 -q`
828 # Check that we have updates ready to install
829 if ! [ -L ${BDHASH}-install ]; then
830 echo "No updates are available to install."
831 if [ $ISFETCHED -eq 0 ]; then
832 echo "Run '$0 fetch' first."
837 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
838 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
839 echo "Update manifest is corrupt -- this should never happen."
840 echo "Re-run '$0 fetch'."
844 # Figure out what directory contains the running kernel
845 BOOTFILE=`sysctl -n kern.bootfile`
846 KERNELDIR=${BOOTFILE%/kernel}
847 if ! [ -d ${KERNELDIR} ]; then
848 echo "Cannot identify running kernel"
853 # Perform sanity checks and set some final parameters in
854 # preparation for UNinstalling updates.
855 rollback_check_params () {
856 # Check that we are root. All sorts of things won't work otherwise.
857 if [ `id -u` != 0 ]; then
858 echo "You must be root to run this."
862 # Check that we have a working directory
863 _WORKDIR_bad="Directory does not exist or is not writable: "
864 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
865 echo -n "`basename $0`: "
866 echo -n "${_WORKDIR_bad}"
870 cd ${WORKDIR} || exit 1
872 # Construct a unique name from ${BASEDIR}
873 BDHASH=`echo ${BASEDIR} | sha256 -q`
875 # Check that we have updates ready to rollback
876 if ! [ -L ${BDHASH}-rollback ]; then
877 echo "No rollback directory found."
880 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
881 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
882 echo "Update manifest is corrupt -- this should never happen."
887 # Perform sanity checks and set some final parameters
888 # in preparation for comparing the system against the
889 # published index. Figure out which index we should
890 # compare against: If the user is running *-p[0-9]+,
891 # strip off the last part; if the user is running
892 # -SECURITY, call it -RELEASE. Chdir into the working
894 IDS_check_params () {
895 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
898 "SERVERNAME must be given via command line or configuration file."
899 _KEYPRINT_z="Key must be given via -k option or configuration file."
900 _KEYPRINT_bad="Invalid key fingerprint: "
901 _WORKDIR_bad="Directory does not exist or is not writable: "
903 if [ -z "${SERVERNAME}" ]; then
904 echo -n "`basename $0`: "
905 echo "${_SERVERNAME_z}"
908 if [ -z "${KEYPRINT}" ]; then
909 echo -n "`basename $0`: "
910 echo "${_KEYPRINT_z}"
913 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
914 echo -n "`basename $0`: "
915 echo -n "${_KEYPRINT_bad}"
919 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
920 echo -n "`basename $0`: "
921 echo -n "${_WORKDIR_bad}"
925 cd ${WORKDIR} || exit 1
927 # Generate release number. The s/SECURITY/RELEASE/ bit exists
928 # to provide an upgrade path for FreeBSD Update 1.x users, since
929 # the kernels provided by FreeBSD Update 1.x are always labelled
932 sed -E 's,-p[0-9]+,,' |
933 sed -E 's,-SECURITY,-RELEASE,'`
935 FETCHDIR=${RELNUM}/${ARCH}
936 PATCHDIR=${RELNUM}/${ARCH}/bp
938 # Figure out what directory contains the running kernel
939 BOOTFILE=`sysctl -n kern.bootfile`
940 KERNELDIR=${BOOTFILE%/kernel}
941 if ! [ -d ${KERNELDIR} ]; then
942 echo "Cannot identify running kernel"
946 # Figure out what kernel configuration is running. We start with
947 # the output of `uname -i`, and then make the following adjustments:
948 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
949 # file says "ident SMP-GENERIC", I don't know...
950 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
951 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
952 # we're running an SMP kernel. This mis-identification is a bug
953 # which was fixed in 6.2-STABLE.
955 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
958 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
959 if sysctl kern.version | grep -qE '/SMP$'; then
966 PHTTPGET=/usr/libexec/phttpget
968 # Set up variables relating to VERBOSELEVEL
969 fetch_setup_verboselevel
972 #### Core functionality -- the actual work gets done here
974 # Use an SRV query to pick a server. If the SRV query doesn't provide
975 # a useful answer, use the server name specified by the user.
976 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
977 # from that; or if no servers are returned, use ${SERVERNAME}.
978 # This allows a user to specify "portsnap.freebsd.org" (in which case
979 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
980 # (in which case portsnap will use that particular server, since there
981 # won't be an SRV entry for that name).
983 # We ignore the Port field, since we are always going to use port 80.
985 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
986 # no mirrors are available for any reason.
987 fetch_pick_server_init () {
990 # Check that host(1) exists (i.e., that the system wasn't built with the
991 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
992 if ! which -s host; then
997 echo -n "Looking up ${SERVERNAME} mirrors... "
999 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
1000 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
1001 # "$name server selection ..."; we allow either format.
1002 MLIST="_http._tcp.${SERVERNAME}"
1003 host -t srv "${MLIST}" |
1004 sed -nE "s/${MLIST} (has SRV record|server selection) //Ip" |
1005 cut -f 1,2,4 -d ' ' |
1007 sort > serverlist_full
1009 # If no records, give up -- we'll just use the server name we were given.
1010 if [ `wc -l < serverlist_full` -eq 0 ]; then
1015 # Report how many mirrors we found.
1016 echo `wc -l < serverlist_full` "mirrors found."
1018 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
1019 # is set, this will be used to generate the seed; otherwise, the seed
1021 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
1022 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
1026 RANDVALUE=`jot -r 1 0 999999999`
1030 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
1031 fetch_pick_server () {
1032 # Generate a list of not-yet-tried mirrors
1033 sort serverlist_tried |
1034 comm -23 serverlist_full - > serverlist
1036 # Have we run out of mirrors?
1037 if [ `wc -l < serverlist` -eq 0 ]; then
1039 No mirrors remaining, giving up.
1041 This may be because upgrading from this platform (${ARCH})
1042 or release (${RELNUM}) is unsupported by `basename $0`. Only
1043 platforms with Tier 1 support can be upgraded by `basename $0`.
1044 See https://www.freebsd.org/platforms/ for more info.
1046 If unsupported, FreeBSD must be upgraded by source.
1051 # Find the highest priority level (lowest numeric value).
1052 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
1054 # Add up the weights of the response lines at that priority level.
1059 SRV_W=`echo $X | cut -f 2 -d ' '`
1060 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
1065 # If all the weights are 0, pretend that they are all 1 instead.
1066 if [ ${SRV_WSUM} -eq 0 ]; then
1067 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
1073 # Pick a value between 0 and the sum of the weights - 1
1074 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
1076 # Read through the list of mirrors and set SERVERNAME. Write the line
1077 # corresponding to the mirror we selected into serverlist_tried so that
1078 # we won't try it again.
1082 SRV_W=`echo $X | cut -f 2 -d ' '`
1083 SRV_W=$(($SRV_W + $SRV_W_ADD))
1084 if [ $SRV_RND -lt $SRV_W ]; then
1085 SERVERNAME=`echo $X | cut -f 3 -d ' '`
1086 echo "$X" >> serverlist_tried
1089 SRV_RND=$(($SRV_RND - $SRV_W))
1096 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
1097 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
1098 fetch_make_patchlist () {
1099 grep -vE "^([0-9a-f]{64})\|\1$" |
1102 if [ -f "files/${Y}.gz" ] ||
1103 [ ! -f "files/${X}.gz" ]; then
1110 # Print user-friendly progress statistics
1115 if [ $(($LNC % 10)) = 0 ]; then
1117 elif [ $(($LNC % 2)) = 0 ]; then
1124 # Function for asking the user if everything is ok
1126 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1127 case "${CONTINUE}" in
1138 # Initialize the working directory
1141 touch tINDEX.present
1144 # Check that we have a public key with an appropriate hash, or
1145 # fetch the key if it doesn't exist. Returns 1 if the key has
1146 # not yet been fetched.
1148 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1152 echo -n "Fetching public key from ${SERVERNAME}... "
1154 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1155 2>${QUIETREDIR} || true
1156 if ! [ -r pub.ssl ]; then
1160 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1161 echo "key has incorrect hash."
1168 # Fetch metadata signature, aka "tag".
1170 echo -n "Fetching metadata signature "
1171 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1173 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1174 2>${QUIETREDIR} || true
1175 if ! [ -r latest.ssl ]; then
1180 openssl rsautl -pubin -inkey pub.ssl -verify \
1181 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1184 if ! [ `wc -l < tag.new` = 1 ] ||
1186 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1188 echo "invalid signature."
1194 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1195 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1196 EOLTIME=`cut -f 6 -d '|' < tag.new`
1199 # Sanity-check the patch number in a tag, to make sure that we're not
1200 # going to "update" backwards and to prevent replay attacks.
1201 fetch_tagsanity () {
1202 # Check that we're not going to move from -pX to -pY with Y < X.
1203 RELPX=`uname -r | sed -E 's,.*-,,'`
1204 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1205 RELPX=`echo ${RELPX} | cut -c 2-`
1209 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1211 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1212 echo " appear older than what"
1213 echo "we are currently running (`uname -r`)!"
1214 echo "Cowardly refusing to proceed any further."
1218 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1219 # it contains a patch number <= RELPATCHNUM, in order to protect
1220 # against rollback (replay) attacks.
1223 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1225 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1227 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1229 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1230 echo " are older than the"
1231 echo -n "most recently seen updates"
1232 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1233 echo "Cowardly refusing to proceed any further."
1239 # Fetch metadata index file
1240 fetch_metadata_index () {
1241 echo ${NDEBUG} "Fetching metadata index... "
1243 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1245 if ! [ -f ${TINDEXHASH} ]; then
1249 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1250 echo "update metadata index corrupt."
1256 # Print an error message about signed metadata being bogus.
1257 fetch_metadata_bogus () {
1259 echo "The update metadata$1 is correctly signed, but"
1260 echo "failed an integrity check."
1261 echo "Cowardly refusing to proceed any further."
1265 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1266 # with the lines not named in $@ from tINDEX.present (if that file exists).
1267 fetch_metadata_index_merge () {
1268 for METAFILE in $@; do
1269 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1271 fetch_metadata_bogus " index"
1275 grep -E "${METAFILE}\|" ${TINDEXHASH}
1277 sort > tINDEX.wanted
1279 if [ -f tINDEX.present ]; then
1280 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1281 sort -m - tINDEX.wanted > tINDEX.new
1284 mv tINDEX.wanted tINDEX.new
1288 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1289 # are added by future versions of the server, this won't cause problems,
1290 # since the only lines which appear in tINDEX.new are the ones which we
1291 # specifically grepped out of ${TINDEXHASH}.
1292 fetch_metadata_index_sanity () {
1293 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1294 fetch_metadata_bogus " index"
1299 # Sanity check the metadata file $1.
1300 fetch_metadata_sanity () {
1301 # Some aliases to save space later: ${P} is a character which can
1302 # appear in a path; ${M} is the four numeric metadata fields; and
1303 # ${H} is a sha256 hash.
1304 P="[-+./:=,%@_[~[:alnum:]]"
1305 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1308 # Check that the first four fields make sense.
1309 if gunzip -c < files/$1.gz |
1310 grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then
1311 fetch_metadata_bogus ""
1315 # Remove the first three fields.
1316 gunzip -c < files/$1.gz |
1317 cut -f 4- -d '|' > sanitycheck.tmp
1319 # Sanity check entries with type 'f'
1320 if grep -E '^f' sanitycheck.tmp |
1321 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1322 fetch_metadata_bogus ""
1326 # Sanity check entries with type 'd'
1327 if grep -E '^d' sanitycheck.tmp |
1328 grep -qvE "^d\|${M}\|\|\$"; then
1329 fetch_metadata_bogus ""
1333 # Sanity check entries with type 'L'
1334 if grep -E '^L' sanitycheck.tmp |
1335 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1336 fetch_metadata_bogus ""
1340 # Sanity check entries with type '-'
1341 if grep -E '^-' sanitycheck.tmp |
1342 grep -qvE "^-\|\|\|\|\|\|"; then
1343 fetch_metadata_bogus ""
1351 # Fetch the metadata index and metadata files listed in $@,
1352 # taking advantage of metadata patches where possible.
1354 fetch_metadata_index || return 1
1355 fetch_metadata_index_merge $@ || return 1
1356 fetch_metadata_index_sanity || return 1
1358 # Generate a list of wanted metadata patches
1359 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1360 fetch_make_patchlist > patchlist
1362 if [ -s patchlist ]; then
1363 # Attempt to fetch metadata patches
1364 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1365 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1366 tr '|' '-' < patchlist |
1367 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1368 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1369 2>${STATSREDIR} | fetch_progress
1372 # Attempt to apply metadata patches
1373 echo -n "Applying metadata patches... "
1374 tr '|' ' ' < patchlist |
1376 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1377 gunzip -c < ${X}-${Y}.gz > diff
1378 gunzip -c < files/${X}.gz > diff-OLD
1380 # Figure out which lines are being added and removed
1383 while read PREFIX; do
1384 look "${PREFIX}" diff-OLD
1387 grep -E '^\+' diff |
1388 cut -c 2- > diff-add
1390 # Generate the new file
1391 comm -23 diff-OLD diff-rm |
1392 sort - diff-add > diff-NEW
1394 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1395 mv diff-NEW files/${Y}
1398 mv diff-NEW ${Y}.bad
1400 rm -f ${X}-${Y}.gz diff
1401 rm -f diff-OLD diff-NEW diff-add diff-rm
1402 done 2>${QUIETREDIR}
1406 # Update metadata without patches
1407 cut -f 2 -d '|' < tINDEX.new |
1409 if [ ! -f "files/${Y}.gz" ]; then
1415 if [ -s filelist ]; then
1416 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1417 echo ${NDEBUG} "metadata files... "
1418 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1419 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1423 if ! [ -f ${Y}.gz ]; then
1427 if [ `gunzip -c < ${Y}.gz |
1428 ${SHA256} -q` = ${Y} ]; then
1429 mv ${Y}.gz files/${Y}.gz
1431 echo "metadata is corrupt."
1438 # Sanity-check the metadata files.
1439 cut -f 2 -d '|' tINDEX.new > filelist
1441 fetch_metadata_sanity ${X} || return 1
1444 # Remove files which are no longer needed
1445 cut -f 2 -d '|' tINDEX.present |
1447 cut -f 2 -d '|' tINDEX.new |
1449 comm -13 - oldfiles |
1450 lam -s "files/" - -s ".gz" |
1452 rm patchlist filelist oldfiles
1456 mv tINDEX.new tINDEX.present
1462 # Extract a subset of a downloaded metadata file containing only the parts
1463 # which are listed in COMPONENTS.
1464 fetch_filter_metadata_components () {
1465 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1466 gunzip -c < files/${METAHASH}.gz > $1.all
1468 # Fish out the lines belonging to components we care about.
1469 for C in ${COMPONENTS}; do
1470 look "`echo ${C} | tr '/' '|'`|" $1.all
1473 # Remove temporary file.
1477 # Generate a filtered version of the metadata file $1 from the downloaded
1478 # file, by fishing out the lines corresponding to components we're trying
1479 # to keep updated, and then removing lines corresponding to paths we want
1481 fetch_filter_metadata () {
1482 # Fish out the lines belonging to components we care about.
1483 fetch_filter_metadata_components $1
1485 # Canonicalize directory names by removing any trailing / in
1486 # order to avoid listing directories multiple times if they
1487 # belong to multiple components. Turning "/" into "" doesn't
1488 # matter, since we add a leading "/" when we use paths later.
1489 cut -f 3- -d '|' $1 |
1490 sed -e 's,/|d|,|d|,' |
1491 sed -e 's,/|-|,|-|,' |
1494 # Figure out which lines to ignore and remove them.
1495 for X in ${IGNOREPATHS}; do
1496 grep -E "^${X}" $1.tmp
1499 comm -13 - $1.tmp > $1
1501 # Remove temporary files.
1505 # Filter the metadata file $1 by adding lines with "/boot/$2"
1506 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1507 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1508 # the original lines which start with that.
1509 # Put another way: Deal with the fact that the FOO kernel is sometimes
1510 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1511 fetch_filter_kernel_names () {
1513 sed -e "s,/boot/$2,${KERNELDIR},g" |
1517 if ! [ -d /boot/$2 ]; then
1518 grep -v ^/boot/$2 $1 > $1.tmp
1523 # For all paths appearing in $1 or $3, inspect the system
1524 # and generate $2 describing what is currently installed.
1525 fetch_inspect_system () {
1529 # Tell the user why his disk is suddenly making lots of noise
1530 echo -n "Inspecting system... "
1532 # Generate list of files to inspect
1537 # Examine each file and output lines of the form
1538 # /path/to/file|type|device-inum|user|group|perm|flags|value
1539 # sorted by device and inode number.
1541 # If the symlink/file/directory does not exist, record this.
1542 if ! [ -e ${BASEDIR}/${F} ]; then
1546 if ! [ -r ${BASEDIR}/${F} ]; then
1547 echo "Cannot read file: ${BASEDIR}/${F}" \
1553 # Otherwise, output an index line.
1554 if [ -L ${BASEDIR}/${F} ]; then
1556 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1557 readlink ${BASEDIR}/${F};
1558 elif [ -f ${BASEDIR}/${F} ]; then
1560 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1561 sha256 -q ${BASEDIR}/${F};
1562 elif [ -d ${BASEDIR}/${F} ]; then
1564 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1566 echo "Unknown file type: ${BASEDIR}/${F}" \
1572 sort -k 3,3 -t '|' > $2.tmp
1575 # Check if an error occurred during system inspection
1576 if [ -f .err ]; then
1580 # Convert to the form
1581 # /path/to/file|type|user|group|perm|flags|value|hlink
1582 # by resolving identical device and inode numbers into hard links.
1583 cut -f 1,3 -d '|' $2.tmp |
1584 sort -k 1,1 -t '|' |
1585 sort -s -u -k 2,2 -t '|' |
1586 join -1 2 -2 3 -t '|' - $2.tmp |
1587 awk -F \| -v OFS=\| \
1589 if (($2 == $3) || ($4 == "-"))
1590 print $3,$4,$5,$6,$7,$8,$9,""
1592 print $3,$4,$5,$6,$7,$8,$9,$2
1597 # We're finished looking around
1601 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1602 # files which differ; generate $3 containing these paths and the old hashes.
1603 fetch_filter_mergechanges () {
1604 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1606 for X in ${MERGECHANGES}; do
1607 grep -E "^${X}" ${F}
1609 cut -f 1,2,7 -d '|' |
1613 # Any line in $2-values which doesn't appear in $1-values and is a
1614 # file means that we should list the path in $3.
1615 comm -13 $1-values $2-values |
1617 cut -f 1 -d '|' > $2-paths
1619 # For each path, pull out one (and only one!) entry from $1-values.
1620 # Note that we cannot distinguish which "old" version the user made
1621 # changes to; but hopefully any changes which occur due to security
1622 # updates will exist in both the "new" version and the version which
1623 # the user has installed, so the merging will still work.
1625 look "${X}|" $1-values |
1627 done < $2-paths > $3
1630 rm $1-values $2-values $2-paths
1633 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1634 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1635 # the paths are listed in $4. For entries in $2 marked "not present"
1636 # (aka. type -), remove lines from $[123] unless there is a corresponding
1638 fetch_filter_unmodified_notpresent () {
1639 # Figure out which lines of $1 and $3 correspond to bits which
1640 # should only be updated if they haven't changed, and fish out
1641 # the (path, type, value) tuples.
1642 # NOTE: We don't consider a file to be "modified" if it matches
1644 for X in ${UPDATEIFUNMODIFIED}; do
1648 cut -f 1,2,7 -d '|' |
1651 # Do the same for $2.
1652 for X in ${UPDATEIFUNMODIFIED}; do
1655 cut -f 1,2,7 -d '|' |
1658 # Any entry in $2-values which is not in $1-values corresponds to
1659 # a path which we need to remove from $1, $2, and $3, unless it
1660 # that path appears in $4.
1661 comm -13 $1-values $2-values |
1662 sort -t '|' -k 1,1 > mlines.tmp
1663 cut -f 1 -d '|' $4 |
1665 join -v 2 -t '|' - mlines.tmp |
1667 rm $1-values $2-values mlines.tmp
1669 # Any lines in $2 which are not in $1 AND are "not present" lines
1670 # also belong in mlines.
1672 cut -f 1,2,7 -d '|' |
1673 fgrep '|-|' >> mlines
1675 # Remove lines from $1, $2, and $3
1676 for X in $1 $2 $3; do
1677 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1678 cut -f 1 -d '|' < mlines |
1680 join -v 2 -t '|' - ${X}.tmp |
1685 # Store a list of the modified files, for future reference
1686 fgrep -v '|-|' mlines |
1687 cut -f 1 -d '|' > modifiedfiles
1691 # For each entry in $1 of type -, remove any corresponding
1692 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1693 # of type - from $1.
1694 fetch_filter_allowadd () {
1695 cut -f 1,2 -d '|' < $1 |
1697 cut -f 1 -d '|' > filesnotpresent
1699 if [ ${ALLOWADD} != "yes" ]; then
1701 join -v 1 -t '|' - filesnotpresent |
1707 join -v 1 -t '|' - filesnotpresent |
1713 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1714 # which don't correspond to entries in $2.
1715 fetch_filter_allowdelete () {
1716 # Produce a lists ${PATH}|${TYPE}
1718 cut -f 1-2 -d '|' < ${X} |
1719 sort -u > ${X}.nodes
1722 # Figure out which lines need to be removed from $1.
1723 if [ ${ALLOWDELETE} != "yes" ]; then
1724 comm -23 $1.nodes $2.nodes > $1.badnodes
1729 # Remove the relevant lines from $1
1732 done < $1.badnodes |
1733 comm -13 - $1 > $1.tmp
1736 rm $1.badnodes $1.nodes $2.nodes
1739 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1740 # with metadata not matching any entry in $1, replace the corresponding
1741 # line of $3 with one having the same metadata as the entry in $2.
1742 fetch_filter_modified_metadata () {
1743 # Fish out the metadata from $1 and $2
1745 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1748 # Find the metadata we need to keep
1749 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1750 comm -13 $1.metadata $2.metadata > keepmeta
1755 # Extract the lines which we need to remove from $3, and
1756 # construct the lines which we need to add to $3.
1760 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1761 look "${NODE}|" $3 >> $3.remove
1762 look "${NODE}|" $3 |
1764 lam -s "${LINE}|" - >> $3.add
1767 # Remove the specified lines and add the new lines.
1770 sort -u - $3.add > $3.tmp
1773 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1776 # Remove lines from $1 and $2 which are identical;
1777 # no need to update a file if it isn't changing.
1778 fetch_filter_uptodate () {
1779 comm -23 $1 $2 > $1.tmp
1780 comm -13 $1 $2 > $2.tmp
1786 # Fetch any "clean" old versions of files we need for merging changes.
1787 fetch_files_premerge () {
1788 # We only need to do anything if $1 is non-empty.
1790 # Tell the user what we're doing
1791 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1793 # List of files wanted
1796 sort -u > files.wanted
1798 # Only fetch the files we don't already have
1800 if [ ! -f "files/${Y}.gz" ]; then
1803 done < files.wanted > filelist
1805 # Actually fetch them
1806 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1807 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1810 # Make sure we got them all, and move them into /files/
1812 if ! [ -f ${Y}.gz ]; then
1816 if [ `gunzip -c < ${Y}.gz |
1817 ${SHA256} -q` = ${Y} ]; then
1818 mv ${Y}.gz files/${Y}.gz
1820 echo "${Y} has incorrect hash."
1827 rm filelist files.wanted
1831 # Prepare to fetch files: Generate a list of the files we need,
1832 # copy the unmodified files we have into /files/, and generate
1833 # a list of patches to download.
1834 fetch_files_prepare () {
1835 # Tell the user why his disk is suddenly making lots of noise
1836 echo -n "Preparing to download files... "
1838 # Reduce indices to ${PATH}|${HASH} pairs
1839 for X in $1 $2 $3; do
1840 cut -f 1,2,7 -d '|' < ${X} |
1846 # List of files wanted
1847 cut -f 2 -d '|' < $3.hashes |
1850 if ! [ -f files/${HASH}.gz ]; then
1855 # Generate a list of unmodified files
1856 comm -12 $1.hashes $2.hashes |
1857 sort -k 1,1 -t '|' > unmodified.files
1859 # Copy all files into /files/. We only need the unmodified files
1860 # for use in patching; but we'll want all of them if the user asks
1861 # to rollback the updates later.
1863 F=`echo "${LINE}" | cut -f 1 -d '|'`
1864 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1866 # Skip files we already have.
1867 if [ -f files/${HASH}.gz ]; then
1871 # Make sure the file hasn't changed.
1872 cp "${BASEDIR}/${F}" tmpfile
1873 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1875 echo "File changed while FreeBSD Update running: ${F}"
1879 # Place the file into storage.
1880 gzip -c < tmpfile > files/${HASH}.gz
1884 # Produce a list of patches to download
1885 sort -k 1,1 -t '|' $3.hashes |
1886 join -t '|' -o 2.2,1.2 - unmodified.files |
1887 fetch_make_patchlist > patchlist
1890 rm unmodified.files $1.hashes $2.hashes $3.hashes
1892 # We don't need the list of possible old files any more.
1895 # We're finished making noise
1901 # Attempt to fetch patches
1902 if [ -s patchlist ]; then
1903 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1904 echo ${NDEBUG} "patches.${DDSTATS}"
1905 tr '|' '-' < patchlist |
1906 lam -s "${PATCHDIR}/" - |
1907 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1908 2>${STATSREDIR} | fetch_progress
1911 # Attempt to apply patches
1912 echo -n "Applying patches... "
1913 tr '|' ' ' < patchlist |
1915 if [ ! -f "${X}-${Y}" ]; then continue; fi
1916 gunzip -c < files/${X}.gz > OLD
1918 bspatch OLD NEW ${X}-${Y}
1920 if [ `${SHA256} -q NEW` = ${Y} ]; then
1924 rm -f diff OLD NEW ${X}-${Y}
1925 done 2>${QUIETREDIR}
1929 # Download files which couldn't be generate via patching
1931 if [ ! -f "files/${Y}.gz" ]; then
1934 done < files.wanted > filelist
1936 if [ -s filelist ]; then
1937 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1938 echo ${NDEBUG} "files... "
1939 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1940 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1941 2>${STATSREDIR} | fetch_progress
1944 if ! [ -f ${Y}.gz ]; then
1948 if [ `gunzip -c < ${Y}.gz |
1949 ${SHA256} -q` = ${Y} ]; then
1950 mv ${Y}.gz files/${Y}.gz
1952 echo "${Y} has incorrect hash."
1960 rm files.wanted filelist patchlist
1963 # Create and populate install manifest directory; and report what updates
1965 fetch_create_manifest () {
1966 # If we have an existing install manifest, nuke it.
1967 if [ -L "${BDHASH}-install" ]; then
1968 rm -r ${BDHASH}-install/
1969 rm ${BDHASH}-install
1972 # Report to the user if any updates were avoided due to local changes
1973 if [ -s modifiedfiles ]; then
1974 cat - modifiedfiles <<- EOF | ${PAGER}
1975 The following files are affected by updates. No changes have
1976 been downloaded, however, because the files have been modified
1982 # If no files will be updated, tell the user and exit
1983 if ! [ -s INDEX-PRESENT ] &&
1984 ! [ -s INDEX-NEW ]; then
1985 rm INDEX-PRESENT INDEX-NEW
1987 echo -n "No updates needed to update system to "
1988 echo "${RELNUM}-p${RELPATCHNUM}."
1992 # Divide files into (a) removed files, (b) added files, and
1993 # (c) updated files.
1994 cut -f 1 -d '|' < INDEX-PRESENT |
1995 sort > INDEX-PRESENT.flist
1996 cut -f 1 -d '|' < INDEX-NEW |
1997 sort > INDEX-NEW.flist
1998 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1999 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
2000 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
2001 rm INDEX-PRESENT.flist INDEX-NEW.flist
2003 # Report removed files, if any
2004 if [ -s files.removed ]; then
2005 cat - files.removed <<- EOF | ${PAGER}
2006 The following files will be removed as part of updating to
2007 ${RELNUM}-p${RELPATCHNUM}:
2012 # Report added files, if any
2013 if [ -s files.added ]; then
2014 cat - files.added <<- EOF | ${PAGER}
2015 The following files will be added as part of updating to
2016 ${RELNUM}-p${RELPATCHNUM}:
2021 # Report updated files, if any
2022 if [ -s files.updated ]; then
2023 cat - files.updated <<- EOF | ${PAGER}
2024 The following files will be updated as part of updating to
2025 ${RELNUM}-p${RELPATCHNUM}:
2030 # Create a directory for the install manifest.
2031 MDIR=`mktemp -d install.XXXXXX` || return 1
2034 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
2035 mv INDEX-NEW ${MDIR}/INDEX-NEW
2037 # Link it into place
2038 ln -s ${MDIR} ${BDHASH}-install
2041 # Warn about any upcoming EoL
2043 # What's the current time?
2044 NOWTIME=`date "+%s"`
2046 # When did we last warn about the EoL date?
2047 if [ -f lasteolwarn ]; then
2048 LASTWARN=`cat lasteolwarn`
2050 LASTWARN=`expr ${NOWTIME} - 63072000`
2053 # If the EoL time is past, warn.
2054 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
2057 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
2058 Any security issues discovered after `date -r ${EOLTIME}`
2059 will not have been corrected.
2064 # Figure out how long it has been since we last warned about the
2065 # upcoming EoL, and how much longer we have left.
2066 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
2067 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
2069 # Don't warn if the EoL is more than 3 months away
2070 if [ ${TIMELEFT} -gt 7884000 ]; then
2074 # Don't warn if the time remaining is more than 3 times the time
2075 # since the last warning.
2076 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
2080 # Figure out what time units to use.
2081 if [ ${TIMELEFT} -lt 604800 ]; then
2084 elif [ ${TIMELEFT} -lt 2678400 ]; then
2092 # Compute the right number of units
2093 NUM=`expr ${TIMELEFT} / ${SIZE}`
2094 if [ ${NUM} != 1 ]; then
2101 WARNING: `uname -sr` is approaching its End-of-Life date.
2102 It is strongly recommended that you upgrade to a newer
2103 release within the next ${NUM} ${UNIT}.
2106 # Update the stored time of last warning
2107 echo ${NOWTIME} > lasteolwarn
2110 # Do the actual work involved in "fetch" / "cron".
2112 workdir_init || return 1
2114 # Prepare the mirror list.
2115 fetch_pick_server_init && fetch_pick_server
2117 # Try to fetch the public key until we run out of servers.
2118 while ! fetch_key; do
2119 fetch_pick_server || return 1
2122 # Try to fetch the metadata index signature ("tag") until we run
2123 # out of available servers; and sanity check the downloaded tag.
2124 while ! fetch_tag; do
2125 fetch_pick_server || return 1
2127 fetch_tagsanity || return 1
2129 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2130 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2132 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2133 # the lines which (a) belong to components we care about, and (b)
2134 # don't correspond to paths we're explicitly ignoring.
2135 fetch_filter_metadata INDEX-NEW || return 1
2136 fetch_filter_metadata INDEX-OLD || return 1
2138 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2139 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2140 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2142 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2143 # system and generate an INDEX-PRESENT file.
2144 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2146 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2147 # correspond to lines in INDEX-PRESENT with hashes not appearing
2148 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2149 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2150 # INDEX-OLD with type -.
2151 fetch_filter_unmodified_notpresent \
2152 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2154 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2155 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2156 # of type - from INDEX-PRESENT.
2157 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2159 # If ${ALLOWDELETE} != "yes", then remove any entries from
2160 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2161 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2163 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2164 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2165 # replace the corresponding line of INDEX-NEW with one having the
2166 # same metadata as the entry in INDEX-PRESENT.
2167 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2169 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2170 # no need to update a file if it isn't changing.
2171 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2173 # Prepare to fetch files: Generate a list of the files we need,
2174 # copy the unmodified files we have into /files/, and generate
2175 # a list of patches to download.
2176 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2179 fetch_files || return 1
2181 # Create and populate install manifest directory; and report what
2182 # updates are available.
2183 fetch_create_manifest || return 1
2185 # Warn about any upcoming EoL
2186 fetch_warn_eol || return 1
2189 # If StrictComponents is not "yes", generate a new components list
2190 # with only the components which appear to be installed.
2191 upgrade_guess_components () {
2192 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2193 # Generate filtered INDEX-ALL with only the components listed
2195 fetch_filter_metadata_components $1 || return 1
2197 # Tell the user why his disk is suddenly making lots of noise
2198 echo -n "Inspecting system... "
2200 # Look at the files on disk, and assume that a component is
2201 # supposed to be present if it is more than half-present.
2202 cut -f 1-3 -d '|' < INDEX-ALL |
2204 while read C S F; do
2205 if [ -e ${BASEDIR}/${F} ]; then
2212 sed -E 's,^ +,,' > compfreq
2213 grep ' = ' compfreq |
2215 sort -k 2,2 -t ' ' > compfreq.total
2216 grep ' + ' compfreq |
2218 sort -k 2,2 -t ' ' > compfreq.present
2219 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2220 while read S P T; do
2221 if [ ${T} -ne 0 -a ${P} -gt `expr ${T} / 2` ]; then
2225 cut -f 2 -d ' ' < compfreq.total > comp.total
2226 rm INDEX-ALL compfreq compfreq.total compfreq.present
2228 # We're done making noise.
2231 # Sometimes the kernel isn't installed where INDEX-ALL
2232 # thinks that it should be: In particular, it is often in
2233 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2234 # deal with this, if "kernel|X" is listed in comp.total
2235 # (i.e., is a component which would be upgraded if it is
2236 # found to be present) we will add it to comp.present.
2237 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2238 # not, we print a warning -- the user is running a kernel
2239 # which isn't part of the release.
2240 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2241 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2243 if grep -qE "^kernel\|" comp.total &&
2244 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2247 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2248 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2249 This kernel will not be updated: you MUST update the kernel manually
2250 before running "$0 install".
2254 # Re-sort the list of installed components and generate
2255 # the list of non-installed components.
2256 sort -u < comp.present > comp.present.tmp
2257 mv comp.present.tmp comp.present
2258 comm -13 comp.present comp.total > comp.absent
2260 # Ask the user to confirm that what we have is correct. To
2261 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2262 # subcomponents must be listed in the configuration file).
2264 echo -n "The following components of FreeBSD "
2265 echo "seem to be installed:"
2266 tr '|' '/' < comp.present |
2269 echo -n "The following components of FreeBSD "
2270 echo "do not seem to be installed:"
2271 tr '|' '/' < comp.absent |
2274 continuep || return 1
2277 # Suck the generated list of components into ${COMPONENTS}.
2278 # Note that comp.present.tmp is used due to issues with
2279 # pipelines and setting variables.
2281 tr '|' '/' < comp.present > comp.present.tmp
2283 COMPONENTS="${COMPONENTS} ${C}"
2284 done < comp.present.tmp
2286 # Delete temporary files
2287 rm comp.present comp.present.tmp comp.absent comp.total
2291 # If StrictComponents is not "yes", COMPONENTS contains an entry
2292 # corresponding to the currently running kernel, and said kernel
2293 # does not exist in the new release, add "kernel/generic" to the
2294 # list of components.
2295 upgrade_guess_new_kernel () {
2296 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2297 # Grab the unfiltered metadata file.
2298 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2299 gunzip -c < files/${METAHASH}.gz > $1.all
2301 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2302 # isn't in $1.all, we need to add kernel/generic.
2303 for C in ${COMPONENTS}; do
2304 if [ ${C} = "kernel/${KCOMP}" ] &&
2305 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2306 COMPONENTS="${COMPONENTS} kernel/generic"
2310 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2311 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2312 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2313 replaced with a "generic" kernel.
2315 continuep || return 1
2319 # Don't need this any more...
2324 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2325 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2326 upgrade_oldall_to_oldnew () {
2327 # For each ${F}|... which appears in INDEX-ALL but does not appear
2328 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2329 cut -f 1 -d '|' < $1 |
2331 cut -f 1 -d '|' < $2 |
2333 comm -13 $1.paths - |
2334 lam - -s "|-||||||" |
2338 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2339 comm -23 $1 $2 > $1.tmp
2342 # Remove lines from INDEX-ALL which have a file name not appearing
2343 # anywhere in INDEX-OLD (since these must be files which haven't
2344 # changed -- if they were new, there would be an entry of type "-").
2345 cut -f 1 -d '|' < $1 |
2347 sort -k 1,1 -t '|' < $2 |
2348 join -t '|' - $1.paths |
2353 # Rename INDEX-ALL to INDEX-NEW.
2357 # Helper for upgrade_merge: Return zero true iff the two files differ only
2358 # in the contents of their RCS tags.
2360 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2361 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2363 if [ $X = $Y ]; then
2370 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2371 # and update $3 to reflect the hashes of merged files.
2373 # We only need to do anything if $1 is non-empty.
2375 cut -f 1 -d '|' $1 |
2378 # Create staging area for merging files
2382 mkdir -p merge/old/${D}
2383 mkdir -p merge/${OLDRELNUM}/${D}
2384 mkdir -p merge/${RELNUM}/${D}
2385 mkdir -p merge/new/${D}
2390 # Currently installed file
2391 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2392 gunzip < files/${V}.gz > merge/old/${F}
2395 if look "${F}|" $1 | fgrep -q "|f|"; then
2396 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2397 gunzip < files/${V}.gz \
2398 > merge/${OLDRELNUM}/${F}
2402 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2403 fgrep -q "|f|"; then
2404 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2405 gunzip < files/${V}.gz \
2406 > merge/${RELNUM}/${F}
2410 # Attempt to automatically merge changes
2411 echo -n "Attempting to automatically merge "
2412 echo -n "changes in files..."
2415 # If the file doesn't exist in the new release,
2416 # the result of "merging changes" is having the file
2418 if ! [ -f merge/${RELNUM}/${F} ]; then
2422 # If the file didn't exist in the old release, we're
2423 # going to throw away the existing file and hope that
2424 # the version from the new release is what we want.
2425 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2426 cp merge/${RELNUM}/${F} merge/new/${F}
2430 # Some files need special treatment.
2432 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2433 # Don't merge these -- we're rebuild them
2434 # after updates are installed.
2435 cp merge/old/${F} merge/new/${F}
2438 if ! diff3 -E -m -L "current version" \
2439 -L "${OLDRELNUM}" -L "${RELNUM}" \
2441 merge/${OLDRELNUM}/${F} \
2442 merge/${RELNUM}/${F} \
2443 > merge/new/${F} 2>/dev/null; then
2444 echo ${F} >> failed.merges
2451 # Ask the user to handle any files which didn't merge.
2453 # If the installed file differs from the version in
2454 # the old release only due to RCS tag expansion
2455 # then just use the version in the new release.
2456 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2457 cp merge/${RELNUM}/${F} merge/new/${F}
2463 The following file could not be merged automatically: ${F}
2464 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2467 read dummy </dev/tty
2468 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2469 done < failed.merges
2472 # Ask the user to confirm that he likes how the result
2475 # Skip files which haven't changed except possibly
2476 # in their RCS tags.
2477 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2478 samef merge/old/${F} merge/new/${F}; then
2482 # Skip files where the installed file differs from
2483 # the old file only due to RCS tags.
2484 if [ -f merge/old/${F} ] &&
2485 [ -f merge/${OLDRELNUM}/${F} ] &&
2486 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2490 # Warn about files which are ceasing to exist.
2491 if ! [ -f merge/new/${F} ]; then
2494 The following file will be removed, as it no longer exists in
2495 FreeBSD ${RELNUM}: ${F}
2497 continuep < /dev/tty || return 1
2501 # Print changes for the user's approval.
2504 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2505 FreeBSD ${RELNUM} have been merged into ${F}:
2507 diff -U 5 -L "current version" -L "new version" \
2508 merge/old/${F} merge/new/${F} || true
2509 continuep < /dev/tty || return 1
2512 # Store merged files.
2514 if [ -f merge/new/${F} ]; then
2515 V=`${SHA256} -q merge/new/${F}`
2517 gzip -c < merge/new/${F} > files/${V}.gz
2520 done < $1-paths > newhashes
2522 # Pull lines out from $3 which need to be updated to
2523 # reflect merged files.
2526 done < $1-paths > $3-oldlines
2528 # Update lines to reflect merged files
2529 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2530 $3-oldlines newhashes > $3-newlines
2532 # Remove old lines from $3 and add new lines.
2535 sort - $3-newlines > $3.tmp
2539 rm $1-paths newhashes $3-oldlines $3-newlines
2543 # We're done with merging files.
2547 # Do the work involved in fetching upgrades to a new release
2549 workdir_init || return 1
2551 # Prepare the mirror list.
2552 fetch_pick_server_init && fetch_pick_server
2554 # Try to fetch the public key until we run out of servers.
2555 while ! fetch_key; do
2556 fetch_pick_server || return 1
2559 # Try to fetch the metadata index signature ("tag") until we run
2560 # out of available servers; and sanity check the downloaded tag.
2561 while ! fetch_tag; do
2562 fetch_pick_server || return 1
2564 fetch_tagsanity || return 1
2566 # Fetch the INDEX-OLD and INDEX-ALL.
2567 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2569 # If StrictComponents is not "yes", generate a new components list
2570 # with only the components which appear to be installed.
2571 upgrade_guess_components INDEX-ALL || return 1
2573 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2574 # the components we want and without anything marked as "Ignore".
2575 fetch_filter_metadata INDEX-OLD || return 1
2576 fetch_filter_metadata INDEX-ALL || return 1
2578 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2579 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2580 mv INDEX-OLD.tmp INDEX-OLD
2583 # Adjust variables for fetching files from the new release.
2585 RELNUM=${TARGETRELEASE}
2586 OLDFETCHDIR=${FETCHDIR}
2587 FETCHDIR=${RELNUM}/${ARCH}
2589 # Try to fetch the NEW metadata index signature ("tag") until we run
2590 # out of available servers; and sanity check the downloaded tag.
2591 while ! fetch_tag; do
2592 fetch_pick_server || return 1
2595 # Fetch the new INDEX-ALL.
2596 fetch_metadata INDEX-ALL || return 1
2598 # If StrictComponents is not "yes", COMPONENTS contains an entry
2599 # corresponding to the currently running kernel, and said kernel
2600 # does not exist in the new release, add "kernel/generic" to the
2601 # list of components.
2602 upgrade_guess_new_kernel INDEX-ALL || return 1
2604 # Filter INDEX-ALL to contain only the components we want and without
2605 # anything marked as "Ignore".
2606 fetch_filter_metadata INDEX-ALL || return 1
2608 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2609 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2610 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2612 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2613 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2614 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2616 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2617 # system and generate an INDEX-PRESENT file.
2618 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2620 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2621 # paths and hashes of old versions of files to merge.
2622 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2624 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2625 # correspond to lines in INDEX-PRESENT with hashes not appearing
2626 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2627 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2628 # INDEX-OLD with type -.
2629 fetch_filter_unmodified_notpresent \
2630 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2632 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2633 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2634 # of type - from INDEX-PRESENT.
2635 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2637 # If ${ALLOWDELETE} != "yes", then remove any entries from
2638 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2639 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2641 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2642 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2643 # replace the corresponding line of INDEX-NEW with one having the
2644 # same metadata as the entry in INDEX-PRESENT.
2645 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2647 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2648 # no need to update a file if it isn't changing.
2649 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2651 # Fetch "clean" files from the old release for merging changes.
2652 fetch_files_premerge tomerge-old
2654 # Prepare to fetch files: Generate a list of the files we need,
2655 # copy the unmodified files we have into /files/, and generate
2656 # a list of patches to download.
2657 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2659 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2660 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2661 fetch_files || return 1
2663 # Merge configuration file changes.
2664 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2666 # Create and populate install manifest directory; and report what
2667 # updates are available.
2668 fetch_create_manifest || return 1
2670 # Leave a note behind to tell the "install" command that the kernel
2671 # needs to be installed before the world.
2672 touch ${BDHASH}-install/kernelfirst
2674 # Remind the user that they need to run "freebsd-update install"
2675 # to install the downloaded bits, in case they didn't RTFM.
2676 echo "To install the downloaded upgrades, run \"$0 install\"."
2679 # Make sure that all the file hashes mentioned in $@ have corresponding
2680 # gzipped files stored in /files/.
2682 # Generate a list of hashes
2689 # Make sure all the hashes exist
2691 if ! [ -f files/${HASH}.gz ]; then
2692 echo -n "Update files missing -- "
2693 echo "this should never happen."
2694 echo "Re-run '$0 fetch'."
2703 # Remove the system immutable flag from files
2705 # Generate file list
2707 cut -f 1 -d '|' > filelist
2711 if ! [ -e ${BASEDIR}/${F} ]; then
2714 echo ${BASEDIR}/${F}
2716 done < filelist | xargs chflags noschg || return 1
2722 # Decide which directory name to use for kernel backups.
2723 backup_kernel_finddir () {
2726 # Pathname does not exist, so it is OK use that name
2727 # for backup directory.
2728 if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then
2732 # If directory do exist, we only use if it has our
2734 if [ -d $BASEDIR/$BACKUPKERNELDIR -a \
2735 -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then
2739 # We could not use current directory name, so add counter to
2740 # the end and try again.
2742 if [ $CNT -gt 9 ]; then
2743 echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)"
2746 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2747 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2751 # Backup the current kernel using hardlinks, if not disabled by user.
2752 # Since we delete all files in the directory used for previous backups
2753 # we create a marker file called ".freebsd-update" in the directory so
2754 # we can determine on the next run that the directory was created by
2755 # freebsd-update and we then do not accidentally remove user files in
2756 # the unlikely case that the user has created a directory with a
2759 # Only make kernel backup is so configured.
2760 if [ $BACKUPKERNEL != yes ]; then
2764 # Decide which directory name to use for kernel backups.
2765 backup_kernel_finddir
2767 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2768 # "not ours", backup_kernel_finddir would have exited, so
2769 # deleting the directory content is as safe as we can make it.
2770 if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then
2771 rm -fr $BASEDIR/$BACKUPKERNELDIR
2774 # Create directories for backup.
2775 mkdir -p $BASEDIR/$BACKUPKERNELDIR
2776 mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \
2777 mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null
2779 # Mark the directory as having been created by freebsd-update.
2780 touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update
2781 if [ $? -ne 0 ]; then
2782 echo "Could not create kernel backup directory"
2786 # Disable pathname expansion to be sure *.symbols is not
2790 # Use find to ignore symbol files, unless disabled by user.
2791 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2794 FINDFILTER="-a ! -name *.debug -a ! -name *.symbols"
2797 # Backup all the kernel files using hardlinks.
2798 (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \
2799 cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;)
2801 # Re-enable patchname expansion.
2806 install_from_index () {
2807 # First pass: Do everything apart from setting file flags. We
2808 # can't set flags yet, because schg inhibits hard linking.
2809 sort -k 1,1 -t '|' $1 |
2811 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2814 # Create a directory
2815 install -d -o ${OWNER} -g ${GROUP} \
2816 -m ${PERM} ${BASEDIR}/${FPATH}
2819 if [ -z "${LINK}" ]; then
2820 # Create a file, without setting flags.
2821 gunzip < files/${HASH}.gz > ${HASH}
2822 install -S -o ${OWNER} -g ${GROUP} \
2823 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2826 # Create a hard link.
2827 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2832 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2837 # Perform a second pass, adding file flags.
2839 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2840 if [ ${TYPE} = "f" ] &&
2841 ! [ ${FLAGS} = "0" ]; then
2842 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2847 # Remove files which we want to delete
2849 # Generate list of new files
2850 cut -f 1 -d '|' < $2 |
2853 # Generate subindex of old files we want to nuke
2854 sort -k 1,1 -t '|' $1 |
2855 join -t '|' -v 1 - newfiles |
2856 sort -r -k 1,1 -t '|' |
2858 tr '|' ' ' > killfiles
2860 # Remove the offending bits
2861 while read FPATH TYPE; do
2864 rmdir ${BASEDIR}/${FPATH}
2867 rm ${BASEDIR}/${FPATH}
2870 rm ${BASEDIR}/${FPATH}
2876 rm newfiles killfiles
2879 # Install new files, delete old files, and update generated files
2881 # If we haven't already dealt with the kernel, deal with it.
2882 if ! [ -f $1/kerneldone ]; then
2883 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2884 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2886 # Backup current kernel before installing a new one
2887 backup_kernel || return 1
2890 install_from_index INDEX-NEW || return 1
2892 # Remove files which need to be deleted
2893 install_delete INDEX-OLD INDEX-NEW || return 1
2895 # Update linker.hints if necessary
2896 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2897 kldxref -R ${BASEDIR}/boot/ 2>/dev/null
2900 # We've finished updating the kernel.
2903 # Do we need to ask for a reboot now?
2904 if [ -f $1/kernelfirst ] &&
2905 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2908 Kernel updates have been installed. Please reboot and run
2909 "$0 install" again to finish installing updates.
2915 # If we haven't already dealt with the world, deal with it.
2916 if ! [ -f $1/worlddone ]; then
2917 # Create any necessary directories first
2918 grep -vE '^/boot/' $1/INDEX-NEW |
2919 grep -E '^[^|]+\|d\|' > INDEX-NEW
2920 install_from_index INDEX-NEW || return 1
2922 # Install new runtime linker
2923 grep -vE '^/boot/' $1/INDEX-NEW |
2924 grep -vE '^[^|]+\|d\|' |
2925 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2926 install_from_index INDEX-NEW || return 1
2928 # Install new shared libraries next
2929 grep -vE '^/boot/' $1/INDEX-NEW |
2930 grep -vE '^[^|]+\|d\|' |
2931 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2932 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2933 install_from_index INDEX-NEW || return 1
2935 # Deal with everything else
2936 grep -vE '^/boot/' $1/INDEX-OLD |
2937 grep -vE '^[^|]+\|d\|' |
2938 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2939 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2940 grep -vE '^/boot/' $1/INDEX-NEW |
2941 grep -vE '^[^|]+\|d\|' |
2942 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2943 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2944 install_from_index INDEX-NEW || return 1
2945 install_delete INDEX-OLD INDEX-NEW || return 1
2947 # Rehash certs if we actually have certctl installed.
2948 if which certctl>/dev/null; then
2949 env DESTDIR=${BASEDIR} certctl rehash
2952 # Rebuild generated pwd files and /etc/login.conf.db.
2953 pwd_mkdb -d ${BASEDIR}/etc -p ${BASEDIR}/etc/master.passwd
2954 cap_mkdb ${BASEDIR}/etc/login.conf
2956 # Rebuild man page databases, if necessary.
2957 for D in /usr/share/man /usr/share/openssl/man; do
2958 if [ ! -d ${BASEDIR}/$D ]; then
2961 if [ -f ${BASEDIR}/$D/mandoc.db ] && \
2962 [ -z "$(find ${BASEDIR}/$D -type f -newer ${BASEDIR}/$D/mandoc.db)" ]; then
2965 makewhatis ${BASEDIR}/$D
2968 # We've finished installing the world and deleting old files
2969 # which are not shared libraries.
2972 # Do we need to ask the user to portupgrade now?
2973 grep -vE '^/boot/' $1/INDEX-NEW |
2974 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2977 if grep -vE '^/boot/' $1/INDEX-OLD |
2978 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2981 join -v 1 - newfiles |
2985 Completing this upgrade requires removing old shared object files.
2986 Please rebuild all installed 3rd party software (e.g., programs
2987 installed from the ports tree) and then run "$0 install"
2988 again to finish installing updates.
2996 # Remove old shared libraries
2997 grep -vE '^/boot/' $1/INDEX-NEW |
2998 grep -vE '^[^|]+\|d\|' |
2999 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
3000 grep -vE '^/boot/' $1/INDEX-OLD |
3001 grep -vE '^[^|]+\|d\|' |
3002 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
3003 install_delete INDEX-OLD INDEX-NEW || return 1
3005 # Remove old directories
3006 grep -vE '^/boot/' $1/INDEX-NEW |
3007 grep -E '^[^|]+\|d\|' > INDEX-NEW
3008 grep -vE '^/boot/' $1/INDEX-OLD |
3009 grep -E '^[^|]+\|d\|' > INDEX-OLD
3010 install_delete INDEX-OLD INDEX-NEW || return 1
3012 # Remove temporary files
3013 rm INDEX-OLD INDEX-NEW
3016 # Rearrange bits to allow the installed updates to be rolled back
3017 install_setup_rollback () {
3018 # Remove the "reboot after installing kernel", "kernel updated", and
3019 # "finished installing the world" flags if present -- they are
3020 # irrelevant when rolling back updates.
3021 if [ -f ${BDHASH}-install/kernelfirst ]; then
3022 rm ${BDHASH}-install/kernelfirst
3023 rm ${BDHASH}-install/kerneldone
3025 if [ -f ${BDHASH}-install/worlddone ]; then
3026 rm ${BDHASH}-install/worlddone
3029 if [ -L ${BDHASH}-rollback ]; then
3030 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
3033 mv ${BDHASH}-install ${BDHASH}-rollback
3036 # Actually install updates
3038 echo -n "Installing updates..."
3040 # Make sure we have all the files we should have
3041 install_verify ${BDHASH}-install/INDEX-OLD \
3042 ${BDHASH}-install/INDEX-NEW || return 1
3044 # Remove system immutable flag from files
3045 install_unschg ${BDHASH}-install/INDEX-OLD \
3046 ${BDHASH}-install/INDEX-NEW || return 1
3048 # Install new files, delete old files, and update linker.hints
3049 install_files ${BDHASH}-install || return 1
3051 # Rearrange bits to allow the installed updates to be rolled back
3052 install_setup_rollback
3057 # Rearrange bits to allow the previous set of updates to be rolled back next.
3058 rollback_setup_rollback () {
3059 if [ -L ${BDHASH}-rollback/rollback ]; then
3060 mv ${BDHASH}-rollback/rollback rollback-tmp
3061 rm -r ${BDHASH}-rollback/
3062 rm ${BDHASH}-rollback
3063 mv rollback-tmp ${BDHASH}-rollback
3065 rm -r ${BDHASH}-rollback/
3066 rm ${BDHASH}-rollback
3070 # Install old files, delete new files, and update linker.hints
3072 # Install old shared library files which don't have the same path as
3073 # a new shared library file.
3074 grep -vE '^/boot/' $1/INDEX-NEW |
3075 grep -E '/lib/.*\.so\.[0-9]+\|' |
3077 sort > INDEX-NEW.libs.flist
3078 grep -vE '^/boot/' $1/INDEX-OLD |
3079 grep -E '/lib/.*\.so\.[0-9]+\|' |
3080 sort -k 1,1 -t '|' - |
3081 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
3082 install_from_index INDEX-OLD || return 1
3084 # Deal with files which are neither kernel nor shared library
3085 grep -vE '^/boot/' $1/INDEX-OLD |
3086 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3087 grep -vE '^/boot/' $1/INDEX-NEW |
3088 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3089 install_from_index INDEX-OLD || return 1
3090 install_delete INDEX-NEW INDEX-OLD || return 1
3092 # Install any old shared library files which we didn't install above.
3093 grep -vE '^/boot/' $1/INDEX-OLD |
3094 grep -E '/lib/.*\.so\.[0-9]+\|' |
3095 sort -k 1,1 -t '|' - |
3096 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
3097 install_from_index INDEX-OLD || return 1
3099 # Delete unneeded shared library files
3100 grep -vE '^/boot/' $1/INDEX-OLD |
3101 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3102 grep -vE '^/boot/' $1/INDEX-NEW |
3103 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3104 install_delete INDEX-NEW INDEX-OLD || return 1
3106 # Deal with kernel files
3107 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
3108 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3109 install_from_index INDEX-OLD || return 1
3110 install_delete INDEX-NEW INDEX-OLD || return 1
3111 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3112 kldxref -R /boot/ 2>/dev/null
3115 # Remove temporary files
3116 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3119 # Actually rollback updates
3121 echo -n "Uninstalling updates..."
3123 # If there are updates waiting to be installed, remove them; we
3124 # want the user to re-run 'fetch' after rolling back updates.
3125 if [ -L ${BDHASH}-install ]; then
3126 rm -r ${BDHASH}-install/
3127 rm ${BDHASH}-install
3130 # Make sure we have all the files we should have
3131 install_verify ${BDHASH}-rollback/INDEX-NEW \
3132 ${BDHASH}-rollback/INDEX-OLD || return 1
3134 # Remove system immutable flag from files
3135 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3136 ${BDHASH}-rollback/INDEX-OLD || return 1
3138 # Install old files, delete new files, and update linker.hints
3139 rollback_files ${BDHASH}-rollback || return 1
3141 # Remove the rollback directory and the symlink pointing to it; and
3142 # rearrange bits to allow the previous set of updates to be rolled
3144 rollback_setup_rollback
3149 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3151 # Get all the lines which mismatch in something other than file
3152 # flags. We ignore file flags because sysinstall doesn't seem to
3153 # set them when it installs FreeBSD; warning about these adds a
3154 # very large amount of noise.
3155 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3156 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3157 cut -f 1-5,7-8 -d '|' $2 |
3158 comm -13 $1.noflags - |
3159 fgrep -v '|-|||||' |
3160 sort -k 1,1 -t '|' |
3161 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3163 # Ignore files which match IDSIGNOREPATHS.
3164 for X in ${IDSIGNOREPATHS}; do
3165 grep -E "^${X}" INDEX-NOTMATCHING
3168 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3169 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3171 # Go through the lines and print warnings.
3173 while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do
3174 # Warn about different object types.
3175 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3176 echo -n "${FPATH} is a "
3178 f) echo -n "regular file, "
3180 d) echo -n "directory, "
3182 L) echo -n "symlink, "
3185 echo -n "but should be a "
3187 f) echo -n "regular file."
3189 d) echo -n "directory."
3191 L) echo -n "symlink."
3196 # Skip other tests, since they don't make sense if
3197 # we're comparing different object types.
3201 # Warn about different owners.
3202 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3203 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3204 echo "but should be owned by user id ${OWNER}."
3207 # Warn about different groups.
3208 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3209 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3210 echo "but should be owned by group id ${GROUP}."
3213 # Warn about different permissions. We do not warn about
3214 # different permissions on symlinks, since some archivers
3215 # don't extract symlink permissions correctly and they are
3217 if ! [ "${PERM}" = "${P_PERM}" ] &&
3218 ! [ "${TYPE}" = "L" ]; then
3219 echo -n "${FPATH} has ${P_PERM} permissions, "
3220 echo "but should have ${PERM} permissions."
3223 # Warn about different file hashes / symlink destinations.
3224 if ! [ "${HASH}" = "${P_HASH}" ]; then
3225 if [ "${TYPE}" = "L" ]; then
3226 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3227 echo "but should be a symlink to ${HASH}."
3229 if [ "${TYPE}" = "f" ]; then
3230 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3231 echo "but should have SHA256 hash ${HASH}."
3235 # We don't warn about different hard links, since some
3236 # some archivers break hard links, and as long as the
3237 # underlying data is correct they really don't matter.
3238 done < INDEX-NOTMATCHING
3241 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3244 # Do the work involved in comparing the system to a "known good" index
3246 workdir_init || return 1
3248 # Prepare the mirror list.
3249 fetch_pick_server_init && fetch_pick_server
3251 # Try to fetch the public key until we run out of servers.
3252 while ! fetch_key; do
3253 fetch_pick_server || return 1
3256 # Try to fetch the metadata index signature ("tag") until we run
3257 # out of available servers; and sanity check the downloaded tag.
3258 while ! fetch_tag; do
3259 fetch_pick_server || return 1
3261 fetch_tagsanity || return 1
3263 # Fetch INDEX-OLD and INDEX-ALL.
3264 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3266 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3267 # the components we want and without anything marked as "Ignore".
3268 fetch_filter_metadata INDEX-OLD || return 1
3269 fetch_filter_metadata INDEX-ALL || return 1
3271 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3272 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3273 mv INDEX-ALL.tmp INDEX-ALL
3276 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3277 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3279 # Inspect the system and generate an INDEX-PRESENT file.
3280 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3282 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3284 IDS_compare INDEX-ALL INDEX-PRESENT
3287 #### Main functions -- call parameter-handling and core functions
3289 # Using the command line, configuration file, and defaults,
3290 # set all the parameters which are needed later.
3298 # Fetch command. Make sure that we're being called
3299 # interactively, then run fetch_check_params and fetch_run
3301 finalize_components_config ${COMPONENTS}
3302 if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then
3303 echo -n "`basename $0` fetch should not "
3304 echo "be run non-interactively."
3305 echo "Run `basename $0` cron instead."
3313 # Cron command. Make sure the parameters are sensible; wait
3314 # rand(3600) seconds; then fetch updates. While fetching updates,
3315 # send output to a temporary file; only print that file if the
3319 sleep `jot -r 1 0 3600`
3321 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3322 finalize_components_config ${COMPONENTS} >> ${TMPFILE}
3323 if ! fetch_run >> ${TMPFILE} ||
3324 ! grep -q "No updates needed" ${TMPFILE} ||
3325 [ ${VERBOSELEVEL} = "debug" ]; then
3326 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3332 # Fetch files for upgrading to a new release.
3334 finalize_components_config ${COMPONENTS}
3335 upgrade_check_params
3336 upgrade_run || exit 1
3339 # Check if there are fetched updates ready to install.
3340 # Chdir into the working directory.
3341 cmd_updatesready () {
3342 finalize_components_config ${COMPONENTS}
3343 # Check if working directory exists (if not, no updates pending)
3344 if ! [ -e "${WORKDIR}" ]; then
3345 echo "No updates are available to install."
3349 # Change into working directory (fail if no permission/directory etc.)
3350 cd ${WORKDIR} || exit 1
3352 # Construct a unique name from ${BASEDIR}
3353 BDHASH=`echo ${BASEDIR} | sha256 -q`
3355 # Check that we have updates ready to install
3356 if ! [ -L ${BDHASH}-install ]; then
3357 echo "No updates are available to install."
3361 echo "There are updates available to install."
3362 echo "Run '$0 install' to proceed."
3365 # Install downloaded updates.
3367 finalize_components_config ${COMPONENTS}
3368 install_check_params
3369 install_run || exit 1
3372 # Rollback most recently installed updates.
3374 finalize_components_config ${COMPONENTS}
3375 rollback_check_params
3376 rollback_run || exit 1
3379 # Compare system against a "known good" index.
3381 finalize_components_config ${COMPONENTS}
3386 # Output configuration.
3388 finalize_components_config ${COMPONENTS}
3389 for X in ${CONFIGOPTIONS}; do
3390 echo $X=$(eval echo \$${X})
3396 # Make sure we find utilities from the base system
3397 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3399 # Set a pager if the user doesn't
3400 if [ -z "$PAGER" ]; then
3404 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3408 for COMMAND in ${COMMANDS}; do