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
49 -k KEY -- Trust an RSA key with SHA256 hash of KEY
50 -r release -- Target for upgrade (e.g., 11.1-RELEASE)
51 -s server -- Server from which to fetch updates
52 (default: update.FreeBSD.org)
53 -t address -- Mail output of cron command, if any, to address
55 --not-running-from-cron
56 -- Run without a tty, for use by automated tools
57 --currently-running release
58 -- Update as if currently running this release
60 fetch -- Fetch updates from server
61 cron -- Sleep rand(3600) seconds, fetch updates, and send an
62 email if updates were found
63 upgrade -- Fetch upgrades to FreeBSD version specified via -r option
64 install -- Install downloaded updates or upgrades
65 rollback -- Uninstall most recently installed updates
66 IDS -- Compare the system against an index of "known good" files.
71 #### Configuration processing functions
74 # Configuration options are set in the following order of priority:
75 # 1. Command line options
76 # 2. Configuration file options
78 # In addition, certain options (e.g., IgnorePaths) can be specified multiple
79 # times and (as long as these are all in the same place, e.g., inside the
80 # configuration file) they will accumulate. Finally, because the path to the
81 # configuration file can be specified at the command line, the entire command
82 # line must be processed before we start reading the configuration file.
84 # Sound like a mess? It is. Here's how we handle this:
85 # 1. Initialize CONFFILE and all the options to "".
86 # 2. Process the command line. Throw an error if a non-accumulating option
88 # 3. If CONFFILE is "", set CONFFILE to /etc/freebsd-update.conf .
89 # 4. For all the configuration options X, set X_saved to X.
90 # 5. Initialize all the options to "".
91 # 6. Read CONFFILE line by line, parsing options.
92 # 7. For each configuration option X, set X to X_saved iff X_saved is not "".
93 # 8. Repeat steps 4-7, except setting options to their default values at (6).
95 CONFIGOPTIONS="KEYPRINT WORKDIR SERVERNAME MAILTO ALLOWADD ALLOWDELETE
96 KEEPMODIFIEDMETADATA COMPONENTS IGNOREPATHS UPDATEIFUNMODIFIED
97 BASEDIR VERBOSELEVEL TARGETRELEASE STRICTCOMPONENTS MERGECHANGES
98 IDSIGNOREPATHS BACKUPKERNEL BACKUPKERNELDIR BACKUPKERNELSYMBOLFILES"
100 # Set all the configuration options to "".
102 for X in ${CONFIGOPTIONS}; do
107 # For each configuration option X, set X_saved to X.
109 for X in ${CONFIGOPTIONS}; do
110 eval ${X}_saved=\$${X}
114 # For each configuration option X, set X to X_saved if X_saved is not "".
116 for X in ${CONFIGOPTIONS}; do
118 if ! [ -z "${_}" ]; then
119 eval ${X}=\$${X}_saved
124 # Set the trusted keyprint.
126 if [ -z ${KEYPRINT} ]; then
133 # Set the working directory.
135 if [ -z ${WORKDIR} ]; then
142 # Set the name of the server (pool) from which to fetch updates
143 config_ServerName () {
144 if [ -z ${SERVERNAME} ]; then
151 # Set the address to which 'cron' output will be mailed.
153 if [ -z ${MAILTO} ]; then
160 # Set whether FreeBSD Update is allowed to add files (or directories, or
161 # symlinks) which did not previously exist.
163 if [ -z ${ALLOWADD} ]; then
180 # Set whether FreeBSD Update is allowed to remove files/directories/symlinks.
181 config_AllowDelete () {
182 if [ -z ${ALLOWDELETE} ]; then
199 # Set whether FreeBSD Update should keep existing inode ownership,
200 # permissions, and flags, in the event that they have been modified locally
202 config_KeepModifiedMetadata () {
203 if [ -z ${KEEPMODIFIEDMETADATA} ]; then
206 KEEPMODIFIEDMETADATA=yes
209 KEEPMODIFIEDMETADATA=no
220 # Add to the list of components which should be kept updated.
221 config_Components () {
223 if [ "$C" = "src" ]; then
224 if [ -e /usr/src/COPYRIGHT ]; then
225 COMPONENTS="${COMPONENTS} ${C}"
227 echo "src component not installed, skipped"
230 COMPONENTS="${COMPONENTS} ${C}"
235 # Add to the list of paths under which updates will be ignored.
236 config_IgnorePaths () {
238 IGNOREPATHS="${IGNOREPATHS} ${C}"
242 # Add to the list of paths which IDS should ignore.
243 config_IDSIgnorePaths () {
245 IDSIGNOREPATHS="${IDSIGNOREPATHS} ${C}"
249 # Add to the list of paths within which updates will be performed only if the
250 # file on disk has not been modified locally.
251 config_UpdateIfUnmodified () {
253 UPDATEIFUNMODIFIED="${UPDATEIFUNMODIFIED} ${C}"
257 # Add to the list of paths within which updates to text files will be merged
258 # instead of overwritten.
259 config_MergeChanges () {
261 MERGECHANGES="${MERGECHANGES} ${C}"
265 # Work on a FreeBSD installation mounted under $1
267 if [ -z ${BASEDIR} ]; then
274 # When fetching upgrades, should we assume the user wants exactly the
275 # components listed in COMPONENTS, rather than trying to guess based on
276 # what's currently installed?
277 config_StrictComponents () {
278 if [ -z ${STRICTCOMPONENTS} ]; then
295 # Upgrade to FreeBSD $1
296 config_TargetRelease () {
297 if [ -z ${TARGETRELEASE} ]; then
302 if echo ${TARGETRELEASE} | grep -qE '^[0-9.]+$'; then
303 TARGETRELEASE="${TARGETRELEASE}-RELEASE"
307 # Define what happens to output of utilities
308 config_VerboseLevel () {
309 if [ -z ${VERBOSELEVEL} ]; then
311 [Dd][Ee][Bb][Uu][Gg])
314 [Nn][Oo][Ss][Tt][Aa][Tt][Ss])
317 [Ss][Tt][Aa][Tt][Ss])
329 config_BackupKernel () {
330 if [ -z ${BACKUPKERNEL} ]; then
347 config_BackupKernelDir () {
348 if [ -z ${BACKUPKERNELDIR} ]; then
350 echo "BackupKernelDir set to empty dir"
354 # We check for some paths which would be extremely odd
355 # to use, but which could cause a lot of problems if
358 /|/bin|/boot|/etc|/lib|/libexec|/sbin|/usr|/var)
359 echo "BackupKernelDir set to invalid path $1"
366 echo "BackupKernelDir ($1) is not an absolute path"
375 config_BackupKernelSymbolFiles () {
376 if [ -z ${BACKUPKERNELSYMBOLFILES} ]; then
379 BACKUPKERNELSYMBOLFILES=yes
382 BACKUPKERNELSYMBOLFILES=no
393 # Handle one line of configuration
395 if [ $# -eq 0 ]; then
404 #### Parameter handling functions.
406 # Initialize parameters to null, just in case they're
407 # set in the environment.
409 # Configration settings
412 # No configuration file set yet
415 # No commands specified yet
418 # Force fetch to proceed
424 # Fetched first in a chain of commands
428 # Parse the command line
430 while [ $# -gt 0 ]; do
432 # Location of configuration file
434 if [ $# -eq 1 ]; then usage; fi
435 if [ ! -z "${CONFFILE}" ]; then usage; fi
441 --not-running-from-cron)
445 shift; export UNAME_r="$1"
448 # Configuration file equivalents
450 if [ $# -eq 1 ]; then usage; fi; shift
451 config_BaseDir $1 || usage
454 if [ $# -eq 1 ]; then usage; fi; shift
455 config_WorkDir $1 || usage
458 if [ $# -eq 1 ]; then usage; fi; shift
459 config_KeyPrint $1 || usage
462 if [ $# -eq 1 ]; then usage; fi; shift
463 config_ServerName $1 || usage
466 if [ $# -eq 1 ]; then usage; fi; shift
467 config_TargetRelease $1 || usage
470 if [ $# -eq 1 ]; then usage; fi; shift
471 config_MailTo $1 || usage
474 if [ $# -eq 1 ]; then usage; fi; shift
475 config_VerboseLevel $1 || usage
478 # Aliases for "-v debug" and "-v nostats"
480 config_VerboseLevel debug || usage
483 config_VerboseLevel nostats || usage
487 cron | fetch | upgrade | install | rollback | IDS)
488 COMMANDS="${COMMANDS} $1"
491 # Anything else is an error
499 # Make sure we have at least one command
500 if [ -z "${COMMANDS}" ]; then
505 # Parse the configuration file
507 # If a configuration file was specified on the command line, check
508 # that it exists and is readable.
509 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
510 echo -n "File does not exist "
511 echo -n "or is not readable: "
516 # If a configuration file was not specified on the command line,
517 # use the default configuration file path. If that default does
518 # not exist, give up looking for any configuration.
519 if [ -z "${CONFFILE}" ]; then
520 CONFFILE="/etc/freebsd-update.conf"
521 if [ ! -r "${CONFFILE}" ]; then
526 # Save the configuration options specified on the command line, and
527 # clear all the options in preparation for reading the config file.
531 # Read the configuration file. Anything after the first '#' is
532 # ignored, and any blank lines are ignored.
536 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
537 if ! configline ${LINEX}; then
538 echo "Error processing configuration file, line $L:"
544 # Merge the settings read from the configuration file with those
545 # provided at the command line.
549 # Provide some default parameters
551 # Save any parameters already configured, and clear the slate
555 # Default configurations
556 config_WorkDir /var/db/freebsd-update
559 config_AllowDelete yes
560 config_KeepModifiedMetadata yes
562 config_VerboseLevel stats
563 config_StrictComponents no
564 config_BackupKernel yes
565 config_BackupKernelDir /boot/kernel.old
566 config_BackupKernelSymbolFiles no
568 # Merge these defaults into the earlier-configured settings
572 # Set utility output filtering options, based on ${VERBOSELEVEL}
573 fetch_setup_verboselevel () {
574 case ${VERBOSELEVEL} in
576 QUIETREDIR="/dev/stderr"
578 STATSREDIR="/dev/stderr"
586 STATSREDIR="/dev/null"
592 QUIETREDIR="/dev/null"
594 STATSREDIR="/dev/stdout"
602 # Perform sanity checks and set some final parameters
603 # in preparation for fetching files. Figure out which
604 # set of updates should be downloaded: If the user is
605 # running *-p[0-9]+, strip off the last part; if the
606 # user is running -SECURITY, call it -RELEASE. Chdir
607 # into the working directory.
608 fetchupgrade_check_params () {
609 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
612 "SERVERNAME must be given via command line or configuration file."
613 _KEYPRINT_z="Key must be given via -k option or configuration file."
614 _KEYPRINT_bad="Invalid key fingerprint: "
615 _WORKDIR_bad="Directory does not exist or is not writable: "
616 _WORKDIR_bad2="Directory is not on a persistent filesystem: "
618 if [ -z "${SERVERNAME}" ]; then
619 echo -n "`basename $0`: "
620 echo "${_SERVERNAME_z}"
623 if [ -z "${KEYPRINT}" ]; then
624 echo -n "`basename $0`: "
625 echo "${_KEYPRINT_z}"
628 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
629 echo -n "`basename $0`: "
630 echo -n "${_KEYPRINT_bad}"
634 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
635 echo -n "`basename $0`: "
636 echo -n "${_WORKDIR_bad}"
640 case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*)
641 echo -n "`basename $0`: "
642 echo -n "${_WORKDIR_bad2}"
648 cd ${WORKDIR} || exit 1
650 # Generate release number. The s/SECURITY/RELEASE/ bit exists
651 # to provide an upgrade path for FreeBSD Update 1.x users, since
652 # the kernels provided by FreeBSD Update 1.x are always labelled
655 sed -E 's,-p[0-9]+,,' |
656 sed -E 's,-SECURITY,-RELEASE,'`
658 FETCHDIR=${RELNUM}/${ARCH}
659 PATCHDIR=${RELNUM}/${ARCH}/bp
661 # Figure out what directory contains the running kernel
662 BOOTFILE=`sysctl -n kern.bootfile`
663 KERNELDIR=${BOOTFILE%/kernel}
664 if ! [ -d ${KERNELDIR} ]; then
665 echo "Cannot identify running kernel"
669 # Figure out what kernel configuration is running. We start with
670 # the output of `uname -i`, and then make the following adjustments:
671 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
672 # file says "ident SMP-GENERIC", I don't know...
673 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
674 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
675 # we're running an SMP kernel. This mis-identification is a bug
676 # which was fixed in 6.2-STABLE.
678 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
681 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
682 if sysctl kern.version | grep -qE '/SMP$'; then
688 BSPATCH=/usr/bin/bspatch
690 PHTTPGET=/usr/libexec/phttpget
692 # Set up variables relating to VERBOSELEVEL
693 fetch_setup_verboselevel
695 # Construct a unique name from ${BASEDIR}
696 BDHASH=`echo ${BASEDIR} | sha256 -q`
699 # Perform sanity checks etc. before fetching updates.
700 fetch_check_params () {
701 fetchupgrade_check_params
703 if ! [ -z "${TARGETRELEASE}" ]; then
704 echo -n "`basename $0`: "
705 echo -n "-r option is meaningless with 'fetch' command. "
706 echo "(Did you mean 'upgrade' instead?)"
710 # Check that we have updates ready to install
711 if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then
712 echo "You have a partially completed upgrade pending"
713 echo "Run '$0 install' first."
714 echo "Run '$0 fetch -F' to proceed anyway."
719 # Perform sanity checks etc. before fetching upgrades.
720 upgrade_check_params () {
721 fetchupgrade_check_params
723 # Unless set otherwise, we're upgrading to the same kernel config.
724 NKERNCONF=${KERNCONF}
726 # We need TARGETRELEASE set
727 _TARGETRELEASE_z="Release target must be specified via -r option."
728 if [ -z "${TARGETRELEASE}" ]; then
729 echo -n "`basename $0`: "
730 echo "${_TARGETRELEASE_z}"
734 # The target release should be != the current release.
735 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
736 echo -n "`basename $0`: "
737 echo "Cannot upgrade from ${RELNUM} to itself"
741 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
742 if [ "${ALLOWADD}" = "no" ]; then
743 echo -n "`basename $0`: "
744 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
745 echo "when upgrading between releases."
748 if [ "${ALLOWDELETE}" = "no" ]; then
749 echo -n "`basename $0`: "
750 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
751 echo "when upgrading between releases."
755 # Set EDITOR to /usr/bin/vi if it isn't already set
756 : ${EDITOR:='/usr/bin/vi'}
759 # Perform sanity checks and set some final parameters in
760 # preparation for installing updates.
761 install_check_params () {
762 # Check that we are root. All sorts of things won't work otherwise.
763 if [ `id -u` != 0 ]; then
764 echo "You must be root to run this."
768 # Check that securelevel <= 0. Otherwise we can't update schg files.
769 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
770 echo "Updates cannot be installed when the system securelevel"
771 echo "is greater than zero."
775 # Check that we have a working directory
776 _WORKDIR_bad="Directory does not exist or is not writable: "
777 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
778 echo -n "`basename $0`: "
779 echo -n "${_WORKDIR_bad}"
783 cd ${WORKDIR} || exit 1
785 # Construct a unique name from ${BASEDIR}
786 BDHASH=`echo ${BASEDIR} | sha256 -q`
788 # Check that we have updates ready to install
789 if ! [ -L ${BDHASH}-install ]; then
790 echo "No updates are available to install."
791 if [ $ISFETCHED -eq 0 ]; then
792 echo "Run '$0 fetch' first."
796 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
797 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
798 echo "Update manifest is corrupt -- this should never happen."
799 echo "Re-run '$0 fetch'."
803 # Figure out what directory contains the running kernel
804 BOOTFILE=`sysctl -n kern.bootfile`
805 KERNELDIR=${BOOTFILE%/kernel}
806 if ! [ -d ${KERNELDIR} ]; then
807 echo "Cannot identify running kernel"
812 # Perform sanity checks and set some final parameters in
813 # preparation for UNinstalling updates.
814 rollback_check_params () {
815 # Check that we are root. All sorts of things won't work otherwise.
816 if [ `id -u` != 0 ]; then
817 echo "You must be root to run this."
821 # Check that we have a working directory
822 _WORKDIR_bad="Directory does not exist or is not writable: "
823 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
824 echo -n "`basename $0`: "
825 echo -n "${_WORKDIR_bad}"
829 cd ${WORKDIR} || exit 1
831 # Construct a unique name from ${BASEDIR}
832 BDHASH=`echo ${BASEDIR} | sha256 -q`
834 # Check that we have updates ready to rollback
835 if ! [ -L ${BDHASH}-rollback ]; then
836 echo "No rollback directory found."
839 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
840 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
841 echo "Update manifest is corrupt -- this should never happen."
846 # Perform sanity checks and set some final parameters
847 # in preparation for comparing the system against the
848 # published index. Figure out which index we should
849 # compare against: If the user is running *-p[0-9]+,
850 # strip off the last part; if the user is running
851 # -SECURITY, call it -RELEASE. Chdir into the working
853 IDS_check_params () {
854 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
857 "SERVERNAME must be given via command line or configuration file."
858 _KEYPRINT_z="Key must be given via -k option or configuration file."
859 _KEYPRINT_bad="Invalid key fingerprint: "
860 _WORKDIR_bad="Directory does not exist or is not writable: "
862 if [ -z "${SERVERNAME}" ]; then
863 echo -n "`basename $0`: "
864 echo "${_SERVERNAME_z}"
867 if [ -z "${KEYPRINT}" ]; then
868 echo -n "`basename $0`: "
869 echo "${_KEYPRINT_z}"
872 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
873 echo -n "`basename $0`: "
874 echo -n "${_KEYPRINT_bad}"
878 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
879 echo -n "`basename $0`: "
880 echo -n "${_WORKDIR_bad}"
884 cd ${WORKDIR} || exit 1
886 # Generate release number. The s/SECURITY/RELEASE/ bit exists
887 # to provide an upgrade path for FreeBSD Update 1.x users, since
888 # the kernels provided by FreeBSD Update 1.x are always labelled
891 sed -E 's,-p[0-9]+,,' |
892 sed -E 's,-SECURITY,-RELEASE,'`
894 FETCHDIR=${RELNUM}/${ARCH}
895 PATCHDIR=${RELNUM}/${ARCH}/bp
897 # Figure out what directory contains the running kernel
898 BOOTFILE=`sysctl -n kern.bootfile`
899 KERNELDIR=${BOOTFILE%/kernel}
900 if ! [ -d ${KERNELDIR} ]; then
901 echo "Cannot identify running kernel"
905 # Figure out what kernel configuration is running. We start with
906 # the output of `uname -i`, and then make the following adjustments:
907 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
908 # file says "ident SMP-GENERIC", I don't know...
909 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
910 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
911 # we're running an SMP kernel. This mis-identification is a bug
912 # which was fixed in 6.2-STABLE.
914 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
917 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
918 if sysctl kern.version | grep -qE '/SMP$'; then
925 PHTTPGET=/usr/libexec/phttpget
927 # Set up variables relating to VERBOSELEVEL
928 fetch_setup_verboselevel
931 #### Core functionality -- the actual work gets done here
933 # Use an SRV query to pick a server. If the SRV query doesn't provide
934 # a useful answer, use the server name specified by the user.
935 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
936 # from that; or if no servers are returned, use ${SERVERNAME}.
937 # This allows a user to specify "portsnap.freebsd.org" (in which case
938 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
939 # (in which case portsnap will use that particular server, since there
940 # won't be an SRV entry for that name).
942 # We ignore the Port field, since we are always going to use port 80.
944 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
945 # no mirrors are available for any reason.
946 fetch_pick_server_init () {
949 # Check that host(1) exists (i.e., that the system wasn't built with the
950 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
951 if ! which -s host; then
956 echo -n "Looking up ${SERVERNAME} mirrors... "
958 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
959 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
960 # "$name server selection ..."; we allow either format.
961 MLIST="_http._tcp.${SERVERNAME}"
962 host -t srv "${MLIST}" |
963 sed -nE "s/${MLIST} (has SRV record|server selection) //Ip" |
964 cut -f 1,2,4 -d ' ' |
966 sort > serverlist_full
968 # If no records, give up -- we'll just use the server name we were given.
969 if [ `wc -l < serverlist_full` -eq 0 ]; then
974 # Report how many mirrors we found.
975 echo `wc -l < serverlist_full` "mirrors found."
977 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
978 # is set, this will be used to generate the seed; otherwise, the seed
980 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
981 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
985 RANDVALUE=`jot -r 1 0 999999999`
989 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
990 fetch_pick_server () {
991 # Generate a list of not-yet-tried mirrors
992 sort serverlist_tried |
993 comm -23 serverlist_full - > serverlist
995 # Have we run out of mirrors?
996 if [ `wc -l < serverlist` -eq 0 ]; then
997 echo "No mirrors remaining, giving up."
1001 # Find the highest priority level (lowest numeric value).
1002 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
1004 # Add up the weights of the response lines at that priority level.
1009 SRV_W=`echo $X | cut -f 2 -d ' '`
1010 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
1015 # If all the weights are 0, pretend that they are all 1 instead.
1016 if [ ${SRV_WSUM} -eq 0 ]; then
1017 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
1023 # Pick a value between 0 and the sum of the weights - 1
1024 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
1026 # Read through the list of mirrors and set SERVERNAME. Write the line
1027 # corresponding to the mirror we selected into serverlist_tried so that
1028 # we won't try it again.
1032 SRV_W=`echo $X | cut -f 2 -d ' '`
1033 SRV_W=$(($SRV_W + $SRV_W_ADD))
1034 if [ $SRV_RND -lt $SRV_W ]; then
1035 SERVERNAME=`echo $X | cut -f 3 -d ' '`
1036 echo "$X" >> serverlist_tried
1039 SRV_RND=$(($SRV_RND - $SRV_W))
1046 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
1047 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
1048 fetch_make_patchlist () {
1049 grep -vE "^([0-9a-f]{64})\|\1$" |
1052 if [ -f "files/${Y}.gz" ] ||
1053 [ ! -f "files/${X}.gz" ]; then
1060 # Print user-friendly progress statistics
1065 if [ $(($LNC % 10)) = 0 ]; then
1067 elif [ $(($LNC % 2)) = 0 ]; then
1074 # Function for asking the user if everything is ok
1076 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1077 case "${CONTINUE}" in
1088 # Initialize the working directory
1091 touch tINDEX.present
1094 # Check that we have a public key with an appropriate hash, or
1095 # fetch the key if it doesn't exist. Returns 1 if the key has
1096 # not yet been fetched.
1098 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1102 echo -n "Fetching public key from ${SERVERNAME}... "
1104 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1105 2>${QUIETREDIR} || true
1106 if ! [ -r pub.ssl ]; then
1110 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1111 echo "key has incorrect hash."
1118 # Fetch metadata signature, aka "tag".
1120 echo -n "Fetching metadata signature "
1121 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1123 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1124 2>${QUIETREDIR} || true
1125 if ! [ -r latest.ssl ]; then
1130 openssl rsautl -pubin -inkey pub.ssl -verify \
1131 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1134 if ! [ `wc -l < tag.new` = 1 ] ||
1136 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1138 echo "invalid signature."
1144 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1145 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1146 EOLTIME=`cut -f 6 -d '|' < tag.new`
1149 # Sanity-check the patch number in a tag, to make sure that we're not
1150 # going to "update" backwards and to prevent replay attacks.
1151 fetch_tagsanity () {
1152 # Check that we're not going to move from -pX to -pY with Y < X.
1153 RELPX=`uname -r | sed -E 's,.*-,,'`
1154 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1155 RELPX=`echo ${RELPX} | cut -c 2-`
1159 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1161 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1162 echo " appear older than what"
1163 echo "we are currently running (`uname -r`)!"
1164 echo "Cowardly refusing to proceed any further."
1168 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1169 # it contains a patch number <= RELPATCHNUM, in order to protect
1170 # against rollback (replay) attacks.
1173 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1175 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1177 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1179 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1180 echo " are older than the"
1181 echo -n "most recently seen updates"
1182 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1183 echo "Cowardly refusing to proceed any further."
1189 # Fetch metadata index file
1190 fetch_metadata_index () {
1191 echo ${NDEBUG} "Fetching metadata index... "
1193 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1195 if ! [ -f ${TINDEXHASH} ]; then
1199 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1200 echo "update metadata index corrupt."
1206 # Print an error message about signed metadata being bogus.
1207 fetch_metadata_bogus () {
1209 echo "The update metadata$1 is correctly signed, but"
1210 echo "failed an integrity check."
1211 echo "Cowardly refusing to proceed any further."
1215 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1216 # with the lines not named in $@ from tINDEX.present (if that file exists).
1217 fetch_metadata_index_merge () {
1218 for METAFILE in $@; do
1219 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1221 fetch_metadata_bogus " index"
1225 grep -E "${METAFILE}\|" ${TINDEXHASH}
1227 sort > tINDEX.wanted
1229 if [ -f tINDEX.present ]; then
1230 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1231 sort -m - tINDEX.wanted > tINDEX.new
1234 mv tINDEX.wanted tINDEX.new
1238 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1239 # are added by future versions of the server, this won't cause problems,
1240 # since the only lines which appear in tINDEX.new are the ones which we
1241 # specifically grepped out of ${TINDEXHASH}.
1242 fetch_metadata_index_sanity () {
1243 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1244 fetch_metadata_bogus " index"
1249 # Sanity check the metadata file $1.
1250 fetch_metadata_sanity () {
1251 # Some aliases to save space later: ${P} is a character which can
1252 # appear in a path; ${M} is the four numeric metadata fields; and
1253 # ${H} is a sha256 hash.
1254 P="[-+./:=,%@_[~[:alnum:]]"
1255 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1258 # Check that the first four fields make sense.
1259 if gunzip -c < files/$1.gz |
1260 grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then
1261 fetch_metadata_bogus ""
1265 # Remove the first three fields.
1266 gunzip -c < files/$1.gz |
1267 cut -f 4- -d '|' > sanitycheck.tmp
1269 # Sanity check entries with type 'f'
1270 if grep -E '^f' sanitycheck.tmp |
1271 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1272 fetch_metadata_bogus ""
1276 # Sanity check entries with type 'd'
1277 if grep -E '^d' sanitycheck.tmp |
1278 grep -qvE "^d\|${M}\|\|\$"; then
1279 fetch_metadata_bogus ""
1283 # Sanity check entries with type 'L'
1284 if grep -E '^L' sanitycheck.tmp |
1285 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1286 fetch_metadata_bogus ""
1290 # Sanity check entries with type '-'
1291 if grep -E '^-' sanitycheck.tmp |
1292 grep -qvE "^-\|\|\|\|\|\|"; then
1293 fetch_metadata_bogus ""
1301 # Fetch the metadata index and metadata files listed in $@,
1302 # taking advantage of metadata patches where possible.
1304 fetch_metadata_index || return 1
1305 fetch_metadata_index_merge $@ || return 1
1306 fetch_metadata_index_sanity || return 1
1308 # Generate a list of wanted metadata patches
1309 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1310 fetch_make_patchlist > patchlist
1312 if [ -s patchlist ]; then
1313 # Attempt to fetch metadata patches
1314 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1315 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1316 tr '|' '-' < patchlist |
1317 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1318 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1319 2>${STATSREDIR} | fetch_progress
1322 # Attempt to apply metadata patches
1323 echo -n "Applying metadata patches... "
1324 tr '|' ' ' < patchlist |
1326 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1327 gunzip -c < ${X}-${Y}.gz > diff
1328 gunzip -c < files/${X}.gz > diff-OLD
1330 # Figure out which lines are being added and removed
1333 while read PREFIX; do
1334 look "${PREFIX}" diff-OLD
1337 grep -E '^\+' diff |
1338 cut -c 2- > diff-add
1340 # Generate the new file
1341 comm -23 diff-OLD diff-rm |
1342 sort - diff-add > diff-NEW
1344 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1345 mv diff-NEW files/${Y}
1348 mv diff-NEW ${Y}.bad
1350 rm -f ${X}-${Y}.gz diff
1351 rm -f diff-OLD diff-NEW diff-add diff-rm
1352 done 2>${QUIETREDIR}
1356 # Update metadata without patches
1357 cut -f 2 -d '|' < tINDEX.new |
1359 if [ ! -f "files/${Y}.gz" ]; then
1365 if [ -s filelist ]; then
1366 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1367 echo ${NDEBUG} "metadata files... "
1368 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1369 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1373 if ! [ -f ${Y}.gz ]; then
1377 if [ `gunzip -c < ${Y}.gz |
1378 ${SHA256} -q` = ${Y} ]; then
1379 mv ${Y}.gz files/${Y}.gz
1381 echo "metadata is corrupt."
1388 # Sanity-check the metadata files.
1389 cut -f 2 -d '|' tINDEX.new > filelist
1391 fetch_metadata_sanity ${X} || return 1
1394 # Remove files which are no longer needed
1395 cut -f 2 -d '|' tINDEX.present |
1397 cut -f 2 -d '|' tINDEX.new |
1399 comm -13 - oldfiles |
1400 lam -s "files/" - -s ".gz" |
1402 rm patchlist filelist oldfiles
1406 mv tINDEX.new tINDEX.present
1412 # Extract a subset of a downloaded metadata file containing only the parts
1413 # which are listed in COMPONENTS.
1414 fetch_filter_metadata_components () {
1415 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1416 gunzip -c < files/${METAHASH}.gz > $1.all
1418 # Fish out the lines belonging to components we care about.
1419 for C in ${COMPONENTS}; do
1420 look "`echo ${C} | tr '/' '|'`|" $1.all
1423 # Remove temporary file.
1427 # Generate a filtered version of the metadata file $1 from the downloaded
1428 # file, by fishing out the lines corresponding to components we're trying
1429 # to keep updated, and then removing lines corresponding to paths we want
1431 fetch_filter_metadata () {
1432 # Fish out the lines belonging to components we care about.
1433 fetch_filter_metadata_components $1
1435 # Canonicalize directory names by removing any trailing / in
1436 # order to avoid listing directories multiple times if they
1437 # belong to multiple components. Turning "/" into "" doesn't
1438 # matter, since we add a leading "/" when we use paths later.
1439 cut -f 3- -d '|' $1 |
1440 sed -e 's,/|d|,|d|,' |
1441 sed -e 's,/|-|,|-|,' |
1444 # Figure out which lines to ignore and remove them.
1445 for X in ${IGNOREPATHS}; do
1446 grep -E "^${X}" $1.tmp
1449 comm -13 - $1.tmp > $1
1451 # Remove temporary files.
1455 # Filter the metadata file $1 by adding lines with "/boot/$2"
1456 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1457 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1458 # the original lines which start with that.
1459 # Put another way: Deal with the fact that the FOO kernel is sometimes
1460 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1461 fetch_filter_kernel_names () {
1463 sed -e "s,/boot/$2,${KERNELDIR},g" |
1467 if ! [ -d /boot/$2 ]; then
1468 grep -v ^/boot/$2 $1 > $1.tmp
1473 # For all paths appearing in $1 or $3, inspect the system
1474 # and generate $2 describing what is currently installed.
1475 fetch_inspect_system () {
1479 # Tell the user why his disk is suddenly making lots of noise
1480 echo -n "Inspecting system... "
1482 # Generate list of files to inspect
1487 # Examine each file and output lines of the form
1488 # /path/to/file|type|device-inum|user|group|perm|flags|value
1489 # sorted by device and inode number.
1491 # If the symlink/file/directory does not exist, record this.
1492 if ! [ -e ${BASEDIR}/${F} ]; then
1496 if ! [ -r ${BASEDIR}/${F} ]; then
1497 echo "Cannot read file: ${BASEDIR}/${F}" \
1503 # Otherwise, output an index line.
1504 if [ -L ${BASEDIR}/${F} ]; then
1506 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1507 readlink ${BASEDIR}/${F};
1508 elif [ -f ${BASEDIR}/${F} ]; then
1510 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1511 sha256 -q ${BASEDIR}/${F};
1512 elif [ -d ${BASEDIR}/${F} ]; then
1514 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1516 echo "Unknown file type: ${BASEDIR}/${F}" \
1522 sort -k 3,3 -t '|' > $2.tmp
1525 # Check if an error occurred during system inspection
1526 if [ -f .err ]; then
1530 # Convert to the form
1531 # /path/to/file|type|user|group|perm|flags|value|hlink
1532 # by resolving identical device and inode numbers into hard links.
1533 cut -f 1,3 -d '|' $2.tmp |
1534 sort -k 1,1 -t '|' |
1535 sort -s -u -k 2,2 -t '|' |
1536 join -1 2 -2 3 -t '|' - $2.tmp |
1537 awk -F \| -v OFS=\| \
1539 if (($2 == $3) || ($4 == "-"))
1540 print $3,$4,$5,$6,$7,$8,$9,""
1542 print $3,$4,$5,$6,$7,$8,$9,$2
1547 # We're finished looking around
1551 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1552 # files which differ; generate $3 containing these paths and the old hashes.
1553 fetch_filter_mergechanges () {
1554 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1556 for X in ${MERGECHANGES}; do
1557 grep -E "^${X}" ${F}
1559 cut -f 1,2,7 -d '|' |
1563 # Any line in $2-values which doesn't appear in $1-values and is a
1564 # file means that we should list the path in $3.
1565 comm -13 $1-values $2-values |
1567 cut -f 1 -d '|' > $2-paths
1569 # For each path, pull out one (and only one!) entry from $1-values.
1570 # Note that we cannot distinguish which "old" version the user made
1571 # changes to; but hopefully any changes which occur due to security
1572 # updates will exist in both the "new" version and the version which
1573 # the user has installed, so the merging will still work.
1575 look "${X}|" $1-values |
1577 done < $2-paths > $3
1580 rm $1-values $2-values $2-paths
1583 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1584 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1585 # the paths are listed in $4. For entries in $2 marked "not present"
1586 # (aka. type -), remove lines from $[123] unless there is a corresponding
1588 fetch_filter_unmodified_notpresent () {
1589 # Figure out which lines of $1 and $3 correspond to bits which
1590 # should only be updated if they haven't changed, and fish out
1591 # the (path, type, value) tuples.
1592 # NOTE: We don't consider a file to be "modified" if it matches
1594 for X in ${UPDATEIFUNMODIFIED}; do
1598 cut -f 1,2,7 -d '|' |
1601 # Do the same for $2.
1602 for X in ${UPDATEIFUNMODIFIED}; do
1605 cut -f 1,2,7 -d '|' |
1608 # Any entry in $2-values which is not in $1-values corresponds to
1609 # a path which we need to remove from $1, $2, and $3, unless it
1610 # that path appears in $4.
1611 comm -13 $1-values $2-values |
1612 sort -t '|' -k 1,1 > mlines.tmp
1613 cut -f 1 -d '|' $4 |
1615 join -v 2 -t '|' - mlines.tmp |
1617 rm $1-values $2-values mlines.tmp
1619 # Any lines in $2 which are not in $1 AND are "not present" lines
1620 # also belong in mlines.
1622 cut -f 1,2,7 -d '|' |
1623 fgrep '|-|' >> mlines
1625 # Remove lines from $1, $2, and $3
1626 for X in $1 $2 $3; do
1627 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1628 cut -f 1 -d '|' < mlines |
1630 join -v 2 -t '|' - ${X}.tmp |
1635 # Store a list of the modified files, for future reference
1636 fgrep -v '|-|' mlines |
1637 cut -f 1 -d '|' > modifiedfiles
1641 # For each entry in $1 of type -, remove any corresponding
1642 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1643 # of type - from $1.
1644 fetch_filter_allowadd () {
1645 cut -f 1,2 -d '|' < $1 |
1647 cut -f 1 -d '|' > filesnotpresent
1649 if [ ${ALLOWADD} != "yes" ]; then
1651 join -v 1 -t '|' - filesnotpresent |
1657 join -v 1 -t '|' - filesnotpresent |
1663 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1664 # which don't correspond to entries in $2.
1665 fetch_filter_allowdelete () {
1666 # Produce a lists ${PATH}|${TYPE}
1668 cut -f 1-2 -d '|' < ${X} |
1669 sort -u > ${X}.nodes
1672 # Figure out which lines need to be removed from $1.
1673 if [ ${ALLOWDELETE} != "yes" ]; then
1674 comm -23 $1.nodes $2.nodes > $1.badnodes
1679 # Remove the relevant lines from $1
1682 done < $1.badnodes |
1683 comm -13 - $1 > $1.tmp
1686 rm $1.badnodes $1.nodes $2.nodes
1689 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1690 # with metadata not matching any entry in $1, replace the corresponding
1691 # line of $3 with one having the same metadata as the entry in $2.
1692 fetch_filter_modified_metadata () {
1693 # Fish out the metadata from $1 and $2
1695 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1698 # Find the metadata we need to keep
1699 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1700 comm -13 $1.metadata $2.metadata > keepmeta
1705 # Extract the lines which we need to remove from $3, and
1706 # construct the lines which we need to add to $3.
1710 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1711 look "${NODE}|" $3 >> $3.remove
1712 look "${NODE}|" $3 |
1714 lam -s "${LINE}|" - >> $3.add
1717 # Remove the specified lines and add the new lines.
1720 sort -u - $3.add > $3.tmp
1723 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1726 # Remove lines from $1 and $2 which are identical;
1727 # no need to update a file if it isn't changing.
1728 fetch_filter_uptodate () {
1729 comm -23 $1 $2 > $1.tmp
1730 comm -13 $1 $2 > $2.tmp
1736 # Fetch any "clean" old versions of files we need for merging changes.
1737 fetch_files_premerge () {
1738 # We only need to do anything if $1 is non-empty.
1740 # Tell the user what we're doing
1741 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1743 # List of files wanted
1746 sort -u > files.wanted
1748 # Only fetch the files we don't already have
1750 if [ ! -f "files/${Y}.gz" ]; then
1753 done < files.wanted > filelist
1755 # Actually fetch them
1756 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1757 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1760 # Make sure we got them all, and move them into /files/
1762 if ! [ -f ${Y}.gz ]; then
1766 if [ `gunzip -c < ${Y}.gz |
1767 ${SHA256} -q` = ${Y} ]; then
1768 mv ${Y}.gz files/${Y}.gz
1770 echo "${Y} has incorrect hash."
1777 rm filelist files.wanted
1781 # Prepare to fetch files: Generate a list of the files we need,
1782 # copy the unmodified files we have into /files/, and generate
1783 # a list of patches to download.
1784 fetch_files_prepare () {
1785 # Tell the user why his disk is suddenly making lots of noise
1786 echo -n "Preparing to download files... "
1788 # Reduce indices to ${PATH}|${HASH} pairs
1789 for X in $1 $2 $3; do
1790 cut -f 1,2,7 -d '|' < ${X} |
1796 # List of files wanted
1797 cut -f 2 -d '|' < $3.hashes |
1800 if ! [ -f files/${HASH}.gz ]; then
1805 # Generate a list of unmodified files
1806 comm -12 $1.hashes $2.hashes |
1807 sort -k 1,1 -t '|' > unmodified.files
1809 # Copy all files into /files/. We only need the unmodified files
1810 # for use in patching; but we'll want all of them if the user asks
1811 # to rollback the updates later.
1813 F=`echo "${LINE}" | cut -f 1 -d '|'`
1814 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1816 # Skip files we already have.
1817 if [ -f files/${HASH}.gz ]; then
1821 # Make sure the file hasn't changed.
1822 cp "${BASEDIR}/${F}" tmpfile
1823 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1825 echo "File changed while FreeBSD Update running: ${F}"
1829 # Place the file into storage.
1830 gzip -c < tmpfile > files/${HASH}.gz
1834 # Produce a list of patches to download
1835 sort -k 1,1 -t '|' $3.hashes |
1836 join -t '|' -o 2.2,1.2 - unmodified.files |
1837 fetch_make_patchlist > patchlist
1840 rm unmodified.files $1.hashes $2.hashes $3.hashes
1842 # We don't need the list of possible old files any more.
1845 # We're finished making noise
1851 # Attempt to fetch patches
1852 if [ -s patchlist ]; then
1853 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1854 echo ${NDEBUG} "patches.${DDSTATS}"
1855 tr '|' '-' < patchlist |
1856 lam -s "${PATCHDIR}/" - |
1857 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1858 2>${STATSREDIR} | fetch_progress
1861 # Attempt to apply patches
1862 echo -n "Applying patches... "
1863 tr '|' ' ' < patchlist |
1865 if [ ! -f "${X}-${Y}" ]; then continue; fi
1866 gunzip -c < files/${X}.gz > OLD
1868 bspatch OLD NEW ${X}-${Y}
1870 if [ `${SHA256} -q NEW` = ${Y} ]; then
1874 rm -f diff OLD NEW ${X}-${Y}
1875 done 2>${QUIETREDIR}
1879 # Download files which couldn't be generate via patching
1881 if [ ! -f "files/${Y}.gz" ]; then
1884 done < files.wanted > filelist
1886 if [ -s filelist ]; then
1887 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1888 echo ${NDEBUG} "files... "
1889 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1890 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1894 if ! [ -f ${Y}.gz ]; then
1898 if [ `gunzip -c < ${Y}.gz |
1899 ${SHA256} -q` = ${Y} ]; then
1900 mv ${Y}.gz files/${Y}.gz
1902 echo "${Y} has incorrect hash."
1910 rm files.wanted filelist patchlist
1913 # Create and populate install manifest directory; and report what updates
1915 fetch_create_manifest () {
1916 # If we have an existing install manifest, nuke it.
1917 if [ -L "${BDHASH}-install" ]; then
1918 rm -r ${BDHASH}-install/
1919 rm ${BDHASH}-install
1922 # Report to the user if any updates were avoided due to local changes
1923 if [ -s modifiedfiles ]; then
1925 echo -n "The following files are affected by updates, "
1926 echo "but no changes have"
1927 echo -n "been downloaded because the files have been "
1928 echo "modified locally:"
1933 # If no files will be updated, tell the user and exit
1934 if ! [ -s INDEX-PRESENT ] &&
1935 ! [ -s INDEX-NEW ]; then
1936 rm INDEX-PRESENT INDEX-NEW
1938 echo -n "No updates needed to update system to "
1939 echo "${RELNUM}-p${RELPATCHNUM}."
1943 # Divide files into (a) removed files, (b) added files, and
1944 # (c) updated files.
1945 cut -f 1 -d '|' < INDEX-PRESENT |
1946 sort > INDEX-PRESENT.flist
1947 cut -f 1 -d '|' < INDEX-NEW |
1948 sort > INDEX-NEW.flist
1949 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1950 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
1951 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
1952 rm INDEX-PRESENT.flist INDEX-NEW.flist
1954 # Report removed files, if any
1955 if [ -s files.removed ]; then
1957 echo -n "The following files will be removed "
1958 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1963 # Report added files, if any
1964 if [ -s files.added ]; then
1966 echo -n "The following files will be added "
1967 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1972 # Report updated files, if any
1973 if [ -s files.updated ]; then
1975 echo -n "The following files will be updated "
1976 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1982 # Create a directory for the install manifest.
1983 MDIR=`mktemp -d install.XXXXXX` || return 1
1986 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
1987 mv INDEX-NEW ${MDIR}/INDEX-NEW
1989 # Link it into place
1990 ln -s ${MDIR} ${BDHASH}-install
1993 # Warn about any upcoming EoL
1995 # What's the current time?
1996 NOWTIME=`date "+%s"`
1998 # When did we last warn about the EoL date?
1999 if [ -f lasteolwarn ]; then
2000 LASTWARN=`cat lasteolwarn`
2002 LASTWARN=`expr ${NOWTIME} - 63072000`
2005 # If the EoL time is past, warn.
2006 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
2009 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
2010 Any security issues discovered after `date -r ${EOLTIME}`
2011 will not have been corrected.
2016 # Figure out how long it has been since we last warned about the
2017 # upcoming EoL, and how much longer we have left.
2018 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
2019 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
2021 # Don't warn if the EoL is more than 3 months away
2022 if [ ${TIMELEFT} -gt 7884000 ]; then
2026 # Don't warn if the time remaining is more than 3 times the time
2027 # since the last warning.
2028 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
2032 # Figure out what time units to use.
2033 if [ ${TIMELEFT} -lt 604800 ]; then
2036 elif [ ${TIMELEFT} -lt 2678400 ]; then
2044 # Compute the right number of units
2045 NUM=`expr ${TIMELEFT} / ${SIZE}`
2046 if [ ${NUM} != 1 ]; then
2053 WARNING: `uname -sr` is approaching its End-of-Life date.
2054 It is strongly recommended that you upgrade to a newer
2055 release within the next ${NUM} ${UNIT}.
2058 # Update the stored time of last warning
2059 echo ${NOWTIME} > lasteolwarn
2062 # Do the actual work involved in "fetch" / "cron".
2064 workdir_init || return 1
2066 # Prepare the mirror list.
2067 fetch_pick_server_init && fetch_pick_server
2069 # Try to fetch the public key until we run out of servers.
2070 while ! fetch_key; do
2071 fetch_pick_server || return 1
2074 # Try to fetch the metadata index signature ("tag") until we run
2075 # out of available servers; and sanity check the downloaded tag.
2076 while ! fetch_tag; do
2077 fetch_pick_server || return 1
2079 fetch_tagsanity || return 1
2081 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2082 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2084 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2085 # the lines which (a) belong to components we care about, and (b)
2086 # don't correspond to paths we're explicitly ignoring.
2087 fetch_filter_metadata INDEX-NEW || return 1
2088 fetch_filter_metadata INDEX-OLD || return 1
2090 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2091 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2092 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2094 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2095 # system and generate an INDEX-PRESENT file.
2096 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2098 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2099 # correspond to lines in INDEX-PRESENT with hashes not appearing
2100 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2101 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2102 # INDEX-OLD with type -.
2103 fetch_filter_unmodified_notpresent \
2104 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2106 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2107 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2108 # of type - from INDEX-PRESENT.
2109 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2111 # If ${ALLOWDELETE} != "yes", then remove any entries from
2112 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2113 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2115 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2116 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2117 # replace the corresponding line of INDEX-NEW with one having the
2118 # same metadata as the entry in INDEX-PRESENT.
2119 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2121 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2122 # no need to update a file if it isn't changing.
2123 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2125 # Prepare to fetch files: Generate a list of the files we need,
2126 # copy the unmodified files we have into /files/, and generate
2127 # a list of patches to download.
2128 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2131 fetch_files || return 1
2133 # Create and populate install manifest directory; and report what
2134 # updates are available.
2135 fetch_create_manifest || return 1
2137 # Warn about any upcoming EoL
2138 fetch_warn_eol || return 1
2141 # If StrictComponents is not "yes", generate a new components list
2142 # with only the components which appear to be installed.
2143 upgrade_guess_components () {
2144 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2145 # Generate filtered INDEX-ALL with only the components listed
2147 fetch_filter_metadata_components $1 || return 1
2149 # Tell the user why his disk is suddenly making lots of noise
2150 echo -n "Inspecting system... "
2152 # Look at the files on disk, and assume that a component is
2153 # supposed to be present if it is more than half-present.
2154 cut -f 1-3 -d '|' < INDEX-ALL |
2156 while read C S F; do
2157 if [ -e ${BASEDIR}/${F} ]; then
2164 sed -E 's,^ +,,' > compfreq
2165 grep ' = ' compfreq |
2167 sort -k 2,2 -t ' ' > compfreq.total
2168 grep ' + ' compfreq |
2170 sort -k 2,2 -t ' ' > compfreq.present
2171 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2172 while read S P T; do
2173 if [ ${P} -gt `expr ${T} / 2` ]; then
2177 cut -f 2 -d ' ' < compfreq.total > comp.total
2178 rm INDEX-ALL compfreq compfreq.total compfreq.present
2180 # We're done making noise.
2183 # Sometimes the kernel isn't installed where INDEX-ALL
2184 # thinks that it should be: In particular, it is often in
2185 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2186 # deal with this, if "kernel|X" is listed in comp.total
2187 # (i.e., is a component which would be upgraded if it is
2188 # found to be present) we will add it to comp.present.
2189 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2190 # not, we print a warning -- the user is running a kernel
2191 # which isn't part of the release.
2192 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2193 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2195 if grep -qE "^kernel\|" comp.total &&
2196 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2199 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2200 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2201 This kernel will not be updated: you MUST update the kernel manually
2202 before running "$0 install".
2206 # Re-sort the list of installed components and generate
2207 # the list of non-installed components.
2208 sort -u < comp.present > comp.present.tmp
2209 mv comp.present.tmp comp.present
2210 comm -13 comp.present comp.total > comp.absent
2212 # Ask the user to confirm that what we have is correct. To
2213 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2214 # subcomponents must be listed in the configuration file).
2216 echo -n "The following components of FreeBSD "
2217 echo "seem to be installed:"
2218 tr '|' '/' < comp.present |
2221 echo -n "The following components of FreeBSD "
2222 echo "do not seem to be installed:"
2223 tr '|' '/' < comp.absent |
2226 continuep || return 1
2229 # Suck the generated list of components into ${COMPONENTS}.
2230 # Note that comp.present.tmp is used due to issues with
2231 # pipelines and setting variables.
2233 tr '|' '/' < comp.present > comp.present.tmp
2235 COMPONENTS="${COMPONENTS} ${C}"
2236 done < comp.present.tmp
2238 # Delete temporary files
2239 rm comp.present comp.present.tmp comp.absent comp.total
2243 # If StrictComponents is not "yes", COMPONENTS contains an entry
2244 # corresponding to the currently running kernel, and said kernel
2245 # does not exist in the new release, add "kernel/generic" to the
2246 # list of components.
2247 upgrade_guess_new_kernel () {
2248 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2249 # Grab the unfiltered metadata file.
2250 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2251 gunzip -c < files/${METAHASH}.gz > $1.all
2253 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2254 # isn't in $1.all, we need to add kernel/generic.
2255 for C in ${COMPONENTS}; do
2256 if [ ${C} = "kernel/${KCOMP}" ] &&
2257 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2258 COMPONENTS="${COMPONENTS} kernel/generic"
2262 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2263 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2264 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2265 replaced with a "generic" kernel.
2267 continuep || return 1
2271 # Don't need this any more...
2276 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2277 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2278 upgrade_oldall_to_oldnew () {
2279 # For each ${F}|... which appears in INDEX-ALL but does not appear
2280 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2281 cut -f 1 -d '|' < $1 |
2283 cut -f 1 -d '|' < $2 |
2285 comm -13 $1.paths - |
2286 lam - -s "|-||||||" |
2290 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2291 comm -23 $1 $2 > $1.tmp
2294 # Remove lines from INDEX-ALL which have a file name not appearing
2295 # anywhere in INDEX-OLD (since these must be files which haven't
2296 # changed -- if they were new, there would be an entry of type "-").
2297 cut -f 1 -d '|' < $1 |
2299 sort -k 1,1 -t '|' < $2 |
2300 join -t '|' - $1.paths |
2305 # Rename INDEX-ALL to INDEX-NEW.
2309 # Helper for upgrade_merge: Return zero true iff the two files differ only
2310 # in the contents of their RCS tags.
2312 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2313 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2315 if [ $X = $Y ]; then
2322 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2323 # and update $3 to reflect the hashes of merged files.
2325 # We only need to do anything if $1 is non-empty.
2327 cut -f 1 -d '|' $1 |
2330 # Create staging area for merging files
2334 mkdir -p merge/old/${D}
2335 mkdir -p merge/${OLDRELNUM}/${D}
2336 mkdir -p merge/${RELNUM}/${D}
2337 mkdir -p merge/new/${D}
2342 # Currently installed file
2343 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2344 gunzip < files/${V}.gz > merge/old/${F}
2347 if look "${F}|" $1 | fgrep -q "|f|"; then
2348 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2349 gunzip < files/${V}.gz \
2350 > merge/${OLDRELNUM}/${F}
2354 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2355 fgrep -q "|f|"; then
2356 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2357 gunzip < files/${V}.gz \
2358 > merge/${RELNUM}/${F}
2362 # Attempt to automatically merge changes
2363 echo -n "Attempting to automatically merge "
2364 echo -n "changes in files..."
2367 # If the file doesn't exist in the new release,
2368 # the result of "merging changes" is having the file
2370 if ! [ -f merge/${RELNUM}/${F} ]; then
2374 # If the file didn't exist in the old release, we're
2375 # going to throw away the existing file and hope that
2376 # the version from the new release is what we want.
2377 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2378 cp merge/${RELNUM}/${F} merge/new/${F}
2382 # Some files need special treatment.
2384 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2385 # Don't merge these -- we're rebuild them
2386 # after updates are installed.
2387 cp merge/old/${F} merge/new/${F}
2390 if ! diff3 -E -m -L "current version" \
2391 -L "${OLDRELNUM}" -L "${RELNUM}" \
2393 merge/${OLDRELNUM}/${F} \
2394 merge/${RELNUM}/${F} \
2395 > merge/new/${F} 2>/dev/null; then
2396 echo ${F} >> failed.merges
2403 # Ask the user to handle any files which didn't merge.
2405 # If the installed file differs from the version in
2406 # the old release only due to RCS tag expansion
2407 # then just use the version in the new release.
2408 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2409 cp merge/${RELNUM}/${F} merge/new/${F}
2415 The following file could not be merged automatically: ${F}
2416 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2419 read dummy </dev/tty
2420 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2421 done < failed.merges
2424 # Ask the user to confirm that he likes how the result
2427 # Skip files which haven't changed except possibly
2428 # in their RCS tags.
2429 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2430 samef merge/old/${F} merge/new/${F}; then
2434 # Skip files where the installed file differs from
2435 # the old file only due to RCS tags.
2436 if [ -f merge/old/${F} ] &&
2437 [ -f merge/${OLDRELNUM}/${F} ] &&
2438 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2442 # Warn about files which are ceasing to exist.
2443 if ! [ -f merge/new/${F} ]; then
2446 The following file will be removed, as it no longer exists in
2447 FreeBSD ${RELNUM}: ${F}
2449 continuep < /dev/tty || return 1
2453 # Print changes for the user's approval.
2456 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2457 FreeBSD ${RELNUM} have been merged into ${F}:
2459 diff -U 5 -L "current version" -L "new version" \
2460 merge/old/${F} merge/new/${F} || true
2461 continuep < /dev/tty || return 1
2464 # Store merged files.
2466 if [ -f merge/new/${F} ]; then
2467 V=`${SHA256} -q merge/new/${F}`
2469 gzip -c < merge/new/${F} > files/${V}.gz
2472 done < $1-paths > newhashes
2474 # Pull lines out from $3 which need to be updated to
2475 # reflect merged files.
2478 done < $1-paths > $3-oldlines
2480 # Update lines to reflect merged files
2481 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2482 $3-oldlines newhashes > $3-newlines
2484 # Remove old lines from $3 and add new lines.
2487 sort - $3-newlines > $3.tmp
2491 rm $1-paths newhashes $3-oldlines $3-newlines
2495 # We're done with merging files.
2499 # Do the work involved in fetching upgrades to a new release
2501 workdir_init || return 1
2503 # Prepare the mirror list.
2504 fetch_pick_server_init && fetch_pick_server
2506 # Try to fetch the public key until we run out of servers.
2507 while ! fetch_key; do
2508 fetch_pick_server || return 1
2511 # Try to fetch the metadata index signature ("tag") until we run
2512 # out of available servers; and sanity check the downloaded tag.
2513 while ! fetch_tag; do
2514 fetch_pick_server || return 1
2516 fetch_tagsanity || return 1
2518 # Fetch the INDEX-OLD and INDEX-ALL.
2519 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2521 # If StrictComponents is not "yes", generate a new components list
2522 # with only the components which appear to be installed.
2523 upgrade_guess_components INDEX-ALL || return 1
2525 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2526 # the components we want and without anything marked as "Ignore".
2527 fetch_filter_metadata INDEX-OLD || return 1
2528 fetch_filter_metadata INDEX-ALL || return 1
2530 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2531 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2532 mv INDEX-OLD.tmp INDEX-OLD
2535 # Adjust variables for fetching files from the new release.
2537 RELNUM=${TARGETRELEASE}
2538 OLDFETCHDIR=${FETCHDIR}
2539 FETCHDIR=${RELNUM}/${ARCH}
2541 # Try to fetch the NEW metadata index signature ("tag") until we run
2542 # out of available servers; and sanity check the downloaded tag.
2543 while ! fetch_tag; do
2544 fetch_pick_server || return 1
2547 # Fetch the new INDEX-ALL.
2548 fetch_metadata INDEX-ALL || return 1
2550 # If StrictComponents is not "yes", COMPONENTS contains an entry
2551 # corresponding to the currently running kernel, and said kernel
2552 # does not exist in the new release, add "kernel/generic" to the
2553 # list of components.
2554 upgrade_guess_new_kernel INDEX-ALL || return 1
2556 # Filter INDEX-ALL to contain only the components we want and without
2557 # anything marked as "Ignore".
2558 fetch_filter_metadata INDEX-ALL || return 1
2560 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2561 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2562 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2564 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2565 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2566 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2568 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2569 # system and generate an INDEX-PRESENT file.
2570 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2572 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2573 # paths and hashes of old versions of files to merge.
2574 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2576 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2577 # correspond to lines in INDEX-PRESENT with hashes not appearing
2578 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2579 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2580 # INDEX-OLD with type -.
2581 fetch_filter_unmodified_notpresent \
2582 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2584 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2585 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2586 # of type - from INDEX-PRESENT.
2587 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2589 # If ${ALLOWDELETE} != "yes", then remove any entries from
2590 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2591 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2593 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2594 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2595 # replace the corresponding line of INDEX-NEW with one having the
2596 # same metadata as the entry in INDEX-PRESENT.
2597 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2599 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2600 # no need to update a file if it isn't changing.
2601 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2603 # Fetch "clean" files from the old release for merging changes.
2604 fetch_files_premerge tomerge-old
2606 # Prepare to fetch files: Generate a list of the files we need,
2607 # copy the unmodified files we have into /files/, and generate
2608 # a list of patches to download.
2609 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2611 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2612 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2613 fetch_files || return 1
2615 # Merge configuration file changes.
2616 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2618 # Create and populate install manifest directory; and report what
2619 # updates are available.
2620 fetch_create_manifest || return 1
2622 # Leave a note behind to tell the "install" command that the kernel
2623 # needs to be installed before the world.
2624 touch ${BDHASH}-install/kernelfirst
2626 # Remind the user that they need to run "freebsd-update install"
2627 # to install the downloaded bits, in case they didn't RTFM.
2628 echo "To install the downloaded upgrades, run \"$0 install\"."
2631 # Make sure that all the file hashes mentioned in $@ have corresponding
2632 # gzipped files stored in /files/.
2634 # Generate a list of hashes
2641 # Make sure all the hashes exist
2643 if ! [ -f files/${HASH}.gz ]; then
2644 echo -n "Update files missing -- "
2645 echo "this should never happen."
2646 echo "Re-run '$0 fetch'."
2655 # Remove the system immutable flag from files
2657 # Generate file list
2659 cut -f 1 -d '|' > filelist
2663 if ! [ -e ${BASEDIR}/${F} ]; then
2666 echo ${BASEDIR}/${F}
2668 done < filelist | xargs chflags noschg || return 1
2674 # Decide which directory name to use for kernel backups.
2675 backup_kernel_finddir () {
2678 # Pathname does not exist, so it is OK use that name
2679 # for backup directory.
2680 if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then
2684 # If directory do exist, we only use if it has our
2686 if [ -d $BASEDIR/$BACKUPKERNELDIR -a \
2687 -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then
2691 # We could not use current directory name, so add counter to
2692 # the end and try again.
2694 if [ $CNT -gt 9 ]; then
2695 echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)"
2698 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2699 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2703 # Backup the current kernel using hardlinks, if not disabled by user.
2704 # Since we delete all files in the directory used for previous backups
2705 # we create a marker file called ".freebsd-update" in the directory so
2706 # we can determine on the next run that the directory was created by
2707 # freebsd-update and we then do not accidentally remove user files in
2708 # the unlikely case that the user has created a directory with a
2711 # Only make kernel backup is so configured.
2712 if [ $BACKUPKERNEL != yes ]; then
2716 # Decide which directory name to use for kernel backups.
2717 backup_kernel_finddir
2719 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2720 # "not ours", backup_kernel_finddir would have exited, so
2721 # deleting the directory content is as safe as we can make it.
2722 if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then
2723 rm -fr $BASEDIR/$BACKUPKERNELDIR
2726 # Create directories for backup.
2727 mkdir -p $BASEDIR/$BACKUPKERNELDIR
2728 mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \
2729 mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null
2731 # Mark the directory as having been created by freebsd-update.
2732 touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update
2733 if [ $? -ne 0 ]; then
2734 echo "Could not create kernel backup directory"
2738 # Disable pathname expansion to be sure *.symbols is not
2742 # Use find to ignore symbol files, unless disabled by user.
2743 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2746 FINDFILTER="-a ! -name *.debug -a ! -name *.symbols"
2749 # Backup all the kernel files using hardlinks.
2750 (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \
2751 cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;)
2753 # Re-enable patchname expansion.
2758 install_from_index () {
2759 # First pass: Do everything apart from setting file flags. We
2760 # can't set flags yet, because schg inhibits hard linking.
2761 sort -k 1,1 -t '|' $1 |
2763 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2766 # Create a directory
2767 install -d -o ${OWNER} -g ${GROUP} \
2768 -m ${PERM} ${BASEDIR}/${FPATH}
2771 if [ -z "${LINK}" ]; then
2772 # Create a file, without setting flags.
2773 gunzip < files/${HASH}.gz > ${HASH}
2774 install -S -o ${OWNER} -g ${GROUP} \
2775 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2778 # Create a hard link.
2779 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2784 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2789 # Perform a second pass, adding file flags.
2791 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2792 if [ ${TYPE} = "f" ] &&
2793 ! [ ${FLAGS} = "0" ]; then
2794 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2799 # Remove files which we want to delete
2801 # Generate list of new files
2802 cut -f 1 -d '|' < $2 |
2805 # Generate subindex of old files we want to nuke
2806 sort -k 1,1 -t '|' $1 |
2807 join -t '|' -v 1 - newfiles |
2808 sort -r -k 1,1 -t '|' |
2810 tr '|' ' ' > killfiles
2812 # Remove the offending bits
2813 while read FPATH TYPE; do
2816 rmdir ${BASEDIR}/${FPATH}
2819 rm ${BASEDIR}/${FPATH}
2822 rm ${BASEDIR}/${FPATH}
2828 rm newfiles killfiles
2831 # Install new files, delete old files, and update linker.hints
2833 # If we haven't already dealt with the kernel, deal with it.
2834 if ! [ -f $1/kerneldone ]; then
2835 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2836 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2838 # Backup current kernel before installing a new one
2839 backup_kernel || return 1
2842 install_from_index INDEX-NEW || return 1
2844 # Remove files which need to be deleted
2845 install_delete INDEX-OLD INDEX-NEW || return 1
2847 # Update linker.hints if necessary
2848 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2849 kldxref -R ${BASEDIR}/boot/ 2>/dev/null
2852 # We've finished updating the kernel.
2855 # Do we need to ask for a reboot now?
2856 if [ -f $1/kernelfirst ] &&
2857 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2860 Kernel updates have been installed. Please reboot and run
2861 "$0 install" again to finish installing updates.
2867 # If we haven't already dealt with the world, deal with it.
2868 if ! [ -f $1/worlddone ]; then
2869 # Create any necessary directories first
2870 grep -vE '^/boot/' $1/INDEX-NEW |
2871 grep -E '^[^|]+\|d\|' > INDEX-NEW
2872 install_from_index INDEX-NEW || return 1
2874 # Install new runtime linker
2875 grep -vE '^/boot/' $1/INDEX-NEW |
2876 grep -vE '^[^|]+\|d\|' |
2877 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2878 install_from_index INDEX-NEW || return 1
2880 # Install new shared libraries next
2881 grep -vE '^/boot/' $1/INDEX-NEW |
2882 grep -vE '^[^|]+\|d\|' |
2883 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2884 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2885 install_from_index INDEX-NEW || return 1
2887 # Deal with everything else
2888 grep -vE '^/boot/' $1/INDEX-OLD |
2889 grep -vE '^[^|]+\|d\|' |
2890 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2891 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2892 grep -vE '^/boot/' $1/INDEX-NEW |
2893 grep -vE '^[^|]+\|d\|' |
2894 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2895 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2896 install_from_index INDEX-NEW || return 1
2897 install_delete INDEX-OLD INDEX-NEW || return 1
2899 # Rebuild /etc/spwd.db and /etc/pwd.db if necessary.
2900 if [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/spwd.db ] ||
2901 [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/pwd.db ]; then
2902 pwd_mkdb -d ${BASEDIR}/etc ${BASEDIR}/etc/master.passwd
2905 # Rebuild /etc/login.conf.db if necessary.
2906 if [ ${BASEDIR}/etc/login.conf -nt ${BASEDIR}/etc/login.conf.db ]; then
2907 cap_mkdb ${BASEDIR}/etc/login.conf
2910 # We've finished installing the world and deleting old files
2911 # which are not shared libraries.
2914 # Do we need to ask the user to portupgrade now?
2915 grep -vE '^/boot/' $1/INDEX-NEW |
2916 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2919 if grep -vE '^/boot/' $1/INDEX-OLD |
2920 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2923 join -v 1 - newfiles |
2927 Completing this upgrade requires removing old shared object files.
2928 Please rebuild all installed 3rd party software (e.g., programs
2929 installed from the ports tree) and then run "$0 install"
2930 again to finish installing updates.
2938 # Remove old shared libraries
2939 grep -vE '^/boot/' $1/INDEX-NEW |
2940 grep -vE '^[^|]+\|d\|' |
2941 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2942 grep -vE '^/boot/' $1/INDEX-OLD |
2943 grep -vE '^[^|]+\|d\|' |
2944 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2945 install_delete INDEX-OLD INDEX-NEW || return 1
2947 # Remove old directories
2948 grep -vE '^/boot/' $1/INDEX-NEW |
2949 grep -E '^[^|]+\|d\|' > INDEX-NEW
2950 grep -vE '^/boot/' $1/INDEX-OLD |
2951 grep -E '^[^|]+\|d\|' > INDEX-OLD
2952 install_delete INDEX-OLD INDEX-NEW || return 1
2954 # Remove temporary files
2955 rm INDEX-OLD INDEX-NEW
2958 # Rearrange bits to allow the installed updates to be rolled back
2959 install_setup_rollback () {
2960 # Remove the "reboot after installing kernel", "kernel updated", and
2961 # "finished installing the world" flags if present -- they are
2962 # irrelevant when rolling back updates.
2963 if [ -f ${BDHASH}-install/kernelfirst ]; then
2964 rm ${BDHASH}-install/kernelfirst
2965 rm ${BDHASH}-install/kerneldone
2967 if [ -f ${BDHASH}-install/worlddone ]; then
2968 rm ${BDHASH}-install/worlddone
2971 if [ -L ${BDHASH}-rollback ]; then
2972 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
2975 mv ${BDHASH}-install ${BDHASH}-rollback
2978 # Actually install updates
2980 echo -n "Installing updates..."
2982 # Make sure we have all the files we should have
2983 install_verify ${BDHASH}-install/INDEX-OLD \
2984 ${BDHASH}-install/INDEX-NEW || return 1
2986 # Remove system immutable flag from files
2987 install_unschg ${BDHASH}-install/INDEX-OLD \
2988 ${BDHASH}-install/INDEX-NEW || return 1
2990 # Install new files, delete old files, and update linker.hints
2991 install_files ${BDHASH}-install || return 1
2993 # Rearrange bits to allow the installed updates to be rolled back
2994 install_setup_rollback
2999 # Rearrange bits to allow the previous set of updates to be rolled back next.
3000 rollback_setup_rollback () {
3001 if [ -L ${BDHASH}-rollback/rollback ]; then
3002 mv ${BDHASH}-rollback/rollback rollback-tmp
3003 rm -r ${BDHASH}-rollback/
3004 rm ${BDHASH}-rollback
3005 mv rollback-tmp ${BDHASH}-rollback
3007 rm -r ${BDHASH}-rollback/
3008 rm ${BDHASH}-rollback
3012 # Install old files, delete new files, and update linker.hints
3014 # Install old shared library files which don't have the same path as
3015 # a new shared library file.
3016 grep -vE '^/boot/' $1/INDEX-NEW |
3017 grep -E '/lib/.*\.so\.[0-9]+\|' |
3019 sort > INDEX-NEW.libs.flist
3020 grep -vE '^/boot/' $1/INDEX-OLD |
3021 grep -E '/lib/.*\.so\.[0-9]+\|' |
3022 sort -k 1,1 -t '|' - |
3023 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
3024 install_from_index INDEX-OLD || return 1
3026 # Deal with files which are neither kernel nor shared library
3027 grep -vE '^/boot/' $1/INDEX-OLD |
3028 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3029 grep -vE '^/boot/' $1/INDEX-NEW |
3030 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3031 install_from_index INDEX-OLD || return 1
3032 install_delete INDEX-NEW INDEX-OLD || return 1
3034 # Install any old shared library files which we didn't install above.
3035 grep -vE '^/boot/' $1/INDEX-OLD |
3036 grep -E '/lib/.*\.so\.[0-9]+\|' |
3037 sort -k 1,1 -t '|' - |
3038 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
3039 install_from_index INDEX-OLD || return 1
3041 # Delete unneeded shared library files
3042 grep -vE '^/boot/' $1/INDEX-OLD |
3043 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3044 grep -vE '^/boot/' $1/INDEX-NEW |
3045 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3046 install_delete INDEX-NEW INDEX-OLD || return 1
3048 # Deal with kernel files
3049 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
3050 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3051 install_from_index INDEX-OLD || return 1
3052 install_delete INDEX-NEW INDEX-OLD || return 1
3053 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3054 kldxref -R /boot/ 2>/dev/null
3057 # Remove temporary files
3058 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3061 # Actually rollback updates
3063 echo -n "Uninstalling updates..."
3065 # If there are updates waiting to be installed, remove them; we
3066 # want the user to re-run 'fetch' after rolling back updates.
3067 if [ -L ${BDHASH}-install ]; then
3068 rm -r ${BDHASH}-install/
3069 rm ${BDHASH}-install
3072 # Make sure we have all the files we should have
3073 install_verify ${BDHASH}-rollback/INDEX-NEW \
3074 ${BDHASH}-rollback/INDEX-OLD || return 1
3076 # Remove system immutable flag from files
3077 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3078 ${BDHASH}-rollback/INDEX-OLD || return 1
3080 # Install old files, delete new files, and update linker.hints
3081 rollback_files ${BDHASH}-rollback || return 1
3083 # Remove the rollback directory and the symlink pointing to it; and
3084 # rearrange bits to allow the previous set of updates to be rolled
3086 rollback_setup_rollback
3091 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3093 # Get all the lines which mismatch in something other than file
3094 # flags. We ignore file flags because sysinstall doesn't seem to
3095 # set them when it installs FreeBSD; warning about these adds a
3096 # very large amount of noise.
3097 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3098 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3099 cut -f 1-5,7-8 -d '|' $2 |
3100 comm -13 $1.noflags - |
3101 fgrep -v '|-|||||' |
3102 sort -k 1,1 -t '|' |
3103 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3105 # Ignore files which match IDSIGNOREPATHS.
3106 for X in ${IDSIGNOREPATHS}; do
3107 grep -E "^${X}" INDEX-NOTMATCHING
3110 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3111 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3113 # Go through the lines and print warnings.
3115 while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do
3116 # Warn about different object types.
3117 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3118 echo -n "${FPATH} is a "
3120 f) echo -n "regular file, "
3122 d) echo -n "directory, "
3124 L) echo -n "symlink, "
3127 echo -n "but should be a "
3129 f) echo -n "regular file."
3131 d) echo -n "directory."
3133 L) echo -n "symlink."
3138 # Skip other tests, since they don't make sense if
3139 # we're comparing different object types.
3143 # Warn about different owners.
3144 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3145 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3146 echo "but should be owned by user id ${OWNER}."
3149 # Warn about different groups.
3150 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3151 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3152 echo "but should be owned by group id ${GROUP}."
3155 # Warn about different permissions. We do not warn about
3156 # different permissions on symlinks, since some archivers
3157 # don't extract symlink permissions correctly and they are
3159 if ! [ "${PERM}" = "${P_PERM}" ] &&
3160 ! [ "${TYPE}" = "L" ]; then
3161 echo -n "${FPATH} has ${P_PERM} permissions, "
3162 echo "but should have ${PERM} permissions."
3165 # Warn about different file hashes / symlink destinations.
3166 if ! [ "${HASH}" = "${P_HASH}" ]; then
3167 if [ "${TYPE}" = "L" ]; then
3168 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3169 echo "but should be a symlink to ${HASH}."
3171 if [ "${TYPE}" = "f" ]; then
3172 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3173 echo "but should have SHA256 hash ${HASH}."
3177 # We don't warn about different hard links, since some
3178 # some archivers break hard links, and as long as the
3179 # underlying data is correct they really don't matter.
3180 done < INDEX-NOTMATCHING
3183 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3186 # Do the work involved in comparing the system to a "known good" index
3188 workdir_init || return 1
3190 # Prepare the mirror list.
3191 fetch_pick_server_init && fetch_pick_server
3193 # Try to fetch the public key until we run out of servers.
3194 while ! fetch_key; do
3195 fetch_pick_server || return 1
3198 # Try to fetch the metadata index signature ("tag") until we run
3199 # out of available servers; and sanity check the downloaded tag.
3200 while ! fetch_tag; do
3201 fetch_pick_server || return 1
3203 fetch_tagsanity || return 1
3205 # Fetch INDEX-OLD and INDEX-ALL.
3206 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3208 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3209 # the components we want and without anything marked as "Ignore".
3210 fetch_filter_metadata INDEX-OLD || return 1
3211 fetch_filter_metadata INDEX-ALL || return 1
3213 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3214 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3215 mv INDEX-ALL.tmp INDEX-ALL
3218 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3219 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3221 # Inspect the system and generate an INDEX-PRESENT file.
3222 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3224 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3226 IDS_compare INDEX-ALL INDEX-PRESENT
3229 #### Main functions -- call parameter-handling and core functions
3231 # Using the command line, configuration file, and defaults,
3232 # set all the parameters which are needed later.
3240 # Fetch command. Make sure that we're being called
3241 # interactively, then run fetch_check_params and fetch_run
3243 if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then
3244 echo -n "`basename $0` fetch should not "
3245 echo "be run non-interactively."
3246 echo "Run `basename $0` cron instead."
3254 # Cron command. Make sure the parameters are sensible; wait
3255 # rand(3600) seconds; then fetch updates. While fetching updates,
3256 # send output to a temporary file; only print that file if the
3260 sleep `jot -r 1 0 3600`
3262 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3263 if ! fetch_run >> ${TMPFILE} ||
3264 ! grep -q "No updates needed" ${TMPFILE} ||
3265 [ ${VERBOSELEVEL} = "debug" ]; then
3266 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3272 # Fetch files for upgrading to a new release.
3274 upgrade_check_params
3275 upgrade_run || exit 1
3278 # Install downloaded updates.
3280 install_check_params
3281 install_run || exit 1
3284 # Rollback most recently installed updates.
3286 rollback_check_params
3287 rollback_run || exit 1
3290 # Compare system against a "known good" index.
3298 # Make sure we find utilities from the base system
3299 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3301 # Set a pager if the user doesn't
3302 if [ -z "$PAGER" ]; then
3306 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3310 for COMMAND in ${COMMANDS}; do