4 # Copyright 2004-2007 Colin Percival
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted providing that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 # POSSIBILITY OF SUCH DAMAGE.
30 #### Usage function -- called from command-line handling code.
32 # Usage instructions. Options not listed:
33 # --debug -- don't filter output from utilities
34 # --no-stats -- don't show progress statistics while fetching files
37 usage: `basename $0` [options] command ... [path]
40 -b basedir -- Operate on a system mounted at basedir
42 -d workdir -- Store working files in workdir
43 (default: /var/db/freebsd-update/)
44 -f conffile -- Read configuration options from conffile
45 (default: /etc/freebsd-update.conf)
46 -F -- Force a fetch operation to proceed
47 -k KEY -- Trust an RSA key with SHA256 hash of KEY
48 -r release -- Target for upgrade (e.g., 11.1-RELEASE)
49 -s server -- Server from which to fetch updates
50 (default: update.FreeBSD.org)
51 -t address -- Mail output of cron command, if any, to address
53 --not-running-from-cron
54 -- Run without a tty, for use by automated tools
55 --currently-running release
56 -- Update as if currently running this release
58 fetch -- Fetch updates from server
59 cron -- Sleep rand(3600) seconds, fetch updates, and send an
60 email if updates were found
61 upgrade -- Fetch upgrades to FreeBSD version specified via -r option
62 install -- Install downloaded updates or upgrades
63 rollback -- Uninstall most recently installed updates
64 IDS -- Compare the system against an index of "known good" files.
69 #### Configuration processing functions
72 # Configuration options are set in the following order of priority:
73 # 1. Command line options
74 # 2. Configuration file options
76 # In addition, certain options (e.g., IgnorePaths) can be specified multiple
77 # times and (as long as these are all in the same place, e.g., inside the
78 # configuration file) they will accumulate. Finally, because the path to the
79 # configuration file can be specified at the command line, the entire command
80 # line must be processed before we start reading the configuration file.
82 # Sound like a mess? It is. Here's how we handle this:
83 # 1. Initialize CONFFILE and all the options to "".
84 # 2. Process the command line. Throw an error if a non-accumulating option
86 # 3. If CONFFILE is "", set CONFFILE to /etc/freebsd-update.conf .
87 # 4. For all the configuration options X, set X_saved to X.
88 # 5. Initialize all the options to "".
89 # 6. Read CONFFILE line by line, parsing options.
90 # 7. For each configuration option X, set X to X_saved iff X_saved is not "".
91 # 8. Repeat steps 4-7, except setting options to their default values at (6).
93 CONFIGOPTIONS="KEYPRINT WORKDIR SERVERNAME MAILTO ALLOWADD ALLOWDELETE
94 KEEPMODIFIEDMETADATA COMPONENTS IGNOREPATHS UPDATEIFUNMODIFIED
95 BASEDIR VERBOSELEVEL TARGETRELEASE STRICTCOMPONENTS MERGECHANGES
96 IDSIGNOREPATHS BACKUPKERNEL BACKUPKERNELDIR BACKUPKERNELSYMBOLFILES"
98 # Set all the configuration options to "".
100 for X in ${CONFIGOPTIONS}; do
105 # For each configuration option X, set X_saved to X.
107 for X in ${CONFIGOPTIONS}; do
108 eval ${X}_saved=\$${X}
112 # For each configuration option X, set X to X_saved if X_saved is not "".
114 for X in ${CONFIGOPTIONS}; do
116 if ! [ -z "${_}" ]; then
117 eval ${X}=\$${X}_saved
122 # Set the trusted keyprint.
124 if [ -z ${KEYPRINT} ]; then
131 # Set the working directory.
133 if [ -z ${WORKDIR} ]; then
140 # Set the name of the server (pool) from which to fetch updates
141 config_ServerName () {
142 if [ -z ${SERVERNAME} ]; then
149 # Set the address to which 'cron' output will be mailed.
151 if [ -z ${MAILTO} ]; then
158 # Set whether FreeBSD Update is allowed to add files (or directories, or
159 # symlinks) which did not previously exist.
161 if [ -z ${ALLOWADD} ]; then
178 # Set whether FreeBSD Update is allowed to remove files/directories/symlinks.
179 config_AllowDelete () {
180 if [ -z ${ALLOWDELETE} ]; then
197 # Set whether FreeBSD Update should keep existing inode ownership,
198 # permissions, and flags, in the event that they have been modified locally
200 config_KeepModifiedMetadata () {
201 if [ -z ${KEEPMODIFIEDMETADATA} ]; then
204 KEEPMODIFIEDMETADATA=yes
207 KEEPMODIFIEDMETADATA=no
218 # Add to the list of components which should be kept updated.
219 config_Components () {
221 if [ "$C" = "src" ]; then
222 if [ -e /usr/src/COPYRIGHT ]; then
223 COMPONENTS="${COMPONENTS} ${C}"
225 echo "src component not installed, skipped"
228 COMPONENTS="${COMPONENTS} ${C}"
233 # Add to the list of paths under which updates will be ignored.
234 config_IgnorePaths () {
236 IGNOREPATHS="${IGNOREPATHS} ${C}"
240 # Add to the list of paths which IDS should ignore.
241 config_IDSIgnorePaths () {
243 IDSIGNOREPATHS="${IDSIGNOREPATHS} ${C}"
247 # Add to the list of paths within which updates will be performed only if the
248 # file on disk has not been modified locally.
249 config_UpdateIfUnmodified () {
251 UPDATEIFUNMODIFIED="${UPDATEIFUNMODIFIED} ${C}"
255 # Add to the list of paths within which updates to text files will be merged
256 # instead of overwritten.
257 config_MergeChanges () {
259 MERGECHANGES="${MERGECHANGES} ${C}"
263 # Work on a FreeBSD installation mounted under $1
265 if [ -z ${BASEDIR} ]; then
272 # When fetching upgrades, should we assume the user wants exactly the
273 # components listed in COMPONENTS, rather than trying to guess based on
274 # what's currently installed?
275 config_StrictComponents () {
276 if [ -z ${STRICTCOMPONENTS} ]; then
293 # Upgrade to FreeBSD $1
294 config_TargetRelease () {
295 if [ -z ${TARGETRELEASE} ]; then
300 if echo ${TARGETRELEASE} | grep -qE '^[0-9.]+$'; then
301 TARGETRELEASE="${TARGETRELEASE}-RELEASE"
305 # Define what happens to output of utilities
306 config_VerboseLevel () {
307 if [ -z ${VERBOSELEVEL} ]; then
309 [Dd][Ee][Bb][Uu][Gg])
312 [Nn][Oo][Ss][Tt][Aa][Tt][Ss])
315 [Ss][Tt][Aa][Tt][Ss])
327 config_BackupKernel () {
328 if [ -z ${BACKUPKERNEL} ]; then
345 config_BackupKernelDir () {
346 if [ -z ${BACKUPKERNELDIR} ]; then
348 echo "BackupKernelDir set to empty dir"
352 # We check for some paths which would be extremely odd
353 # to use, but which could cause a lot of problems if
356 /|/bin|/boot|/etc|/lib|/libexec|/sbin|/usr|/var)
357 echo "BackupKernelDir set to invalid path $1"
364 echo "BackupKernelDir ($1) is not an absolute path"
373 config_BackupKernelSymbolFiles () {
374 if [ -z ${BACKUPKERNELSYMBOLFILES} ]; then
377 BACKUPKERNELSYMBOLFILES=yes
380 BACKUPKERNELSYMBOLFILES=no
391 # Handle one line of configuration
393 if [ $# -eq 0 ]; then
402 #### Parameter handling functions.
404 # Initialize parameters to null, just in case they're
405 # set in the environment.
407 # Configration settings
410 # No configuration file set yet
413 # No commands specified yet
416 # Force fetch to proceed
422 # Fetched first in a chain of commands
426 # Parse the command line
428 while [ $# -gt 0 ]; do
430 # Location of configuration file
432 if [ $# -eq 1 ]; then usage; fi
433 if [ ! -z "${CONFFILE}" ]; then usage; fi
439 --not-running-from-cron)
443 shift; export UNAME_r="$1"
446 # Configuration file equivalents
448 if [ $# -eq 1 ]; then usage; fi; shift
449 config_BaseDir $1 || usage
452 if [ $# -eq 1 ]; then usage; fi; shift
453 config_WorkDir $1 || usage
456 if [ $# -eq 1 ]; then usage; fi; shift
457 config_KeyPrint $1 || usage
460 if [ $# -eq 1 ]; then usage; fi; shift
461 config_ServerName $1 || usage
464 if [ $# -eq 1 ]; then usage; fi; shift
465 config_TargetRelease $1 || usage
468 if [ $# -eq 1 ]; then usage; fi; shift
469 config_MailTo $1 || usage
472 if [ $# -eq 1 ]; then usage; fi; shift
473 config_VerboseLevel $1 || usage
476 # Aliases for "-v debug" and "-v nostats"
478 config_VerboseLevel debug || usage
481 config_VerboseLevel nostats || usage
485 cron | fetch | upgrade | install | rollback | IDS)
486 COMMANDS="${COMMANDS} $1"
489 # Anything else is an error
497 # Make sure we have at least one command
498 if [ -z "${COMMANDS}" ]; then
503 # Parse the configuration file
505 # If a configuration file was specified on the command line, check
506 # that it exists and is readable.
507 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
508 echo -n "File does not exist "
509 echo -n "or is not readable: "
514 # If a configuration file was not specified on the command line,
515 # use the default configuration file path. If that default does
516 # not exist, give up looking for any configuration.
517 if [ -z "${CONFFILE}" ]; then
518 CONFFILE="/etc/freebsd-update.conf"
519 if [ ! -r "${CONFFILE}" ]; then
524 # Save the configuration options specified on the command line, and
525 # clear all the options in preparation for reading the config file.
529 # Read the configuration file. Anything after the first '#' is
530 # ignored, and any blank lines are ignored.
534 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
535 if ! configline ${LINEX}; then
536 echo "Error processing configuration file, line $L:"
542 # Merge the settings read from the configuration file with those
543 # provided at the command line.
547 # Provide some default parameters
549 # Save any parameters already configured, and clear the slate
553 # Default configurations
554 config_WorkDir /var/db/freebsd-update
557 config_AllowDelete yes
558 config_KeepModifiedMetadata yes
560 config_VerboseLevel stats
561 config_StrictComponents no
562 config_BackupKernel yes
563 config_BackupKernelDir /boot/kernel.old
564 config_BackupKernelSymbolFiles no
566 # Merge these defaults into the earlier-configured settings
570 # Set utility output filtering options, based on ${VERBOSELEVEL}
571 fetch_setup_verboselevel () {
572 case ${VERBOSELEVEL} in
574 QUIETREDIR="/dev/stderr"
576 STATSREDIR="/dev/stderr"
584 STATSREDIR="/dev/null"
590 QUIETREDIR="/dev/null"
592 STATSREDIR="/dev/stdout"
600 # Perform sanity checks and set some final parameters
601 # in preparation for fetching files. Figure out which
602 # set of updates should be downloaded: If the user is
603 # running *-p[0-9]+, strip off the last part; if the
604 # user is running -SECURITY, call it -RELEASE. Chdir
605 # into the working directory.
606 fetchupgrade_check_params () {
607 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
610 "SERVERNAME must be given via command line or configuration file."
611 _KEYPRINT_z="Key must be given via -k option or configuration file."
612 _KEYPRINT_bad="Invalid key fingerprint: "
613 _WORKDIR_bad="Directory does not exist or is not writable: "
614 _WORKDIR_bad2="Directory is not on a persistent filesystem: "
616 if [ -z "${SERVERNAME}" ]; then
617 echo -n "`basename $0`: "
618 echo "${_SERVERNAME_z}"
621 if [ -z "${KEYPRINT}" ]; then
622 echo -n "`basename $0`: "
623 echo "${_KEYPRINT_z}"
626 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
627 echo -n "`basename $0`: "
628 echo -n "${_KEYPRINT_bad}"
632 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
633 echo -n "`basename $0`: "
634 echo -n "${_WORKDIR_bad}"
638 case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*)
639 echo -n "`basename $0`: "
640 echo -n "${_WORKDIR_bad2}"
646 cd ${WORKDIR} || exit 1
648 # Generate release number. The s/SECURITY/RELEASE/ bit exists
649 # to provide an upgrade path for FreeBSD Update 1.x users, since
650 # the kernels provided by FreeBSD Update 1.x are always labelled
653 sed -E 's,-p[0-9]+,,' |
654 sed -E 's,-SECURITY,-RELEASE,'`
656 FETCHDIR=${RELNUM}/${ARCH}
657 PATCHDIR=${RELNUM}/${ARCH}/bp
659 # Figure out what directory contains the running kernel
660 BOOTFILE=`sysctl -n kern.bootfile`
661 KERNELDIR=${BOOTFILE%/kernel}
662 if ! [ -d ${KERNELDIR} ]; then
663 echo "Cannot identify running kernel"
667 # Figure out what kernel configuration is running. We start with
668 # the output of `uname -i`, and then make the following adjustments:
669 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
670 # file says "ident SMP-GENERIC", I don't know...
671 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
672 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
673 # we're running an SMP kernel. This mis-identification is a bug
674 # which was fixed in 6.2-STABLE.
676 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
679 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
680 if sysctl kern.version | grep -qE '/SMP$'; then
686 BSPATCH=/usr/bin/bspatch
688 PHTTPGET=/usr/libexec/phttpget
690 # Set up variables relating to VERBOSELEVEL
691 fetch_setup_verboselevel
693 # Construct a unique name from ${BASEDIR}
694 BDHASH=`echo ${BASEDIR} | sha256 -q`
697 # Perform sanity checks etc. before fetching updates.
698 fetch_check_params () {
699 fetchupgrade_check_params
701 if ! [ -z "${TARGETRELEASE}" ]; then
702 echo -n "`basename $0`: "
703 echo -n "-r option is meaningless with 'fetch' command. "
704 echo "(Did you mean 'upgrade' instead?)"
708 # Check that we have updates ready to install
709 if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then
710 echo "You have a partially completed upgrade pending"
711 echo "Run '$0 install' first."
712 echo "Run '$0 fetch -F' to proceed anyway."
717 # Perform sanity checks etc. before fetching upgrades.
718 upgrade_check_params () {
719 fetchupgrade_check_params
721 # Unless set otherwise, we're upgrading to the same kernel config.
722 NKERNCONF=${KERNCONF}
724 # We need TARGETRELEASE set
725 _TARGETRELEASE_z="Release target must be specified via -r option."
726 if [ -z "${TARGETRELEASE}" ]; then
727 echo -n "`basename $0`: "
728 echo "${_TARGETRELEASE_z}"
732 # The target release should be != the current release.
733 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
734 echo -n "`basename $0`: "
735 echo "Cannot upgrade from ${RELNUM} to itself"
739 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
740 if [ "${ALLOWADD}" = "no" ]; then
741 echo -n "`basename $0`: "
742 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
743 echo "when upgrading between releases."
746 if [ "${ALLOWDELETE}" = "no" ]; then
747 echo -n "`basename $0`: "
748 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
749 echo "when upgrading between releases."
753 # Set EDITOR to /usr/bin/vi if it isn't already set
754 : ${EDITOR:='/usr/bin/vi'}
757 # Perform sanity checks and set some final parameters in
758 # preparation for installing updates.
759 install_check_params () {
760 # Check that we are root. All sorts of things won't work otherwise.
761 if [ `id -u` != 0 ]; then
762 echo "You must be root to run this."
766 # Check that securelevel <= 0. Otherwise we can't update schg files.
767 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
768 echo "Updates cannot be installed when the system securelevel"
769 echo "is greater than zero."
773 # Check that we have a working directory
774 _WORKDIR_bad="Directory does not exist or is not writable: "
775 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
776 echo -n "`basename $0`: "
777 echo -n "${_WORKDIR_bad}"
781 cd ${WORKDIR} || exit 1
783 # Construct a unique name from ${BASEDIR}
784 BDHASH=`echo ${BASEDIR} | sha256 -q`
786 # Check that we have updates ready to install
787 if ! [ -L ${BDHASH}-install ]; then
788 echo "No updates are available to install."
789 if [ $ISFETCHED -eq 0 ]; then
790 echo "Run '$0 fetch' first."
794 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
795 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
796 echo "Update manifest is corrupt -- this should never happen."
797 echo "Re-run '$0 fetch'."
801 # Figure out what directory contains the running kernel
802 BOOTFILE=`sysctl -n kern.bootfile`
803 KERNELDIR=${BOOTFILE%/kernel}
804 if ! [ -d ${KERNELDIR} ]; then
805 echo "Cannot identify running kernel"
810 # Perform sanity checks and set some final parameters in
811 # preparation for UNinstalling updates.
812 rollback_check_params () {
813 # Check that we are root. All sorts of things won't work otherwise.
814 if [ `id -u` != 0 ]; then
815 echo "You must be root to run this."
819 # Check that we have a working directory
820 _WORKDIR_bad="Directory does not exist or is not writable: "
821 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
822 echo -n "`basename $0`: "
823 echo -n "${_WORKDIR_bad}"
827 cd ${WORKDIR} || exit 1
829 # Construct a unique name from ${BASEDIR}
830 BDHASH=`echo ${BASEDIR} | sha256 -q`
832 # Check that we have updates ready to rollback
833 if ! [ -L ${BDHASH}-rollback ]; then
834 echo "No rollback directory found."
837 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
838 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
839 echo "Update manifest is corrupt -- this should never happen."
844 # Perform sanity checks and set some final parameters
845 # in preparation for comparing the system against the
846 # published index. Figure out which index we should
847 # compare against: If the user is running *-p[0-9]+,
848 # strip off the last part; if the user is running
849 # -SECURITY, call it -RELEASE. Chdir into the working
851 IDS_check_params () {
852 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
855 "SERVERNAME must be given via command line or configuration file."
856 _KEYPRINT_z="Key must be given via -k option or configuration file."
857 _KEYPRINT_bad="Invalid key fingerprint: "
858 _WORKDIR_bad="Directory does not exist or is not writable: "
860 if [ -z "${SERVERNAME}" ]; then
861 echo -n "`basename $0`: "
862 echo "${_SERVERNAME_z}"
865 if [ -z "${KEYPRINT}" ]; then
866 echo -n "`basename $0`: "
867 echo "${_KEYPRINT_z}"
870 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
871 echo -n "`basename $0`: "
872 echo -n "${_KEYPRINT_bad}"
876 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
877 echo -n "`basename $0`: "
878 echo -n "${_WORKDIR_bad}"
882 cd ${WORKDIR} || exit 1
884 # Generate release number. The s/SECURITY/RELEASE/ bit exists
885 # to provide an upgrade path for FreeBSD Update 1.x users, since
886 # the kernels provided by FreeBSD Update 1.x are always labelled
889 sed -E 's,-p[0-9]+,,' |
890 sed -E 's,-SECURITY,-RELEASE,'`
892 FETCHDIR=${RELNUM}/${ARCH}
893 PATCHDIR=${RELNUM}/${ARCH}/bp
895 # Figure out what directory contains the running kernel
896 BOOTFILE=`sysctl -n kern.bootfile`
897 KERNELDIR=${BOOTFILE%/kernel}
898 if ! [ -d ${KERNELDIR} ]; then
899 echo "Cannot identify running kernel"
903 # Figure out what kernel configuration is running. We start with
904 # the output of `uname -i`, and then make the following adjustments:
905 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
906 # file says "ident SMP-GENERIC", I don't know...
907 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
908 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
909 # we're running an SMP kernel. This mis-identification is a bug
910 # which was fixed in 6.2-STABLE.
912 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
915 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
916 if sysctl kern.version | grep -qE '/SMP$'; then
923 PHTTPGET=/usr/libexec/phttpget
925 # Set up variables relating to VERBOSELEVEL
926 fetch_setup_verboselevel
929 #### Core functionality -- the actual work gets done here
931 # Use an SRV query to pick a server. If the SRV query doesn't provide
932 # a useful answer, use the server name specified by the user.
933 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
934 # from that; or if no servers are returned, use ${SERVERNAME}.
935 # This allows a user to specify "portsnap.freebsd.org" (in which case
936 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
937 # (in which case portsnap will use that particular server, since there
938 # won't be an SRV entry for that name).
940 # We ignore the Port field, since we are always going to use port 80.
942 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
943 # no mirrors are available for any reason.
944 fetch_pick_server_init () {
947 # Check that host(1) exists (i.e., that the system wasn't built with the
948 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
949 if ! which -s host; then
954 echo -n "Looking up ${SERVERNAME} mirrors... "
956 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
957 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
958 # "$name server selection ..."; we allow either format.
959 MLIST="_http._tcp.${SERVERNAME}"
960 host -t srv "${MLIST}" |
961 sed -nE "s/${MLIST} (has SRV record|server selection) //Ip" |
962 cut -f 1,2,4 -d ' ' |
964 sort > serverlist_full
966 # If no records, give up -- we'll just use the server name we were given.
967 if [ `wc -l < serverlist_full` -eq 0 ]; then
972 # Report how many mirrors we found.
973 echo `wc -l < serverlist_full` "mirrors found."
975 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
976 # is set, this will be used to generate the seed; otherwise, the seed
978 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
979 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
983 RANDVALUE=`jot -r 1 0 999999999`
987 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
988 fetch_pick_server () {
989 # Generate a list of not-yet-tried mirrors
990 sort serverlist_tried |
991 comm -23 serverlist_full - > serverlist
993 # Have we run out of mirrors?
994 if [ `wc -l < serverlist` -eq 0 ]; then
995 echo "No mirrors remaining, giving up."
999 # Find the highest priority level (lowest numeric value).
1000 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
1002 # Add up the weights of the response lines at that priority level.
1007 SRV_W=`echo $X | cut -f 2 -d ' '`
1008 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
1013 # If all the weights are 0, pretend that they are all 1 instead.
1014 if [ ${SRV_WSUM} -eq 0 ]; then
1015 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
1021 # Pick a value between 0 and the sum of the weights - 1
1022 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
1024 # Read through the list of mirrors and set SERVERNAME. Write the line
1025 # corresponding to the mirror we selected into serverlist_tried so that
1026 # we won't try it again.
1030 SRV_W=`echo $X | cut -f 2 -d ' '`
1031 SRV_W=$(($SRV_W + $SRV_W_ADD))
1032 if [ $SRV_RND -lt $SRV_W ]; then
1033 SERVERNAME=`echo $X | cut -f 3 -d ' '`
1034 echo "$X" >> serverlist_tried
1037 SRV_RND=$(($SRV_RND - $SRV_W))
1044 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
1045 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
1046 fetch_make_patchlist () {
1047 grep -vE "^([0-9a-f]{64})\|\1$" |
1050 if [ -f "files/${Y}.gz" ] ||
1051 [ ! -f "files/${X}.gz" ]; then
1058 # Print user-friendly progress statistics
1063 if [ $(($LNC % 10)) = 0 ]; then
1065 elif [ $(($LNC % 2)) = 0 ]; then
1072 # Function for asking the user if everything is ok
1074 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1075 case "${CONTINUE}" in
1086 # Initialize the working directory
1089 touch tINDEX.present
1092 # Check that we have a public key with an appropriate hash, or
1093 # fetch the key if it doesn't exist. Returns 1 if the key has
1094 # not yet been fetched.
1096 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1100 echo -n "Fetching public key from ${SERVERNAME}... "
1102 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1103 2>${QUIETREDIR} || true
1104 if ! [ -r pub.ssl ]; then
1108 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1109 echo "key has incorrect hash."
1116 # Fetch metadata signature, aka "tag".
1118 echo -n "Fetching metadata signature "
1119 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1121 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1122 2>${QUIETREDIR} || true
1123 if ! [ -r latest.ssl ]; then
1128 openssl rsautl -pubin -inkey pub.ssl -verify \
1129 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1132 if ! [ `wc -l < tag.new` = 1 ] ||
1134 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1136 echo "invalid signature."
1142 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1143 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1144 EOLTIME=`cut -f 6 -d '|' < tag.new`
1147 # Sanity-check the patch number in a tag, to make sure that we're not
1148 # going to "update" backwards and to prevent replay attacks.
1149 fetch_tagsanity () {
1150 # Check that we're not going to move from -pX to -pY with Y < X.
1151 RELPX=`uname -r | sed -E 's,.*-,,'`
1152 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1153 RELPX=`echo ${RELPX} | cut -c 2-`
1157 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1159 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1160 echo " appear older than what"
1161 echo "we are currently running (`uname -r`)!"
1162 echo "Cowardly refusing to proceed any further."
1166 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1167 # it contains a patch number <= RELPATCHNUM, in order to protect
1168 # against rollback (replay) attacks.
1171 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1173 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1175 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1177 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1178 echo " are older than the"
1179 echo -n "most recently seen updates"
1180 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1181 echo "Cowardly refusing to proceed any further."
1187 # Fetch metadata index file
1188 fetch_metadata_index () {
1189 echo ${NDEBUG} "Fetching metadata index... "
1191 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1193 if ! [ -f ${TINDEXHASH} ]; then
1197 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1198 echo "update metadata index corrupt."
1204 # Print an error message about signed metadata being bogus.
1205 fetch_metadata_bogus () {
1207 echo "The update metadata$1 is correctly signed, but"
1208 echo "failed an integrity check."
1209 echo "Cowardly refusing to proceed any further."
1213 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1214 # with the lines not named in $@ from tINDEX.present (if that file exists).
1215 fetch_metadata_index_merge () {
1216 for METAFILE in $@; do
1217 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1219 fetch_metadata_bogus " index"
1223 grep -E "${METAFILE}\|" ${TINDEXHASH}
1225 sort > tINDEX.wanted
1227 if [ -f tINDEX.present ]; then
1228 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1229 sort -m - tINDEX.wanted > tINDEX.new
1232 mv tINDEX.wanted tINDEX.new
1236 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1237 # are added by future versions of the server, this won't cause problems,
1238 # since the only lines which appear in tINDEX.new are the ones which we
1239 # specifically grepped out of ${TINDEXHASH}.
1240 fetch_metadata_index_sanity () {
1241 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1242 fetch_metadata_bogus " index"
1247 # Sanity check the metadata file $1.
1248 fetch_metadata_sanity () {
1249 # Some aliases to save space later: ${P} is a character which can
1250 # appear in a path; ${M} is the four numeric metadata fields; and
1251 # ${H} is a sha256 hash.
1252 P="[-+./:=,%@_[~[:alnum:]]"
1253 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1256 # Check that the first four fields make sense.
1257 if gunzip -c < files/$1.gz |
1258 grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then
1259 fetch_metadata_bogus ""
1263 # Remove the first three fields.
1264 gunzip -c < files/$1.gz |
1265 cut -f 4- -d '|' > sanitycheck.tmp
1267 # Sanity check entries with type 'f'
1268 if grep -E '^f' sanitycheck.tmp |
1269 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1270 fetch_metadata_bogus ""
1274 # Sanity check entries with type 'd'
1275 if grep -E '^d' sanitycheck.tmp |
1276 grep -qvE "^d\|${M}\|\|\$"; then
1277 fetch_metadata_bogus ""
1281 # Sanity check entries with type 'L'
1282 if grep -E '^L' sanitycheck.tmp |
1283 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1284 fetch_metadata_bogus ""
1288 # Sanity check entries with type '-'
1289 if grep -E '^-' sanitycheck.tmp |
1290 grep -qvE "^-\|\|\|\|\|\|"; then
1291 fetch_metadata_bogus ""
1299 # Fetch the metadata index and metadata files listed in $@,
1300 # taking advantage of metadata patches where possible.
1302 fetch_metadata_index || return 1
1303 fetch_metadata_index_merge $@ || return 1
1304 fetch_metadata_index_sanity || return 1
1306 # Generate a list of wanted metadata patches
1307 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1308 fetch_make_patchlist > patchlist
1310 if [ -s patchlist ]; then
1311 # Attempt to fetch metadata patches
1312 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1313 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1314 tr '|' '-' < patchlist |
1315 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1316 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1317 2>${STATSREDIR} | fetch_progress
1320 # Attempt to apply metadata patches
1321 echo -n "Applying metadata patches... "
1322 tr '|' ' ' < patchlist |
1324 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1325 gunzip -c < ${X}-${Y}.gz > diff
1326 gunzip -c < files/${X}.gz > diff-OLD
1328 # Figure out which lines are being added and removed
1331 while read PREFIX; do
1332 look "${PREFIX}" diff-OLD
1335 grep -E '^\+' diff |
1336 cut -c 2- > diff-add
1338 # Generate the new file
1339 comm -23 diff-OLD diff-rm |
1340 sort - diff-add > diff-NEW
1342 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1343 mv diff-NEW files/${Y}
1346 mv diff-NEW ${Y}.bad
1348 rm -f ${X}-${Y}.gz diff
1349 rm -f diff-OLD diff-NEW diff-add diff-rm
1350 done 2>${QUIETREDIR}
1354 # Update metadata without patches
1355 cut -f 2 -d '|' < tINDEX.new |
1357 if [ ! -f "files/${Y}.gz" ]; then
1363 if [ -s filelist ]; then
1364 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1365 echo ${NDEBUG} "metadata files... "
1366 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1367 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1371 if ! [ -f ${Y}.gz ]; then
1375 if [ `gunzip -c < ${Y}.gz |
1376 ${SHA256} -q` = ${Y} ]; then
1377 mv ${Y}.gz files/${Y}.gz
1379 echo "metadata is corrupt."
1386 # Sanity-check the metadata files.
1387 cut -f 2 -d '|' tINDEX.new > filelist
1389 fetch_metadata_sanity ${X} || return 1
1392 # Remove files which are no longer needed
1393 cut -f 2 -d '|' tINDEX.present |
1395 cut -f 2 -d '|' tINDEX.new |
1397 comm -13 - oldfiles |
1398 lam -s "files/" - -s ".gz" |
1400 rm patchlist filelist oldfiles
1404 mv tINDEX.new tINDEX.present
1410 # Extract a subset of a downloaded metadata file containing only the parts
1411 # which are listed in COMPONENTS.
1412 fetch_filter_metadata_components () {
1413 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1414 gunzip -c < files/${METAHASH}.gz > $1.all
1416 # Fish out the lines belonging to components we care about.
1417 for C in ${COMPONENTS}; do
1418 look "`echo ${C} | tr '/' '|'`|" $1.all
1421 # Remove temporary file.
1425 # Generate a filtered version of the metadata file $1 from the downloaded
1426 # file, by fishing out the lines corresponding to components we're trying
1427 # to keep updated, and then removing lines corresponding to paths we want
1429 fetch_filter_metadata () {
1430 # Fish out the lines belonging to components we care about.
1431 fetch_filter_metadata_components $1
1433 # Canonicalize directory names by removing any trailing / in
1434 # order to avoid listing directories multiple times if they
1435 # belong to multiple components. Turning "/" into "" doesn't
1436 # matter, since we add a leading "/" when we use paths later.
1437 cut -f 3- -d '|' $1 |
1438 sed -e 's,/|d|,|d|,' |
1439 sed -e 's,/|-|,|-|,' |
1442 # Figure out which lines to ignore and remove them.
1443 for X in ${IGNOREPATHS}; do
1444 grep -E "^${X}" $1.tmp
1447 comm -13 - $1.tmp > $1
1449 # Remove temporary files.
1453 # Filter the metadata file $1 by adding lines with "/boot/$2"
1454 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1455 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1456 # the original lines which start with that.
1457 # Put another way: Deal with the fact that the FOO kernel is sometimes
1458 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1459 fetch_filter_kernel_names () {
1461 sed -e "s,/boot/$2,${KERNELDIR},g" |
1465 if ! [ -d /boot/$2 ]; then
1466 grep -v ^/boot/$2 $1 > $1.tmp
1471 # For all paths appearing in $1 or $3, inspect the system
1472 # and generate $2 describing what is currently installed.
1473 fetch_inspect_system () {
1477 # Tell the user why his disk is suddenly making lots of noise
1478 echo -n "Inspecting system... "
1480 # Generate list of files to inspect
1485 # Examine each file and output lines of the form
1486 # /path/to/file|type|device-inum|user|group|perm|flags|value
1487 # sorted by device and inode number.
1489 # If the symlink/file/directory does not exist, record this.
1490 if ! [ -e ${BASEDIR}/${F} ]; then
1494 if ! [ -r ${BASEDIR}/${F} ]; then
1495 echo "Cannot read file: ${BASEDIR}/${F}" \
1501 # Otherwise, output an index line.
1502 if [ -L ${BASEDIR}/${F} ]; then
1504 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1505 readlink ${BASEDIR}/${F};
1506 elif [ -f ${BASEDIR}/${F} ]; then
1508 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1509 sha256 -q ${BASEDIR}/${F};
1510 elif [ -d ${BASEDIR}/${F} ]; then
1512 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1514 echo "Unknown file type: ${BASEDIR}/${F}" \
1520 sort -k 3,3 -t '|' > $2.tmp
1523 # Check if an error occurred during system inspection
1524 if [ -f .err ]; then
1528 # Convert to the form
1529 # /path/to/file|type|user|group|perm|flags|value|hlink
1530 # by resolving identical device and inode numbers into hard links.
1531 cut -f 1,3 -d '|' $2.tmp |
1532 sort -k 1,1 -t '|' |
1533 sort -s -u -k 2,2 -t '|' |
1534 join -1 2 -2 3 -t '|' - $2.tmp |
1535 awk -F \| -v OFS=\| \
1537 if (($2 == $3) || ($4 == "-"))
1538 print $3,$4,$5,$6,$7,$8,$9,""
1540 print $3,$4,$5,$6,$7,$8,$9,$2
1545 # We're finished looking around
1549 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1550 # files which differ; generate $3 containing these paths and the old hashes.
1551 fetch_filter_mergechanges () {
1552 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1554 for X in ${MERGECHANGES}; do
1555 grep -E "^${X}" ${F}
1557 cut -f 1,2,7 -d '|' |
1561 # Any line in $2-values which doesn't appear in $1-values and is a
1562 # file means that we should list the path in $3.
1563 comm -13 $1-values $2-values |
1565 cut -f 1 -d '|' > $2-paths
1567 # For each path, pull out one (and only one!) entry from $1-values.
1568 # Note that we cannot distinguish which "old" version the user made
1569 # changes to; but hopefully any changes which occur due to security
1570 # updates will exist in both the "new" version and the version which
1571 # the user has installed, so the merging will still work.
1573 look "${X}|" $1-values |
1575 done < $2-paths > $3
1578 rm $1-values $2-values $2-paths
1581 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1582 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1583 # the paths are listed in $4. For entries in $2 marked "not present"
1584 # (aka. type -), remove lines from $[123] unless there is a corresponding
1586 fetch_filter_unmodified_notpresent () {
1587 # Figure out which lines of $1 and $3 correspond to bits which
1588 # should only be updated if they haven't changed, and fish out
1589 # the (path, type, value) tuples.
1590 # NOTE: We don't consider a file to be "modified" if it matches
1592 for X in ${UPDATEIFUNMODIFIED}; do
1596 cut -f 1,2,7 -d '|' |
1599 # Do the same for $2.
1600 for X in ${UPDATEIFUNMODIFIED}; do
1603 cut -f 1,2,7 -d '|' |
1606 # Any entry in $2-values which is not in $1-values corresponds to
1607 # a path which we need to remove from $1, $2, and $3, unless it
1608 # that path appears in $4.
1609 comm -13 $1-values $2-values |
1610 sort -t '|' -k 1,1 > mlines.tmp
1611 cut -f 1 -d '|' $4 |
1613 join -v 2 -t '|' - mlines.tmp |
1615 rm $1-values $2-values mlines.tmp
1617 # Any lines in $2 which are not in $1 AND are "not present" lines
1618 # also belong in mlines.
1620 cut -f 1,2,7 -d '|' |
1621 fgrep '|-|' >> mlines
1623 # Remove lines from $1, $2, and $3
1624 for X in $1 $2 $3; do
1625 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1626 cut -f 1 -d '|' < mlines |
1628 join -v 2 -t '|' - ${X}.tmp |
1633 # Store a list of the modified files, for future reference
1634 fgrep -v '|-|' mlines |
1635 cut -f 1 -d '|' > modifiedfiles
1639 # For each entry in $1 of type -, remove any corresponding
1640 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1641 # of type - from $1.
1642 fetch_filter_allowadd () {
1643 cut -f 1,2 -d '|' < $1 |
1645 cut -f 1 -d '|' > filesnotpresent
1647 if [ ${ALLOWADD} != "yes" ]; then
1649 join -v 1 -t '|' - filesnotpresent |
1655 join -v 1 -t '|' - filesnotpresent |
1661 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1662 # which don't correspond to entries in $2.
1663 fetch_filter_allowdelete () {
1664 # Produce a lists ${PATH}|${TYPE}
1666 cut -f 1-2 -d '|' < ${X} |
1667 sort -u > ${X}.nodes
1670 # Figure out which lines need to be removed from $1.
1671 if [ ${ALLOWDELETE} != "yes" ]; then
1672 comm -23 $1.nodes $2.nodes > $1.badnodes
1677 # Remove the relevant lines from $1
1680 done < $1.badnodes |
1681 comm -13 - $1 > $1.tmp
1684 rm $1.badnodes $1.nodes $2.nodes
1687 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1688 # with metadata not matching any entry in $1, replace the corresponding
1689 # line of $3 with one having the same metadata as the entry in $2.
1690 fetch_filter_modified_metadata () {
1691 # Fish out the metadata from $1 and $2
1693 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1696 # Find the metadata we need to keep
1697 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1698 comm -13 $1.metadata $2.metadata > keepmeta
1703 # Extract the lines which we need to remove from $3, and
1704 # construct the lines which we need to add to $3.
1708 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1709 look "${NODE}|" $3 >> $3.remove
1710 look "${NODE}|" $3 |
1712 lam -s "${LINE}|" - >> $3.add
1715 # Remove the specified lines and add the new lines.
1718 sort -u - $3.add > $3.tmp
1721 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1724 # Remove lines from $1 and $2 which are identical;
1725 # no need to update a file if it isn't changing.
1726 fetch_filter_uptodate () {
1727 comm -23 $1 $2 > $1.tmp
1728 comm -13 $1 $2 > $2.tmp
1734 # Fetch any "clean" old versions of files we need for merging changes.
1735 fetch_files_premerge () {
1736 # We only need to do anything if $1 is non-empty.
1738 # Tell the user what we're doing
1739 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1741 # List of files wanted
1744 sort -u > files.wanted
1746 # Only fetch the files we don't already have
1748 if [ ! -f "files/${Y}.gz" ]; then
1751 done < files.wanted > filelist
1753 # Actually fetch them
1754 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1755 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1758 # Make sure we got them all, and move them into /files/
1760 if ! [ -f ${Y}.gz ]; then
1764 if [ `gunzip -c < ${Y}.gz |
1765 ${SHA256} -q` = ${Y} ]; then
1766 mv ${Y}.gz files/${Y}.gz
1768 echo "${Y} has incorrect hash."
1775 rm filelist files.wanted
1779 # Prepare to fetch files: Generate a list of the files we need,
1780 # copy the unmodified files we have into /files/, and generate
1781 # a list of patches to download.
1782 fetch_files_prepare () {
1783 # Tell the user why his disk is suddenly making lots of noise
1784 echo -n "Preparing to download files... "
1786 # Reduce indices to ${PATH}|${HASH} pairs
1787 for X in $1 $2 $3; do
1788 cut -f 1,2,7 -d '|' < ${X} |
1794 # List of files wanted
1795 cut -f 2 -d '|' < $3.hashes |
1798 if ! [ -f files/${HASH}.gz ]; then
1803 # Generate a list of unmodified files
1804 comm -12 $1.hashes $2.hashes |
1805 sort -k 1,1 -t '|' > unmodified.files
1807 # Copy all files into /files/. We only need the unmodified files
1808 # for use in patching; but we'll want all of them if the user asks
1809 # to rollback the updates later.
1811 F=`echo "${LINE}" | cut -f 1 -d '|'`
1812 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1814 # Skip files we already have.
1815 if [ -f files/${HASH}.gz ]; then
1819 # Make sure the file hasn't changed.
1820 cp "${BASEDIR}/${F}" tmpfile
1821 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1823 echo "File changed while FreeBSD Update running: ${F}"
1827 # Place the file into storage.
1828 gzip -c < tmpfile > files/${HASH}.gz
1832 # Produce a list of patches to download
1833 sort -k 1,1 -t '|' $3.hashes |
1834 join -t '|' -o 2.2,1.2 - unmodified.files |
1835 fetch_make_patchlist > patchlist
1838 rm unmodified.files $1.hashes $2.hashes $3.hashes
1840 # We don't need the list of possible old files any more.
1843 # We're finished making noise
1849 # Attempt to fetch patches
1850 if [ -s patchlist ]; then
1851 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1852 echo ${NDEBUG} "patches.${DDSTATS}"
1853 tr '|' '-' < patchlist |
1854 lam -s "${PATCHDIR}/" - |
1855 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1856 2>${STATSREDIR} | fetch_progress
1859 # Attempt to apply patches
1860 echo -n "Applying patches... "
1861 tr '|' ' ' < patchlist |
1863 if [ ! -f "${X}-${Y}" ]; then continue; fi
1864 gunzip -c < files/${X}.gz > OLD
1866 bspatch OLD NEW ${X}-${Y}
1868 if [ `${SHA256} -q NEW` = ${Y} ]; then
1872 rm -f diff OLD NEW ${X}-${Y}
1873 done 2>${QUIETREDIR}
1877 # Download files which couldn't be generate via patching
1879 if [ ! -f "files/${Y}.gz" ]; then
1882 done < files.wanted > filelist
1884 if [ -s filelist ]; then
1885 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1886 echo ${NDEBUG} "files... "
1887 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1888 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1892 if ! [ -f ${Y}.gz ]; then
1896 if [ `gunzip -c < ${Y}.gz |
1897 ${SHA256} -q` = ${Y} ]; then
1898 mv ${Y}.gz files/${Y}.gz
1900 echo "${Y} has incorrect hash."
1908 rm files.wanted filelist patchlist
1911 # Create and populate install manifest directory; and report what updates
1913 fetch_create_manifest () {
1914 # If we have an existing install manifest, nuke it.
1915 if [ -L "${BDHASH}-install" ]; then
1916 rm -r ${BDHASH}-install/
1917 rm ${BDHASH}-install
1920 # Report to the user if any updates were avoided due to local changes
1921 if [ -s modifiedfiles ]; then
1923 echo -n "The following files are affected by updates, "
1924 echo "but no changes have"
1925 echo -n "been downloaded because the files have been "
1926 echo "modified locally:"
1931 # If no files will be updated, tell the user and exit
1932 if ! [ -s INDEX-PRESENT ] &&
1933 ! [ -s INDEX-NEW ]; then
1934 rm INDEX-PRESENT INDEX-NEW
1936 echo -n "No updates needed to update system to "
1937 echo "${RELNUM}-p${RELPATCHNUM}."
1941 # Divide files into (a) removed files, (b) added files, and
1942 # (c) updated files.
1943 cut -f 1 -d '|' < INDEX-PRESENT |
1944 sort > INDEX-PRESENT.flist
1945 cut -f 1 -d '|' < INDEX-NEW |
1946 sort > INDEX-NEW.flist
1947 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1948 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
1949 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
1950 rm INDEX-PRESENT.flist INDEX-NEW.flist
1952 # Report removed files, if any
1953 if [ -s files.removed ]; then
1955 echo -n "The following files will be removed "
1956 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1961 # Report added files, if any
1962 if [ -s files.added ]; then
1964 echo -n "The following files will be added "
1965 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1970 # Report updated files, if any
1971 if [ -s files.updated ]; then
1973 echo -n "The following files will be updated "
1974 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1980 # Create a directory for the install manifest.
1981 MDIR=`mktemp -d install.XXXXXX` || return 1
1984 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
1985 mv INDEX-NEW ${MDIR}/INDEX-NEW
1987 # Link it into place
1988 ln -s ${MDIR} ${BDHASH}-install
1991 # Warn about any upcoming EoL
1993 # What's the current time?
1994 NOWTIME=`date "+%s"`
1996 # When did we last warn about the EoL date?
1997 if [ -f lasteolwarn ]; then
1998 LASTWARN=`cat lasteolwarn`
2000 LASTWARN=`expr ${NOWTIME} - 63072000`
2003 # If the EoL time is past, warn.
2004 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
2007 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
2008 Any security issues discovered after `date -r ${EOLTIME}`
2009 will not have been corrected.
2014 # Figure out how long it has been since we last warned about the
2015 # upcoming EoL, and how much longer we have left.
2016 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
2017 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
2019 # Don't warn if the EoL is more than 3 months away
2020 if [ ${TIMELEFT} -gt 7884000 ]; then
2024 # Don't warn if the time remaining is more than 3 times the time
2025 # since the last warning.
2026 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
2030 # Figure out what time units to use.
2031 if [ ${TIMELEFT} -lt 604800 ]; then
2034 elif [ ${TIMELEFT} -lt 2678400 ]; then
2042 # Compute the right number of units
2043 NUM=`expr ${TIMELEFT} / ${SIZE}`
2044 if [ ${NUM} != 1 ]; then
2051 WARNING: `uname -sr` is approaching its End-of-Life date.
2052 It is strongly recommended that you upgrade to a newer
2053 release within the next ${NUM} ${UNIT}.
2056 # Update the stored time of last warning
2057 echo ${NOWTIME} > lasteolwarn
2060 # Do the actual work involved in "fetch" / "cron".
2062 workdir_init || return 1
2064 # Prepare the mirror list.
2065 fetch_pick_server_init && fetch_pick_server
2067 # Try to fetch the public key until we run out of servers.
2068 while ! fetch_key; do
2069 fetch_pick_server || return 1
2072 # Try to fetch the metadata index signature ("tag") until we run
2073 # out of available servers; and sanity check the downloaded tag.
2074 while ! fetch_tag; do
2075 fetch_pick_server || return 1
2077 fetch_tagsanity || return 1
2079 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2080 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2082 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2083 # the lines which (a) belong to components we care about, and (b)
2084 # don't correspond to paths we're explicitly ignoring.
2085 fetch_filter_metadata INDEX-NEW || return 1
2086 fetch_filter_metadata INDEX-OLD || return 1
2088 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2089 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2090 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2092 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2093 # system and generate an INDEX-PRESENT file.
2094 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2096 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2097 # correspond to lines in INDEX-PRESENT with hashes not appearing
2098 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2099 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2100 # INDEX-OLD with type -.
2101 fetch_filter_unmodified_notpresent \
2102 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2104 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2105 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2106 # of type - from INDEX-PRESENT.
2107 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2109 # If ${ALLOWDELETE} != "yes", then remove any entries from
2110 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2111 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2113 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2114 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2115 # replace the corresponding line of INDEX-NEW with one having the
2116 # same metadata as the entry in INDEX-PRESENT.
2117 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2119 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2120 # no need to update a file if it isn't changing.
2121 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2123 # Prepare to fetch files: Generate a list of the files we need,
2124 # copy the unmodified files we have into /files/, and generate
2125 # a list of patches to download.
2126 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2129 fetch_files || return 1
2131 # Create and populate install manifest directory; and report what
2132 # updates are available.
2133 fetch_create_manifest || return 1
2135 # Warn about any upcoming EoL
2136 fetch_warn_eol || return 1
2139 # If StrictComponents is not "yes", generate a new components list
2140 # with only the components which appear to be installed.
2141 upgrade_guess_components () {
2142 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2143 # Generate filtered INDEX-ALL with only the components listed
2145 fetch_filter_metadata_components $1 || return 1
2147 # Tell the user why his disk is suddenly making lots of noise
2148 echo -n "Inspecting system... "
2150 # Look at the files on disk, and assume that a component is
2151 # supposed to be present if it is more than half-present.
2152 cut -f 1-3 -d '|' < INDEX-ALL |
2154 while read C S F; do
2155 if [ -e ${BASEDIR}/${F} ]; then
2162 sed -E 's,^ +,,' > compfreq
2163 grep ' = ' compfreq |
2165 sort -k 2,2 -t ' ' > compfreq.total
2166 grep ' + ' compfreq |
2168 sort -k 2,2 -t ' ' > compfreq.present
2169 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2170 while read S P T; do
2171 if [ ${P} -gt `expr ${T} / 2` ]; then
2175 cut -f 2 -d ' ' < compfreq.total > comp.total
2176 rm INDEX-ALL compfreq compfreq.total compfreq.present
2178 # We're done making noise.
2181 # Sometimes the kernel isn't installed where INDEX-ALL
2182 # thinks that it should be: In particular, it is often in
2183 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2184 # deal with this, if "kernel|X" is listed in comp.total
2185 # (i.e., is a component which would be upgraded if it is
2186 # found to be present) we will add it to comp.present.
2187 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2188 # not, we print a warning -- the user is running a kernel
2189 # which isn't part of the release.
2190 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2191 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2193 if grep -qE "^kernel\|" comp.total &&
2194 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2197 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2198 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2199 This kernel will not be updated: you MUST update the kernel manually
2200 before running "$0 install".
2204 # Re-sort the list of installed components and generate
2205 # the list of non-installed components.
2206 sort -u < comp.present > comp.present.tmp
2207 mv comp.present.tmp comp.present
2208 comm -13 comp.present comp.total > comp.absent
2210 # Ask the user to confirm that what we have is correct. To
2211 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2212 # subcomponents must be listed in the configuration file).
2214 echo -n "The following components of FreeBSD "
2215 echo "seem to be installed:"
2216 tr '|' '/' < comp.present |
2219 echo -n "The following components of FreeBSD "
2220 echo "do not seem to be installed:"
2221 tr '|' '/' < comp.absent |
2224 continuep || return 1
2227 # Suck the generated list of components into ${COMPONENTS}.
2228 # Note that comp.present.tmp is used due to issues with
2229 # pipelines and setting variables.
2231 tr '|' '/' < comp.present > comp.present.tmp
2233 COMPONENTS="${COMPONENTS} ${C}"
2234 done < comp.present.tmp
2236 # Delete temporary files
2237 rm comp.present comp.present.tmp comp.absent comp.total
2241 # If StrictComponents is not "yes", COMPONENTS contains an entry
2242 # corresponding to the currently running kernel, and said kernel
2243 # does not exist in the new release, add "kernel/generic" to the
2244 # list of components.
2245 upgrade_guess_new_kernel () {
2246 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2247 # Grab the unfiltered metadata file.
2248 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2249 gunzip -c < files/${METAHASH}.gz > $1.all
2251 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2252 # isn't in $1.all, we need to add kernel/generic.
2253 for C in ${COMPONENTS}; do
2254 if [ ${C} = "kernel/${KCOMP}" ] &&
2255 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2256 COMPONENTS="${COMPONENTS} kernel/generic"
2260 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2261 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2262 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2263 replaced with a "generic" kernel.
2265 continuep || return 1
2269 # Don't need this any more...
2274 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2275 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2276 upgrade_oldall_to_oldnew () {
2277 # For each ${F}|... which appears in INDEX-ALL but does not appear
2278 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2279 cut -f 1 -d '|' < $1 |
2281 cut -f 1 -d '|' < $2 |
2283 comm -13 $1.paths - |
2284 lam - -s "|-||||||" |
2288 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2289 comm -23 $1 $2 > $1.tmp
2292 # Remove lines from INDEX-ALL which have a file name not appearing
2293 # anywhere in INDEX-OLD (since these must be files which haven't
2294 # changed -- if they were new, there would be an entry of type "-").
2295 cut -f 1 -d '|' < $1 |
2297 sort -k 1,1 -t '|' < $2 |
2298 join -t '|' - $1.paths |
2303 # Rename INDEX-ALL to INDEX-NEW.
2307 # Helper for upgrade_merge: Return zero true iff the two files differ only
2308 # in the contents of their RCS tags.
2310 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2311 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2313 if [ $X = $Y ]; then
2320 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2321 # and update $3 to reflect the hashes of merged files.
2323 # We only need to do anything if $1 is non-empty.
2325 cut -f 1 -d '|' $1 |
2328 # Create staging area for merging files
2332 mkdir -p merge/old/${D}
2333 mkdir -p merge/${OLDRELNUM}/${D}
2334 mkdir -p merge/${RELNUM}/${D}
2335 mkdir -p merge/new/${D}
2340 # Currently installed file
2341 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2342 gunzip < files/${V}.gz > merge/old/${F}
2345 if look "${F}|" $1 | fgrep -q "|f|"; then
2346 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2347 gunzip < files/${V}.gz \
2348 > merge/${OLDRELNUM}/${F}
2352 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2353 fgrep -q "|f|"; then
2354 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2355 gunzip < files/${V}.gz \
2356 > merge/${RELNUM}/${F}
2360 # Attempt to automatically merge changes
2361 echo -n "Attempting to automatically merge "
2362 echo -n "changes in files..."
2365 # If the file doesn't exist in the new release,
2366 # the result of "merging changes" is having the file
2368 if ! [ -f merge/${RELNUM}/${F} ]; then
2372 # If the file didn't exist in the old release, we're
2373 # going to throw away the existing file and hope that
2374 # the version from the new release is what we want.
2375 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2376 cp merge/${RELNUM}/${F} merge/new/${F}
2380 # Some files need special treatment.
2382 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2383 # Don't merge these -- we're rebuild them
2384 # after updates are installed.
2385 cp merge/old/${F} merge/new/${F}
2388 if ! diff3 -E -m -L "current version" \
2389 -L "${OLDRELNUM}" -L "${RELNUM}" \
2391 merge/${OLDRELNUM}/${F} \
2392 merge/${RELNUM}/${F} \
2393 > merge/new/${F} 2>/dev/null; then
2394 echo ${F} >> failed.merges
2401 # Ask the user to handle any files which didn't merge.
2403 # If the installed file differs from the version in
2404 # the old release only due to RCS tag expansion
2405 # then just use the version in the new release.
2406 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2407 cp merge/${RELNUM}/${F} merge/new/${F}
2413 The following file could not be merged automatically: ${F}
2414 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2417 read dummy </dev/tty
2418 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2419 done < failed.merges
2422 # Ask the user to confirm that he likes how the result
2425 # Skip files which haven't changed except possibly
2426 # in their RCS tags.
2427 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2428 samef merge/old/${F} merge/new/${F}; then
2432 # Skip files where the installed file differs from
2433 # the old file only due to RCS tags.
2434 if [ -f merge/old/${F} ] &&
2435 [ -f merge/${OLDRELNUM}/${F} ] &&
2436 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2440 # Warn about files which are ceasing to exist.
2441 if ! [ -f merge/new/${F} ]; then
2444 The following file will be removed, as it no longer exists in
2445 FreeBSD ${RELNUM}: ${F}
2447 continuep < /dev/tty || return 1
2451 # Print changes for the user's approval.
2454 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2455 FreeBSD ${RELNUM} have been merged into ${F}:
2457 diff -U 5 -L "current version" -L "new version" \
2458 merge/old/${F} merge/new/${F} || true
2459 continuep < /dev/tty || return 1
2462 # Store merged files.
2464 if [ -f merge/new/${F} ]; then
2465 V=`${SHA256} -q merge/new/${F}`
2467 gzip -c < merge/new/${F} > files/${V}.gz
2470 done < $1-paths > newhashes
2472 # Pull lines out from $3 which need to be updated to
2473 # reflect merged files.
2476 done < $1-paths > $3-oldlines
2478 # Update lines to reflect merged files
2479 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2480 $3-oldlines newhashes > $3-newlines
2482 # Remove old lines from $3 and add new lines.
2485 sort - $3-newlines > $3.tmp
2489 rm $1-paths newhashes $3-oldlines $3-newlines
2493 # We're done with merging files.
2497 # Do the work involved in fetching upgrades to a new release
2499 workdir_init || return 1
2501 # Prepare the mirror list.
2502 fetch_pick_server_init && fetch_pick_server
2504 # Try to fetch the public key until we run out of servers.
2505 while ! fetch_key; do
2506 fetch_pick_server || return 1
2509 # Try to fetch the metadata index signature ("tag") until we run
2510 # out of available servers; and sanity check the downloaded tag.
2511 while ! fetch_tag; do
2512 fetch_pick_server || return 1
2514 fetch_tagsanity || return 1
2516 # Fetch the INDEX-OLD and INDEX-ALL.
2517 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2519 # If StrictComponents is not "yes", generate a new components list
2520 # with only the components which appear to be installed.
2521 upgrade_guess_components INDEX-ALL || return 1
2523 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2524 # the components we want and without anything marked as "Ignore".
2525 fetch_filter_metadata INDEX-OLD || return 1
2526 fetch_filter_metadata INDEX-ALL || return 1
2528 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2529 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2530 mv INDEX-OLD.tmp INDEX-OLD
2533 # Adjust variables for fetching files from the new release.
2535 RELNUM=${TARGETRELEASE}
2536 OLDFETCHDIR=${FETCHDIR}
2537 FETCHDIR=${RELNUM}/${ARCH}
2539 # Try to fetch the NEW metadata index signature ("tag") until we run
2540 # out of available servers; and sanity check the downloaded tag.
2541 while ! fetch_tag; do
2542 fetch_pick_server || return 1
2545 # Fetch the new INDEX-ALL.
2546 fetch_metadata INDEX-ALL || return 1
2548 # If StrictComponents is not "yes", COMPONENTS contains an entry
2549 # corresponding to the currently running kernel, and said kernel
2550 # does not exist in the new release, add "kernel/generic" to the
2551 # list of components.
2552 upgrade_guess_new_kernel INDEX-ALL || return 1
2554 # Filter INDEX-ALL to contain only the components we want and without
2555 # anything marked as "Ignore".
2556 fetch_filter_metadata INDEX-ALL || return 1
2558 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2559 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2560 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2562 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2563 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2564 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2566 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2567 # system and generate an INDEX-PRESENT file.
2568 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2570 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2571 # paths and hashes of old versions of files to merge.
2572 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2574 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2575 # correspond to lines in INDEX-PRESENT with hashes not appearing
2576 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2577 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2578 # INDEX-OLD with type -.
2579 fetch_filter_unmodified_notpresent \
2580 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2582 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2583 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2584 # of type - from INDEX-PRESENT.
2585 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2587 # If ${ALLOWDELETE} != "yes", then remove any entries from
2588 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2589 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2591 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2592 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2593 # replace the corresponding line of INDEX-NEW with one having the
2594 # same metadata as the entry in INDEX-PRESENT.
2595 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2597 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2598 # no need to update a file if it isn't changing.
2599 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2601 # Fetch "clean" files from the old release for merging changes.
2602 fetch_files_premerge tomerge-old
2604 # Prepare to fetch files: Generate a list of the files we need,
2605 # copy the unmodified files we have into /files/, and generate
2606 # a list of patches to download.
2607 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2609 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2610 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2611 fetch_files || return 1
2613 # Merge configuration file changes.
2614 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2616 # Create and populate install manifest directory; and report what
2617 # updates are available.
2618 fetch_create_manifest || return 1
2620 # Leave a note behind to tell the "install" command that the kernel
2621 # needs to be installed before the world.
2622 touch ${BDHASH}-install/kernelfirst
2624 # Remind the user that they need to run "freebsd-update install"
2625 # to install the downloaded bits, in case they didn't RTFM.
2626 echo "To install the downloaded upgrades, run \"$0 install\"."
2629 # Make sure that all the file hashes mentioned in $@ have corresponding
2630 # gzipped files stored in /files/.
2632 # Generate a list of hashes
2639 # Make sure all the hashes exist
2641 if ! [ -f files/${HASH}.gz ]; then
2642 echo -n "Update files missing -- "
2643 echo "this should never happen."
2644 echo "Re-run '$0 fetch'."
2653 # Remove the system immutable flag from files
2655 # Generate file list
2657 cut -f 1 -d '|' > filelist
2661 if ! [ -e ${BASEDIR}/${F} ]; then
2664 echo ${BASEDIR}/${F}
2666 done < filelist | xargs chflags noschg || return 1
2672 # Decide which directory name to use for kernel backups.
2673 backup_kernel_finddir () {
2676 # Pathname does not exist, so it is OK use that name
2677 # for backup directory.
2678 if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then
2682 # If directory do exist, we only use if it has our
2684 if [ -d $BASEDIR/$BACKUPKERNELDIR -a \
2685 -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then
2689 # We could not use current directory name, so add counter to
2690 # the end and try again.
2692 if [ $CNT -gt 9 ]; then
2693 echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)"
2696 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2697 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2701 # Backup the current kernel using hardlinks, if not disabled by user.
2702 # Since we delete all files in the directory used for previous backups
2703 # we create a marker file called ".freebsd-update" in the directory so
2704 # we can determine on the next run that the directory was created by
2705 # freebsd-update and we then do not accidentally remove user files in
2706 # the unlikely case that the user has created a directory with a
2709 # Only make kernel backup is so configured.
2710 if [ $BACKUPKERNEL != yes ]; then
2714 # Decide which directory name to use for kernel backups.
2715 backup_kernel_finddir
2717 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2718 # "not ours", backup_kernel_finddir would have exited, so
2719 # deleting the directory content is as safe as we can make it.
2720 if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then
2721 rm -fr $BASEDIR/$BACKUPKERNELDIR
2724 # Create directories for backup.
2725 mkdir -p $BASEDIR/$BACKUPKERNELDIR
2726 mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \
2727 mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null
2729 # Mark the directory as having been created by freebsd-update.
2730 touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update
2731 if [ $? -ne 0 ]; then
2732 echo "Could not create kernel backup directory"
2736 # Disable pathname expansion to be sure *.symbols is not
2740 # Use find to ignore symbol files, unless disabled by user.
2741 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2744 FINDFILTER="-a ! -name *.debug -a ! -name *.symbols"
2747 # Backup all the kernel files using hardlinks.
2748 (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \
2749 cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;)
2751 # Re-enable patchname expansion.
2756 install_from_index () {
2757 # First pass: Do everything apart from setting file flags. We
2758 # can't set flags yet, because schg inhibits hard linking.
2759 sort -k 1,1 -t '|' $1 |
2761 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2764 # Create a directory
2765 install -d -o ${OWNER} -g ${GROUP} \
2766 -m ${PERM} ${BASEDIR}/${FPATH}
2769 if [ -z "${LINK}" ]; then
2770 # Create a file, without setting flags.
2771 gunzip < files/${HASH}.gz > ${HASH}
2772 install -S -o ${OWNER} -g ${GROUP} \
2773 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2776 # Create a hard link.
2777 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2782 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2787 # Perform a second pass, adding file flags.
2789 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2790 if [ ${TYPE} = "f" ] &&
2791 ! [ ${FLAGS} = "0" ]; then
2792 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2797 # Remove files which we want to delete
2799 # Generate list of new files
2800 cut -f 1 -d '|' < $2 |
2803 # Generate subindex of old files we want to nuke
2804 sort -k 1,1 -t '|' $1 |
2805 join -t '|' -v 1 - newfiles |
2806 sort -r -k 1,1 -t '|' |
2808 tr '|' ' ' > killfiles
2810 # Remove the offending bits
2811 while read FPATH TYPE; do
2814 rmdir ${BASEDIR}/${FPATH}
2817 rm ${BASEDIR}/${FPATH}
2820 rm ${BASEDIR}/${FPATH}
2826 rm newfiles killfiles
2829 # Install new files, delete old files, and update linker.hints
2831 # If we haven't already dealt with the kernel, deal with it.
2832 if ! [ -f $1/kerneldone ]; then
2833 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2834 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2836 # Backup current kernel before installing a new one
2837 backup_kernel || return 1
2840 install_from_index INDEX-NEW || return 1
2842 # Remove files which need to be deleted
2843 install_delete INDEX-OLD INDEX-NEW || return 1
2845 # Update linker.hints if necessary
2846 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2847 kldxref -R ${BASEDIR}/boot/ 2>/dev/null
2850 # We've finished updating the kernel.
2853 # Do we need to ask for a reboot now?
2854 if [ -f $1/kernelfirst ] &&
2855 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2858 Kernel updates have been installed. Please reboot and run
2859 "$0 install" again to finish installing updates.
2865 # If we haven't already dealt with the world, deal with it.
2866 if ! [ -f $1/worlddone ]; then
2867 # Create any necessary directories first
2868 grep -vE '^/boot/' $1/INDEX-NEW |
2869 grep -E '^[^|]+\|d\|' > INDEX-NEW
2870 install_from_index INDEX-NEW || return 1
2872 # Install new runtime linker
2873 grep -vE '^/boot/' $1/INDEX-NEW |
2874 grep -vE '^[^|]+\|d\|' |
2875 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2876 install_from_index INDEX-NEW || return 1
2878 # Install new shared libraries next
2879 grep -vE '^/boot/' $1/INDEX-NEW |
2880 grep -vE '^[^|]+\|d\|' |
2881 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2882 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2883 install_from_index INDEX-NEW || return 1
2885 # Deal with everything else
2886 grep -vE '^/boot/' $1/INDEX-OLD |
2887 grep -vE '^[^|]+\|d\|' |
2888 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2889 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2890 grep -vE '^/boot/' $1/INDEX-NEW |
2891 grep -vE '^[^|]+\|d\|' |
2892 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2893 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2894 install_from_index INDEX-NEW || return 1
2895 install_delete INDEX-OLD INDEX-NEW || return 1
2897 # Rebuild /etc/spwd.db and /etc/pwd.db if necessary.
2898 if [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/spwd.db ] ||
2899 [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/pwd.db ]; then
2900 pwd_mkdb -d ${BASEDIR}/etc ${BASEDIR}/etc/master.passwd
2903 # Rebuild /etc/login.conf.db if necessary.
2904 if [ ${BASEDIR}/etc/login.conf -nt ${BASEDIR}/etc/login.conf.db ]; then
2905 cap_mkdb ${BASEDIR}/etc/login.conf
2908 # We've finished installing the world and deleting old files
2909 # which are not shared libraries.
2912 # Do we need to ask the user to portupgrade now?
2913 grep -vE '^/boot/' $1/INDEX-NEW |
2914 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2917 if grep -vE '^/boot/' $1/INDEX-OLD |
2918 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2921 join -v 1 - newfiles |
2925 Completing this upgrade requires removing old shared object files.
2926 Please rebuild all installed 3rd party software (e.g., programs
2927 installed from the ports tree) and then run "$0 install"
2928 again to finish installing updates.
2936 # Remove old shared libraries
2937 grep -vE '^/boot/' $1/INDEX-NEW |
2938 grep -vE '^[^|]+\|d\|' |
2939 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2940 grep -vE '^/boot/' $1/INDEX-OLD |
2941 grep -vE '^[^|]+\|d\|' |
2942 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2943 install_delete INDEX-OLD INDEX-NEW || return 1
2945 # Remove old directories
2946 grep -vE '^/boot/' $1/INDEX-NEW |
2947 grep -E '^[^|]+\|d\|' > INDEX-NEW
2948 grep -vE '^/boot/' $1/INDEX-OLD |
2949 grep -E '^[^|]+\|d\|' > INDEX-OLD
2950 install_delete INDEX-OLD INDEX-NEW || return 1
2952 # Remove temporary files
2953 rm INDEX-OLD INDEX-NEW
2956 # Rearrange bits to allow the installed updates to be rolled back
2957 install_setup_rollback () {
2958 # Remove the "reboot after installing kernel", "kernel updated", and
2959 # "finished installing the world" flags if present -- they are
2960 # irrelevant when rolling back updates.
2961 if [ -f ${BDHASH}-install/kernelfirst ]; then
2962 rm ${BDHASH}-install/kernelfirst
2963 rm ${BDHASH}-install/kerneldone
2965 if [ -f ${BDHASH}-install/worlddone ]; then
2966 rm ${BDHASH}-install/worlddone
2969 if [ -L ${BDHASH}-rollback ]; then
2970 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
2973 mv ${BDHASH}-install ${BDHASH}-rollback
2976 # Actually install updates
2978 echo -n "Installing updates..."
2980 # Make sure we have all the files we should have
2981 install_verify ${BDHASH}-install/INDEX-OLD \
2982 ${BDHASH}-install/INDEX-NEW || return 1
2984 # Remove system immutable flag from files
2985 install_unschg ${BDHASH}-install/INDEX-OLD \
2986 ${BDHASH}-install/INDEX-NEW || return 1
2988 # Install new files, delete old files, and update linker.hints
2989 install_files ${BDHASH}-install || return 1
2991 # Rearrange bits to allow the installed updates to be rolled back
2992 install_setup_rollback
2997 # Rearrange bits to allow the previous set of updates to be rolled back next.
2998 rollback_setup_rollback () {
2999 if [ -L ${BDHASH}-rollback/rollback ]; then
3000 mv ${BDHASH}-rollback/rollback rollback-tmp
3001 rm -r ${BDHASH}-rollback/
3002 rm ${BDHASH}-rollback
3003 mv rollback-tmp ${BDHASH}-rollback
3005 rm -r ${BDHASH}-rollback/
3006 rm ${BDHASH}-rollback
3010 # Install old files, delete new files, and update linker.hints
3012 # Install old shared library files which don't have the same path as
3013 # a new shared library file.
3014 grep -vE '^/boot/' $1/INDEX-NEW |
3015 grep -E '/lib/.*\.so\.[0-9]+\|' |
3017 sort > INDEX-NEW.libs.flist
3018 grep -vE '^/boot/' $1/INDEX-OLD |
3019 grep -E '/lib/.*\.so\.[0-9]+\|' |
3020 sort -k 1,1 -t '|' - |
3021 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
3022 install_from_index INDEX-OLD || return 1
3024 # Deal with files which are neither kernel nor shared library
3025 grep -vE '^/boot/' $1/INDEX-OLD |
3026 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3027 grep -vE '^/boot/' $1/INDEX-NEW |
3028 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3029 install_from_index INDEX-OLD || return 1
3030 install_delete INDEX-NEW INDEX-OLD || return 1
3032 # Install any old shared library files which we didn't install above.
3033 grep -vE '^/boot/' $1/INDEX-OLD |
3034 grep -E '/lib/.*\.so\.[0-9]+\|' |
3035 sort -k 1,1 -t '|' - |
3036 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
3037 install_from_index INDEX-OLD || return 1
3039 # Delete unneeded shared library files
3040 grep -vE '^/boot/' $1/INDEX-OLD |
3041 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3042 grep -vE '^/boot/' $1/INDEX-NEW |
3043 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3044 install_delete INDEX-NEW INDEX-OLD || return 1
3046 # Deal with kernel files
3047 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
3048 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3049 install_from_index INDEX-OLD || return 1
3050 install_delete INDEX-NEW INDEX-OLD || return 1
3051 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3052 kldxref -R /boot/ 2>/dev/null
3055 # Remove temporary files
3056 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3059 # Actually rollback updates
3061 echo -n "Uninstalling updates..."
3063 # If there are updates waiting to be installed, remove them; we
3064 # want the user to re-run 'fetch' after rolling back updates.
3065 if [ -L ${BDHASH}-install ]; then
3066 rm -r ${BDHASH}-install/
3067 rm ${BDHASH}-install
3070 # Make sure we have all the files we should have
3071 install_verify ${BDHASH}-rollback/INDEX-NEW \
3072 ${BDHASH}-rollback/INDEX-OLD || return 1
3074 # Remove system immutable flag from files
3075 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3076 ${BDHASH}-rollback/INDEX-OLD || return 1
3078 # Install old files, delete new files, and update linker.hints
3079 rollback_files ${BDHASH}-rollback || return 1
3081 # Remove the rollback directory and the symlink pointing to it; and
3082 # rearrange bits to allow the previous set of updates to be rolled
3084 rollback_setup_rollback
3089 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3091 # Get all the lines which mismatch in something other than file
3092 # flags. We ignore file flags because sysinstall doesn't seem to
3093 # set them when it installs FreeBSD; warning about these adds a
3094 # very large amount of noise.
3095 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3096 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3097 cut -f 1-5,7-8 -d '|' $2 |
3098 comm -13 $1.noflags - |
3099 fgrep -v '|-|||||' |
3100 sort -k 1,1 -t '|' |
3101 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3103 # Ignore files which match IDSIGNOREPATHS.
3104 for X in ${IDSIGNOREPATHS}; do
3105 grep -E "^${X}" INDEX-NOTMATCHING
3108 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3109 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3111 # Go through the lines and print warnings.
3113 while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do
3114 # Warn about different object types.
3115 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3116 echo -n "${FPATH} is a "
3118 f) echo -n "regular file, "
3120 d) echo -n "directory, "
3122 L) echo -n "symlink, "
3125 echo -n "but should be a "
3127 f) echo -n "regular file."
3129 d) echo -n "directory."
3131 L) echo -n "symlink."
3136 # Skip other tests, since they don't make sense if
3137 # we're comparing different object types.
3141 # Warn about different owners.
3142 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3143 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3144 echo "but should be owned by user id ${OWNER}."
3147 # Warn about different groups.
3148 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3149 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3150 echo "but should be owned by group id ${GROUP}."
3153 # Warn about different permissions. We do not warn about
3154 # different permissions on symlinks, since some archivers
3155 # don't extract symlink permissions correctly and they are
3157 if ! [ "${PERM}" = "${P_PERM}" ] &&
3158 ! [ "${TYPE}" = "L" ]; then
3159 echo -n "${FPATH} has ${P_PERM} permissions, "
3160 echo "but should have ${PERM} permissions."
3163 # Warn about different file hashes / symlink destinations.
3164 if ! [ "${HASH}" = "${P_HASH}" ]; then
3165 if [ "${TYPE}" = "L" ]; then
3166 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3167 echo "but should be a symlink to ${HASH}."
3169 if [ "${TYPE}" = "f" ]; then
3170 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3171 echo "but should have SHA256 hash ${HASH}."
3175 # We don't warn about different hard links, since some
3176 # some archivers break hard links, and as long as the
3177 # underlying data is correct they really don't matter.
3178 done < INDEX-NOTMATCHING
3181 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3184 # Do the work involved in comparing the system to a "known good" index
3186 workdir_init || return 1
3188 # Prepare the mirror list.
3189 fetch_pick_server_init && fetch_pick_server
3191 # Try to fetch the public key until we run out of servers.
3192 while ! fetch_key; do
3193 fetch_pick_server || return 1
3196 # Try to fetch the metadata index signature ("tag") until we run
3197 # out of available servers; and sanity check the downloaded tag.
3198 while ! fetch_tag; do
3199 fetch_pick_server || return 1
3201 fetch_tagsanity || return 1
3203 # Fetch INDEX-OLD and INDEX-ALL.
3204 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3206 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3207 # the components we want and without anything marked as "Ignore".
3208 fetch_filter_metadata INDEX-OLD || return 1
3209 fetch_filter_metadata INDEX-ALL || return 1
3211 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3212 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3213 mv INDEX-ALL.tmp INDEX-ALL
3216 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3217 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3219 # Inspect the system and generate an INDEX-PRESENT file.
3220 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3222 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3224 IDS_compare INDEX-ALL INDEX-PRESENT
3227 #### Main functions -- call parameter-handling and core functions
3229 # Using the command line, configuration file, and defaults,
3230 # set all the parameters which are needed later.
3238 # Fetch command. Make sure that we're being called
3239 # interactively, then run fetch_check_params and fetch_run
3241 if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then
3242 echo -n "`basename $0` fetch should not "
3243 echo "be run non-interactively."
3244 echo "Run `basename $0` cron instead."
3252 # Cron command. Make sure the parameters are sensible; wait
3253 # rand(3600) seconds; then fetch updates. While fetching updates,
3254 # send output to a temporary file; only print that file if the
3258 sleep `jot -r 1 0 3600`
3260 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3261 if ! fetch_run >> ${TMPFILE} ||
3262 ! grep -q "No updates needed" ${TMPFILE} ||
3263 [ ${VERBOSELEVEL} = "debug" ]; then
3264 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3270 # Fetch files for upgrading to a new release.
3272 upgrade_check_params
3273 upgrade_run || exit 1
3276 # Install downloaded updates.
3278 install_check_params
3279 install_run || exit 1
3282 # Rollback most recently installed updates.
3284 rollback_check_params
3285 rollback_run || exit 1
3288 # Compare system against a "known good" index.
3296 # Make sure we find utilities from the base system
3297 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3299 # Set a pager if the user doesn't
3300 if [ -z "$PAGER" ]; then
3304 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3308 for COMMAND in ${COMMANDS}; do