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., 6.2-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
56 fetch -- Fetch updates from server
57 cron -- Sleep rand(3600) seconds, fetch updates, and send an
58 email if updates were found
59 upgrade -- Fetch upgrades to FreeBSD version specified via -r option
60 install -- Install downloaded updates or upgrades
61 rollback -- Uninstall most recently installed updates
62 IDS -- Compare the system against an index of "known good" files.
67 #### Configuration processing functions
70 # Configuration options are set in the following order of priority:
71 # 1. Command line options
72 # 2. Configuration file options
74 # In addition, certain options (e.g., IgnorePaths) can be specified multiple
75 # times and (as long as these are all in the same place, e.g., inside the
76 # configuration file) they will accumulate. Finally, because the path to the
77 # configuration file can be specified at the command line, the entire command
78 # line must be processed before we start reading the configuration file.
80 # Sound like a mess? It is. Here's how we handle this:
81 # 1. Initialize CONFFILE and all the options to "".
82 # 2. Process the command line. Throw an error if a non-accumulating option
84 # 3. If CONFFILE is "", set CONFFILE to /etc/freebsd-update.conf .
85 # 4. For all the configuration options X, set X_saved to X.
86 # 5. Initialize all the options to "".
87 # 6. Read CONFFILE line by line, parsing options.
88 # 7. For each configuration option X, set X to X_saved iff X_saved is not "".
89 # 8. Repeat steps 4-7, except setting options to their default values at (6).
91 CONFIGOPTIONS="KEYPRINT WORKDIR SERVERNAME MAILTO ALLOWADD ALLOWDELETE
92 KEEPMODIFIEDMETADATA COMPONENTS IGNOREPATHS UPDATEIFUNMODIFIED
93 BASEDIR VERBOSELEVEL TARGETRELEASE STRICTCOMPONENTS MERGECHANGES
94 IDSIGNOREPATHS BACKUPKERNEL BACKUPKERNELDIR BACKUPKERNELSYMBOLFILES"
96 # Set all the configuration options to "".
98 for X in ${CONFIGOPTIONS}; do
103 # For each configuration option X, set X_saved to X.
105 for X in ${CONFIGOPTIONS}; do
106 eval ${X}_saved=\$${X}
110 # For each configuration option X, set X to X_saved if X_saved is not "".
112 for X in ${CONFIGOPTIONS}; do
114 if ! [ -z "${_}" ]; then
115 eval ${X}=\$${X}_saved
120 # Set the trusted keyprint.
122 if [ -z ${KEYPRINT} ]; then
129 # Set the working directory.
131 if [ -z ${WORKDIR} ]; then
138 # Set the name of the server (pool) from which to fetch updates
139 config_ServerName () {
140 if [ -z ${SERVERNAME} ]; then
147 # Set the address to which 'cron' output will be mailed.
149 if [ -z ${MAILTO} ]; then
156 # Set whether FreeBSD Update is allowed to add files (or directories, or
157 # symlinks) which did not previously exist.
159 if [ -z ${ALLOWADD} ]; then
176 # Set whether FreeBSD Update is allowed to remove files/directories/symlinks.
177 config_AllowDelete () {
178 if [ -z ${ALLOWDELETE} ]; then
195 # Set whether FreeBSD Update should keep existing inode ownership,
196 # permissions, and flags, in the event that they have been modified locally
198 config_KeepModifiedMetadata () {
199 if [ -z ${KEEPMODIFIEDMETADATA} ]; then
202 KEEPMODIFIEDMETADATA=yes
205 KEEPMODIFIEDMETADATA=no
216 # Add to the list of components which should be kept updated.
217 config_Components () {
219 if [ "$C" = "src" ]; then
220 if [ -e /usr/src/COPYRIGHT ]; then
221 COMPONENTS="${COMPONENTS} ${C}"
223 echo "src component not installed, skipped"
226 COMPONENTS="${COMPONENTS} ${C}"
231 # Add to the list of paths under which updates will be ignored.
232 config_IgnorePaths () {
234 IGNOREPATHS="${IGNOREPATHS} ${C}"
238 # Add to the list of paths which IDS should ignore.
239 config_IDSIgnorePaths () {
241 IDSIGNOREPATHS="${IDSIGNOREPATHS} ${C}"
245 # Add to the list of paths within which updates will be performed only if the
246 # file on disk has not been modified locally.
247 config_UpdateIfUnmodified () {
249 UPDATEIFUNMODIFIED="${UPDATEIFUNMODIFIED} ${C}"
253 # Add to the list of paths within which updates to text files will be merged
254 # instead of overwritten.
255 config_MergeChanges () {
257 MERGECHANGES="${MERGECHANGES} ${C}"
261 # Work on a FreeBSD installation mounted under $1
263 if [ -z ${BASEDIR} ]; then
270 # When fetching upgrades, should we assume the user wants exactly the
271 # components listed in COMPONENTS, rather than trying to guess based on
272 # what's currently installed?
273 config_StrictComponents () {
274 if [ -z ${STRICTCOMPONENTS} ]; then
291 # Upgrade to FreeBSD $1
292 config_TargetRelease () {
293 if [ -z ${TARGETRELEASE} ]; then
298 if echo ${TARGETRELEASE} | grep -qE '^[0-9.]+$'; then
299 TARGETRELEASE="${TARGETRELEASE}-RELEASE"
303 # Define what happens to output of utilities
304 config_VerboseLevel () {
305 if [ -z ${VERBOSELEVEL} ]; then
307 [Dd][Ee][Bb][Uu][Gg])
310 [Nn][Oo][Ss][Tt][Aa][Tt][Ss])
313 [Ss][Tt][Aa][Tt][Ss])
325 config_BackupKernel () {
326 if [ -z ${BACKUPKERNEL} ]; then
343 config_BackupKernelDir () {
344 if [ -z ${BACKUPKERNELDIR} ]; then
346 echo "BackupKernelDir set to empty dir"
350 # We check for some paths which would be extremely odd
351 # to use, but which could cause a lot of problems if
354 /|/bin|/boot|/etc|/lib|/libexec|/sbin|/usr|/var)
355 echo "BackupKernelDir set to invalid path $1"
362 echo "BackupKernelDir ($1) is not an absolute path"
371 config_BackupKernelSymbolFiles () {
372 if [ -z ${BACKUPKERNELSYMBOLFILES} ]; then
375 BACKUPKERNELSYMBOLFILES=yes
378 BACKUPKERNELSYMBOLFILES=no
389 # Handle one line of configuration
391 if [ $# -eq 0 ]; then
400 #### Parameter handling functions.
402 # Initialize parameters to null, just in case they're
403 # set in the environment.
405 # Configration settings
408 # No configuration file set yet
411 # No commands specified yet
414 # Force fetch to proceed
421 # Parse the command line
423 while [ $# -gt 0 ]; do
425 # Location of configuration file
427 if [ $# -eq 1 ]; then usage; fi
428 if [ ! -z "${CONFFILE}" ]; then usage; fi
434 --not-running-from-cron)
438 # Configuration file equivalents
440 if [ $# -eq 1 ]; then usage; fi; shift
441 config_BaseDir $1 || usage
444 if [ $# -eq 1 ]; then usage; fi; shift
445 config_WorkDir $1 || usage
448 if [ $# -eq 1 ]; then usage; fi; shift
449 config_KeyPrint $1 || usage
452 if [ $# -eq 1 ]; then usage; fi; shift
453 config_ServerName $1 || usage
456 if [ $# -eq 1 ]; then usage; fi; shift
457 config_TargetRelease $1 || usage
460 if [ $# -eq 1 ]; then usage; fi; shift
461 config_MailTo $1 || usage
464 if [ $# -eq 1 ]; then usage; fi; shift
465 config_VerboseLevel $1 || usage
468 # Aliases for "-v debug" and "-v nostats"
470 config_VerboseLevel debug || usage
473 config_VerboseLevel nostats || usage
477 cron | fetch | upgrade | install | rollback | IDS)
478 COMMANDS="${COMMANDS} $1"
481 # Anything else is an error
489 # Make sure we have at least one command
490 if [ -z "${COMMANDS}" ]; then
495 # Parse the configuration file
497 # If a configuration file was specified on the command line, check
498 # that it exists and is readable.
499 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
500 echo -n "File does not exist "
501 echo -n "or is not readable: "
506 # If a configuration file was not specified on the command line,
507 # use the default configuration file path. If that default does
508 # not exist, give up looking for any configuration.
509 if [ -z "${CONFFILE}" ]; then
510 CONFFILE="/etc/freebsd-update.conf"
511 if [ ! -r "${CONFFILE}" ]; then
516 # Save the configuration options specified on the command line, and
517 # clear all the options in preparation for reading the config file.
521 # Read the configuration file. Anything after the first '#' is
522 # ignored, and any blank lines are ignored.
526 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
527 if ! configline ${LINEX}; then
528 echo "Error processing configuration file, line $L:"
534 # Merge the settings read from the configuration file with those
535 # provided at the command line.
539 # Provide some default parameters
541 # Save any parameters already configured, and clear the slate
545 # Default configurations
546 config_WorkDir /var/db/freebsd-update
549 config_AllowDelete yes
550 config_KeepModifiedMetadata yes
552 config_VerboseLevel stats
553 config_StrictComponents no
554 config_BackupKernel yes
555 config_BackupKernelDir /boot/kernel.old
556 config_BackupKernelSymbolFiles no
558 # Merge these defaults into the earlier-configured settings
562 # Set utility output filtering options, based on ${VERBOSELEVEL}
563 fetch_setup_verboselevel () {
564 case ${VERBOSELEVEL} in
566 QUIETREDIR="/dev/stderr"
568 STATSREDIR="/dev/stderr"
576 STATSREDIR="/dev/null"
582 QUIETREDIR="/dev/null"
584 STATSREDIR="/dev/stdout"
592 # Perform sanity checks and set some final parameters
593 # in preparation for fetching files. Figure out which
594 # set of updates should be downloaded: If the user is
595 # running *-p[0-9]+, strip off the last part; if the
596 # user is running -SECURITY, call it -RELEASE. Chdir
597 # into the working directory.
598 fetchupgrade_check_params () {
599 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
602 "SERVERNAME must be given via command line or configuration file."
603 _KEYPRINT_z="Key must be given via -k option or configuration file."
604 _KEYPRINT_bad="Invalid key fingerprint: "
605 _WORKDIR_bad="Directory does not exist or is not writable: "
606 _WORKDIR_bad2="Directory is not on a persistent filesystem: "
608 if [ -z "${SERVERNAME}" ]; then
609 echo -n "`basename $0`: "
610 echo "${_SERVERNAME_z}"
613 if [ -z "${KEYPRINT}" ]; then
614 echo -n "`basename $0`: "
615 echo "${_KEYPRINT_z}"
618 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
619 echo -n "`basename $0`: "
620 echo -n "${_KEYPRINT_bad}"
624 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
625 echo -n "`basename $0`: "
626 echo -n "${_WORKDIR_bad}"
630 case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*)
631 echo -n "`basename $0`: "
632 echo -n "${_WORKDIR_bad2}"
638 cd ${WORKDIR} || exit 1
640 # Generate release number. The s/SECURITY/RELEASE/ bit exists
641 # to provide an upgrade path for FreeBSD Update 1.x users, since
642 # the kernels provided by FreeBSD Update 1.x are always labelled
645 sed -E 's,-p[0-9]+,,' |
646 sed -E 's,-SECURITY,-RELEASE,'`
648 FETCHDIR=${RELNUM}/${ARCH}
649 PATCHDIR=${RELNUM}/${ARCH}/bp
651 # Figure out what directory contains the running kernel
652 BOOTFILE=`sysctl -n kern.bootfile`
653 KERNELDIR=${BOOTFILE%/kernel}
654 if ! [ -d ${KERNELDIR} ]; then
655 echo "Cannot identify running kernel"
659 # Figure out what kernel configuration is running. We start with
660 # the output of `uname -i`, and then make the following adjustments:
661 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
662 # file says "ident SMP-GENERIC", I don't know...
663 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
664 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
665 # we're running an SMP kernel. This mis-identification is a bug
666 # which was fixed in 6.2-STABLE.
668 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
671 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
672 if sysctl kern.version | grep -qE '/SMP$'; then
678 BSPATCH=/usr/bin/bspatch
680 PHTTPGET=/usr/libexec/phttpget
682 # Set up variables relating to VERBOSELEVEL
683 fetch_setup_verboselevel
685 # Construct a unique name from ${BASEDIR}
686 BDHASH=`echo ${BASEDIR} | sha256 -q`
689 # Perform sanity checks etc. before fetching updates.
690 fetch_check_params () {
691 fetchupgrade_check_params
693 if ! [ -z "${TARGETRELEASE}" ]; then
694 echo -n "`basename $0`: "
695 echo -n "-r option is meaningless with 'fetch' command. "
696 echo "(Did you mean 'upgrade' instead?)"
700 # Check that we have updates ready to install
701 if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then
702 echo "You have a partially completed upgrade pending"
703 echo "Run '$0 install' first."
704 echo "Run '$0 fetch -F' to proceed anyway."
709 # Perform sanity checks etc. before fetching upgrades.
710 upgrade_check_params () {
711 fetchupgrade_check_params
713 # Unless set otherwise, we're upgrading to the same kernel config.
714 NKERNCONF=${KERNCONF}
716 # We need TARGETRELEASE set
717 _TARGETRELEASE_z="Release target must be specified via -r option."
718 if [ -z "${TARGETRELEASE}" ]; then
719 echo -n "`basename $0`: "
720 echo "${_TARGETRELEASE_z}"
724 # The target release should be != the current release.
725 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
726 echo -n "`basename $0`: "
727 echo "Cannot upgrade from ${RELNUM} to itself"
731 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
732 if [ "${ALLOWADD}" = "no" ]; then
733 echo -n "`basename $0`: "
734 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
735 echo "when upgrading between releases."
738 if [ "${ALLOWDELETE}" = "no" ]; then
739 echo -n "`basename $0`: "
740 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
741 echo "when upgrading between releases."
745 # Set EDITOR to /usr/bin/vi if it isn't already set
746 : ${EDITOR:='/usr/bin/vi'}
749 # Perform sanity checks and set some final parameters in
750 # preparation for installing updates.
751 install_check_params () {
752 # Check that we are root. All sorts of things won't work otherwise.
753 if [ `id -u` != 0 ]; then
754 echo "You must be root to run this."
758 # Check that securelevel <= 0. Otherwise we can't update schg files.
759 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
760 echo "Updates cannot be installed when the system securelevel"
761 echo "is greater than zero."
765 # Check that we have a working directory
766 _WORKDIR_bad="Directory does not exist or is not writable: "
767 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
768 echo -n "`basename $0`: "
769 echo -n "${_WORKDIR_bad}"
773 cd ${WORKDIR} || exit 1
775 # Construct a unique name from ${BASEDIR}
776 BDHASH=`echo ${BASEDIR} | sha256 -q`
778 # Check that we have updates ready to install
779 if ! [ -L ${BDHASH}-install ]; then
780 echo "No updates are available to install."
781 echo "Run '$0 fetch' first."
784 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
785 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
786 echo "Update manifest is corrupt -- this should never happen."
787 echo "Re-run '$0 fetch'."
791 # Figure out what directory contains the running kernel
792 BOOTFILE=`sysctl -n kern.bootfile`
793 KERNELDIR=${BOOTFILE%/kernel}
794 if ! [ -d ${KERNELDIR} ]; then
795 echo "Cannot identify running kernel"
800 # Perform sanity checks and set some final parameters in
801 # preparation for UNinstalling updates.
802 rollback_check_params () {
803 # Check that we are root. All sorts of things won't work otherwise.
804 if [ `id -u` != 0 ]; then
805 echo "You must be root to run this."
809 # Check that we have a working directory
810 _WORKDIR_bad="Directory does not exist or is not writable: "
811 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
812 echo -n "`basename $0`: "
813 echo -n "${_WORKDIR_bad}"
817 cd ${WORKDIR} || exit 1
819 # Construct a unique name from ${BASEDIR}
820 BDHASH=`echo ${BASEDIR} | sha256 -q`
822 # Check that we have updates ready to rollback
823 if ! [ -L ${BDHASH}-rollback ]; then
824 echo "No rollback directory found."
827 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
828 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
829 echo "Update manifest is corrupt -- this should never happen."
834 # Perform sanity checks and set some final parameters
835 # in preparation for comparing the system against the
836 # published index. Figure out which index we should
837 # compare against: If the user is running *-p[0-9]+,
838 # strip off the last part; if the user is running
839 # -SECURITY, call it -RELEASE. Chdir into the working
841 IDS_check_params () {
842 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
845 "SERVERNAME must be given via command line or configuration file."
846 _KEYPRINT_z="Key must be given via -k option or configuration file."
847 _KEYPRINT_bad="Invalid key fingerprint: "
848 _WORKDIR_bad="Directory does not exist or is not writable: "
850 if [ -z "${SERVERNAME}" ]; then
851 echo -n "`basename $0`: "
852 echo "${_SERVERNAME_z}"
855 if [ -z "${KEYPRINT}" ]; then
856 echo -n "`basename $0`: "
857 echo "${_KEYPRINT_z}"
860 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
861 echo -n "`basename $0`: "
862 echo -n "${_KEYPRINT_bad}"
866 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
867 echo -n "`basename $0`: "
868 echo -n "${_WORKDIR_bad}"
872 cd ${WORKDIR} || exit 1
874 # Generate release number. The s/SECURITY/RELEASE/ bit exists
875 # to provide an upgrade path for FreeBSD Update 1.x users, since
876 # the kernels provided by FreeBSD Update 1.x are always labelled
879 sed -E 's,-p[0-9]+,,' |
880 sed -E 's,-SECURITY,-RELEASE,'`
882 FETCHDIR=${RELNUM}/${ARCH}
883 PATCHDIR=${RELNUM}/${ARCH}/bp
885 # Figure out what directory contains the running kernel
886 BOOTFILE=`sysctl -n kern.bootfile`
887 KERNELDIR=${BOOTFILE%/kernel}
888 if ! [ -d ${KERNELDIR} ]; then
889 echo "Cannot identify running kernel"
893 # Figure out what kernel configuration is running. We start with
894 # the output of `uname -i`, and then make the following adjustments:
895 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
896 # file says "ident SMP-GENERIC", I don't know...
897 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
898 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
899 # we're running an SMP kernel. This mis-identification is a bug
900 # which was fixed in 6.2-STABLE.
902 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
905 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
906 if sysctl kern.version | grep -qE '/SMP$'; then
913 PHTTPGET=/usr/libexec/phttpget
915 # Set up variables relating to VERBOSELEVEL
916 fetch_setup_verboselevel
919 #### Core functionality -- the actual work gets done here
921 # Use an SRV query to pick a server. If the SRV query doesn't provide
922 # a useful answer, use the server name specified by the user.
923 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
924 # from that; or if no servers are returned, use ${SERVERNAME}.
925 # This allows a user to specify "portsnap.freebsd.org" (in which case
926 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
927 # (in which case portsnap will use that particular server, since there
928 # won't be an SRV entry for that name).
930 # We ignore the Port field, since we are always going to use port 80.
932 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
933 # no mirrors are available for any reason.
934 fetch_pick_server_init () {
937 # Check that host(1) exists (i.e., that the system wasn't built with the
938 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
939 if ! which -s host; then
944 echo -n "Looking up ${SERVERNAME} mirrors... "
946 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
947 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
948 # "$name server selection ..."; we allow either format.
949 MLIST="_http._tcp.${SERVERNAME}"
950 host -t srv "${MLIST}" |
951 sed -nE "s/${MLIST} (has SRV record|server selection) //p" |
952 cut -f 1,2,4 -d ' ' |
954 sort > serverlist_full
956 # If no records, give up -- we'll just use the server name we were given.
957 if [ `wc -l < serverlist_full` -eq 0 ]; then
962 # Report how many mirrors we found.
963 echo `wc -l < serverlist_full` "mirrors found."
965 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
966 # is set, this will be used to generate the seed; otherwise, the seed
968 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
969 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
973 RANDVALUE=`jot -r 1 0 999999999`
977 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
978 fetch_pick_server () {
979 # Generate a list of not-yet-tried mirrors
980 sort serverlist_tried |
981 comm -23 serverlist_full - > serverlist
983 # Have we run out of mirrors?
984 if [ `wc -l < serverlist` -eq 0 ]; then
985 echo "No mirrors remaining, giving up."
989 # Find the highest priority level (lowest numeric value).
990 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
992 # Add up the weights of the response lines at that priority level.
997 SRV_W=`echo $X | cut -f 2 -d ' '`
998 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
1003 # If all the weights are 0, pretend that they are all 1 instead.
1004 if [ ${SRV_WSUM} -eq 0 ]; then
1005 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
1011 # Pick a value between 0 and the sum of the weights - 1
1012 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
1014 # Read through the list of mirrors and set SERVERNAME. Write the line
1015 # corresponding to the mirror we selected into serverlist_tried so that
1016 # we won't try it again.
1020 SRV_W=`echo $X | cut -f 2 -d ' '`
1021 SRV_W=$(($SRV_W + $SRV_W_ADD))
1022 if [ $SRV_RND -lt $SRV_W ]; then
1023 SERVERNAME=`echo $X | cut -f 3 -d ' '`
1024 echo "$X" >> serverlist_tried
1027 SRV_RND=$(($SRV_RND - $SRV_W))
1034 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
1035 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
1036 fetch_make_patchlist () {
1037 grep -vE "^([0-9a-f]{64})\|\1$" |
1040 if [ -f "files/${Y}.gz" ] ||
1041 [ ! -f "files/${X}.gz" ]; then
1048 # Print user-friendly progress statistics
1053 if [ $(($LNC % 10)) = 0 ]; then
1055 elif [ $(($LNC % 2)) = 0 ]; then
1062 # Function for asking the user if everything is ok
1064 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1065 case "${CONTINUE}" in
1076 # Initialize the working directory
1079 touch tINDEX.present
1082 # Check that we have a public key with an appropriate hash, or
1083 # fetch the key if it doesn't exist. Returns 1 if the key has
1084 # not yet been fetched.
1086 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1090 echo -n "Fetching public key from ${SERVERNAME}... "
1092 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1093 2>${QUIETREDIR} || true
1094 if ! [ -r pub.ssl ]; then
1098 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1099 echo "key has incorrect hash."
1106 # Fetch metadata signature, aka "tag".
1108 echo -n "Fetching metadata signature "
1109 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1111 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1112 2>${QUIETREDIR} || true
1113 if ! [ -r latest.ssl ]; then
1118 openssl rsautl -pubin -inkey pub.ssl -verify \
1119 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1122 if ! [ `wc -l < tag.new` = 1 ] ||
1124 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1126 echo "invalid signature."
1132 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1133 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1134 EOLTIME=`cut -f 6 -d '|' < tag.new`
1137 # Sanity-check the patch number in a tag, to make sure that we're not
1138 # going to "update" backwards and to prevent replay attacks.
1139 fetch_tagsanity () {
1140 # Check that we're not going to move from -pX to -pY with Y < X.
1141 RELPX=`uname -r | sed -E 's,.*-,,'`
1142 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1143 RELPX=`echo ${RELPX} | cut -c 2-`
1147 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1149 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1150 echo " appear older than what"
1151 echo "we are currently running (`uname -r`)!"
1152 echo "Cowardly refusing to proceed any further."
1156 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1157 # it contains a patch number <= RELPATCHNUM, in order to protect
1158 # against rollback (replay) attacks.
1161 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1163 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1165 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1167 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1168 echo " are older than the"
1169 echo -n "most recently seen updates"
1170 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1171 echo "Cowardly refusing to proceed any further."
1177 # Fetch metadata index file
1178 fetch_metadata_index () {
1179 echo ${NDEBUG} "Fetching metadata index... "
1181 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1183 if ! [ -f ${TINDEXHASH} ]; then
1187 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1188 echo "update metadata index corrupt."
1194 # Print an error message about signed metadata being bogus.
1195 fetch_metadata_bogus () {
1197 echo "The update metadata$1 is correctly signed, but"
1198 echo "failed an integrity check."
1199 echo "Cowardly refusing to proceed any further."
1203 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1204 # with the lines not named in $@ from tINDEX.present (if that file exists).
1205 fetch_metadata_index_merge () {
1206 for METAFILE in $@; do
1207 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1209 fetch_metadata_bogus " index"
1213 grep -E "${METAFILE}\|" ${TINDEXHASH}
1215 sort > tINDEX.wanted
1217 if [ -f tINDEX.present ]; then
1218 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1219 sort -m - tINDEX.wanted > tINDEX.new
1222 mv tINDEX.wanted tINDEX.new
1226 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1227 # are added by future versions of the server, this won't cause problems,
1228 # since the only lines which appear in tINDEX.new are the ones which we
1229 # specifically grepped out of ${TINDEXHASH}.
1230 fetch_metadata_index_sanity () {
1231 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1232 fetch_metadata_bogus " index"
1237 # Sanity check the metadata file $1.
1238 fetch_metadata_sanity () {
1239 # Some aliases to save space later: ${P} is a character which can
1240 # appear in a path; ${M} is the four numeric metadata fields; and
1241 # ${H} is a sha256 hash.
1242 P="[-+./:=,%@_[~[:alnum:]]"
1243 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1246 # Check that the first four fields make sense.
1247 if gunzip -c < files/$1.gz |
1248 grep -qvE "^[a-z]+\|[0-9a-z]+\|${P}+\|[fdL-]\|"; then
1249 fetch_metadata_bogus ""
1253 # Remove the first three fields.
1254 gunzip -c < files/$1.gz |
1255 cut -f 4- -d '|' > sanitycheck.tmp
1257 # Sanity check entries with type 'f'
1258 if grep -E '^f' sanitycheck.tmp |
1259 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1260 fetch_metadata_bogus ""
1264 # Sanity check entries with type 'd'
1265 if grep -E '^d' sanitycheck.tmp |
1266 grep -qvE "^d\|${M}\|\|\$"; then
1267 fetch_metadata_bogus ""
1271 # Sanity check entries with type 'L'
1272 if grep -E '^L' sanitycheck.tmp |
1273 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1274 fetch_metadata_bogus ""
1278 # Sanity check entries with type '-'
1279 if grep -E '^-' sanitycheck.tmp |
1280 grep -qvE "^-\|\|\|\|\|\|"; then
1281 fetch_metadata_bogus ""
1289 # Fetch the metadata index and metadata files listed in $@,
1290 # taking advantage of metadata patches where possible.
1292 fetch_metadata_index || return 1
1293 fetch_metadata_index_merge $@ || return 1
1294 fetch_metadata_index_sanity || return 1
1296 # Generate a list of wanted metadata patches
1297 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1298 fetch_make_patchlist > patchlist
1300 if [ -s patchlist ]; then
1301 # Attempt to fetch metadata patches
1302 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1303 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1304 tr '|' '-' < patchlist |
1305 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1306 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1307 2>${STATSREDIR} | fetch_progress
1310 # Attempt to apply metadata patches
1311 echo -n "Applying metadata patches... "
1312 tr '|' ' ' < patchlist |
1314 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1315 gunzip -c < ${X}-${Y}.gz > diff
1316 gunzip -c < files/${X}.gz > diff-OLD
1318 # Figure out which lines are being added and removed
1321 while read PREFIX; do
1322 look "${PREFIX}" diff-OLD
1325 grep -E '^\+' diff |
1326 cut -c 2- > diff-add
1328 # Generate the new file
1329 comm -23 diff-OLD diff-rm |
1330 sort - diff-add > diff-NEW
1332 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1333 mv diff-NEW files/${Y}
1336 mv diff-NEW ${Y}.bad
1338 rm -f ${X}-${Y}.gz diff
1339 rm -f diff-OLD diff-NEW diff-add diff-rm
1340 done 2>${QUIETREDIR}
1344 # Update metadata without patches
1345 cut -f 2 -d '|' < tINDEX.new |
1347 if [ ! -f "files/${Y}.gz" ]; then
1353 if [ -s filelist ]; then
1354 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1355 echo ${NDEBUG} "metadata files... "
1356 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1357 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1361 if ! [ -f ${Y}.gz ]; then
1365 if [ `gunzip -c < ${Y}.gz |
1366 ${SHA256} -q` = ${Y} ]; then
1367 mv ${Y}.gz files/${Y}.gz
1369 echo "metadata is corrupt."
1376 # Sanity-check the metadata files.
1377 cut -f 2 -d '|' tINDEX.new > filelist
1379 fetch_metadata_sanity ${X} || return 1
1382 # Remove files which are no longer needed
1383 cut -f 2 -d '|' tINDEX.present |
1385 cut -f 2 -d '|' tINDEX.new |
1387 comm -13 - oldfiles |
1388 lam -s "files/" - -s ".gz" |
1390 rm patchlist filelist oldfiles
1394 mv tINDEX.new tINDEX.present
1400 # Extract a subset of a downloaded metadata file containing only the parts
1401 # which are listed in COMPONENTS.
1402 fetch_filter_metadata_components () {
1403 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1404 gunzip -c < files/${METAHASH}.gz > $1.all
1406 # Fish out the lines belonging to components we care about.
1407 for C in ${COMPONENTS}; do
1408 look "`echo ${C} | tr '/' '|'`|" $1.all
1411 # Remove temporary file.
1415 # Generate a filtered version of the metadata file $1 from the downloaded
1416 # file, by fishing out the lines corresponding to components we're trying
1417 # to keep updated, and then removing lines corresponding to paths we want
1419 fetch_filter_metadata () {
1420 # Fish out the lines belonging to components we care about.
1421 fetch_filter_metadata_components $1
1423 # Canonicalize directory names by removing any trailing / in
1424 # order to avoid listing directories multiple times if they
1425 # belong to multiple components. Turning "/" into "" doesn't
1426 # matter, since we add a leading "/" when we use paths later.
1427 cut -f 3- -d '|' $1 |
1428 sed -e 's,/|d|,|d|,' |
1429 sed -e 's,/|-|,|-|,' |
1432 # Figure out which lines to ignore and remove them.
1433 for X in ${IGNOREPATHS}; do
1434 grep -E "^${X}" $1.tmp
1437 comm -13 - $1.tmp > $1
1439 # Remove temporary files.
1443 # Filter the metadata file $1 by adding lines with "/boot/$2"
1444 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1445 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1446 # the original lines which start with that.
1447 # Put another way: Deal with the fact that the FOO kernel is sometimes
1448 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1449 fetch_filter_kernel_names () {
1451 sed -e "s,/boot/$2,${KERNELDIR},g" |
1455 if ! [ -d /boot/$2 ]; then
1456 grep -v ^/boot/$2 $1 > $1.tmp
1461 # For all paths appearing in $1 or $3, inspect the system
1462 # and generate $2 describing what is currently installed.
1463 fetch_inspect_system () {
1467 # Tell the user why his disk is suddenly making lots of noise
1468 echo -n "Inspecting system... "
1470 # Generate list of files to inspect
1475 # Examine each file and output lines of the form
1476 # /path/to/file|type|device-inum|user|group|perm|flags|value
1477 # sorted by device and inode number.
1479 # If the symlink/file/directory does not exist, record this.
1480 if ! [ -e ${BASEDIR}/${F} ]; then
1484 if ! [ -r ${BASEDIR}/${F} ]; then
1485 echo "Cannot read file: ${BASEDIR}/${F}" \
1491 # Otherwise, output an index line.
1492 if [ -L ${BASEDIR}/${F} ]; then
1494 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1495 readlink ${BASEDIR}/${F};
1496 elif [ -f ${BASEDIR}/${F} ]; then
1498 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1499 sha256 -q ${BASEDIR}/${F};
1500 elif [ -d ${BASEDIR}/${F} ]; then
1502 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1504 echo "Unknown file type: ${BASEDIR}/${F}" \
1510 sort -k 3,3 -t '|' > $2.tmp
1513 # Check if an error occurred during system inspection
1514 if [ -f .err ]; then
1518 # Convert to the form
1519 # /path/to/file|type|user|group|perm|flags|value|hlink
1520 # by resolving identical device and inode numbers into hard links.
1521 cut -f 1,3 -d '|' $2.tmp |
1522 sort -k 1,1 -t '|' |
1523 sort -s -u -k 2,2 -t '|' |
1524 join -1 2 -2 3 -t '|' - $2.tmp |
1525 awk -F \| -v OFS=\| \
1527 if (($2 == $3) || ($4 == "-"))
1528 print $3,$4,$5,$6,$7,$8,$9,""
1530 print $3,$4,$5,$6,$7,$8,$9,$2
1535 # We're finished looking around
1539 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1540 # files which differ; generate $3 containing these paths and the old hashes.
1541 fetch_filter_mergechanges () {
1542 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1544 for X in ${MERGECHANGES}; do
1545 grep -E "^${X}" ${F}
1547 cut -f 1,2,7 -d '|' |
1551 # Any line in $2-values which doesn't appear in $1-values and is a
1552 # file means that we should list the path in $3.
1553 comm -13 $1-values $2-values |
1555 cut -f 1 -d '|' > $2-paths
1557 # For each path, pull out one (and only one!) entry from $1-values.
1558 # Note that we cannot distinguish which "old" version the user made
1559 # changes to; but hopefully any changes which occur due to security
1560 # updates will exist in both the "new" version and the version which
1561 # the user has installed, so the merging will still work.
1563 look "${X}|" $1-values |
1565 done < $2-paths > $3
1568 rm $1-values $2-values $2-paths
1571 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1572 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1573 # the paths are listed in $4. For entries in $2 marked "not present"
1574 # (aka. type -), remove lines from $[123] unless there is a corresponding
1576 fetch_filter_unmodified_notpresent () {
1577 # Figure out which lines of $1 and $3 correspond to bits which
1578 # should only be updated if they haven't changed, and fish out
1579 # the (path, type, value) tuples.
1580 # NOTE: We don't consider a file to be "modified" if it matches
1582 for X in ${UPDATEIFUNMODIFIED}; do
1586 cut -f 1,2,7 -d '|' |
1589 # Do the same for $2.
1590 for X in ${UPDATEIFUNMODIFIED}; do
1593 cut -f 1,2,7 -d '|' |
1596 # Any entry in $2-values which is not in $1-values corresponds to
1597 # a path which we need to remove from $1, $2, and $3, unless it
1598 # that path appears in $4.
1599 comm -13 $1-values $2-values |
1600 sort -t '|' -k 1,1 > mlines.tmp
1601 cut -f 1 -d '|' $4 |
1603 join -v 2 -t '|' - mlines.tmp |
1605 rm $1-values $2-values mlines.tmp
1607 # Any lines in $2 which are not in $1 AND are "not present" lines
1608 # also belong in mlines.
1610 cut -f 1,2,7 -d '|' |
1611 fgrep '|-|' >> mlines
1613 # Remove lines from $1, $2, and $3
1614 for X in $1 $2 $3; do
1615 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1616 cut -f 1 -d '|' < mlines |
1618 join -v 2 -t '|' - ${X}.tmp |
1623 # Store a list of the modified files, for future reference
1624 fgrep -v '|-|' mlines |
1625 cut -f 1 -d '|' > modifiedfiles
1629 # For each entry in $1 of type -, remove any corresponding
1630 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1631 # of type - from $1.
1632 fetch_filter_allowadd () {
1633 cut -f 1,2 -d '|' < $1 |
1635 cut -f 1 -d '|' > filesnotpresent
1637 if [ ${ALLOWADD} != "yes" ]; then
1639 join -v 1 -t '|' - filesnotpresent |
1645 join -v 1 -t '|' - filesnotpresent |
1651 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1652 # which don't correspond to entries in $2.
1653 fetch_filter_allowdelete () {
1654 # Produce a lists ${PATH}|${TYPE}
1656 cut -f 1-2 -d '|' < ${X} |
1657 sort -u > ${X}.nodes
1660 # Figure out which lines need to be removed from $1.
1661 if [ ${ALLOWDELETE} != "yes" ]; then
1662 comm -23 $1.nodes $2.nodes > $1.badnodes
1667 # Remove the relevant lines from $1
1670 done < $1.badnodes |
1671 comm -13 - $1 > $1.tmp
1674 rm $1.badnodes $1.nodes $2.nodes
1677 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1678 # with metadata not matching any entry in $1, replace the corresponding
1679 # line of $3 with one having the same metadata as the entry in $2.
1680 fetch_filter_modified_metadata () {
1681 # Fish out the metadata from $1 and $2
1683 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1686 # Find the metadata we need to keep
1687 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1688 comm -13 $1.metadata $2.metadata > keepmeta
1693 # Extract the lines which we need to remove from $3, and
1694 # construct the lines which we need to add to $3.
1698 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1699 look "${NODE}|" $3 >> $3.remove
1700 look "${NODE}|" $3 |
1702 lam -s "${LINE}|" - >> $3.add
1705 # Remove the specified lines and add the new lines.
1708 sort -u - $3.add > $3.tmp
1711 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1714 # Remove lines from $1 and $2 which are identical;
1715 # no need to update a file if it isn't changing.
1716 fetch_filter_uptodate () {
1717 comm -23 $1 $2 > $1.tmp
1718 comm -13 $1 $2 > $2.tmp
1724 # Fetch any "clean" old versions of files we need for merging changes.
1725 fetch_files_premerge () {
1726 # We only need to do anything if $1 is non-empty.
1728 # Tell the user what we're doing
1729 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1731 # List of files wanted
1734 sort -u > files.wanted
1736 # Only fetch the files we don't already have
1738 if [ ! -f "files/${Y}.gz" ]; then
1741 done < files.wanted > filelist
1743 # Actually fetch them
1744 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1745 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1748 # Make sure we got them all, and move them into /files/
1750 if ! [ -f ${Y}.gz ]; then
1754 if [ `gunzip -c < ${Y}.gz |
1755 ${SHA256} -q` = ${Y} ]; then
1756 mv ${Y}.gz files/${Y}.gz
1758 echo "${Y} has incorrect hash."
1765 rm filelist files.wanted
1769 # Prepare to fetch files: Generate a list of the files we need,
1770 # copy the unmodified files we have into /files/, and generate
1771 # a list of patches to download.
1772 fetch_files_prepare () {
1773 # Tell the user why his disk is suddenly making lots of noise
1774 echo -n "Preparing to download files... "
1776 # Reduce indices to ${PATH}|${HASH} pairs
1777 for X in $1 $2 $3; do
1778 cut -f 1,2,7 -d '|' < ${X} |
1784 # List of files wanted
1785 cut -f 2 -d '|' < $3.hashes |
1788 if ! [ -f files/${HASH}.gz ]; then
1793 # Generate a list of unmodified files
1794 comm -12 $1.hashes $2.hashes |
1795 sort -k 1,1 -t '|' > unmodified.files
1797 # Copy all files into /files/. We only need the unmodified files
1798 # for use in patching; but we'll want all of them if the user asks
1799 # to rollback the updates later.
1801 F=`echo "${LINE}" | cut -f 1 -d '|'`
1802 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1804 # Skip files we already have.
1805 if [ -f files/${HASH}.gz ]; then
1809 # Make sure the file hasn't changed.
1810 cp "${BASEDIR}/${F}" tmpfile
1811 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1813 echo "File changed while FreeBSD Update running: ${F}"
1817 # Place the file into storage.
1818 gzip -c < tmpfile > files/${HASH}.gz
1822 # Produce a list of patches to download
1823 sort -k 1,1 -t '|' $3.hashes |
1824 join -t '|' -o 2.2,1.2 - unmodified.files |
1825 fetch_make_patchlist > patchlist
1828 rm unmodified.files $1.hashes $2.hashes $3.hashes
1830 # We don't need the list of possible old files any more.
1833 # We're finished making noise
1839 # Attempt to fetch patches
1840 if [ -s patchlist ]; then
1841 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1842 echo ${NDEBUG} "patches.${DDSTATS}"
1843 tr '|' '-' < patchlist |
1844 lam -s "${PATCHDIR}/" - |
1845 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1846 2>${STATSREDIR} | fetch_progress
1849 # Attempt to apply patches
1850 echo -n "Applying patches... "
1851 tr '|' ' ' < patchlist |
1853 if [ ! -f "${X}-${Y}" ]; then continue; fi
1854 gunzip -c < files/${X}.gz > OLD
1856 bspatch OLD NEW ${X}-${Y}
1858 if [ `${SHA256} -q NEW` = ${Y} ]; then
1862 rm -f diff OLD NEW ${X}-${Y}
1863 done 2>${QUIETREDIR}
1867 # Download files which couldn't be generate via patching
1869 if [ ! -f "files/${Y}.gz" ]; then
1872 done < files.wanted > filelist
1874 if [ -s filelist ]; then
1875 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1876 echo ${NDEBUG} "files... "
1877 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1878 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1882 if ! [ -f ${Y}.gz ]; then
1886 if [ `gunzip -c < ${Y}.gz |
1887 ${SHA256} -q` = ${Y} ]; then
1888 mv ${Y}.gz files/${Y}.gz
1890 echo "${Y} has incorrect hash."
1898 rm files.wanted filelist patchlist
1901 # Create and populate install manifest directory; and report what updates
1903 fetch_create_manifest () {
1904 # If we have an existing install manifest, nuke it.
1905 if [ -L "${BDHASH}-install" ]; then
1906 rm -r ${BDHASH}-install/
1907 rm ${BDHASH}-install
1910 # Report to the user if any updates were avoided due to local changes
1911 if [ -s modifiedfiles ]; then
1913 echo -n "The following files are affected by updates, "
1914 echo "but no changes have"
1915 echo -n "been downloaded because the files have been "
1916 echo "modified locally:"
1921 # If no files will be updated, tell the user and exit
1922 if ! [ -s INDEX-PRESENT ] &&
1923 ! [ -s INDEX-NEW ]; then
1924 rm INDEX-PRESENT INDEX-NEW
1926 echo -n "No updates needed to update system to "
1927 echo "${RELNUM}-p${RELPATCHNUM}."
1931 # Divide files into (a) removed files, (b) added files, and
1932 # (c) updated files.
1933 cut -f 1 -d '|' < INDEX-PRESENT |
1934 sort > INDEX-PRESENT.flist
1935 cut -f 1 -d '|' < INDEX-NEW |
1936 sort > INDEX-NEW.flist
1937 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1938 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
1939 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
1940 rm INDEX-PRESENT.flist INDEX-NEW.flist
1942 # Report removed files, if any
1943 if [ -s files.removed ]; then
1945 echo -n "The following files will be removed "
1946 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1951 # Report added files, if any
1952 if [ -s files.added ]; then
1954 echo -n "The following files will be added "
1955 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1960 # Report updated files, if any
1961 if [ -s files.updated ]; then
1963 echo -n "The following files will be updated "
1964 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1970 # Create a directory for the install manifest.
1971 MDIR=`mktemp -d install.XXXXXX` || return 1
1974 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
1975 mv INDEX-NEW ${MDIR}/INDEX-NEW
1977 # Link it into place
1978 ln -s ${MDIR} ${BDHASH}-install
1981 # Warn about any upcoming EoL
1983 # What's the current time?
1984 NOWTIME=`date "+%s"`
1986 # When did we last warn about the EoL date?
1987 if [ -f lasteolwarn ]; then
1988 LASTWARN=`cat lasteolwarn`
1990 LASTWARN=`expr ${NOWTIME} - 63072000`
1993 # If the EoL time is past, warn.
1994 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
1997 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
1998 Any security issues discovered after `date -r ${EOLTIME}`
1999 will not have been corrected.
2004 # Figure out how long it has been since we last warned about the
2005 # upcoming EoL, and how much longer we have left.
2006 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
2007 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
2009 # Don't warn if the EoL is more than 3 months away
2010 if [ ${TIMELEFT} -gt 7884000 ]; then
2014 # Don't warn if the time remaining is more than 3 times the time
2015 # since the last warning.
2016 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
2020 # Figure out what time units to use.
2021 if [ ${TIMELEFT} -lt 604800 ]; then
2024 elif [ ${TIMELEFT} -lt 2678400 ]; then
2032 # Compute the right number of units
2033 NUM=`expr ${TIMELEFT} / ${SIZE}`
2034 if [ ${NUM} != 1 ]; then
2041 WARNING: `uname -sr` is approaching its End-of-Life date.
2042 It is strongly recommended that you upgrade to a newer
2043 release within the next ${NUM} ${UNIT}.
2046 # Update the stored time of last warning
2047 echo ${NOWTIME} > lasteolwarn
2050 # Do the actual work involved in "fetch" / "cron".
2052 workdir_init || return 1
2054 # Prepare the mirror list.
2055 fetch_pick_server_init && fetch_pick_server
2057 # Try to fetch the public key until we run out of servers.
2058 while ! fetch_key; do
2059 fetch_pick_server || return 1
2062 # Try to fetch the metadata index signature ("tag") until we run
2063 # out of available servers; and sanity check the downloaded tag.
2064 while ! fetch_tag; do
2065 fetch_pick_server || return 1
2067 fetch_tagsanity || return 1
2069 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2070 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2072 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2073 # the lines which (a) belong to components we care about, and (b)
2074 # don't correspond to paths we're explicitly ignoring.
2075 fetch_filter_metadata INDEX-NEW || return 1
2076 fetch_filter_metadata INDEX-OLD || return 1
2078 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2079 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2080 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2082 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2083 # system and generate an INDEX-PRESENT file.
2084 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2086 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2087 # correspond to lines in INDEX-PRESENT with hashes not appearing
2088 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2089 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2090 # INDEX-OLD with type -.
2091 fetch_filter_unmodified_notpresent \
2092 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2094 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2095 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2096 # of type - from INDEX-PRESENT.
2097 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2099 # If ${ALLOWDELETE} != "yes", then remove any entries from
2100 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2101 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2103 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2104 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2105 # replace the corresponding line of INDEX-NEW with one having the
2106 # same metadata as the entry in INDEX-PRESENT.
2107 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2109 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2110 # no need to update a file if it isn't changing.
2111 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2113 # Prepare to fetch files: Generate a list of the files we need,
2114 # copy the unmodified files we have into /files/, and generate
2115 # a list of patches to download.
2116 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2119 fetch_files || return 1
2121 # Create and populate install manifest directory; and report what
2122 # updates are available.
2123 fetch_create_manifest || return 1
2125 # Warn about any upcoming EoL
2126 fetch_warn_eol || return 1
2129 # If StrictComponents is not "yes", generate a new components list
2130 # with only the components which appear to be installed.
2131 upgrade_guess_components () {
2132 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2133 # Generate filtered INDEX-ALL with only the components listed
2135 fetch_filter_metadata_components $1 || return 1
2137 # Tell the user why his disk is suddenly making lots of noise
2138 echo -n "Inspecting system... "
2140 # Look at the files on disk, and assume that a component is
2141 # supposed to be present if it is more than half-present.
2142 cut -f 1-3 -d '|' < INDEX-ALL |
2144 while read C S F; do
2145 if [ -e ${BASEDIR}/${F} ]; then
2152 sed -E 's,^ +,,' > compfreq
2153 grep ' = ' compfreq |
2155 sort -k 2,2 -t ' ' > compfreq.total
2156 grep ' + ' compfreq |
2158 sort -k 2,2 -t ' ' > compfreq.present
2159 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2160 while read S P T; do
2161 if [ ${P} -gt `expr ${T} / 2` ]; then
2165 cut -f 2 -d ' ' < compfreq.total > comp.total
2166 rm INDEX-ALL compfreq compfreq.total compfreq.present
2168 # We're done making noise.
2171 # Sometimes the kernel isn't installed where INDEX-ALL
2172 # thinks that it should be: In particular, it is often in
2173 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2174 # deal with this, if "kernel|X" is listed in comp.total
2175 # (i.e., is a component which would be upgraded if it is
2176 # found to be present) we will add it to comp.present.
2177 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2178 # not, we print a warning -- the user is running a kernel
2179 # which isn't part of the release.
2180 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2181 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2183 if grep -qE "^kernel\|" comp.total &&
2184 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2187 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2188 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2189 This kernel will not be updated: you MUST update the kernel manually
2190 before running "$0 install".
2194 # Re-sort the list of installed components and generate
2195 # the list of non-installed components.
2196 sort -u < comp.present > comp.present.tmp
2197 mv comp.present.tmp comp.present
2198 comm -13 comp.present comp.total > comp.absent
2200 # Ask the user to confirm that what we have is correct. To
2201 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2202 # subcomponents must be listed in the configuration file).
2204 echo -n "The following components of FreeBSD "
2205 echo "seem to be installed:"
2206 tr '|' '/' < comp.present |
2209 echo -n "The following components of FreeBSD "
2210 echo "do not seem to be installed:"
2211 tr '|' '/' < comp.absent |
2214 continuep || return 1
2217 # Suck the generated list of components into ${COMPONENTS}.
2218 # Note that comp.present.tmp is used due to issues with
2219 # pipelines and setting variables.
2221 tr '|' '/' < comp.present > comp.present.tmp
2223 COMPONENTS="${COMPONENTS} ${C}"
2224 done < comp.present.tmp
2226 # Delete temporary files
2227 rm comp.present comp.present.tmp comp.absent comp.total
2231 # If StrictComponents is not "yes", COMPONENTS contains an entry
2232 # corresponding to the currently running kernel, and said kernel
2233 # does not exist in the new release, add "kernel/generic" to the
2234 # list of components.
2235 upgrade_guess_new_kernel () {
2236 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2237 # Grab the unfiltered metadata file.
2238 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2239 gunzip -c < files/${METAHASH}.gz > $1.all
2241 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2242 # isn't in $1.all, we need to add kernel/generic.
2243 for C in ${COMPONENTS}; do
2244 if [ ${C} = "kernel/${KCOMP}" ] &&
2245 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2246 COMPONENTS="${COMPONENTS} kernel/generic"
2250 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2251 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2252 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2253 replaced with a "generic" kernel.
2255 continuep || return 1
2259 # Don't need this any more...
2264 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2265 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2266 upgrade_oldall_to_oldnew () {
2267 # For each ${F}|... which appears in INDEX-ALL but does not appear
2268 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2269 cut -f 1 -d '|' < $1 |
2271 cut -f 1 -d '|' < $2 |
2273 comm -13 $1.paths - |
2274 lam - -s "|-||||||" |
2278 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2279 comm -23 $1 $2 > $1.tmp
2282 # Remove lines from INDEX-ALL which have a file name not appearing
2283 # anywhere in INDEX-OLD (since these must be files which haven't
2284 # changed -- if they were new, there would be an entry of type "-").
2285 cut -f 1 -d '|' < $1 |
2287 sort -k 1,1 -t '|' < $2 |
2288 join -t '|' - $1.paths |
2293 # Rename INDEX-ALL to INDEX-NEW.
2297 # Helper for upgrade_merge: Return zero true iff the two files differ only
2298 # in the contents of their RCS tags.
2300 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2301 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2303 if [ $X = $Y ]; then
2310 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2311 # and update $3 to reflect the hashes of merged files.
2313 # We only need to do anything if $1 is non-empty.
2315 cut -f 1 -d '|' $1 |
2318 # Create staging area for merging files
2322 mkdir -p merge/old/${D}
2323 mkdir -p merge/${OLDRELNUM}/${D}
2324 mkdir -p merge/${RELNUM}/${D}
2325 mkdir -p merge/new/${D}
2330 # Currently installed file
2331 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2332 gunzip < files/${V}.gz > merge/old/${F}
2335 if look "${F}|" $1 | fgrep -q "|f|"; then
2336 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2337 gunzip < files/${V}.gz \
2338 > merge/${OLDRELNUM}/${F}
2342 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2343 fgrep -q "|f|"; then
2344 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2345 gunzip < files/${V}.gz \
2346 > merge/${RELNUM}/${F}
2350 # Attempt to automatically merge changes
2351 echo -n "Attempting to automatically merge "
2352 echo -n "changes in files..."
2355 # If the file doesn't exist in the new release,
2356 # the result of "merging changes" is having the file
2358 if ! [ -f merge/${RELNUM}/${F} ]; then
2362 # If the file didn't exist in the old release, we're
2363 # going to throw away the existing file and hope that
2364 # the version from the new release is what we want.
2365 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2366 cp merge/${RELNUM}/${F} merge/new/${F}
2370 # Some files need special treatment.
2372 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2373 # Don't merge these -- we're rebuild them
2374 # after updates are installed.
2375 cp merge/old/${F} merge/new/${F}
2378 if ! merge -p -L "current version" \
2379 -L "${OLDRELNUM}" -L "${RELNUM}" \
2381 merge/${OLDRELNUM}/${F} \
2382 merge/${RELNUM}/${F} \
2383 > merge/new/${F} 2>/dev/null; then
2384 echo ${F} >> failed.merges
2391 # Ask the user to handle any files which didn't merge.
2393 # If the installed file differs from the version in
2394 # the old release only due to RCS tag expansion
2395 # then just use the version in the new release.
2396 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2397 cp merge/${RELNUM}/${F} merge/new/${F}
2403 The following file could not be merged automatically: ${F}
2404 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2407 read dummy </dev/tty
2408 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2409 done < failed.merges
2412 # Ask the user to confirm that he likes how the result
2415 # Skip files which haven't changed except possibly
2416 # in their RCS tags.
2417 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2418 samef merge/old/${F} merge/new/${F}; then
2422 # Skip files where the installed file differs from
2423 # the old file only due to RCS tags.
2424 if [ -f merge/old/${F} ] &&
2425 [ -f merge/${OLDRELNUM}/${F} ] &&
2426 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2430 # Warn about files which are ceasing to exist.
2431 if ! [ -f merge/new/${F} ]; then
2434 The following file will be removed, as it no longer exists in
2435 FreeBSD ${RELNUM}: ${F}
2437 continuep < /dev/tty || return 1
2441 # Print changes for the user's approval.
2444 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2445 FreeBSD ${RELNUM} have been merged into ${F}:
2447 diff -U 5 -L "current version" -L "new version" \
2448 merge/old/${F} merge/new/${F} || true
2449 continuep < /dev/tty || return 1
2452 # Store merged files.
2454 if [ -f merge/new/${F} ]; then
2455 V=`${SHA256} -q merge/new/${F}`
2457 gzip -c < merge/new/${F} > files/${V}.gz
2460 done < $1-paths > newhashes
2462 # Pull lines out from $3 which need to be updated to
2463 # reflect merged files.
2466 done < $1-paths > $3-oldlines
2468 # Update lines to reflect merged files
2469 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2470 $3-oldlines newhashes > $3-newlines
2472 # Remove old lines from $3 and add new lines.
2475 sort - $3-newlines > $3.tmp
2479 rm $1-paths newhashes $3-oldlines $3-newlines
2483 # We're done with merging files.
2487 # Do the work involved in fetching upgrades to a new release
2489 workdir_init || return 1
2491 # Prepare the mirror list.
2492 fetch_pick_server_init && fetch_pick_server
2494 # Try to fetch the public key until we run out of servers.
2495 while ! fetch_key; do
2496 fetch_pick_server || return 1
2499 # Try to fetch the metadata index signature ("tag") until we run
2500 # out of available servers; and sanity check the downloaded tag.
2501 while ! fetch_tag; do
2502 fetch_pick_server || return 1
2504 fetch_tagsanity || return 1
2506 # Fetch the INDEX-OLD and INDEX-ALL.
2507 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2509 # If StrictComponents is not "yes", generate a new components list
2510 # with only the components which appear to be installed.
2511 upgrade_guess_components INDEX-ALL || return 1
2513 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2514 # the components we want and without anything marked as "Ignore".
2515 fetch_filter_metadata INDEX-OLD || return 1
2516 fetch_filter_metadata INDEX-ALL || return 1
2518 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2519 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2520 mv INDEX-OLD.tmp INDEX-OLD
2523 # Adjust variables for fetching files from the new release.
2525 RELNUM=${TARGETRELEASE}
2526 OLDFETCHDIR=${FETCHDIR}
2527 FETCHDIR=${RELNUM}/${ARCH}
2529 # Try to fetch the NEW metadata index signature ("tag") until we run
2530 # out of available servers; and sanity check the downloaded tag.
2531 while ! fetch_tag; do
2532 fetch_pick_server || return 1
2535 # Fetch the new INDEX-ALL.
2536 fetch_metadata INDEX-ALL || return 1
2538 # If StrictComponents is not "yes", COMPONENTS contains an entry
2539 # corresponding to the currently running kernel, and said kernel
2540 # does not exist in the new release, add "kernel/generic" to the
2541 # list of components.
2542 upgrade_guess_new_kernel INDEX-ALL || return 1
2544 # Filter INDEX-ALL to contain only the components we want and without
2545 # anything marked as "Ignore".
2546 fetch_filter_metadata INDEX-ALL || return 1
2548 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2549 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2550 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2552 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2553 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2554 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2556 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2557 # system and generate an INDEX-PRESENT file.
2558 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2560 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2561 # paths and hashes of old versions of files to merge.
2562 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2564 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2565 # correspond to lines in INDEX-PRESENT with hashes not appearing
2566 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2567 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2568 # INDEX-OLD with type -.
2569 fetch_filter_unmodified_notpresent \
2570 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2572 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2573 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2574 # of type - from INDEX-PRESENT.
2575 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2577 # If ${ALLOWDELETE} != "yes", then remove any entries from
2578 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2579 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2581 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2582 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2583 # replace the corresponding line of INDEX-NEW with one having the
2584 # same metadata as the entry in INDEX-PRESENT.
2585 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2587 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2588 # no need to update a file if it isn't changing.
2589 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2591 # Fetch "clean" files from the old release for merging changes.
2592 fetch_files_premerge tomerge-old
2594 # Prepare to fetch files: Generate a list of the files we need,
2595 # copy the unmodified files we have into /files/, and generate
2596 # a list of patches to download.
2597 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2599 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2600 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2601 fetch_files || return 1
2603 # Merge configuration file changes.
2604 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2606 # Create and populate install manifest directory; and report what
2607 # updates are available.
2608 fetch_create_manifest || return 1
2610 # Leave a note behind to tell the "install" command that the kernel
2611 # needs to be installed before the world.
2612 touch ${BDHASH}-install/kernelfirst
2614 # Remind the user that they need to run "freebsd-update install"
2615 # to install the downloaded bits, in case they didn't RTFM.
2616 echo "To install the downloaded upgrades, run \"$0 install\"."
2619 # Make sure that all the file hashes mentioned in $@ have corresponding
2620 # gzipped files stored in /files/.
2622 # Generate a list of hashes
2629 # Make sure all the hashes exist
2631 if ! [ -f files/${HASH}.gz ]; then
2632 echo -n "Update files missing -- "
2633 echo "this should never happen."
2634 echo "Re-run '$0 fetch'."
2643 # Remove the system immutable flag from files
2645 # Generate file list
2647 cut -f 1 -d '|' > filelist
2651 if ! [ -e ${BASEDIR}/${F} ]; then
2654 echo ${BASEDIR}/${F}
2656 done < filelist | xargs chflags noschg || return 1
2662 # Decide which directory name to use for kernel backups.
2663 backup_kernel_finddir () {
2666 # Pathname does not exist, so it is OK use that name
2667 # for backup directory.
2668 if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then
2672 # If directory do exist, we only use if it has our
2674 if [ -d $BASEDIR/$BACKUPKERNELDIR -a \
2675 -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then
2679 # We could not use current directory name, so add counter to
2680 # the end and try again.
2682 if [ $CNT -gt 9 ]; then
2683 echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)"
2686 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2687 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2691 # Backup the current kernel using hardlinks, if not disabled by user.
2692 # Since we delete all files in the directory used for previous backups
2693 # we create a marker file called ".freebsd-update" in the directory so
2694 # we can determine on the next run that the directory was created by
2695 # freebsd-update and we then do not accidentally remove user files in
2696 # the unlikely case that the user has created a directory with a
2699 # Only make kernel backup is so configured.
2700 if [ $BACKUPKERNEL != yes ]; then
2704 # Decide which directory name to use for kernel backups.
2705 backup_kernel_finddir
2707 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2708 # "not ours", backup_kernel_finddir would have exited, so
2709 # deleting the directory content is as safe as we can make it.
2710 if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then
2711 rm -fr $BASEDIR/$BACKUPKERNELDIR
2714 # Create directories for backup.
2715 mkdir -p $BASEDIR/$BACKUPKERNELDIR
2716 mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \
2717 mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null
2719 # Mark the directory as having been created by freebsd-update.
2720 touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update
2721 if [ $? -ne 0 ]; then
2722 echo "Could not create kernel backup directory"
2726 # Disable pathname expansion to be sure *.symbols is not
2730 # Use find to ignore symbol files, unless disabled by user.
2731 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2734 FINDFILTER=-"a ! -name *.symbols"
2737 # Backup all the kernel files using hardlinks.
2738 (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \
2739 cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;)
2741 # Re-enable patchname expansion.
2746 install_from_index () {
2747 # First pass: Do everything apart from setting file flags. We
2748 # can't set flags yet, because schg inhibits hard linking.
2749 sort -k 1,1 -t '|' $1 |
2751 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2754 # Create a directory
2755 install -d -o ${OWNER} -g ${GROUP} \
2756 -m ${PERM} ${BASEDIR}/${FPATH}
2759 if [ -z "${LINK}" ]; then
2760 # Create a file, without setting flags.
2761 gunzip < files/${HASH}.gz > ${HASH}
2762 install -S -o ${OWNER} -g ${GROUP} \
2763 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2766 # Create a hard link.
2767 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2772 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2777 # Perform a second pass, adding file flags.
2779 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2780 if [ ${TYPE} = "f" ] &&
2781 ! [ ${FLAGS} = "0" ]; then
2782 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2787 # Remove files which we want to delete
2789 # Generate list of new files
2790 cut -f 1 -d '|' < $2 |
2793 # Generate subindex of old files we want to nuke
2794 sort -k 1,1 -t '|' $1 |
2795 join -t '|' -v 1 - newfiles |
2796 sort -r -k 1,1 -t '|' |
2798 tr '|' ' ' > killfiles
2800 # Remove the offending bits
2801 while read FPATH TYPE; do
2804 rmdir ${BASEDIR}/${FPATH}
2807 rm ${BASEDIR}/${FPATH}
2810 rm ${BASEDIR}/${FPATH}
2816 rm newfiles killfiles
2819 # Install new files, delete old files, and update linker.hints
2821 # If we haven't already dealt with the kernel, deal with it.
2822 if ! [ -f $1/kerneldone ]; then
2823 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2824 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2826 # Backup current kernel before installing a new one
2827 backup_kernel || return 1
2830 install_from_index INDEX-NEW || return 1
2832 # Remove files which need to be deleted
2833 install_delete INDEX-OLD INDEX-NEW || return 1
2835 # Update linker.hints if necessary
2836 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2837 kldxref -R ${BASEDIR}/boot/ 2>/dev/null
2840 # We've finished updating the kernel.
2843 # Do we need to ask for a reboot now?
2844 if [ -f $1/kernelfirst ] &&
2845 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2848 Kernel updates have been installed. Please reboot and run
2849 "$0 install" again to finish installing updates.
2855 # If we haven't already dealt with the world, deal with it.
2856 if ! [ -f $1/worlddone ]; then
2857 # Create any necessary directories first
2858 grep -vE '^/boot/' $1/INDEX-NEW |
2859 grep -E '^[^|]+\|d\|' > INDEX-NEW
2860 install_from_index INDEX-NEW || return 1
2862 # Install new runtime linker
2863 grep -vE '^/boot/' $1/INDEX-NEW |
2864 grep -vE '^[^|]+\|d\|' |
2865 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2866 install_from_index INDEX-NEW || return 1
2868 # Install new shared libraries next
2869 grep -vE '^/boot/' $1/INDEX-NEW |
2870 grep -vE '^[^|]+\|d\|' |
2871 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2872 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2873 install_from_index INDEX-NEW || return 1
2875 # Deal with everything else
2876 grep -vE '^/boot/' $1/INDEX-OLD |
2877 grep -vE '^[^|]+\|d\|' |
2878 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2879 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2880 grep -vE '^/boot/' $1/INDEX-NEW |
2881 grep -vE '^[^|]+\|d\|' |
2882 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2883 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2884 install_from_index INDEX-NEW || return 1
2885 install_delete INDEX-OLD INDEX-NEW || return 1
2887 # Rebuild /etc/spwd.db and /etc/pwd.db if necessary.
2888 if [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/spwd.db ] ||
2889 [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/pwd.db ]; then
2890 pwd_mkdb -d ${BASEDIR}/etc ${BASEDIR}/etc/master.passwd
2893 # Rebuild /etc/login.conf.db if necessary.
2894 if [ ${BASEDIR}/etc/login.conf -nt ${BASEDIR}/etc/login.conf.db ]; then
2895 cap_mkdb ${BASEDIR}/etc/login.conf
2898 # We've finished installing the world and deleting old files
2899 # which are not shared libraries.
2902 # Do we need to ask the user to portupgrade now?
2903 grep -vE '^/boot/' $1/INDEX-NEW |
2904 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2907 if grep -vE '^/boot/' $1/INDEX-OLD |
2908 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2911 join -v 1 - newfiles |
2915 Completing this upgrade requires removing old shared object files.
2916 Please rebuild all installed 3rd party software (e.g., programs
2917 installed from the ports tree) and then run "$0 install"
2918 again to finish installing updates.
2926 # Remove old shared libraries
2927 grep -vE '^/boot/' $1/INDEX-NEW |
2928 grep -vE '^[^|]+\|d\|' |
2929 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2930 grep -vE '^/boot/' $1/INDEX-OLD |
2931 grep -vE '^[^|]+\|d\|' |
2932 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2933 install_delete INDEX-OLD INDEX-NEW || return 1
2935 # Remove old directories
2936 grep -vE '^/boot/' $1/INDEX-NEW |
2937 grep -E '^[^|]+\|d\|' > INDEX-NEW
2938 grep -vE '^/boot/' $1/INDEX-OLD |
2939 grep -E '^[^|]+\|d\|' > INDEX-OLD
2940 install_delete INDEX-OLD INDEX-NEW || return 1
2942 # Remove temporary files
2943 rm INDEX-OLD INDEX-NEW
2946 # Rearrange bits to allow the installed updates to be rolled back
2947 install_setup_rollback () {
2948 # Remove the "reboot after installing kernel", "kernel updated", and
2949 # "finished installing the world" flags if present -- they are
2950 # irrelevant when rolling back updates.
2951 if [ -f ${BDHASH}-install/kernelfirst ]; then
2952 rm ${BDHASH}-install/kernelfirst
2953 rm ${BDHASH}-install/kerneldone
2955 if [ -f ${BDHASH}-install/worlddone ]; then
2956 rm ${BDHASH}-install/worlddone
2959 if [ -L ${BDHASH}-rollback ]; then
2960 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
2963 mv ${BDHASH}-install ${BDHASH}-rollback
2966 # Actually install updates
2968 echo -n "Installing updates..."
2970 # Make sure we have all the files we should have
2971 install_verify ${BDHASH}-install/INDEX-OLD \
2972 ${BDHASH}-install/INDEX-NEW || return 1
2974 # Remove system immutable flag from files
2975 install_unschg ${BDHASH}-install/INDEX-OLD \
2976 ${BDHASH}-install/INDEX-NEW || return 1
2978 # Install new files, delete old files, and update linker.hints
2979 install_files ${BDHASH}-install || return 1
2981 # Rearrange bits to allow the installed updates to be rolled back
2982 install_setup_rollback
2987 # Rearrange bits to allow the previous set of updates to be rolled back next.
2988 rollback_setup_rollback () {
2989 if [ -L ${BDHASH}-rollback/rollback ]; then
2990 mv ${BDHASH}-rollback/rollback rollback-tmp
2991 rm -r ${BDHASH}-rollback/
2992 rm ${BDHASH}-rollback
2993 mv rollback-tmp ${BDHASH}-rollback
2995 rm -r ${BDHASH}-rollback/
2996 rm ${BDHASH}-rollback
3000 # Install old files, delete new files, and update linker.hints
3002 # Install old shared library files which don't have the same path as
3003 # a new shared library file.
3004 grep -vE '^/boot/' $1/INDEX-NEW |
3005 grep -E '/lib/.*\.so\.[0-9]+\|' |
3007 sort > INDEX-NEW.libs.flist
3008 grep -vE '^/boot/' $1/INDEX-OLD |
3009 grep -E '/lib/.*\.so\.[0-9]+\|' |
3010 sort -k 1,1 -t '|' - |
3011 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
3012 install_from_index INDEX-OLD || return 1
3014 # Deal with files which are neither kernel nor shared library
3015 grep -vE '^/boot/' $1/INDEX-OLD |
3016 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3017 grep -vE '^/boot/' $1/INDEX-NEW |
3018 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3019 install_from_index INDEX-OLD || return 1
3020 install_delete INDEX-NEW INDEX-OLD || return 1
3022 # Install any old shared library files which we didn't install above.
3023 grep -vE '^/boot/' $1/INDEX-OLD |
3024 grep -E '/lib/.*\.so\.[0-9]+\|' |
3025 sort -k 1,1 -t '|' - |
3026 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
3027 install_from_index INDEX-OLD || return 1
3029 # Delete unneeded shared library files
3030 grep -vE '^/boot/' $1/INDEX-OLD |
3031 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3032 grep -vE '^/boot/' $1/INDEX-NEW |
3033 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3034 install_delete INDEX-NEW INDEX-OLD || return 1
3036 # Deal with kernel files
3037 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
3038 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3039 install_from_index INDEX-OLD || return 1
3040 install_delete INDEX-NEW INDEX-OLD || return 1
3041 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3042 kldxref -R /boot/ 2>/dev/null
3045 # Remove temporary files
3046 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3049 # Actually rollback updates
3051 echo -n "Uninstalling updates..."
3053 # If there are updates waiting to be installed, remove them; we
3054 # want the user to re-run 'fetch' after rolling back updates.
3055 if [ -L ${BDHASH}-install ]; then
3056 rm -r ${BDHASH}-install/
3057 rm ${BDHASH}-install
3060 # Make sure we have all the files we should have
3061 install_verify ${BDHASH}-rollback/INDEX-NEW \
3062 ${BDHASH}-rollback/INDEX-OLD || return 1
3064 # Remove system immutable flag from files
3065 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3066 ${BDHASH}-rollback/INDEX-OLD || return 1
3068 # Install old files, delete new files, and update linker.hints
3069 rollback_files ${BDHASH}-rollback || return 1
3071 # Remove the rollback directory and the symlink pointing to it; and
3072 # rearrange bits to allow the previous set of updates to be rolled
3074 rollback_setup_rollback
3079 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3081 # Get all the lines which mismatch in something other than file
3082 # flags. We ignore file flags because sysinstall doesn't seem to
3083 # set them when it installs FreeBSD; warning about these adds a
3084 # very large amount of noise.
3085 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3086 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3087 cut -f 1-5,7-8 -d '|' $2 |
3088 comm -13 $1.noflags - |
3089 fgrep -v '|-|||||' |
3090 sort -k 1,1 -t '|' |
3091 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3093 # Ignore files which match IDSIGNOREPATHS.
3094 for X in ${IDSIGNOREPATHS}; do
3095 grep -E "^${X}" INDEX-NOTMATCHING
3098 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3099 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3101 # Go through the lines and print warnings.
3103 while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do
3104 # Warn about different object types.
3105 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3106 echo -n "${FPATH} is a "
3108 f) echo -n "regular file, "
3110 d) echo -n "directory, "
3112 L) echo -n "symlink, "
3115 echo -n "but should be a "
3117 f) echo -n "regular file."
3119 d) echo -n "directory."
3121 L) echo -n "symlink."
3126 # Skip other tests, since they don't make sense if
3127 # we're comparing different object types.
3131 # Warn about different owners.
3132 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3133 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3134 echo "but should be owned by user id ${OWNER}."
3137 # Warn about different groups.
3138 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3139 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3140 echo "but should be owned by group id ${GROUP}."
3143 # Warn about different permissions. We do not warn about
3144 # different permissions on symlinks, since some archivers
3145 # don't extract symlink permissions correctly and they are
3147 if ! [ "${PERM}" = "${P_PERM}" ] &&
3148 ! [ "${TYPE}" = "L" ]; then
3149 echo -n "${FPATH} has ${P_PERM} permissions, "
3150 echo "but should have ${PERM} permissions."
3153 # Warn about different file hashes / symlink destinations.
3154 if ! [ "${HASH}" = "${P_HASH}" ]; then
3155 if [ "${TYPE}" = "L" ]; then
3156 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3157 echo "but should be a symlink to ${HASH}."
3159 if [ "${TYPE}" = "f" ]; then
3160 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3161 echo "but should have SHA256 hash ${HASH}."
3165 # We don't warn about different hard links, since some
3166 # some archivers break hard links, and as long as the
3167 # underlying data is correct they really don't matter.
3168 done < INDEX-NOTMATCHING
3171 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3174 # Do the work involved in comparing the system to a "known good" index
3176 workdir_init || return 1
3178 # Prepare the mirror list.
3179 fetch_pick_server_init && fetch_pick_server
3181 # Try to fetch the public key until we run out of servers.
3182 while ! fetch_key; do
3183 fetch_pick_server || return 1
3186 # Try to fetch the metadata index signature ("tag") until we run
3187 # out of available servers; and sanity check the downloaded tag.
3188 while ! fetch_tag; do
3189 fetch_pick_server || return 1
3191 fetch_tagsanity || return 1
3193 # Fetch INDEX-OLD and INDEX-ALL.
3194 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3196 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3197 # the components we want and without anything marked as "Ignore".
3198 fetch_filter_metadata INDEX-OLD || return 1
3199 fetch_filter_metadata INDEX-ALL || return 1
3201 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3202 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3203 mv INDEX-ALL.tmp INDEX-ALL
3206 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3207 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3209 # Inspect the system and generate an INDEX-PRESENT file.
3210 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3212 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3214 IDS_compare INDEX-ALL INDEX-PRESENT
3217 #### Main functions -- call parameter-handling and core functions
3219 # Using the command line, configuration file, and defaults,
3220 # set all the parameters which are needed later.
3228 # Fetch command. Make sure that we're being called
3229 # interactively, then run fetch_check_params and fetch_run
3231 if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then
3232 echo -n "`basename $0` fetch should not "
3233 echo "be run non-interactively."
3234 echo "Run `basename $0` cron instead."
3241 # Cron command. Make sure the parameters are sensible; wait
3242 # rand(3600) seconds; then fetch updates. While fetching updates,
3243 # send output to a temporary file; only print that file if the
3247 sleep `jot -r 1 0 3600`
3249 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3250 if ! fetch_run >> ${TMPFILE} ||
3251 ! grep -q "No updates needed" ${TMPFILE} ||
3252 [ ${VERBOSELEVEL} = "debug" ]; then
3253 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3259 # Fetch files for upgrading to a new release.
3261 upgrade_check_params
3262 upgrade_run || exit 1
3265 # Install downloaded updates.
3267 install_check_params
3268 install_run || exit 1
3271 # Rollback most recently installed updates.
3273 rollback_check_params
3274 rollback_run || exit 1
3277 # Compare system against a "known good" index.
3285 # Make sure we find utilities from the base system
3286 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3288 # Set a pager if the user doesn't
3289 if [ -z "$PAGER" ]; then
3293 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3297 for COMMAND in ${COMMANDS}; do