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
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
423 # Parse the command line
425 while [ $# -gt 0 ]; do
427 # Location of configuration file
429 if [ $# -eq 1 ]; then usage; fi
430 if [ ! -z "${CONFFILE}" ]; then usage; fi
436 --not-running-from-cron)
440 shift; export UNAME_r="$1"
443 # Configuration file equivalents
445 if [ $# -eq 1 ]; then usage; fi; shift
446 config_BaseDir $1 || usage
449 if [ $# -eq 1 ]; then usage; fi; shift
450 config_WorkDir $1 || usage
453 if [ $# -eq 1 ]; then usage; fi; shift
454 config_KeyPrint $1 || usage
457 if [ $# -eq 1 ]; then usage; fi; shift
458 config_ServerName $1 || usage
461 if [ $# -eq 1 ]; then usage; fi; shift
462 config_TargetRelease $1 || usage
465 if [ $# -eq 1 ]; then usage; fi; shift
466 config_MailTo $1 || usage
469 if [ $# -eq 1 ]; then usage; fi; shift
470 config_VerboseLevel $1 || usage
473 # Aliases for "-v debug" and "-v nostats"
475 config_VerboseLevel debug || usage
478 config_VerboseLevel nostats || usage
482 cron | fetch | upgrade | install | rollback | IDS)
483 COMMANDS="${COMMANDS} $1"
486 # Anything else is an error
494 # Make sure we have at least one command
495 if [ -z "${COMMANDS}" ]; then
500 # Parse the configuration file
502 # If a configuration file was specified on the command line, check
503 # that it exists and is readable.
504 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
505 echo -n "File does not exist "
506 echo -n "or is not readable: "
511 # If a configuration file was not specified on the command line,
512 # use the default configuration file path. If that default does
513 # not exist, give up looking for any configuration.
514 if [ -z "${CONFFILE}" ]; then
515 CONFFILE="/etc/freebsd-update.conf"
516 if [ ! -r "${CONFFILE}" ]; then
521 # Save the configuration options specified on the command line, and
522 # clear all the options in preparation for reading the config file.
526 # Read the configuration file. Anything after the first '#' is
527 # ignored, and any blank lines are ignored.
531 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
532 if ! configline ${LINEX}; then
533 echo "Error processing configuration file, line $L:"
539 # Merge the settings read from the configuration file with those
540 # provided at the command line.
544 # Provide some default parameters
546 # Save any parameters already configured, and clear the slate
550 # Default configurations
551 config_WorkDir /var/db/freebsd-update
554 config_AllowDelete yes
555 config_KeepModifiedMetadata yes
557 config_VerboseLevel stats
558 config_StrictComponents no
559 config_BackupKernel yes
560 config_BackupKernelDir /boot/kernel.old
561 config_BackupKernelSymbolFiles no
563 # Merge these defaults into the earlier-configured settings
567 # Set utility output filtering options, based on ${VERBOSELEVEL}
568 fetch_setup_verboselevel () {
569 case ${VERBOSELEVEL} in
571 QUIETREDIR="/dev/stderr"
573 STATSREDIR="/dev/stderr"
581 STATSREDIR="/dev/null"
587 QUIETREDIR="/dev/null"
589 STATSREDIR="/dev/stdout"
597 # Perform sanity checks and set some final parameters
598 # in preparation for fetching files. Figure out which
599 # set of updates should be downloaded: If the user is
600 # running *-p[0-9]+, strip off the last part; if the
601 # user is running -SECURITY, call it -RELEASE. Chdir
602 # into the working directory.
603 fetchupgrade_check_params () {
604 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
607 "SERVERNAME must be given via command line or configuration file."
608 _KEYPRINT_z="Key must be given via -k option or configuration file."
609 _KEYPRINT_bad="Invalid key fingerprint: "
610 _WORKDIR_bad="Directory does not exist or is not writable: "
611 _WORKDIR_bad2="Directory is not on a persistent filesystem: "
613 if [ -z "${SERVERNAME}" ]; then
614 echo -n "`basename $0`: "
615 echo "${_SERVERNAME_z}"
618 if [ -z "${KEYPRINT}" ]; then
619 echo -n "`basename $0`: "
620 echo "${_KEYPRINT_z}"
623 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
624 echo -n "`basename $0`: "
625 echo -n "${_KEYPRINT_bad}"
629 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
630 echo -n "`basename $0`: "
631 echo -n "${_WORKDIR_bad}"
635 case `df -T ${WORKDIR}` in */dev/md[0-9]* | *tmpfs*)
636 echo -n "`basename $0`: "
637 echo -n "${_WORKDIR_bad2}"
643 cd ${WORKDIR} || exit 1
645 # Generate release number. The s/SECURITY/RELEASE/ bit exists
646 # to provide an upgrade path for FreeBSD Update 1.x users, since
647 # the kernels provided by FreeBSD Update 1.x are always labelled
650 sed -E 's,-p[0-9]+,,' |
651 sed -E 's,-SECURITY,-RELEASE,'`
653 FETCHDIR=${RELNUM}/${ARCH}
654 PATCHDIR=${RELNUM}/${ARCH}/bp
656 # Figure out what directory contains the running kernel
657 BOOTFILE=`sysctl -n kern.bootfile`
658 KERNELDIR=${BOOTFILE%/kernel}
659 if ! [ -d ${KERNELDIR} ]; then
660 echo "Cannot identify running kernel"
664 # Figure out what kernel configuration is running. We start with
665 # the output of `uname -i`, and then make the following adjustments:
666 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
667 # file says "ident SMP-GENERIC", I don't know...
668 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
669 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
670 # we're running an SMP kernel. This mis-identification is a bug
671 # which was fixed in 6.2-STABLE.
673 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
676 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
677 if sysctl kern.version | grep -qE '/SMP$'; then
683 BSPATCH=/usr/bin/bspatch
685 PHTTPGET=/usr/libexec/phttpget
687 # Set up variables relating to VERBOSELEVEL
688 fetch_setup_verboselevel
690 # Construct a unique name from ${BASEDIR}
691 BDHASH=`echo ${BASEDIR} | sha256 -q`
694 # Perform sanity checks etc. before fetching updates.
695 fetch_check_params () {
696 fetchupgrade_check_params
698 if ! [ -z "${TARGETRELEASE}" ]; then
699 echo -n "`basename $0`: "
700 echo -n "-r option is meaningless with 'fetch' command. "
701 echo "(Did you mean 'upgrade' instead?)"
705 # Check that we have updates ready to install
706 if [ -f ${BDHASH}-install/kerneldone -a $FORCEFETCH -eq 0 ]; then
707 echo "You have a partially completed upgrade pending"
708 echo "Run '$0 install' first."
709 echo "Run '$0 fetch -F' to proceed anyway."
714 # Perform sanity checks etc. before fetching upgrades.
715 upgrade_check_params () {
716 fetchupgrade_check_params
718 # Unless set otherwise, we're upgrading to the same kernel config.
719 NKERNCONF=${KERNCONF}
721 # We need TARGETRELEASE set
722 _TARGETRELEASE_z="Release target must be specified via -r option."
723 if [ -z "${TARGETRELEASE}" ]; then
724 echo -n "`basename $0`: "
725 echo "${_TARGETRELEASE_z}"
729 # The target release should be != the current release.
730 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
731 echo -n "`basename $0`: "
732 echo "Cannot upgrade from ${RELNUM} to itself"
736 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
737 if [ "${ALLOWADD}" = "no" ]; then
738 echo -n "`basename $0`: "
739 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
740 echo "when upgrading between releases."
743 if [ "${ALLOWDELETE}" = "no" ]; then
744 echo -n "`basename $0`: "
745 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
746 echo "when upgrading between releases."
750 # Set EDITOR to /usr/bin/vi if it isn't already set
751 : ${EDITOR:='/usr/bin/vi'}
754 # Perform sanity checks and set some final parameters in
755 # preparation for installing updates.
756 install_check_params () {
757 # Check that we are root. All sorts of things won't work otherwise.
758 if [ `id -u` != 0 ]; then
759 echo "You must be root to run this."
763 # Check that securelevel <= 0. Otherwise we can't update schg files.
764 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
765 echo "Updates cannot be installed when the system securelevel"
766 echo "is greater than zero."
770 # Check that we have a working directory
771 _WORKDIR_bad="Directory does not exist or is not writable: "
772 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
773 echo -n "`basename $0`: "
774 echo -n "${_WORKDIR_bad}"
778 cd ${WORKDIR} || exit 1
780 # Construct a unique name from ${BASEDIR}
781 BDHASH=`echo ${BASEDIR} | sha256 -q`
783 # Check that we have updates ready to install
784 if ! [ -L ${BDHASH}-install ]; then
785 echo "No updates are available to install."
786 echo "Run '$0 fetch' first."
789 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
790 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
791 echo "Update manifest is corrupt -- this should never happen."
792 echo "Re-run '$0 fetch'."
796 # Figure out what directory contains the running kernel
797 BOOTFILE=`sysctl -n kern.bootfile`
798 KERNELDIR=${BOOTFILE%/kernel}
799 if ! [ -d ${KERNELDIR} ]; then
800 echo "Cannot identify running kernel"
805 # Perform sanity checks and set some final parameters in
806 # preparation for UNinstalling updates.
807 rollback_check_params () {
808 # Check that we are root. All sorts of things won't work otherwise.
809 if [ `id -u` != 0 ]; then
810 echo "You must be root to run this."
814 # Check that we have a working directory
815 _WORKDIR_bad="Directory does not exist or is not writable: "
816 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
817 echo -n "`basename $0`: "
818 echo -n "${_WORKDIR_bad}"
822 cd ${WORKDIR} || exit 1
824 # Construct a unique name from ${BASEDIR}
825 BDHASH=`echo ${BASEDIR} | sha256 -q`
827 # Check that we have updates ready to rollback
828 if ! [ -L ${BDHASH}-rollback ]; then
829 echo "No rollback directory found."
832 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
833 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
834 echo "Update manifest is corrupt -- this should never happen."
839 # Perform sanity checks and set some final parameters
840 # in preparation for comparing the system against the
841 # published index. Figure out which index we should
842 # compare against: If the user is running *-p[0-9]+,
843 # strip off the last part; if the user is running
844 # -SECURITY, call it -RELEASE. Chdir into the working
846 IDS_check_params () {
847 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
850 "SERVERNAME must be given via command line or configuration file."
851 _KEYPRINT_z="Key must be given via -k option or configuration file."
852 _KEYPRINT_bad="Invalid key fingerprint: "
853 _WORKDIR_bad="Directory does not exist or is not writable: "
855 if [ -z "${SERVERNAME}" ]; then
856 echo -n "`basename $0`: "
857 echo "${_SERVERNAME_z}"
860 if [ -z "${KEYPRINT}" ]; then
861 echo -n "`basename $0`: "
862 echo "${_KEYPRINT_z}"
865 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
866 echo -n "`basename $0`: "
867 echo -n "${_KEYPRINT_bad}"
871 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
872 echo -n "`basename $0`: "
873 echo -n "${_WORKDIR_bad}"
877 cd ${WORKDIR} || exit 1
879 # Generate release number. The s/SECURITY/RELEASE/ bit exists
880 # to provide an upgrade path for FreeBSD Update 1.x users, since
881 # the kernels provided by FreeBSD Update 1.x are always labelled
884 sed -E 's,-p[0-9]+,,' |
885 sed -E 's,-SECURITY,-RELEASE,'`
887 FETCHDIR=${RELNUM}/${ARCH}
888 PATCHDIR=${RELNUM}/${ARCH}/bp
890 # Figure out what directory contains the running kernel
891 BOOTFILE=`sysctl -n kern.bootfile`
892 KERNELDIR=${BOOTFILE%/kernel}
893 if ! [ -d ${KERNELDIR} ]; then
894 echo "Cannot identify running kernel"
898 # Figure out what kernel configuration is running. We start with
899 # the output of `uname -i`, and then make the following adjustments:
900 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
901 # file says "ident SMP-GENERIC", I don't know...
902 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
903 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
904 # we're running an SMP kernel. This mis-identification is a bug
905 # which was fixed in 6.2-STABLE.
907 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
910 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
911 if sysctl kern.version | grep -qE '/SMP$'; then
918 PHTTPGET=/usr/libexec/phttpget
920 # Set up variables relating to VERBOSELEVEL
921 fetch_setup_verboselevel
924 #### Core functionality -- the actual work gets done here
926 # Use an SRV query to pick a server. If the SRV query doesn't provide
927 # a useful answer, use the server name specified by the user.
928 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
929 # from that; or if no servers are returned, use ${SERVERNAME}.
930 # This allows a user to specify "portsnap.freebsd.org" (in which case
931 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
932 # (in which case portsnap will use that particular server, since there
933 # won't be an SRV entry for that name).
935 # We ignore the Port field, since we are always going to use port 80.
937 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
938 # no mirrors are available for any reason.
939 fetch_pick_server_init () {
942 # Check that host(1) exists (i.e., that the system wasn't built with the
943 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
944 if ! which -s host; then
949 echo -n "Looking up ${SERVERNAME} mirrors... "
951 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
952 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
953 # "$name server selection ..."; we allow either format.
954 MLIST="_http._tcp.${SERVERNAME}"
955 host -t srv "${MLIST}" |
956 sed -nE "s/${MLIST} (has SRV record|server selection) //p" |
957 cut -f 1,2,4 -d ' ' |
959 sort > serverlist_full
961 # If no records, give up -- we'll just use the server name we were given.
962 if [ `wc -l < serverlist_full` -eq 0 ]; then
967 # Report how many mirrors we found.
968 echo `wc -l < serverlist_full` "mirrors found."
970 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
971 # is set, this will be used to generate the seed; otherwise, the seed
973 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
974 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
978 RANDVALUE=`jot -r 1 0 999999999`
982 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
983 fetch_pick_server () {
984 # Generate a list of not-yet-tried mirrors
985 sort serverlist_tried |
986 comm -23 serverlist_full - > serverlist
988 # Have we run out of mirrors?
989 if [ `wc -l < serverlist` -eq 0 ]; then
990 echo "No mirrors remaining, giving up."
994 # Find the highest priority level (lowest numeric value).
995 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
997 # Add up the weights of the response lines at that priority level.
1002 SRV_W=`echo $X | cut -f 2 -d ' '`
1003 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
1008 # If all the weights are 0, pretend that they are all 1 instead.
1009 if [ ${SRV_WSUM} -eq 0 ]; then
1010 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
1016 # Pick a value between 0 and the sum of the weights - 1
1017 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
1019 # Read through the list of mirrors and set SERVERNAME. Write the line
1020 # corresponding to the mirror we selected into serverlist_tried so that
1021 # we won't try it again.
1025 SRV_W=`echo $X | cut -f 2 -d ' '`
1026 SRV_W=$(($SRV_W + $SRV_W_ADD))
1027 if [ $SRV_RND -lt $SRV_W ]; then
1028 SERVERNAME=`echo $X | cut -f 3 -d ' '`
1029 echo "$X" >> serverlist_tried
1032 SRV_RND=$(($SRV_RND - $SRV_W))
1039 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
1040 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
1041 fetch_make_patchlist () {
1042 grep -vE "^([0-9a-f]{64})\|\1$" |
1045 if [ -f "files/${Y}.gz" ] ||
1046 [ ! -f "files/${X}.gz" ]; then
1053 # Print user-friendly progress statistics
1058 if [ $(($LNC % 10)) = 0 ]; then
1060 elif [ $(($LNC % 2)) = 0 ]; then
1067 # Function for asking the user if everything is ok
1069 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1070 case "${CONTINUE}" in
1081 # Initialize the working directory
1084 touch tINDEX.present
1087 # Check that we have a public key with an appropriate hash, or
1088 # fetch the key if it doesn't exist. Returns 1 if the key has
1089 # not yet been fetched.
1091 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1095 echo -n "Fetching public key from ${SERVERNAME}... "
1097 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1098 2>${QUIETREDIR} || true
1099 if ! [ -r pub.ssl ]; then
1103 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1104 echo "key has incorrect hash."
1111 # Fetch metadata signature, aka "tag".
1113 echo -n "Fetching metadata signature "
1114 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1116 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1117 2>${QUIETREDIR} || true
1118 if ! [ -r latest.ssl ]; then
1123 openssl rsautl -pubin -inkey pub.ssl -verify \
1124 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1127 if ! [ `wc -l < tag.new` = 1 ] ||
1129 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1131 echo "invalid signature."
1137 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1138 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1139 EOLTIME=`cut -f 6 -d '|' < tag.new`
1142 # Sanity-check the patch number in a tag, to make sure that we're not
1143 # going to "update" backwards and to prevent replay attacks.
1144 fetch_tagsanity () {
1145 # Check that we're not going to move from -pX to -pY with Y < X.
1146 RELPX=`uname -r | sed -E 's,.*-,,'`
1147 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1148 RELPX=`echo ${RELPX} | cut -c 2-`
1152 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1154 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1155 echo " appear older than what"
1156 echo "we are currently running (`uname -r`)!"
1157 echo "Cowardly refusing to proceed any further."
1161 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1162 # it contains a patch number <= RELPATCHNUM, in order to protect
1163 # against rollback (replay) attacks.
1166 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1168 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1170 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1172 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1173 echo " are older than the"
1174 echo -n "most recently seen updates"
1175 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1176 echo "Cowardly refusing to proceed any further."
1182 # Fetch metadata index file
1183 fetch_metadata_index () {
1184 echo ${NDEBUG} "Fetching metadata index... "
1186 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1188 if ! [ -f ${TINDEXHASH} ]; then
1192 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1193 echo "update metadata index corrupt."
1199 # Print an error message about signed metadata being bogus.
1200 fetch_metadata_bogus () {
1202 echo "The update metadata$1 is correctly signed, but"
1203 echo "failed an integrity check."
1204 echo "Cowardly refusing to proceed any further."
1208 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1209 # with the lines not named in $@ from tINDEX.present (if that file exists).
1210 fetch_metadata_index_merge () {
1211 for METAFILE in $@; do
1212 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1214 fetch_metadata_bogus " index"
1218 grep -E "${METAFILE}\|" ${TINDEXHASH}
1220 sort > tINDEX.wanted
1222 if [ -f tINDEX.present ]; then
1223 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1224 sort -m - tINDEX.wanted > tINDEX.new
1227 mv tINDEX.wanted tINDEX.new
1231 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1232 # are added by future versions of the server, this won't cause problems,
1233 # since the only lines which appear in tINDEX.new are the ones which we
1234 # specifically grepped out of ${TINDEXHASH}.
1235 fetch_metadata_index_sanity () {
1236 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1237 fetch_metadata_bogus " index"
1242 # Sanity check the metadata file $1.
1243 fetch_metadata_sanity () {
1244 # Some aliases to save space later: ${P} is a character which can
1245 # appear in a path; ${M} is the four numeric metadata fields; and
1246 # ${H} is a sha256 hash.
1247 P="[-+./:=,%@_[~[:alnum:]]"
1248 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1251 # Check that the first four fields make sense.
1252 if gunzip -c < files/$1.gz |
1253 grep -qvE "^[a-z]+\|[0-9a-z-]+\|${P}+\|[fdL-]\|"; then
1254 fetch_metadata_bogus ""
1258 # Remove the first three fields.
1259 gunzip -c < files/$1.gz |
1260 cut -f 4- -d '|' > sanitycheck.tmp
1262 # Sanity check entries with type 'f'
1263 if grep -E '^f' sanitycheck.tmp |
1264 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1265 fetch_metadata_bogus ""
1269 # Sanity check entries with type 'd'
1270 if grep -E '^d' sanitycheck.tmp |
1271 grep -qvE "^d\|${M}\|\|\$"; then
1272 fetch_metadata_bogus ""
1276 # Sanity check entries with type 'L'
1277 if grep -E '^L' sanitycheck.tmp |
1278 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1279 fetch_metadata_bogus ""
1283 # Sanity check entries with type '-'
1284 if grep -E '^-' sanitycheck.tmp |
1285 grep -qvE "^-\|\|\|\|\|\|"; then
1286 fetch_metadata_bogus ""
1294 # Fetch the metadata index and metadata files listed in $@,
1295 # taking advantage of metadata patches where possible.
1297 fetch_metadata_index || return 1
1298 fetch_metadata_index_merge $@ || return 1
1299 fetch_metadata_index_sanity || return 1
1301 # Generate a list of wanted metadata patches
1302 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1303 fetch_make_patchlist > patchlist
1305 if [ -s patchlist ]; then
1306 # Attempt to fetch metadata patches
1307 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1308 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1309 tr '|' '-' < patchlist |
1310 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1311 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1312 2>${STATSREDIR} | fetch_progress
1315 # Attempt to apply metadata patches
1316 echo -n "Applying metadata patches... "
1317 tr '|' ' ' < patchlist |
1319 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1320 gunzip -c < ${X}-${Y}.gz > diff
1321 gunzip -c < files/${X}.gz > diff-OLD
1323 # Figure out which lines are being added and removed
1326 while read PREFIX; do
1327 look "${PREFIX}" diff-OLD
1330 grep -E '^\+' diff |
1331 cut -c 2- > diff-add
1333 # Generate the new file
1334 comm -23 diff-OLD diff-rm |
1335 sort - diff-add > diff-NEW
1337 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1338 mv diff-NEW files/${Y}
1341 mv diff-NEW ${Y}.bad
1343 rm -f ${X}-${Y}.gz diff
1344 rm -f diff-OLD diff-NEW diff-add diff-rm
1345 done 2>${QUIETREDIR}
1349 # Update metadata without patches
1350 cut -f 2 -d '|' < tINDEX.new |
1352 if [ ! -f "files/${Y}.gz" ]; then
1358 if [ -s filelist ]; then
1359 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1360 echo ${NDEBUG} "metadata files... "
1361 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1362 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1366 if ! [ -f ${Y}.gz ]; then
1370 if [ `gunzip -c < ${Y}.gz |
1371 ${SHA256} -q` = ${Y} ]; then
1372 mv ${Y}.gz files/${Y}.gz
1374 echo "metadata is corrupt."
1381 # Sanity-check the metadata files.
1382 cut -f 2 -d '|' tINDEX.new > filelist
1384 fetch_metadata_sanity ${X} || return 1
1387 # Remove files which are no longer needed
1388 cut -f 2 -d '|' tINDEX.present |
1390 cut -f 2 -d '|' tINDEX.new |
1392 comm -13 - oldfiles |
1393 lam -s "files/" - -s ".gz" |
1395 rm patchlist filelist oldfiles
1399 mv tINDEX.new tINDEX.present
1405 # Extract a subset of a downloaded metadata file containing only the parts
1406 # which are listed in COMPONENTS.
1407 fetch_filter_metadata_components () {
1408 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1409 gunzip -c < files/${METAHASH}.gz > $1.all
1411 # Fish out the lines belonging to components we care about.
1412 for C in ${COMPONENTS}; do
1413 look "`echo ${C} | tr '/' '|'`|" $1.all
1416 # Remove temporary file.
1420 # Generate a filtered version of the metadata file $1 from the downloaded
1421 # file, by fishing out the lines corresponding to components we're trying
1422 # to keep updated, and then removing lines corresponding to paths we want
1424 fetch_filter_metadata () {
1425 # Fish out the lines belonging to components we care about.
1426 fetch_filter_metadata_components $1
1428 # Canonicalize directory names by removing any trailing / in
1429 # order to avoid listing directories multiple times if they
1430 # belong to multiple components. Turning "/" into "" doesn't
1431 # matter, since we add a leading "/" when we use paths later.
1432 cut -f 3- -d '|' $1 |
1433 sed -e 's,/|d|,|d|,' |
1434 sed -e 's,/|-|,|-|,' |
1437 # Figure out which lines to ignore and remove them.
1438 for X in ${IGNOREPATHS}; do
1439 grep -E "^${X}" $1.tmp
1442 comm -13 - $1.tmp > $1
1444 # Remove temporary files.
1448 # Filter the metadata file $1 by adding lines with "/boot/$2"
1449 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1450 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1451 # the original lines which start with that.
1452 # Put another way: Deal with the fact that the FOO kernel is sometimes
1453 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1454 fetch_filter_kernel_names () {
1456 sed -e "s,/boot/$2,${KERNELDIR},g" |
1460 if ! [ -d /boot/$2 ]; then
1461 grep -v ^/boot/$2 $1 > $1.tmp
1466 # For all paths appearing in $1 or $3, inspect the system
1467 # and generate $2 describing what is currently installed.
1468 fetch_inspect_system () {
1472 # Tell the user why his disk is suddenly making lots of noise
1473 echo -n "Inspecting system... "
1475 # Generate list of files to inspect
1480 # Examine each file and output lines of the form
1481 # /path/to/file|type|device-inum|user|group|perm|flags|value
1482 # sorted by device and inode number.
1484 # If the symlink/file/directory does not exist, record this.
1485 if ! [ -e ${BASEDIR}/${F} ]; then
1489 if ! [ -r ${BASEDIR}/${F} ]; then
1490 echo "Cannot read file: ${BASEDIR}/${F}" \
1496 # Otherwise, output an index line.
1497 if [ -L ${BASEDIR}/${F} ]; then
1499 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1500 readlink ${BASEDIR}/${F};
1501 elif [ -f ${BASEDIR}/${F} ]; then
1503 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1504 sha256 -q ${BASEDIR}/${F};
1505 elif [ -d ${BASEDIR}/${F} ]; then
1507 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1509 echo "Unknown file type: ${BASEDIR}/${F}" \
1515 sort -k 3,3 -t '|' > $2.tmp
1518 # Check if an error occurred during system inspection
1519 if [ -f .err ]; then
1523 # Convert to the form
1524 # /path/to/file|type|user|group|perm|flags|value|hlink
1525 # by resolving identical device and inode numbers into hard links.
1526 cut -f 1,3 -d '|' $2.tmp |
1527 sort -k 1,1 -t '|' |
1528 sort -s -u -k 2,2 -t '|' |
1529 join -1 2 -2 3 -t '|' - $2.tmp |
1530 awk -F \| -v OFS=\| \
1532 if (($2 == $3) || ($4 == "-"))
1533 print $3,$4,$5,$6,$7,$8,$9,""
1535 print $3,$4,$5,$6,$7,$8,$9,$2
1540 # We're finished looking around
1544 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1545 # files which differ; generate $3 containing these paths and the old hashes.
1546 fetch_filter_mergechanges () {
1547 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1549 for X in ${MERGECHANGES}; do
1550 grep -E "^${X}" ${F}
1552 cut -f 1,2,7 -d '|' |
1556 # Any line in $2-values which doesn't appear in $1-values and is a
1557 # file means that we should list the path in $3.
1558 comm -13 $1-values $2-values |
1560 cut -f 1 -d '|' > $2-paths
1562 # For each path, pull out one (and only one!) entry from $1-values.
1563 # Note that we cannot distinguish which "old" version the user made
1564 # changes to; but hopefully any changes which occur due to security
1565 # updates will exist in both the "new" version and the version which
1566 # the user has installed, so the merging will still work.
1568 look "${X}|" $1-values |
1570 done < $2-paths > $3
1573 rm $1-values $2-values $2-paths
1576 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1577 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1578 # the paths are listed in $4. For entries in $2 marked "not present"
1579 # (aka. type -), remove lines from $[123] unless there is a corresponding
1581 fetch_filter_unmodified_notpresent () {
1582 # Figure out which lines of $1 and $3 correspond to bits which
1583 # should only be updated if they haven't changed, and fish out
1584 # the (path, type, value) tuples.
1585 # NOTE: We don't consider a file to be "modified" if it matches
1587 for X in ${UPDATEIFUNMODIFIED}; do
1591 cut -f 1,2,7 -d '|' |
1594 # Do the same for $2.
1595 for X in ${UPDATEIFUNMODIFIED}; do
1598 cut -f 1,2,7 -d '|' |
1601 # Any entry in $2-values which is not in $1-values corresponds to
1602 # a path which we need to remove from $1, $2, and $3, unless it
1603 # that path appears in $4.
1604 comm -13 $1-values $2-values |
1605 sort -t '|' -k 1,1 > mlines.tmp
1606 cut -f 1 -d '|' $4 |
1608 join -v 2 -t '|' - mlines.tmp |
1610 rm $1-values $2-values mlines.tmp
1612 # Any lines in $2 which are not in $1 AND are "not present" lines
1613 # also belong in mlines.
1615 cut -f 1,2,7 -d '|' |
1616 fgrep '|-|' >> mlines
1618 # Remove lines from $1, $2, and $3
1619 for X in $1 $2 $3; do
1620 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1621 cut -f 1 -d '|' < mlines |
1623 join -v 2 -t '|' - ${X}.tmp |
1628 # Store a list of the modified files, for future reference
1629 fgrep -v '|-|' mlines |
1630 cut -f 1 -d '|' > modifiedfiles
1634 # For each entry in $1 of type -, remove any corresponding
1635 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1636 # of type - from $1.
1637 fetch_filter_allowadd () {
1638 cut -f 1,2 -d '|' < $1 |
1640 cut -f 1 -d '|' > filesnotpresent
1642 if [ ${ALLOWADD} != "yes" ]; then
1644 join -v 1 -t '|' - filesnotpresent |
1650 join -v 1 -t '|' - filesnotpresent |
1656 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1657 # which don't correspond to entries in $2.
1658 fetch_filter_allowdelete () {
1659 # Produce a lists ${PATH}|${TYPE}
1661 cut -f 1-2 -d '|' < ${X} |
1662 sort -u > ${X}.nodes
1665 # Figure out which lines need to be removed from $1.
1666 if [ ${ALLOWDELETE} != "yes" ]; then
1667 comm -23 $1.nodes $2.nodes > $1.badnodes
1672 # Remove the relevant lines from $1
1675 done < $1.badnodes |
1676 comm -13 - $1 > $1.tmp
1679 rm $1.badnodes $1.nodes $2.nodes
1682 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1683 # with metadata not matching any entry in $1, replace the corresponding
1684 # line of $3 with one having the same metadata as the entry in $2.
1685 fetch_filter_modified_metadata () {
1686 # Fish out the metadata from $1 and $2
1688 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1691 # Find the metadata we need to keep
1692 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1693 comm -13 $1.metadata $2.metadata > keepmeta
1698 # Extract the lines which we need to remove from $3, and
1699 # construct the lines which we need to add to $3.
1703 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1704 look "${NODE}|" $3 >> $3.remove
1705 look "${NODE}|" $3 |
1707 lam -s "${LINE}|" - >> $3.add
1710 # Remove the specified lines and add the new lines.
1713 sort -u - $3.add > $3.tmp
1716 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1719 # Remove lines from $1 and $2 which are identical;
1720 # no need to update a file if it isn't changing.
1721 fetch_filter_uptodate () {
1722 comm -23 $1 $2 > $1.tmp
1723 comm -13 $1 $2 > $2.tmp
1729 # Fetch any "clean" old versions of files we need for merging changes.
1730 fetch_files_premerge () {
1731 # We only need to do anything if $1 is non-empty.
1733 # Tell the user what we're doing
1734 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1736 # List of files wanted
1739 sort -u > files.wanted
1741 # Only fetch the files we don't already have
1743 if [ ! -f "files/${Y}.gz" ]; then
1746 done < files.wanted > filelist
1748 # Actually fetch them
1749 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1750 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1753 # Make sure we got them all, and move them into /files/
1755 if ! [ -f ${Y}.gz ]; then
1759 if [ `gunzip -c < ${Y}.gz |
1760 ${SHA256} -q` = ${Y} ]; then
1761 mv ${Y}.gz files/${Y}.gz
1763 echo "${Y} has incorrect hash."
1770 rm filelist files.wanted
1774 # Prepare to fetch files: Generate a list of the files we need,
1775 # copy the unmodified files we have into /files/, and generate
1776 # a list of patches to download.
1777 fetch_files_prepare () {
1778 # Tell the user why his disk is suddenly making lots of noise
1779 echo -n "Preparing to download files... "
1781 # Reduce indices to ${PATH}|${HASH} pairs
1782 for X in $1 $2 $3; do
1783 cut -f 1,2,7 -d '|' < ${X} |
1789 # List of files wanted
1790 cut -f 2 -d '|' < $3.hashes |
1793 if ! [ -f files/${HASH}.gz ]; then
1798 # Generate a list of unmodified files
1799 comm -12 $1.hashes $2.hashes |
1800 sort -k 1,1 -t '|' > unmodified.files
1802 # Copy all files into /files/. We only need the unmodified files
1803 # for use in patching; but we'll want all of them if the user asks
1804 # to rollback the updates later.
1806 F=`echo "${LINE}" | cut -f 1 -d '|'`
1807 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1809 # Skip files we already have.
1810 if [ -f files/${HASH}.gz ]; then
1814 # Make sure the file hasn't changed.
1815 cp "${BASEDIR}/${F}" tmpfile
1816 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1818 echo "File changed while FreeBSD Update running: ${F}"
1822 # Place the file into storage.
1823 gzip -c < tmpfile > files/${HASH}.gz
1827 # Produce a list of patches to download
1828 sort -k 1,1 -t '|' $3.hashes |
1829 join -t '|' -o 2.2,1.2 - unmodified.files |
1830 fetch_make_patchlist > patchlist
1833 rm unmodified.files $1.hashes $2.hashes $3.hashes
1835 # We don't need the list of possible old files any more.
1838 # We're finished making noise
1844 # Attempt to fetch patches
1845 if [ -s patchlist ]; then
1846 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1847 echo ${NDEBUG} "patches.${DDSTATS}"
1848 tr '|' '-' < patchlist |
1849 lam -s "${PATCHDIR}/" - |
1850 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1851 2>${STATSREDIR} | fetch_progress
1854 # Attempt to apply patches
1855 echo -n "Applying patches... "
1856 tr '|' ' ' < patchlist |
1858 if [ ! -f "${X}-${Y}" ]; then continue; fi
1859 gunzip -c < files/${X}.gz > OLD
1861 bspatch OLD NEW ${X}-${Y}
1863 if [ `${SHA256} -q NEW` = ${Y} ]; then
1867 rm -f diff OLD NEW ${X}-${Y}
1868 done 2>${QUIETREDIR}
1872 # Download files which couldn't be generate via patching
1874 if [ ! -f "files/${Y}.gz" ]; then
1877 done < files.wanted > filelist
1879 if [ -s filelist ]; then
1880 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1881 echo ${NDEBUG} "files... "
1882 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1883 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1887 if ! [ -f ${Y}.gz ]; then
1891 if [ `gunzip -c < ${Y}.gz |
1892 ${SHA256} -q` = ${Y} ]; then
1893 mv ${Y}.gz files/${Y}.gz
1895 echo "${Y} has incorrect hash."
1903 rm files.wanted filelist patchlist
1906 # Create and populate install manifest directory; and report what updates
1908 fetch_create_manifest () {
1909 # If we have an existing install manifest, nuke it.
1910 if [ -L "${BDHASH}-install" ]; then
1911 rm -r ${BDHASH}-install/
1912 rm ${BDHASH}-install
1915 # Report to the user if any updates were avoided due to local changes
1916 if [ -s modifiedfiles ]; then
1918 echo -n "The following files are affected by updates, "
1919 echo "but no changes have"
1920 echo -n "been downloaded because the files have been "
1921 echo "modified locally:"
1926 # If no files will be updated, tell the user and exit
1927 if ! [ -s INDEX-PRESENT ] &&
1928 ! [ -s INDEX-NEW ]; then
1929 rm INDEX-PRESENT INDEX-NEW
1931 echo -n "No updates needed to update system to "
1932 echo "${RELNUM}-p${RELPATCHNUM}."
1936 # Divide files into (a) removed files, (b) added files, and
1937 # (c) updated files.
1938 cut -f 1 -d '|' < INDEX-PRESENT |
1939 sort > INDEX-PRESENT.flist
1940 cut -f 1 -d '|' < INDEX-NEW |
1941 sort > INDEX-NEW.flist
1942 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1943 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
1944 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
1945 rm INDEX-PRESENT.flist INDEX-NEW.flist
1947 # Report removed files, if any
1948 if [ -s files.removed ]; then
1950 echo -n "The following files will be removed "
1951 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1956 # Report added files, if any
1957 if [ -s files.added ]; then
1959 echo -n "The following files will be added "
1960 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1965 # Report updated files, if any
1966 if [ -s files.updated ]; then
1968 echo -n "The following files will be updated "
1969 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1975 # Create a directory for the install manifest.
1976 MDIR=`mktemp -d install.XXXXXX` || return 1
1979 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
1980 mv INDEX-NEW ${MDIR}/INDEX-NEW
1982 # Link it into place
1983 ln -s ${MDIR} ${BDHASH}-install
1986 # Warn about any upcoming EoL
1988 # What's the current time?
1989 NOWTIME=`date "+%s"`
1991 # When did we last warn about the EoL date?
1992 if [ -f lasteolwarn ]; then
1993 LASTWARN=`cat lasteolwarn`
1995 LASTWARN=`expr ${NOWTIME} - 63072000`
1998 # If the EoL time is past, warn.
1999 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
2002 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
2003 Any security issues discovered after `date -r ${EOLTIME}`
2004 will not have been corrected.
2009 # Figure out how long it has been since we last warned about the
2010 # upcoming EoL, and how much longer we have left.
2011 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
2012 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
2014 # Don't warn if the EoL is more than 3 months away
2015 if [ ${TIMELEFT} -gt 7884000 ]; then
2019 # Don't warn if the time remaining is more than 3 times the time
2020 # since the last warning.
2021 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
2025 # Figure out what time units to use.
2026 if [ ${TIMELEFT} -lt 604800 ]; then
2029 elif [ ${TIMELEFT} -lt 2678400 ]; then
2037 # Compute the right number of units
2038 NUM=`expr ${TIMELEFT} / ${SIZE}`
2039 if [ ${NUM} != 1 ]; then
2046 WARNING: `uname -sr` is approaching its End-of-Life date.
2047 It is strongly recommended that you upgrade to a newer
2048 release within the next ${NUM} ${UNIT}.
2051 # Update the stored time of last warning
2052 echo ${NOWTIME} > lasteolwarn
2055 # Do the actual work involved in "fetch" / "cron".
2057 workdir_init || return 1
2059 # Prepare the mirror list.
2060 fetch_pick_server_init && fetch_pick_server
2062 # Try to fetch the public key until we run out of servers.
2063 while ! fetch_key; do
2064 fetch_pick_server || return 1
2067 # Try to fetch the metadata index signature ("tag") until we run
2068 # out of available servers; and sanity check the downloaded tag.
2069 while ! fetch_tag; do
2070 fetch_pick_server || return 1
2072 fetch_tagsanity || return 1
2074 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2075 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2077 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2078 # the lines which (a) belong to components we care about, and (b)
2079 # don't correspond to paths we're explicitly ignoring.
2080 fetch_filter_metadata INDEX-NEW || return 1
2081 fetch_filter_metadata INDEX-OLD || return 1
2083 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2084 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2085 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2087 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2088 # system and generate an INDEX-PRESENT file.
2089 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2091 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2092 # correspond to lines in INDEX-PRESENT with hashes not appearing
2093 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2094 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2095 # INDEX-OLD with type -.
2096 fetch_filter_unmodified_notpresent \
2097 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2099 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2100 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2101 # of type - from INDEX-PRESENT.
2102 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2104 # If ${ALLOWDELETE} != "yes", then remove any entries from
2105 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2106 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2108 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2109 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2110 # replace the corresponding line of INDEX-NEW with one having the
2111 # same metadata as the entry in INDEX-PRESENT.
2112 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2114 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2115 # no need to update a file if it isn't changing.
2116 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2118 # Prepare to fetch files: Generate a list of the files we need,
2119 # copy the unmodified files we have into /files/, and generate
2120 # a list of patches to download.
2121 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2124 fetch_files || return 1
2126 # Create and populate install manifest directory; and report what
2127 # updates are available.
2128 fetch_create_manifest || return 1
2130 # Warn about any upcoming EoL
2131 fetch_warn_eol || return 1
2134 # If StrictComponents is not "yes", generate a new components list
2135 # with only the components which appear to be installed.
2136 upgrade_guess_components () {
2137 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2138 # Generate filtered INDEX-ALL with only the components listed
2140 fetch_filter_metadata_components $1 || return 1
2142 # Tell the user why his disk is suddenly making lots of noise
2143 echo -n "Inspecting system... "
2145 # Look at the files on disk, and assume that a component is
2146 # supposed to be present if it is more than half-present.
2147 cut -f 1-3 -d '|' < INDEX-ALL |
2149 while read C S F; do
2150 if [ -e ${BASEDIR}/${F} ]; then
2157 sed -E 's,^ +,,' > compfreq
2158 grep ' = ' compfreq |
2160 sort -k 2,2 -t ' ' > compfreq.total
2161 grep ' + ' compfreq |
2163 sort -k 2,2 -t ' ' > compfreq.present
2164 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2165 while read S P T; do
2166 if [ ${P} -gt `expr ${T} / 2` ]; then
2170 cut -f 2 -d ' ' < compfreq.total > comp.total
2171 rm INDEX-ALL compfreq compfreq.total compfreq.present
2173 # We're done making noise.
2176 # Sometimes the kernel isn't installed where INDEX-ALL
2177 # thinks that it should be: In particular, it is often in
2178 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2179 # deal with this, if "kernel|X" is listed in comp.total
2180 # (i.e., is a component which would be upgraded if it is
2181 # found to be present) we will add it to comp.present.
2182 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2183 # not, we print a warning -- the user is running a kernel
2184 # which isn't part of the release.
2185 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2186 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2188 if grep -qE "^kernel\|" comp.total &&
2189 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2192 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2193 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2194 This kernel will not be updated: you MUST update the kernel manually
2195 before running "$0 install".
2199 # Re-sort the list of installed components and generate
2200 # the list of non-installed components.
2201 sort -u < comp.present > comp.present.tmp
2202 mv comp.present.tmp comp.present
2203 comm -13 comp.present comp.total > comp.absent
2205 # Ask the user to confirm that what we have is correct. To
2206 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2207 # subcomponents must be listed in the configuration file).
2209 echo -n "The following components of FreeBSD "
2210 echo "seem to be installed:"
2211 tr '|' '/' < comp.present |
2214 echo -n "The following components of FreeBSD "
2215 echo "do not seem to be installed:"
2216 tr '|' '/' < comp.absent |
2219 continuep || return 1
2222 # Suck the generated list of components into ${COMPONENTS}.
2223 # Note that comp.present.tmp is used due to issues with
2224 # pipelines and setting variables.
2226 tr '|' '/' < comp.present > comp.present.tmp
2228 COMPONENTS="${COMPONENTS} ${C}"
2229 done < comp.present.tmp
2231 # Delete temporary files
2232 rm comp.present comp.present.tmp comp.absent comp.total
2236 # If StrictComponents is not "yes", COMPONENTS contains an entry
2237 # corresponding to the currently running kernel, and said kernel
2238 # does not exist in the new release, add "kernel/generic" to the
2239 # list of components.
2240 upgrade_guess_new_kernel () {
2241 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2242 # Grab the unfiltered metadata file.
2243 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2244 gunzip -c < files/${METAHASH}.gz > $1.all
2246 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2247 # isn't in $1.all, we need to add kernel/generic.
2248 for C in ${COMPONENTS}; do
2249 if [ ${C} = "kernel/${KCOMP}" ] &&
2250 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2251 COMPONENTS="${COMPONENTS} kernel/generic"
2255 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2256 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2257 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2258 replaced with a "generic" kernel.
2260 continuep || return 1
2264 # Don't need this any more...
2269 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2270 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2271 upgrade_oldall_to_oldnew () {
2272 # For each ${F}|... which appears in INDEX-ALL but does not appear
2273 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2274 cut -f 1 -d '|' < $1 |
2276 cut -f 1 -d '|' < $2 |
2278 comm -13 $1.paths - |
2279 lam - -s "|-||||||" |
2283 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2284 comm -23 $1 $2 > $1.tmp
2287 # Remove lines from INDEX-ALL which have a file name not appearing
2288 # anywhere in INDEX-OLD (since these must be files which haven't
2289 # changed -- if they were new, there would be an entry of type "-").
2290 cut -f 1 -d '|' < $1 |
2292 sort -k 1,1 -t '|' < $2 |
2293 join -t '|' - $1.paths |
2298 # Rename INDEX-ALL to INDEX-NEW.
2302 # Helper for upgrade_merge: Return zero true iff the two files differ only
2303 # in the contents of their RCS tags.
2305 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2306 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2308 if [ $X = $Y ]; then
2315 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2316 # and update $3 to reflect the hashes of merged files.
2318 # We only need to do anything if $1 is non-empty.
2320 cut -f 1 -d '|' $1 |
2323 # Create staging area for merging files
2327 mkdir -p merge/old/${D}
2328 mkdir -p merge/${OLDRELNUM}/${D}
2329 mkdir -p merge/${RELNUM}/${D}
2330 mkdir -p merge/new/${D}
2335 # Currently installed file
2336 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2337 gunzip < files/${V}.gz > merge/old/${F}
2340 if look "${F}|" $1 | fgrep -q "|f|"; then
2341 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2342 gunzip < files/${V}.gz \
2343 > merge/${OLDRELNUM}/${F}
2347 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2348 fgrep -q "|f|"; then
2349 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2350 gunzip < files/${V}.gz \
2351 > merge/${RELNUM}/${F}
2355 # Attempt to automatically merge changes
2356 echo -n "Attempting to automatically merge "
2357 echo -n "changes in files..."
2360 # If the file doesn't exist in the new release,
2361 # the result of "merging changes" is having the file
2363 if ! [ -f merge/${RELNUM}/${F} ]; then
2367 # If the file didn't exist in the old release, we're
2368 # going to throw away the existing file and hope that
2369 # the version from the new release is what we want.
2370 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2371 cp merge/${RELNUM}/${F} merge/new/${F}
2375 # Some files need special treatment.
2377 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2378 # Don't merge these -- we're rebuild them
2379 # after updates are installed.
2380 cp merge/old/${F} merge/new/${F}
2383 if ! merge -p -L "current version" \
2384 -L "${OLDRELNUM}" -L "${RELNUM}" \
2386 merge/${OLDRELNUM}/${F} \
2387 merge/${RELNUM}/${F} \
2388 > merge/new/${F} 2>/dev/null; then
2389 echo ${F} >> failed.merges
2396 # Ask the user to handle any files which didn't merge.
2398 # If the installed file differs from the version in
2399 # the old release only due to RCS tag expansion
2400 # then just use the version in the new release.
2401 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2402 cp merge/${RELNUM}/${F} merge/new/${F}
2408 The following file could not be merged automatically: ${F}
2409 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2412 read dummy </dev/tty
2413 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2414 done < failed.merges
2417 # Ask the user to confirm that he likes how the result
2420 # Skip files which haven't changed except possibly
2421 # in their RCS tags.
2422 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2423 samef merge/old/${F} merge/new/${F}; then
2427 # Skip files where the installed file differs from
2428 # the old file only due to RCS tags.
2429 if [ -f merge/old/${F} ] &&
2430 [ -f merge/${OLDRELNUM}/${F} ] &&
2431 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2435 # Warn about files which are ceasing to exist.
2436 if ! [ -f merge/new/${F} ]; then
2439 The following file will be removed, as it no longer exists in
2440 FreeBSD ${RELNUM}: ${F}
2442 continuep < /dev/tty || return 1
2446 # Print changes for the user's approval.
2449 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2450 FreeBSD ${RELNUM} have been merged into ${F}:
2452 diff -U 5 -L "current version" -L "new version" \
2453 merge/old/${F} merge/new/${F} || true
2454 continuep < /dev/tty || return 1
2457 # Store merged files.
2459 if [ -f merge/new/${F} ]; then
2460 V=`${SHA256} -q merge/new/${F}`
2462 gzip -c < merge/new/${F} > files/${V}.gz
2465 done < $1-paths > newhashes
2467 # Pull lines out from $3 which need to be updated to
2468 # reflect merged files.
2471 done < $1-paths > $3-oldlines
2473 # Update lines to reflect merged files
2474 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2475 $3-oldlines newhashes > $3-newlines
2477 # Remove old lines from $3 and add new lines.
2480 sort - $3-newlines > $3.tmp
2484 rm $1-paths newhashes $3-oldlines $3-newlines
2488 # We're done with merging files.
2492 # Do the work involved in fetching upgrades to a new release
2494 workdir_init || return 1
2496 # Prepare the mirror list.
2497 fetch_pick_server_init && fetch_pick_server
2499 # Try to fetch the public key until we run out of servers.
2500 while ! fetch_key; do
2501 fetch_pick_server || return 1
2504 # Try to fetch the metadata index signature ("tag") until we run
2505 # out of available servers; and sanity check the downloaded tag.
2506 while ! fetch_tag; do
2507 fetch_pick_server || return 1
2509 fetch_tagsanity || return 1
2511 # Fetch the INDEX-OLD and INDEX-ALL.
2512 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2514 # If StrictComponents is not "yes", generate a new components list
2515 # with only the components which appear to be installed.
2516 upgrade_guess_components INDEX-ALL || return 1
2518 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2519 # the components we want and without anything marked as "Ignore".
2520 fetch_filter_metadata INDEX-OLD || return 1
2521 fetch_filter_metadata INDEX-ALL || return 1
2523 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2524 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2525 mv INDEX-OLD.tmp INDEX-OLD
2528 # Adjust variables for fetching files from the new release.
2530 RELNUM=${TARGETRELEASE}
2531 OLDFETCHDIR=${FETCHDIR}
2532 FETCHDIR=${RELNUM}/${ARCH}
2534 # Try to fetch the NEW metadata index signature ("tag") until we run
2535 # out of available servers; and sanity check the downloaded tag.
2536 while ! fetch_tag; do
2537 fetch_pick_server || return 1
2540 # Fetch the new INDEX-ALL.
2541 fetch_metadata INDEX-ALL || return 1
2543 # If StrictComponents is not "yes", COMPONENTS contains an entry
2544 # corresponding to the currently running kernel, and said kernel
2545 # does not exist in the new release, add "kernel/generic" to the
2546 # list of components.
2547 upgrade_guess_new_kernel INDEX-ALL || return 1
2549 # Filter INDEX-ALL to contain only the components we want and without
2550 # anything marked as "Ignore".
2551 fetch_filter_metadata INDEX-ALL || return 1
2553 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2554 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2555 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2557 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2558 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2559 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2561 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2562 # system and generate an INDEX-PRESENT file.
2563 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2565 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2566 # paths and hashes of old versions of files to merge.
2567 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2569 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2570 # correspond to lines in INDEX-PRESENT with hashes not appearing
2571 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2572 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2573 # INDEX-OLD with type -.
2574 fetch_filter_unmodified_notpresent \
2575 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2577 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2578 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2579 # of type - from INDEX-PRESENT.
2580 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2582 # If ${ALLOWDELETE} != "yes", then remove any entries from
2583 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2584 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2586 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2587 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2588 # replace the corresponding line of INDEX-NEW with one having the
2589 # same metadata as the entry in INDEX-PRESENT.
2590 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2592 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2593 # no need to update a file if it isn't changing.
2594 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2596 # Fetch "clean" files from the old release for merging changes.
2597 fetch_files_premerge tomerge-old
2599 # Prepare to fetch files: Generate a list of the files we need,
2600 # copy the unmodified files we have into /files/, and generate
2601 # a list of patches to download.
2602 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2604 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2605 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2606 fetch_files || return 1
2608 # Merge configuration file changes.
2609 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2611 # Create and populate install manifest directory; and report what
2612 # updates are available.
2613 fetch_create_manifest || return 1
2615 # Leave a note behind to tell the "install" command that the kernel
2616 # needs to be installed before the world.
2617 touch ${BDHASH}-install/kernelfirst
2619 # Remind the user that they need to run "freebsd-update install"
2620 # to install the downloaded bits, in case they didn't RTFM.
2621 echo "To install the downloaded upgrades, run \"$0 install\"."
2624 # Make sure that all the file hashes mentioned in $@ have corresponding
2625 # gzipped files stored in /files/.
2627 # Generate a list of hashes
2634 # Make sure all the hashes exist
2636 if ! [ -f files/${HASH}.gz ]; then
2637 echo -n "Update files missing -- "
2638 echo "this should never happen."
2639 echo "Re-run '$0 fetch'."
2648 # Remove the system immutable flag from files
2650 # Generate file list
2652 cut -f 1 -d '|' > filelist
2656 if ! [ -e ${BASEDIR}/${F} ]; then
2659 echo ${BASEDIR}/${F}
2661 done < filelist | xargs chflags noschg || return 1
2667 # Decide which directory name to use for kernel backups.
2668 backup_kernel_finddir () {
2671 # Pathname does not exist, so it is OK use that name
2672 # for backup directory.
2673 if [ ! -e $BASEDIR/$BACKUPKERNELDIR ]; then
2677 # If directory do exist, we only use if it has our
2679 if [ -d $BASEDIR/$BACKUPKERNELDIR -a \
2680 -e $BASEDIR/$BACKUPKERNELDIR/.freebsd-update ]; then
2684 # We could not use current directory name, so add counter to
2685 # the end and try again.
2687 if [ $CNT -gt 9 ]; then
2688 echo "Could not find valid backup dir ($BASEDIR/$BACKUPKERNELDIR)"
2691 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2692 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2696 # Backup the current kernel using hardlinks, if not disabled by user.
2697 # Since we delete all files in the directory used for previous backups
2698 # we create a marker file called ".freebsd-update" in the directory so
2699 # we can determine on the next run that the directory was created by
2700 # freebsd-update and we then do not accidentally remove user files in
2701 # the unlikely case that the user has created a directory with a
2704 # Only make kernel backup is so configured.
2705 if [ $BACKUPKERNEL != yes ]; then
2709 # Decide which directory name to use for kernel backups.
2710 backup_kernel_finddir
2712 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2713 # "not ours", backup_kernel_finddir would have exited, so
2714 # deleting the directory content is as safe as we can make it.
2715 if [ -d $BASEDIR/$BACKUPKERNELDIR ]; then
2716 rm -fr $BASEDIR/$BACKUPKERNELDIR
2719 # Create directories for backup.
2720 mkdir -p $BASEDIR/$BACKUPKERNELDIR
2721 mtree -cdn -p "${BASEDIR}/${KERNELDIR}" | \
2722 mtree -Ue -p "${BASEDIR}/${BACKUPKERNELDIR}" > /dev/null
2724 # Mark the directory as having been created by freebsd-update.
2725 touch $BASEDIR/$BACKUPKERNELDIR/.freebsd-update
2726 if [ $? -ne 0 ]; then
2727 echo "Could not create kernel backup directory"
2731 # Disable pathname expansion to be sure *.symbols is not
2735 # Use find to ignore symbol files, unless disabled by user.
2736 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2739 FINDFILTER=-"a ! -name *.symbols"
2742 # Backup all the kernel files using hardlinks.
2743 (cd ${BASEDIR}/${KERNELDIR} && find . -type f $FINDFILTER -exec \
2744 cp -pl '{}' ${BASEDIR}/${BACKUPKERNELDIR}/'{}' \;)
2746 # Re-enable patchname expansion.
2751 install_from_index () {
2752 # First pass: Do everything apart from setting file flags. We
2753 # can't set flags yet, because schg inhibits hard linking.
2754 sort -k 1,1 -t '|' $1 |
2756 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2759 # Create a directory
2760 install -d -o ${OWNER} -g ${GROUP} \
2761 -m ${PERM} ${BASEDIR}/${FPATH}
2764 if [ -z "${LINK}" ]; then
2765 # Create a file, without setting flags.
2766 gunzip < files/${HASH}.gz > ${HASH}
2767 install -S -o ${OWNER} -g ${GROUP} \
2768 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2771 # Create a hard link.
2772 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2777 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2782 # Perform a second pass, adding file flags.
2784 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2785 if [ ${TYPE} = "f" ] &&
2786 ! [ ${FLAGS} = "0" ]; then
2787 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2792 # Remove files which we want to delete
2794 # Generate list of new files
2795 cut -f 1 -d '|' < $2 |
2798 # Generate subindex of old files we want to nuke
2799 sort -k 1,1 -t '|' $1 |
2800 join -t '|' -v 1 - newfiles |
2801 sort -r -k 1,1 -t '|' |
2803 tr '|' ' ' > killfiles
2805 # Remove the offending bits
2806 while read FPATH TYPE; do
2809 rmdir ${BASEDIR}/${FPATH}
2812 rm ${BASEDIR}/${FPATH}
2815 rm ${BASEDIR}/${FPATH}
2821 rm newfiles killfiles
2824 # Install new files, delete old files, and update linker.hints
2826 # If we haven't already dealt with the kernel, deal with it.
2827 if ! [ -f $1/kerneldone ]; then
2828 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2829 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2831 # Backup current kernel before installing a new one
2832 backup_kernel || return 1
2835 install_from_index INDEX-NEW || return 1
2837 # Remove files which need to be deleted
2838 install_delete INDEX-OLD INDEX-NEW || return 1
2840 # Update linker.hints if necessary
2841 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2842 kldxref -R ${BASEDIR}/boot/ 2>/dev/null
2845 # We've finished updating the kernel.
2848 # Do we need to ask for a reboot now?
2849 if [ -f $1/kernelfirst ] &&
2850 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2853 Kernel updates have been installed. Please reboot and run
2854 "$0 install" again to finish installing updates.
2860 # If we haven't already dealt with the world, deal with it.
2861 if ! [ -f $1/worlddone ]; then
2862 # Create any necessary directories first
2863 grep -vE '^/boot/' $1/INDEX-NEW |
2864 grep -E '^[^|]+\|d\|' > INDEX-NEW
2865 install_from_index INDEX-NEW || return 1
2867 # Install new runtime linker
2868 grep -vE '^/boot/' $1/INDEX-NEW |
2869 grep -vE '^[^|]+\|d\|' |
2870 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2871 install_from_index INDEX-NEW || return 1
2873 # Install new shared libraries next
2874 grep -vE '^/boot/' $1/INDEX-NEW |
2875 grep -vE '^[^|]+\|d\|' |
2876 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2877 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2878 install_from_index INDEX-NEW || return 1
2880 # Deal with everything else
2881 grep -vE '^/boot/' $1/INDEX-OLD |
2882 grep -vE '^[^|]+\|d\|' |
2883 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2884 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2885 grep -vE '^/boot/' $1/INDEX-NEW |
2886 grep -vE '^[^|]+\|d\|' |
2887 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2888 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2889 install_from_index INDEX-NEW || return 1
2890 install_delete INDEX-OLD INDEX-NEW || return 1
2892 # Rebuild /etc/spwd.db and /etc/pwd.db if necessary.
2893 if [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/spwd.db ] ||
2894 [ ${BASEDIR}/etc/master.passwd -nt ${BASEDIR}/etc/pwd.db ]; then
2895 pwd_mkdb -d ${BASEDIR}/etc ${BASEDIR}/etc/master.passwd
2898 # Rebuild /etc/login.conf.db if necessary.
2899 if [ ${BASEDIR}/etc/login.conf -nt ${BASEDIR}/etc/login.conf.db ]; then
2900 cap_mkdb ${BASEDIR}/etc/login.conf
2903 # We've finished installing the world and deleting old files
2904 # which are not shared libraries.
2907 # Do we need to ask the user to portupgrade now?
2908 grep -vE '^/boot/' $1/INDEX-NEW |
2909 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2912 if grep -vE '^/boot/' $1/INDEX-OLD |
2913 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2916 join -v 1 - newfiles |
2920 Completing this upgrade requires removing old shared object files.
2921 Please rebuild all installed 3rd party software (e.g., programs
2922 installed from the ports tree) and then run "$0 install"
2923 again to finish installing updates.
2931 # Remove old shared libraries
2932 grep -vE '^/boot/' $1/INDEX-NEW |
2933 grep -vE '^[^|]+\|d\|' |
2934 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2935 grep -vE '^/boot/' $1/INDEX-OLD |
2936 grep -vE '^[^|]+\|d\|' |
2937 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2938 install_delete INDEX-OLD INDEX-NEW || return 1
2940 # Remove old directories
2941 grep -vE '^/boot/' $1/INDEX-NEW |
2942 grep -E '^[^|]+\|d\|' > INDEX-NEW
2943 grep -vE '^/boot/' $1/INDEX-OLD |
2944 grep -E '^[^|]+\|d\|' > INDEX-OLD
2945 install_delete INDEX-OLD INDEX-NEW || return 1
2947 # Remove temporary files
2948 rm INDEX-OLD INDEX-NEW
2951 # Rearrange bits to allow the installed updates to be rolled back
2952 install_setup_rollback () {
2953 # Remove the "reboot after installing kernel", "kernel updated", and
2954 # "finished installing the world" flags if present -- they are
2955 # irrelevant when rolling back updates.
2956 if [ -f ${BDHASH}-install/kernelfirst ]; then
2957 rm ${BDHASH}-install/kernelfirst
2958 rm ${BDHASH}-install/kerneldone
2960 if [ -f ${BDHASH}-install/worlddone ]; then
2961 rm ${BDHASH}-install/worlddone
2964 if [ -L ${BDHASH}-rollback ]; then
2965 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
2968 mv ${BDHASH}-install ${BDHASH}-rollback
2971 # Actually install updates
2973 echo -n "Installing updates..."
2975 # Make sure we have all the files we should have
2976 install_verify ${BDHASH}-install/INDEX-OLD \
2977 ${BDHASH}-install/INDEX-NEW || return 1
2979 # Remove system immutable flag from files
2980 install_unschg ${BDHASH}-install/INDEX-OLD \
2981 ${BDHASH}-install/INDEX-NEW || return 1
2983 # Install new files, delete old files, and update linker.hints
2984 install_files ${BDHASH}-install || return 1
2986 # Rearrange bits to allow the installed updates to be rolled back
2987 install_setup_rollback
2992 # Rearrange bits to allow the previous set of updates to be rolled back next.
2993 rollback_setup_rollback () {
2994 if [ -L ${BDHASH}-rollback/rollback ]; then
2995 mv ${BDHASH}-rollback/rollback rollback-tmp
2996 rm -r ${BDHASH}-rollback/
2997 rm ${BDHASH}-rollback
2998 mv rollback-tmp ${BDHASH}-rollback
3000 rm -r ${BDHASH}-rollback/
3001 rm ${BDHASH}-rollback
3005 # Install old files, delete new files, and update linker.hints
3007 # Install old shared library files which don't have the same path as
3008 # a new shared library file.
3009 grep -vE '^/boot/' $1/INDEX-NEW |
3010 grep -E '/lib/.*\.so\.[0-9]+\|' |
3012 sort > INDEX-NEW.libs.flist
3013 grep -vE '^/boot/' $1/INDEX-OLD |
3014 grep -E '/lib/.*\.so\.[0-9]+\|' |
3015 sort -k 1,1 -t '|' - |
3016 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
3017 install_from_index INDEX-OLD || return 1
3019 # Deal with files which are neither kernel nor shared library
3020 grep -vE '^/boot/' $1/INDEX-OLD |
3021 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3022 grep -vE '^/boot/' $1/INDEX-NEW |
3023 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3024 install_from_index INDEX-OLD || return 1
3025 install_delete INDEX-NEW INDEX-OLD || return 1
3027 # Install any old shared library files which we didn't install above.
3028 grep -vE '^/boot/' $1/INDEX-OLD |
3029 grep -E '/lib/.*\.so\.[0-9]+\|' |
3030 sort -k 1,1 -t '|' - |
3031 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
3032 install_from_index INDEX-OLD || return 1
3034 # Delete unneeded shared library files
3035 grep -vE '^/boot/' $1/INDEX-OLD |
3036 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
3037 grep -vE '^/boot/' $1/INDEX-NEW |
3038 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
3039 install_delete INDEX-NEW INDEX-OLD || return 1
3041 # Deal with kernel files
3042 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
3043 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3044 install_from_index INDEX-OLD || return 1
3045 install_delete INDEX-NEW INDEX-OLD || return 1
3046 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3047 kldxref -R /boot/ 2>/dev/null
3050 # Remove temporary files
3051 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3054 # Actually rollback updates
3056 echo -n "Uninstalling updates..."
3058 # If there are updates waiting to be installed, remove them; we
3059 # want the user to re-run 'fetch' after rolling back updates.
3060 if [ -L ${BDHASH}-install ]; then
3061 rm -r ${BDHASH}-install/
3062 rm ${BDHASH}-install
3065 # Make sure we have all the files we should have
3066 install_verify ${BDHASH}-rollback/INDEX-NEW \
3067 ${BDHASH}-rollback/INDEX-OLD || return 1
3069 # Remove system immutable flag from files
3070 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3071 ${BDHASH}-rollback/INDEX-OLD || return 1
3073 # Install old files, delete new files, and update linker.hints
3074 rollback_files ${BDHASH}-rollback || return 1
3076 # Remove the rollback directory and the symlink pointing to it; and
3077 # rearrange bits to allow the previous set of updates to be rolled
3079 rollback_setup_rollback
3084 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3086 # Get all the lines which mismatch in something other than file
3087 # flags. We ignore file flags because sysinstall doesn't seem to
3088 # set them when it installs FreeBSD; warning about these adds a
3089 # very large amount of noise.
3090 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3091 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3092 cut -f 1-5,7-8 -d '|' $2 |
3093 comm -13 $1.noflags - |
3094 fgrep -v '|-|||||' |
3095 sort -k 1,1 -t '|' |
3096 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3098 # Ignore files which match IDSIGNOREPATHS.
3099 for X in ${IDSIGNOREPATHS}; do
3100 grep -E "^${X}" INDEX-NOTMATCHING
3103 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3104 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3106 # Go through the lines and print warnings.
3108 while read FPATH TYPE OWNER GROUP PERM HASH LINK P_TYPE P_OWNER P_GROUP P_PERM P_HASH P_LINK; do
3109 # Warn about different object types.
3110 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3111 echo -n "${FPATH} is a "
3113 f) echo -n "regular file, "
3115 d) echo -n "directory, "
3117 L) echo -n "symlink, "
3120 echo -n "but should be a "
3122 f) echo -n "regular file."
3124 d) echo -n "directory."
3126 L) echo -n "symlink."
3131 # Skip other tests, since they don't make sense if
3132 # we're comparing different object types.
3136 # Warn about different owners.
3137 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3138 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3139 echo "but should be owned by user id ${OWNER}."
3142 # Warn about different groups.
3143 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3144 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3145 echo "but should be owned by group id ${GROUP}."
3148 # Warn about different permissions. We do not warn about
3149 # different permissions on symlinks, since some archivers
3150 # don't extract symlink permissions correctly and they are
3152 if ! [ "${PERM}" = "${P_PERM}" ] &&
3153 ! [ "${TYPE}" = "L" ]; then
3154 echo -n "${FPATH} has ${P_PERM} permissions, "
3155 echo "but should have ${PERM} permissions."
3158 # Warn about different file hashes / symlink destinations.
3159 if ! [ "${HASH}" = "${P_HASH}" ]; then
3160 if [ "${TYPE}" = "L" ]; then
3161 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3162 echo "but should be a symlink to ${HASH}."
3164 if [ "${TYPE}" = "f" ]; then
3165 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3166 echo "but should have SHA256 hash ${HASH}."
3170 # We don't warn about different hard links, since some
3171 # some archivers break hard links, and as long as the
3172 # underlying data is correct they really don't matter.
3173 done < INDEX-NOTMATCHING
3176 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3179 # Do the work involved in comparing the system to a "known good" index
3181 workdir_init || return 1
3183 # Prepare the mirror list.
3184 fetch_pick_server_init && fetch_pick_server
3186 # Try to fetch the public key until we run out of servers.
3187 while ! fetch_key; do
3188 fetch_pick_server || return 1
3191 # Try to fetch the metadata index signature ("tag") until we run
3192 # out of available servers; and sanity check the downloaded tag.
3193 while ! fetch_tag; do
3194 fetch_pick_server || return 1
3196 fetch_tagsanity || return 1
3198 # Fetch INDEX-OLD and INDEX-ALL.
3199 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3201 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3202 # the components we want and without anything marked as "Ignore".
3203 fetch_filter_metadata INDEX-OLD || return 1
3204 fetch_filter_metadata INDEX-ALL || return 1
3206 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3207 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3208 mv INDEX-ALL.tmp INDEX-ALL
3211 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3212 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3214 # Inspect the system and generate an INDEX-PRESENT file.
3215 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3217 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3219 IDS_compare INDEX-ALL INDEX-PRESENT
3222 #### Main functions -- call parameter-handling and core functions
3224 # Using the command line, configuration file, and defaults,
3225 # set all the parameters which are needed later.
3233 # Fetch command. Make sure that we're being called
3234 # interactively, then run fetch_check_params and fetch_run
3236 if [ ! -t 0 -a $NOTTYOK -eq 0 ]; then
3237 echo -n "`basename $0` fetch should not "
3238 echo "be run non-interactively."
3239 echo "Run `basename $0` cron instead."
3246 # Cron command. Make sure the parameters are sensible; wait
3247 # rand(3600) seconds; then fetch updates. While fetching updates,
3248 # send output to a temporary file; only print that file if the
3252 sleep `jot -r 1 0 3600`
3254 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3255 if ! fetch_run >> ${TMPFILE} ||
3256 ! grep -q "No updates needed" ${TMPFILE} ||
3257 [ ${VERBOSELEVEL} = "debug" ]; then
3258 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3264 # Fetch files for upgrading to a new release.
3266 upgrade_check_params
3267 upgrade_run || exit 1
3270 # Install downloaded updates.
3272 install_check_params
3273 install_run || exit 1
3276 # Rollback most recently installed updates.
3278 rollback_check_params
3279 rollback_run || exit 1
3282 # Compare system against a "known good" index.
3290 # Make sure we find utilities from the base system
3291 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3293 # Set a pager if the user doesn't
3294 if [ -z "$PAGER" ]; then
3298 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3302 for COMMAND in ${COMMANDS}; do