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 -k KEY -- Trust an RSA key with SHA256 hash of KEY
47 -r release -- Target for upgrade (e.g., 6.2-RELEASE)
48 -s server -- Server from which to fetch updates
49 (default: update.FreeBSD.org)
50 -t address -- Mail output of cron command, if any, to address
53 fetch -- Fetch updates from server
54 cron -- Sleep rand(3600) seconds, fetch updates, and send an
55 email if updates were found
56 upgrade -- Fetch upgrades to FreeBSD version specified via -r option
57 install -- Install downloaded updates or upgrades
58 rollback -- Uninstall most recently installed updates
59 IDS -- Compare the system against an index of "known good" files.
64 #### Configuration processing functions
67 # Configuration options are set in the following order of priority:
68 # 1. Command line options
69 # 2. Configuration file options
71 # In addition, certain options (e.g., IgnorePaths) can be specified multiple
72 # times and (as long as these are all in the same place, e.g., inside the
73 # configuration file) they will accumulate. Finally, because the path to the
74 # configuration file can be specified at the command line, the entire command
75 # line must be processed before we start reading the configuration file.
77 # Sound like a mess? It is. Here's how we handle this:
78 # 1. Initialize CONFFILE and all the options to "".
79 # 2. Process the command line. Throw an error if a non-accumulating option
81 # 3. If CONFFILE is "", set CONFFILE to /etc/freebsd-update.conf .
82 # 4. For all the configuration options X, set X_saved to X.
83 # 5. Initialize all the options to "".
84 # 6. Read CONFFILE line by line, parsing options.
85 # 7. For each configuration option X, set X to X_saved iff X_saved is not "".
86 # 8. Repeat steps 4-7, except setting options to their default values at (6).
88 CONFIGOPTIONS="KEYPRINT WORKDIR SERVERNAME MAILTO ALLOWADD ALLOWDELETE
89 KEEPMODIFIEDMETADATA COMPONENTS IGNOREPATHS UPDATEIFUNMODIFIED
90 BASEDIR VERBOSELEVEL TARGETRELEASE STRICTCOMPONENTS MERGECHANGES
91 IDSIGNOREPATHS BACKUPKERNEL BACKUPKERNELDIR BACKUPKERNELSYMBOLFILES"
93 # Set all the configuration options to "".
95 for X in ${CONFIGOPTIONS}; do
100 # For each configuration option X, set X_saved to X.
102 for X in ${CONFIGOPTIONS}; do
103 eval ${X}_saved=\$${X}
107 # For each configuration option X, set X to X_saved if X_saved is not "".
109 for X in ${CONFIGOPTIONS}; do
111 if ! [ -z "${_}" ]; then
112 eval ${X}=\$${X}_saved
117 # Set the trusted keyprint.
119 if [ -z ${KEYPRINT} ]; then
126 # Set the working directory.
128 if [ -z ${WORKDIR} ]; then
135 # Set the name of the server (pool) from which to fetch updates
136 config_ServerName () {
137 if [ -z ${SERVERNAME} ]; then
144 # Set the address to which 'cron' output will be mailed.
146 if [ -z ${MAILTO} ]; then
153 # Set whether FreeBSD Update is allowed to add files (or directories, or
154 # symlinks) which did not previously exist.
156 if [ -z ${ALLOWADD} ]; then
173 # Set whether FreeBSD Update is allowed to remove files/directories/symlinks.
174 config_AllowDelete () {
175 if [ -z ${ALLOWDELETE} ]; then
192 # Set whether FreeBSD Update should keep existing inode ownership,
193 # permissions, and flags, in the event that they have been modified locally
195 config_KeepModifiedMetadata () {
196 if [ -z ${KEEPMODIFIEDMETADATA} ]; then
199 KEEPMODIFIEDMETADATA=yes
202 KEEPMODIFIEDMETADATA=no
213 # Add to the list of components which should be kept updated.
214 config_Components () {
216 COMPONENTS="${COMPONENTS} ${C}"
220 # Add to the list of paths under which updates will be ignored.
221 config_IgnorePaths () {
223 IGNOREPATHS="${IGNOREPATHS} ${C}"
227 # Add to the list of paths which IDS should ignore.
228 config_IDSIgnorePaths () {
230 IDSIGNOREPATHS="${IDSIGNOREPATHS} ${C}"
234 # Add to the list of paths within which updates will be performed only if the
235 # file on disk has not been modified locally.
236 config_UpdateIfUnmodified () {
238 UPDATEIFUNMODIFIED="${UPDATEIFUNMODIFIED} ${C}"
242 # Add to the list of paths within which updates to text files will be merged
243 # instead of overwritten.
244 config_MergeChanges () {
246 MERGECHANGES="${MERGECHANGES} ${C}"
250 # Work on a FreeBSD installation mounted under $1
252 if [ -z ${BASEDIR} ]; then
259 # When fetching upgrades, should we assume the user wants exactly the
260 # components listed in COMPONENTS, rather than trying to guess based on
261 # what's currently installed?
262 config_StrictComponents () {
263 if [ -z ${STRICTCOMPONENTS} ]; then
280 # Upgrade to FreeBSD $1
281 config_TargetRelease () {
282 if [ -z ${TARGETRELEASE} ]; then
287 if echo ${TARGETRELEASE} | grep -qE '^[0-9.]+$'; then
288 TARGETRELEASE="${TARGETRELEASE}-RELEASE"
292 # Define what happens to output of utilities
293 config_VerboseLevel () {
294 if [ -z ${VERBOSELEVEL} ]; then
296 [Dd][Ee][Bb][Uu][Gg])
299 [Nn][Oo][Ss][Tt][Aa][Tt][Ss])
302 [Ss][Tt][Aa][Tt][Ss])
314 config_BackupKernel () {
315 if [ -z ${BACKUPKERNEL} ]; then
332 config_BackupKernelDir () {
333 if [ -z ${BACKUPKERNELDIR} ]; then
335 echo "BackupKernelDir set to empty dir"
339 # We check for some paths which would be extremely odd
340 # to use, but which could cause a lot of problems if
343 /|/bin|/boot|/etc|/lib|/libexec|/sbin|/usr|/var)
344 echo "BackupKernelDir set to invalid path $1"
351 echo "BackupKernelDir ($1) is not an absolute path"
360 config_BackupKernelSymbolFiles () {
361 if [ -z ${BACKUPKERNELSYMBOLFILES} ]; then
364 BACKUPKERNELSYMBOLFILES=yes
367 BACKUPKERNELSYMBOLFILES=no
378 # Handle one line of configuration
380 if [ $# -eq 0 ]; then
389 #### Parameter handling functions.
391 # Initialize parameters to null, just in case they're
392 # set in the environment.
394 # Configration settings
397 # No configuration file set yet
400 # No commands specified yet
404 # Parse the command line
406 while [ $# -gt 0 ]; do
408 # Location of configuration file
410 if [ $# -eq 1 ]; then usage; fi
411 if [ ! -z "${CONFFILE}" ]; then usage; fi
415 # Configuration file equivalents
417 if [ $# -eq 1 ]; then usage; fi; shift
418 config_BaseDir $1 || usage
421 if [ $# -eq 1 ]; then usage; fi; shift
422 config_WorkDir $1 || usage
425 if [ $# -eq 1 ]; then usage; fi; shift
426 config_KeyPrint $1 || usage
429 if [ $# -eq 1 ]; then usage; fi; shift
430 config_ServerName $1 || usage
433 if [ $# -eq 1 ]; then usage; fi; shift
434 config_TargetRelease $1 || usage
437 if [ $# -eq 1 ]; then usage; fi; shift
438 config_MailTo $1 || usage
441 if [ $# -eq 1 ]; then usage; fi; shift
442 config_VerboseLevel $1 || usage
445 # Aliases for "-v debug" and "-v nostats"
447 config_VerboseLevel debug || usage
450 config_VerboseLevel nostats || usage
454 cron | fetch | upgrade | install | rollback | IDS)
455 COMMANDS="${COMMANDS} $1"
458 # Anything else is an error
466 # Make sure we have at least one command
467 if [ -z "${COMMANDS}" ]; then
472 # Parse the configuration file
474 # If a configuration file was specified on the command line, check
475 # that it exists and is readable.
476 if [ ! -z "${CONFFILE}" ] && [ ! -r "${CONFFILE}" ]; then
477 echo -n "File does not exist "
478 echo -n "or is not readable: "
483 # If a configuration file was not specified on the command line,
484 # use the default configuration file path. If that default does
485 # not exist, give up looking for any configuration.
486 if [ -z "${CONFFILE}" ]; then
487 CONFFILE="/etc/freebsd-update.conf"
488 if [ ! -r "${CONFFILE}" ]; then
493 # Save the configuration options specified on the command line, and
494 # clear all the options in preparation for reading the config file.
498 # Read the configuration file. Anything after the first '#' is
499 # ignored, and any blank lines are ignored.
503 LINEX=`echo "${LINE}" | cut -f 1 -d '#'`
504 if ! configline ${LINEX}; then
505 echo "Error processing configuration file, line $L:"
511 # Merge the settings read from the configuration file with those
512 # provided at the command line.
516 # Provide some default parameters
518 # Save any parameters already configured, and clear the slate
522 # Default configurations
523 config_WorkDir /var/db/freebsd-update
526 config_AllowDelete yes
527 config_KeepModifiedMetadata yes
529 config_VerboseLevel stats
530 config_StrictComponents no
531 config_BackupKernel yes
532 config_BackupKernelDir /boot/kernel.old
533 config_BackupKernelSymbolFiles no
535 # Merge these defaults into the earlier-configured settings
539 # Set utility output filtering options, based on ${VERBOSELEVEL}
540 fetch_setup_verboselevel () {
541 case ${VERBOSELEVEL} in
543 QUIETREDIR="/dev/stderr"
545 STATSREDIR="/dev/stderr"
553 STATSREDIR="/dev/null"
559 QUIETREDIR="/dev/null"
561 STATSREDIR="/dev/stdout"
569 # Perform sanity checks and set some final parameters
570 # in preparation for fetching files. Figure out which
571 # set of updates should be downloaded: If the user is
572 # running *-p[0-9]+, strip off the last part; if the
573 # user is running -SECURITY, call it -RELEASE. Chdir
574 # into the working directory.
575 fetchupgrade_check_params () {
576 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
579 "SERVERNAME must be given via command line or configuration file."
580 _KEYPRINT_z="Key must be given via -k option or configuration file."
581 _KEYPRINT_bad="Invalid key fingerprint: "
582 _WORKDIR_bad="Directory does not exist or is not writable: "
584 if [ -z "${SERVERNAME}" ]; then
585 echo -n "`basename $0`: "
586 echo "${_SERVERNAME_z}"
589 if [ -z "${KEYPRINT}" ]; then
590 echo -n "`basename $0`: "
591 echo "${_KEYPRINT_z}"
594 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
595 echo -n "`basename $0`: "
596 echo -n "${_KEYPRINT_bad}"
600 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
601 echo -n "`basename $0`: "
602 echo -n "${_WORKDIR_bad}"
607 cd ${WORKDIR} || exit 1
609 # Generate release number. The s/SECURITY/RELEASE/ bit exists
610 # to provide an upgrade path for FreeBSD Update 1.x users, since
611 # the kernels provided by FreeBSD Update 1.x are always labelled
614 sed -E 's,-p[0-9]+,,' |
615 sed -E 's,-SECURITY,-RELEASE,'`
617 FETCHDIR=${RELNUM}/${ARCH}
618 PATCHDIR=${RELNUM}/${ARCH}/bp
620 # Figure out what directory contains the running kernel
621 BOOTFILE=`sysctl -n kern.bootfile`
622 KERNELDIR=${BOOTFILE%/kernel}
623 if ! [ -d ${KERNELDIR} ]; then
624 echo "Cannot identify running kernel"
628 # Figure out what kernel configuration is running. We start with
629 # the output of `uname -i`, and then make the following adjustments:
630 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
631 # file says "ident SMP-GENERIC", I don't know...
632 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
633 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
634 # we're running an SMP kernel. This mis-identification is a bug
635 # which was fixed in 6.2-STABLE.
637 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
640 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
641 if sysctl kern.version | grep -qE '/SMP$'; then
647 BSPATCH=/usr/bin/bspatch
649 PHTTPGET=/usr/libexec/phttpget
651 # Set up variables relating to VERBOSELEVEL
652 fetch_setup_verboselevel
654 # Construct a unique name from ${BASEDIR}
655 BDHASH=`echo ${BASEDIR} | sha256 -q`
658 # Perform sanity checks etc. before fetching updates.
659 fetch_check_params () {
660 fetchupgrade_check_params
662 if ! [ -z "${TARGETRELEASE}" ]; then
663 echo -n "`basename $0`: "
664 echo -n "-r option is meaningless with 'fetch' command. "
665 echo "(Did you mean 'upgrade' instead?)"
670 # Perform sanity checks etc. before fetching upgrades.
671 upgrade_check_params () {
672 fetchupgrade_check_params
674 # Unless set otherwise, we're upgrading to the same kernel config.
675 NKERNCONF=${KERNCONF}
677 # We need TARGETRELEASE set
678 _TARGETRELEASE_z="Release target must be specified via -r option."
679 if [ -z "${TARGETRELEASE}" ]; then
680 echo -n "`basename $0`: "
681 echo "${_TARGETRELEASE_z}"
685 # The target release should be != the current release.
686 if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then
687 echo -n "`basename $0`: "
688 echo "Cannot upgrade from ${RELNUM} to itself"
692 # Turning off AllowAdd or AllowDelete is a bad idea for upgrades.
693 if [ "${ALLOWADD}" = "no" ]; then
694 echo -n "`basename $0`: "
695 echo -n "WARNING: \"AllowAdd no\" is a bad idea "
696 echo "when upgrading between releases."
699 if [ "${ALLOWDELETE}" = "no" ]; then
700 echo -n "`basename $0`: "
701 echo -n "WARNING: \"AllowDelete no\" is a bad idea "
702 echo "when upgrading between releases."
706 # Set EDITOR to /usr/bin/vi if it isn't already set
707 : ${EDITOR:='/usr/bin/vi'}
710 # Perform sanity checks and set some final parameters in
711 # preparation for installing updates.
712 install_check_params () {
713 # Check that we are root. All sorts of things won't work otherwise.
714 if [ `id -u` != 0 ]; then
715 echo "You must be root to run this."
719 # Check that securelevel <= 0. Otherwise we can't update schg files.
720 if [ `sysctl -n kern.securelevel` -gt 0 ]; then
721 echo "Updates cannot be installed when the system securelevel"
722 echo "is greater than zero."
726 # Check that we have a working directory
727 _WORKDIR_bad="Directory does not exist or is not writable: "
728 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
729 echo -n "`basename $0`: "
730 echo -n "${_WORKDIR_bad}"
734 cd ${WORKDIR} || exit 1
736 # Construct a unique name from ${BASEDIR}
737 BDHASH=`echo ${BASEDIR} | sha256 -q`
739 # Check that we have updates ready to install
740 if ! [ -L ${BDHASH}-install ]; then
741 echo "No updates are available to install."
742 echo "Run '$0 fetch' first."
745 if ! [ -f ${BDHASH}-install/INDEX-OLD ] ||
746 ! [ -f ${BDHASH}-install/INDEX-NEW ]; then
747 echo "Update manifest is corrupt -- this should never happen."
748 echo "Re-run '$0 fetch'."
752 # Figure out what directory contains the running kernel
753 BOOTFILE=`sysctl -n kern.bootfile`
754 KERNELDIR=${BOOTFILE%/kernel}
755 if ! [ -d ${KERNELDIR} ]; then
756 echo "Cannot identify running kernel"
761 # Perform sanity checks and set some final parameters in
762 # preparation for UNinstalling updates.
763 rollback_check_params () {
764 # Check that we are root. All sorts of things won't work otherwise.
765 if [ `id -u` != 0 ]; then
766 echo "You must be root to run this."
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 rollback
784 if ! [ -L ${BDHASH}-rollback ]; then
785 echo "No rollback directory found."
788 if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] ||
789 ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then
790 echo "Update manifest is corrupt -- this should never happen."
795 # Perform sanity checks and set some final parameters
796 # in preparation for comparing the system against the
797 # published index. Figure out which index we should
798 # compare against: If the user is running *-p[0-9]+,
799 # strip off the last part; if the user is running
800 # -SECURITY, call it -RELEASE. Chdir into the working
802 IDS_check_params () {
803 export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)"
806 "SERVERNAME must be given via command line or configuration file."
807 _KEYPRINT_z="Key must be given via -k option or configuration file."
808 _KEYPRINT_bad="Invalid key fingerprint: "
809 _WORKDIR_bad="Directory does not exist or is not writable: "
811 if [ -z "${SERVERNAME}" ]; then
812 echo -n "`basename $0`: "
813 echo "${_SERVERNAME_z}"
816 if [ -z "${KEYPRINT}" ]; then
817 echo -n "`basename $0`: "
818 echo "${_KEYPRINT_z}"
821 if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then
822 echo -n "`basename $0`: "
823 echo -n "${_KEYPRINT_bad}"
827 if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then
828 echo -n "`basename $0`: "
829 echo -n "${_WORKDIR_bad}"
833 cd ${WORKDIR} || exit 1
835 # Generate release number. The s/SECURITY/RELEASE/ bit exists
836 # to provide an upgrade path for FreeBSD Update 1.x users, since
837 # the kernels provided by FreeBSD Update 1.x are always labelled
840 sed -E 's,-p[0-9]+,,' |
841 sed -E 's,-SECURITY,-RELEASE,'`
843 FETCHDIR=${RELNUM}/${ARCH}
844 PATCHDIR=${RELNUM}/${ARCH}/bp
846 # Figure out what directory contains the running kernel
847 BOOTFILE=`sysctl -n kern.bootfile`
848 KERNELDIR=${BOOTFILE%/kernel}
849 if ! [ -d ${KERNELDIR} ]; then
850 echo "Cannot identify running kernel"
854 # Figure out what kernel configuration is running. We start with
855 # the output of `uname -i`, and then make the following adjustments:
856 # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config
857 # file says "ident SMP-GENERIC", I don't know...
858 # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64"
859 # _and_ `sysctl kern.version` contains a line which ends "/SMP", then
860 # we're running an SMP kernel. This mis-identification is a bug
861 # which was fixed in 6.2-STABLE.
863 if [ ${KERNCONF} = "SMP-GENERIC" ]; then
866 if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then
867 if sysctl kern.version | grep -qE '/SMP$'; then
874 PHTTPGET=/usr/libexec/phttpget
876 # Set up variables relating to VERBOSELEVEL
877 fetch_setup_verboselevel
880 #### Core functionality -- the actual work gets done here
882 # Use an SRV query to pick a server. If the SRV query doesn't provide
883 # a useful answer, use the server name specified by the user.
884 # Put another way... look up _http._tcp.${SERVERNAME} and pick a server
885 # from that; or if no servers are returned, use ${SERVERNAME}.
886 # This allows a user to specify "portsnap.freebsd.org" (in which case
887 # portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org"
888 # (in which case portsnap will use that particular server, since there
889 # won't be an SRV entry for that name).
891 # We ignore the Port field, since we are always going to use port 80.
893 # Fetch the mirror list, but do not pick a mirror yet. Returns 1 if
894 # no mirrors are available for any reason.
895 fetch_pick_server_init () {
898 # Check that host(1) exists (i.e., that the system wasn't built with the
899 # WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist.
900 if ! which -s host; then
905 echo -n "Looking up ${SERVERNAME} mirrors... "
907 # Issue the SRV query and pull out the Priority, Weight, and Target fields.
908 # BIND 9 prints "$name has SRV record ..." while BIND 8 prints
909 # "$name server selection ..."; we allow either format.
910 MLIST="_http._tcp.${SERVERNAME}"
911 host -t srv "${MLIST}" |
912 sed -nE "s/${MLIST} (has SRV record|server selection) //p" |
913 cut -f 1,2,4 -d ' ' |
915 sort > serverlist_full
917 # If no records, give up -- we'll just use the server name we were given.
918 if [ `wc -l < serverlist_full` -eq 0 ]; then
923 # Report how many mirrors we found.
924 echo `wc -l < serverlist_full` "mirrors found."
926 # Generate a random seed for use in picking mirrors. If HTTP_PROXY
927 # is set, this will be used to generate the seed; otherwise, the seed
929 if [ -n "${HTTP_PROXY}${http_proxy}" ]; then
930 RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" |
934 RANDVALUE=`jot -r 1 0 999999999`
938 # Pick a mirror. Returns 1 if we have run out of mirrors to try.
939 fetch_pick_server () {
940 # Generate a list of not-yet-tried mirrors
941 sort serverlist_tried |
942 comm -23 serverlist_full - > serverlist
944 # Have we run out of mirrors?
945 if [ `wc -l < serverlist` -eq 0 ]; then
946 echo "No mirrors remaining, giving up."
950 # Find the highest priority level (lowest numeric value).
951 SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1`
953 # Add up the weights of the response lines at that priority level.
958 SRV_W=`echo $X | cut -f 2 -d ' '`
959 SRV_WSUM=$(($SRV_WSUM + $SRV_W))
964 # If all the weights are 0, pretend that they are all 1 instead.
965 if [ ${SRV_WSUM} -eq 0 ]; then
966 SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l`
972 # Pick a value between 0 and the sum of the weights - 1
973 SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}`
975 # Read through the list of mirrors and set SERVERNAME. Write the line
976 # corresponding to the mirror we selected into serverlist_tried so that
977 # we won't try it again.
981 SRV_W=`echo $X | cut -f 2 -d ' '`
982 SRV_W=$(($SRV_W + $SRV_W_ADD))
983 if [ $SRV_RND -lt $SRV_W ]; then
984 SERVERNAME=`echo $X | cut -f 3 -d ' '`
985 echo "$X" >> serverlist_tried
988 SRV_RND=$(($SRV_RND - $SRV_W))
995 # Take a list of ${oldhash}|${newhash} and output a list of needed patches,
996 # i.e., those for which we have ${oldhash} and don't have ${newhash}.
997 fetch_make_patchlist () {
998 grep -vE "^([0-9a-f]{64})\|\1$" |
1001 if [ -f "files/${Y}.gz" ] ||
1002 [ ! -f "files/${X}.gz" ]; then
1009 # Print user-friendly progress statistics
1014 if [ $(($LNC % 10)) = 0 ]; then
1016 elif [ $(($LNC % 2)) = 0 ]; then
1023 # Function for asking the user if everything is ok
1025 while read -p "Does this look reasonable (y/n)? " CONTINUE; do
1026 case "${CONTINUE}" in
1037 # Initialize the working directory
1040 touch tINDEX.present
1043 # Check that we have a public key with an appropriate hash, or
1044 # fetch the key if it doesn't exist. Returns 1 if the key has
1045 # not yet been fetched.
1047 if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1051 echo -n "Fetching public key from ${SERVERNAME}... "
1053 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \
1054 2>${QUIETREDIR} || true
1055 if ! [ -r pub.ssl ]; then
1059 if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then
1060 echo "key has incorrect hash."
1067 # Fetch metadata signature, aka "tag".
1069 echo -n "Fetching metadata signature "
1070 echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... "
1072 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \
1073 2>${QUIETREDIR} || true
1074 if ! [ -r latest.ssl ]; then
1079 openssl rsautl -pubin -inkey pub.ssl -verify \
1080 < latest.ssl > tag.new 2>${QUIETREDIR} || true
1083 if ! [ `wc -l < tag.new` = 1 ] ||
1085 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1087 echo "invalid signature."
1093 RELPATCHNUM=`cut -f 4 -d '|' < tag.new`
1094 TINDEXHASH=`cut -f 5 -d '|' < tag.new`
1095 EOLTIME=`cut -f 6 -d '|' < tag.new`
1098 # Sanity-check the patch number in a tag, to make sure that we're not
1099 # going to "update" backwards and to prevent replay attacks.
1100 fetch_tagsanity () {
1101 # Check that we're not going to move from -pX to -pY with Y < X.
1102 RELPX=`uname -r | sed -E 's,.*-,,'`
1103 if echo ${RELPX} | grep -qE '^p[0-9]+$'; then
1104 RELPX=`echo ${RELPX} | cut -c 2-`
1108 if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then
1110 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1111 echo " appear older than what"
1112 echo "we are currently running (`uname -r`)!"
1113 echo "Cowardly refusing to proceed any further."
1117 # If "tag" exists and corresponds to ${RELNUM}, make sure that
1118 # it contains a patch number <= RELPATCHNUM, in order to protect
1119 # against rollback (replay) attacks.
1122 "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \
1124 LASTRELPATCHNUM=`cut -f 4 -d '|' < tag`
1126 if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then
1128 echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})"
1129 echo " are older than the"
1130 echo -n "most recently seen updates"
1131 echo " (${RELNUM}-p${LASTRELPATCHNUM})."
1132 echo "Cowardly refusing to proceed any further."
1138 # Fetch metadata index file
1139 fetch_metadata_index () {
1140 echo ${NDEBUG} "Fetching metadata index... "
1142 fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH}
1144 if ! [ -f ${TINDEXHASH} ]; then
1148 if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then
1149 echo "update metadata index corrupt."
1155 # Print an error message about signed metadata being bogus.
1156 fetch_metadata_bogus () {
1158 echo "The update metadata$1 is correctly signed, but"
1159 echo "failed an integrity check."
1160 echo "Cowardly refusing to proceed any further."
1164 # Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH}
1165 # with the lines not named in $@ from tINDEX.present (if that file exists).
1166 fetch_metadata_index_merge () {
1167 for METAFILE in $@; do
1168 if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \
1170 fetch_metadata_bogus " index"
1174 grep -E "${METAFILE}\|" ${TINDEXHASH}
1176 sort > tINDEX.wanted
1178 if [ -f tINDEX.present ]; then
1179 join -t '|' -v 2 tINDEX.wanted tINDEX.present |
1180 sort -m - tINDEX.wanted > tINDEX.new
1183 mv tINDEX.wanted tINDEX.new
1187 # Sanity check all the lines of tINDEX.new. Even if more metadata lines
1188 # are added by future versions of the server, this won't cause problems,
1189 # since the only lines which appear in tINDEX.new are the ones which we
1190 # specifically grepped out of ${TINDEXHASH}.
1191 fetch_metadata_index_sanity () {
1192 if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then
1193 fetch_metadata_bogus " index"
1198 # Sanity check the metadata file $1.
1199 fetch_metadata_sanity () {
1200 # Some aliases to save space later: ${P} is a character which can
1201 # appear in a path; ${M} is the four numeric metadata fields; and
1202 # ${H} is a sha256 hash.
1203 P="[-+./:=%@_[~[:alnum:]]"
1204 M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+"
1207 # Check that the first four fields make sense.
1208 if gunzip -c < files/$1.gz |
1209 grep -qvE "^[a-z]+\|[0-9a-z]+\|${P}+\|[fdL-]\|"; then
1210 fetch_metadata_bogus ""
1214 # Remove the first three fields.
1215 gunzip -c < files/$1.gz |
1216 cut -f 4- -d '|' > sanitycheck.tmp
1218 # Sanity check entries with type 'f'
1219 if grep -E '^f' sanitycheck.tmp |
1220 grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then
1221 fetch_metadata_bogus ""
1225 # Sanity check entries with type 'd'
1226 if grep -E '^d' sanitycheck.tmp |
1227 grep -qvE "^d\|${M}\|\|\$"; then
1228 fetch_metadata_bogus ""
1232 # Sanity check entries with type 'L'
1233 if grep -E '^L' sanitycheck.tmp |
1234 grep -qvE "^L\|${M}\|${P}*\|\$"; then
1235 fetch_metadata_bogus ""
1239 # Sanity check entries with type '-'
1240 if grep -E '^-' sanitycheck.tmp |
1241 grep -qvE "^-\|\|\|\|\|\|"; then
1242 fetch_metadata_bogus ""
1250 # Fetch the metadata index and metadata files listed in $@,
1251 # taking advantage of metadata patches where possible.
1253 fetch_metadata_index || return 1
1254 fetch_metadata_index_merge $@ || return 1
1255 fetch_metadata_index_sanity || return 1
1257 # Generate a list of wanted metadata patches
1258 join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new |
1259 fetch_make_patchlist > patchlist
1261 if [ -s patchlist ]; then
1262 # Attempt to fetch metadata patches
1263 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1264 echo ${NDEBUG} "metadata patches.${DDSTATS}"
1265 tr '|' '-' < patchlist |
1266 lam -s "${FETCHDIR}/tp/" - -s ".gz" |
1267 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1268 2>${STATSREDIR} | fetch_progress
1271 # Attempt to apply metadata patches
1272 echo -n "Applying metadata patches... "
1273 tr '|' ' ' < patchlist |
1275 if [ ! -f "${X}-${Y}.gz" ]; then continue; fi
1276 gunzip -c < ${X}-${Y}.gz > diff
1277 gunzip -c < files/${X}.gz > diff-OLD
1279 # Figure out which lines are being added and removed
1282 while read PREFIX; do
1283 look "${PREFIX}" diff-OLD
1286 grep -E '^\+' diff |
1287 cut -c 2- > diff-add
1289 # Generate the new file
1290 comm -23 diff-OLD diff-rm |
1291 sort - diff-add > diff-NEW
1293 if [ `${SHA256} -q diff-NEW` = ${Y} ]; then
1294 mv diff-NEW files/${Y}
1297 mv diff-NEW ${Y}.bad
1299 rm -f ${X}-${Y}.gz diff
1300 rm -f diff-OLD diff-NEW diff-add diff-rm
1301 done 2>${QUIETREDIR}
1305 # Update metadata without patches
1306 cut -f 2 -d '|' < tINDEX.new |
1308 if [ ! -f "files/${Y}.gz" ]; then
1314 if [ -s filelist ]; then
1315 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1316 echo ${NDEBUG} "metadata files... "
1317 lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist |
1318 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1322 if ! [ -f ${Y}.gz ]; then
1326 if [ `gunzip -c < ${Y}.gz |
1327 ${SHA256} -q` = ${Y} ]; then
1328 mv ${Y}.gz files/${Y}.gz
1330 echo "metadata is corrupt."
1337 # Sanity-check the metadata files.
1338 cut -f 2 -d '|' tINDEX.new > filelist
1340 fetch_metadata_sanity ${X} || return 1
1343 # Remove files which are no longer needed
1344 cut -f 2 -d '|' tINDEX.present |
1346 cut -f 2 -d '|' tINDEX.new |
1348 comm -13 - oldfiles |
1349 lam -s "files/" - -s ".gz" |
1351 rm patchlist filelist oldfiles
1355 mv tINDEX.new tINDEX.present
1361 # Extract a subset of a downloaded metadata file containing only the parts
1362 # which are listed in COMPONENTS.
1363 fetch_filter_metadata_components () {
1364 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
1365 gunzip -c < files/${METAHASH}.gz > $1.all
1367 # Fish out the lines belonging to components we care about.
1368 for C in ${COMPONENTS}; do
1369 look "`echo ${C} | tr '/' '|'`|" $1.all
1372 # Remove temporary file.
1376 # Generate a filtered version of the metadata file $1 from the downloaded
1377 # file, by fishing out the lines corresponding to components we're trying
1378 # to keep updated, and then removing lines corresponding to paths we want
1380 fetch_filter_metadata () {
1381 # Fish out the lines belonging to components we care about.
1382 fetch_filter_metadata_components $1
1384 # Canonicalize directory names by removing any trailing / in
1385 # order to avoid listing directories multiple times if they
1386 # belong to multiple components. Turning "/" into "" doesn't
1387 # matter, since we add a leading "/" when we use paths later.
1388 cut -f 3- -d '|' $1 |
1389 sed -e 's,/|d|,|d|,' |
1390 sed -e 's,/|-|,|-|,' |
1393 # Figure out which lines to ignore and remove them.
1394 for X in ${IGNOREPATHS}; do
1395 grep -E "^${X}" $1.tmp
1398 comm -13 - $1.tmp > $1
1400 # Remove temporary files.
1404 # Filter the metadata file $1 by adding lines with "/boot/$2"
1405 # replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the
1406 # trailing "/kernel"); and if "/boot/$2" does not exist, remove
1407 # the original lines which start with that.
1408 # Put another way: Deal with the fact that the FOO kernel is sometimes
1409 # installed in /boot/FOO/ and is sometimes installed elsewhere.
1410 fetch_filter_kernel_names () {
1412 sed -e "s,/boot/$2,${KERNELDIR},g" |
1416 if ! [ -d /boot/$2 ]; then
1417 grep -v ^/boot/$2 $1 > $1.tmp
1422 # For all paths appearing in $1 or $3, inspect the system
1423 # and generate $2 describing what is currently installed.
1424 fetch_inspect_system () {
1428 # Tell the user why his disk is suddenly making lots of noise
1429 echo -n "Inspecting system... "
1431 # Generate list of files to inspect
1436 # Examine each file and output lines of the form
1437 # /path/to/file|type|device-inum|user|group|perm|flags|value
1438 # sorted by device and inode number.
1440 # If the symlink/file/directory does not exist, record this.
1441 if ! [ -e ${BASEDIR}/${F} ]; then
1445 if ! [ -r ${BASEDIR}/${F} ]; then
1446 echo "Cannot read file: ${BASEDIR}/${F}" \
1452 # Otherwise, output an index line.
1453 if [ -L ${BASEDIR}/${F} ]; then
1455 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1456 readlink ${BASEDIR}/${F};
1457 elif [ -f ${BASEDIR}/${F} ]; then
1459 stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1460 sha256 -q ${BASEDIR}/${F};
1461 elif [ -d ${BASEDIR}/${F} ]; then
1463 stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F};
1465 echo "Unknown file type: ${BASEDIR}/${F}" \
1471 sort -k 3,3 -t '|' > $2.tmp
1474 # Check if an error occurred during system inspection
1475 if [ -f .err ]; then
1479 # Convert to the form
1480 # /path/to/file|type|user|group|perm|flags|value|hlink
1481 # by resolving identical device and inode numbers into hard links.
1482 cut -f 1,3 -d '|' $2.tmp |
1483 sort -k 1,1 -t '|' |
1484 sort -s -u -k 2,2 -t '|' |
1485 join -1 2 -2 3 -t '|' - $2.tmp |
1486 awk -F \| -v OFS=\| \
1488 if (($2 == $3) || ($4 == "-"))
1489 print $3,$4,$5,$6,$7,$8,$9,""
1491 print $3,$4,$5,$6,$7,$8,$9,$2
1496 # We're finished looking around
1500 # For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any
1501 # files which differ; generate $3 containing these paths and the old hashes.
1502 fetch_filter_mergechanges () {
1503 # Pull out the paths and hashes of the files matching ${MERGECHANGES}.
1505 for X in ${MERGECHANGES}; do
1506 grep -E "^${X}" ${F}
1508 cut -f 1,2,7 -d '|' |
1512 # Any line in $2-values which doesn't appear in $1-values and is a
1513 # file means that we should list the path in $3.
1514 comm -13 $1-values $2-values |
1516 cut -f 1 -d '|' > $2-paths
1518 # For each path, pull out one (and only one!) entry from $1-values.
1519 # Note that we cannot distinguish which "old" version the user made
1520 # changes to; but hopefully any changes which occur due to security
1521 # updates will exist in both the "new" version and the version which
1522 # the user has installed, so the merging will still work.
1524 look "${X}|" $1-values |
1526 done < $2-paths > $3
1529 rm $1-values $2-values $2-paths
1532 # For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123]
1533 # which correspond to lines in $2 with hashes not matching $1 or $3, unless
1534 # the paths are listed in $4. For entries in $2 marked "not present"
1535 # (aka. type -), remove lines from $[123] unless there is a corresponding
1537 fetch_filter_unmodified_notpresent () {
1538 # Figure out which lines of $1 and $3 correspond to bits which
1539 # should only be updated if they haven't changed, and fish out
1540 # the (path, type, value) tuples.
1541 # NOTE: We don't consider a file to be "modified" if it matches
1543 for X in ${UPDATEIFUNMODIFIED}; do
1547 cut -f 1,2,7 -d '|' |
1550 # Do the same for $2.
1551 for X in ${UPDATEIFUNMODIFIED}; do
1554 cut -f 1,2,7 -d '|' |
1557 # Any entry in $2-values which is not in $1-values corresponds to
1558 # a path which we need to remove from $1, $2, and $3, unless it
1559 # that path appears in $4.
1560 comm -13 $1-values $2-values |
1561 sort -t '|' -k 1,1 > mlines.tmp
1562 cut -f 1 -d '|' $4 |
1564 join -v 2 -t '|' - mlines.tmp |
1566 rm $1-values $2-values mlines.tmp
1568 # Any lines in $2 which are not in $1 AND are "not present" lines
1569 # also belong in mlines.
1571 cut -f 1,2,7 -d '|' |
1572 fgrep '|-|' >> mlines
1574 # Remove lines from $1, $2, and $3
1575 for X in $1 $2 $3; do
1576 sort -t '|' -k 1,1 ${X} > ${X}.tmp
1577 cut -f 1 -d '|' < mlines |
1579 join -v 2 -t '|' - ${X}.tmp |
1584 # Store a list of the modified files, for future reference
1585 fgrep -v '|-|' mlines |
1586 cut -f 1 -d '|' > modifiedfiles
1590 # For each entry in $1 of type -, remove any corresponding
1591 # entry from $2 if ${ALLOWADD} != "yes". Remove all entries
1592 # of type - from $1.
1593 fetch_filter_allowadd () {
1594 cut -f 1,2 -d '|' < $1 |
1596 cut -f 1 -d '|' > filesnotpresent
1598 if [ ${ALLOWADD} != "yes" ]; then
1600 join -v 1 -t '|' - filesnotpresent |
1606 join -v 1 -t '|' - filesnotpresent |
1612 # If ${ALLOWDELETE} != "yes", then remove any entries from $1
1613 # which don't correspond to entries in $2.
1614 fetch_filter_allowdelete () {
1615 # Produce a lists ${PATH}|${TYPE}
1617 cut -f 1-2 -d '|' < ${X} |
1618 sort -u > ${X}.nodes
1621 # Figure out which lines need to be removed from $1.
1622 if [ ${ALLOWDELETE} != "yes" ]; then
1623 comm -23 $1.nodes $2.nodes > $1.badnodes
1628 # Remove the relevant lines from $1
1631 done < $1.badnodes |
1632 comm -13 - $1 > $1.tmp
1635 rm $1.badnodes $1.nodes $2.nodes
1638 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2
1639 # with metadata not matching any entry in $1, replace the corresponding
1640 # line of $3 with one having the same metadata as the entry in $2.
1641 fetch_filter_modified_metadata () {
1642 # Fish out the metadata from $1 and $2
1644 cut -f 1-6 -d '|' < ${X} > ${X}.metadata
1647 # Find the metadata we need to keep
1648 if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then
1649 comm -13 $1.metadata $2.metadata > keepmeta
1654 # Extract the lines which we need to remove from $3, and
1655 # construct the lines which we need to add to $3.
1659 NODE=`echo "${LINE}" | cut -f 1-2 -d '|'`
1660 look "${NODE}|" $3 >> $3.remove
1661 look "${NODE}|" $3 |
1663 lam -s "${LINE}|" - >> $3.add
1666 # Remove the specified lines and add the new lines.
1669 sort -u - $3.add > $3.tmp
1672 rm keepmeta $1.metadata $2.metadata $3.add $3.remove
1675 # Remove lines from $1 and $2 which are identical;
1676 # no need to update a file if it isn't changing.
1677 fetch_filter_uptodate () {
1678 comm -23 $1 $2 > $1.tmp
1679 comm -13 $1 $2 > $2.tmp
1685 # Fetch any "clean" old versions of files we need for merging changes.
1686 fetch_files_premerge () {
1687 # We only need to do anything if $1 is non-empty.
1689 # Tell the user what we're doing
1690 echo -n "Fetching files from ${OLDRELNUM} for merging... "
1692 # List of files wanted
1695 sort -u > files.wanted
1697 # Only fetch the files we don't already have
1699 if [ ! -f "files/${Y}.gz" ]; then
1702 done < files.wanted > filelist
1704 # Actually fetch them
1705 lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist |
1706 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1709 # Make sure we got them all, and move them into /files/
1711 if ! [ -f ${Y}.gz ]; then
1715 if [ `gunzip -c < ${Y}.gz |
1716 ${SHA256} -q` = ${Y} ]; then
1717 mv ${Y}.gz files/${Y}.gz
1719 echo "${Y} has incorrect hash."
1726 rm filelist files.wanted
1730 # Prepare to fetch files: Generate a list of the files we need,
1731 # copy the unmodified files we have into /files/, and generate
1732 # a list of patches to download.
1733 fetch_files_prepare () {
1734 # Tell the user why his disk is suddenly making lots of noise
1735 echo -n "Preparing to download files... "
1737 # Reduce indices to ${PATH}|${HASH} pairs
1738 for X in $1 $2 $3; do
1739 cut -f 1,2,7 -d '|' < ${X} |
1745 # List of files wanted
1746 cut -f 2 -d '|' < $3.hashes |
1749 if ! [ -f files/${HASH}.gz ]; then
1754 # Generate a list of unmodified files
1755 comm -12 $1.hashes $2.hashes |
1756 sort -k 1,1 -t '|' > unmodified.files
1758 # Copy all files into /files/. We only need the unmodified files
1759 # for use in patching; but we'll want all of them if the user asks
1760 # to rollback the updates later.
1762 F=`echo "${LINE}" | cut -f 1 -d '|'`
1763 HASH=`echo "${LINE}" | cut -f 2 -d '|'`
1765 # Skip files we already have.
1766 if [ -f files/${HASH}.gz ]; then
1770 # Make sure the file hasn't changed.
1771 cp "${BASEDIR}/${F}" tmpfile
1772 if [ `sha256 -q tmpfile` != ${HASH} ]; then
1774 echo "File changed while FreeBSD Update running: ${F}"
1778 # Place the file into storage.
1779 gzip -c < tmpfile > files/${HASH}.gz
1783 # Produce a list of patches to download
1784 sort -k 1,1 -t '|' $3.hashes |
1785 join -t '|' -o 2.2,1.2 - unmodified.files |
1786 fetch_make_patchlist > patchlist
1789 rm unmodified.files $1.hashes $2.hashes $3.hashes
1791 # We don't need the list of possible old files any more.
1794 # We're finished making noise
1800 # Attempt to fetch patches
1801 if [ -s patchlist ]; then
1802 echo -n "Fetching `wc -l < patchlist | tr -d ' '` "
1803 echo ${NDEBUG} "patches.${DDSTATS}"
1804 tr '|' '-' < patchlist |
1805 lam -s "${PATCHDIR}/" - |
1806 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1807 2>${STATSREDIR} | fetch_progress
1810 # Attempt to apply patches
1811 echo -n "Applying patches... "
1812 tr '|' ' ' < patchlist |
1814 if [ ! -f "${X}-${Y}" ]; then continue; fi
1815 gunzip -c < files/${X}.gz > OLD
1817 bspatch OLD NEW ${X}-${Y}
1819 if [ `${SHA256} -q NEW` = ${Y} ]; then
1823 rm -f diff OLD NEW ${X}-${Y}
1824 done 2>${QUIETREDIR}
1828 # Download files which couldn't be generate via patching
1830 if [ ! -f "files/${Y}.gz" ]; then
1833 done < files.wanted > filelist
1835 if [ -s filelist ]; then
1836 echo -n "Fetching `wc -l < filelist | tr -d ' '` "
1837 echo ${NDEBUG} "files... "
1838 lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist |
1839 xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \
1843 if ! [ -f ${Y}.gz ]; then
1847 if [ `gunzip -c < ${Y}.gz |
1848 ${SHA256} -q` = ${Y} ]; then
1849 mv ${Y}.gz files/${Y}.gz
1851 echo "${Y} has incorrect hash."
1859 rm files.wanted filelist patchlist
1862 # Create and populate install manifest directory; and report what updates
1864 fetch_create_manifest () {
1865 # If we have an existing install manifest, nuke it.
1866 if [ -L "${BDHASH}-install" ]; then
1867 rm -r ${BDHASH}-install/
1868 rm ${BDHASH}-install
1871 # Report to the user if any updates were avoided due to local changes
1872 if [ -s modifiedfiles ]; then
1874 echo -n "The following files are affected by updates, "
1875 echo "but no changes have"
1876 echo -n "been downloaded because the files have been "
1877 echo "modified locally:"
1882 # If no files will be updated, tell the user and exit
1883 if ! [ -s INDEX-PRESENT ] &&
1884 ! [ -s INDEX-NEW ]; then
1885 rm INDEX-PRESENT INDEX-NEW
1887 echo -n "No updates needed to update system to "
1888 echo "${RELNUM}-p${RELPATCHNUM}."
1892 # Divide files into (a) removed files, (b) added files, and
1893 # (c) updated files.
1894 cut -f 1 -d '|' < INDEX-PRESENT |
1895 sort > INDEX-PRESENT.flist
1896 cut -f 1 -d '|' < INDEX-NEW |
1897 sort > INDEX-NEW.flist
1898 comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed
1899 comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added
1900 comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated
1901 rm INDEX-PRESENT.flist INDEX-NEW.flist
1903 # Report removed files, if any
1904 if [ -s files.removed ]; then
1906 echo -n "The following files will be removed "
1907 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1912 # Report added files, if any
1913 if [ -s files.added ]; then
1915 echo -n "The following files will be added "
1916 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1921 # Report updated files, if any
1922 if [ -s files.updated ]; then
1924 echo -n "The following files will be updated "
1925 echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:"
1931 # Create a directory for the install manifest.
1932 MDIR=`mktemp -d install.XXXXXX` || return 1
1935 mv INDEX-PRESENT ${MDIR}/INDEX-OLD
1936 mv INDEX-NEW ${MDIR}/INDEX-NEW
1938 # Link it into place
1939 ln -s ${MDIR} ${BDHASH}-install
1942 # Warn about any upcoming EoL
1944 # What's the current time?
1945 NOWTIME=`date "+%s"`
1947 # When did we last warn about the EoL date?
1948 if [ -f lasteolwarn ]; then
1949 LASTWARN=`cat lasteolwarn`
1951 LASTWARN=`expr ${NOWTIME} - 63072000`
1954 # If the EoL time is past, warn.
1955 if [ ${EOLTIME} -lt ${NOWTIME} ]; then
1958 WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE.
1959 Any security issues discovered after `date -r ${EOLTIME}`
1960 will not have been corrected.
1965 # Figure out how long it has been since we last warned about the
1966 # upcoming EoL, and how much longer we have left.
1967 SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}`
1968 TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}`
1970 # Don't warn if the EoL is more than 3 months away
1971 if [ ${TIMELEFT} -gt 7884000 ]; then
1975 # Don't warn if the time remaining is more than 3 times the time
1976 # since the last warning.
1977 if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then
1981 # Figure out what time units to use.
1982 if [ ${TIMELEFT} -lt 604800 ]; then
1985 elif [ ${TIMELEFT} -lt 2678400 ]; then
1993 # Compute the right number of units
1994 NUM=`expr ${TIMELEFT} / ${SIZE}`
1995 if [ ${NUM} != 1 ]; then
2002 WARNING: `uname -sr` is approaching its End-of-Life date.
2003 It is strongly recommended that you upgrade to a newer
2004 release within the next ${NUM} ${UNIT}.
2007 # Update the stored time of last warning
2008 echo ${NOWTIME} > lasteolwarn
2011 # Do the actual work involved in "fetch" / "cron".
2013 workdir_init || return 1
2015 # Prepare the mirror list.
2016 fetch_pick_server_init && fetch_pick_server
2018 # Try to fetch the public key until we run out of servers.
2019 while ! fetch_key; do
2020 fetch_pick_server || return 1
2023 # Try to fetch the metadata index signature ("tag") until we run
2024 # out of available servers; and sanity check the downloaded tag.
2025 while ! fetch_tag; do
2026 fetch_pick_server || return 1
2028 fetch_tagsanity || return 1
2030 # Fetch the latest INDEX-NEW and INDEX-OLD files.
2031 fetch_metadata INDEX-NEW INDEX-OLD || return 1
2033 # Generate filtered INDEX-NEW and INDEX-OLD files containing only
2034 # the lines which (a) belong to components we care about, and (b)
2035 # don't correspond to paths we're explicitly ignoring.
2036 fetch_filter_metadata INDEX-NEW || return 1
2037 fetch_filter_metadata INDEX-OLD || return 1
2039 # Translate /boot/${KERNCONF} into ${KERNELDIR}
2040 fetch_filter_kernel_names INDEX-NEW ${KERNCONF}
2041 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2043 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2044 # system and generate an INDEX-PRESENT file.
2045 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2047 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2048 # correspond to lines in INDEX-PRESENT with hashes not appearing
2049 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2050 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2051 # INDEX-OLD with type -.
2052 fetch_filter_unmodified_notpresent \
2053 INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null
2055 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2056 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2057 # of type - from INDEX-PRESENT.
2058 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2060 # If ${ALLOWDELETE} != "yes", then remove any entries from
2061 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2062 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2064 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2065 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2066 # replace the corresponding line of INDEX-NEW with one having the
2067 # same metadata as the entry in INDEX-PRESENT.
2068 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2070 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2071 # no need to update a file if it isn't changing.
2072 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2074 # Prepare to fetch files: Generate a list of the files we need,
2075 # copy the unmodified files we have into /files/, and generate
2076 # a list of patches to download.
2077 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2080 fetch_files || return 1
2082 # Create and populate install manifest directory; and report what
2083 # updates are available.
2084 fetch_create_manifest || return 1
2086 # Warn about any upcoming EoL
2087 fetch_warn_eol || return 1
2090 # If StrictComponents is not "yes", generate a new components list
2091 # with only the components which appear to be installed.
2092 upgrade_guess_components () {
2093 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2094 # Generate filtered INDEX-ALL with only the components listed
2096 fetch_filter_metadata_components $1 || return 1
2098 # Tell the user why his disk is suddenly making lots of noise
2099 echo -n "Inspecting system... "
2101 # Look at the files on disk, and assume that a component is
2102 # supposed to be present if it is more than half-present.
2103 cut -f 1-3 -d '|' < INDEX-ALL |
2105 while read C S F; do
2106 if [ -e ${BASEDIR}/${F} ]; then
2113 sed -E 's,^ +,,' > compfreq
2114 grep ' = ' compfreq |
2116 sort -k 2,2 -t ' ' > compfreq.total
2117 grep ' + ' compfreq |
2119 sort -k 2,2 -t ' ' > compfreq.present
2120 join -t ' ' -1 2 -2 2 compfreq.present compfreq.total |
2121 while read S P T; do
2122 if [ ${P} -gt `expr ${T} / 2` ]; then
2126 cut -f 2 -d ' ' < compfreq.total > comp.total
2127 rm INDEX-ALL compfreq compfreq.total compfreq.present
2129 # We're done making noise.
2132 # Sometimes the kernel isn't installed where INDEX-ALL
2133 # thinks that it should be: In particular, it is often in
2134 # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To
2135 # deal with this, if "kernel|X" is listed in comp.total
2136 # (i.e., is a component which would be upgraded if it is
2137 # found to be present) we will add it to comp.present.
2138 # If "kernel|<anything>" is in comp.total but "kernel|X" is
2139 # not, we print a warning -- the user is running a kernel
2140 # which isn't part of the release.
2141 KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'`
2142 grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present
2144 if grep -qE "^kernel\|" comp.total &&
2145 ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then
2148 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2149 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2150 This kernel will not be updated: you MUST update the kernel manually
2151 before running "$0 install".
2155 # Re-sort the list of installed components and generate
2156 # the list of non-installed components.
2157 sort -u < comp.present > comp.present.tmp
2158 mv comp.present.tmp comp.present
2159 comm -13 comp.present comp.total > comp.absent
2161 # Ask the user to confirm that what we have is correct. To
2162 # reduce user confusion, translate "X|Y" back to "X/Y" (as
2163 # subcomponents must be listed in the configuration file).
2165 echo -n "The following components of FreeBSD "
2166 echo "seem to be installed:"
2167 tr '|' '/' < comp.present |
2170 echo -n "The following components of FreeBSD "
2171 echo "do not seem to be installed:"
2172 tr '|' '/' < comp.absent |
2175 continuep || return 1
2178 # Suck the generated list of components into ${COMPONENTS}.
2179 # Note that comp.present.tmp is used due to issues with
2180 # pipelines and setting variables.
2182 tr '|' '/' < comp.present > comp.present.tmp
2184 COMPONENTS="${COMPONENTS} ${C}"
2185 done < comp.present.tmp
2187 # Delete temporary files
2188 rm comp.present comp.present.tmp comp.absent comp.total
2192 # If StrictComponents is not "yes", COMPONENTS contains an entry
2193 # corresponding to the currently running kernel, and said kernel
2194 # does not exist in the new release, add "kernel/generic" to the
2195 # list of components.
2196 upgrade_guess_new_kernel () {
2197 if [ "${STRICTCOMPONENTS}" = "no" ]; then
2198 # Grab the unfiltered metadata file.
2199 METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'`
2200 gunzip -c < files/${METAHASH}.gz > $1.all
2202 # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component
2203 # isn't in $1.all, we need to add kernel/generic.
2204 for C in ${COMPONENTS}; do
2205 if [ ${C} = "kernel/${KCOMP}" ] &&
2206 ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then
2207 COMPONENTS="${COMPONENTS} kernel/generic"
2211 WARNING: This system is running a "${KCOMP}" kernel, which is not a
2212 kernel configuration distributed as part of FreeBSD ${RELNUM}.
2213 As part of upgrading to FreeBSD ${RELNUM}, this kernel will be
2214 replaced with a "generic" kernel.
2216 continuep || return 1
2220 # Don't need this any more...
2225 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2226 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2227 upgrade_oldall_to_oldnew () {
2228 # For each ${F}|... which appears in INDEX-ALL but does not appear
2229 # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD.
2230 cut -f 1 -d '|' < $1 |
2232 cut -f 1 -d '|' < $2 |
2234 comm -13 $1.paths - |
2235 lam - -s "|-||||||" |
2239 # Remove lines from INDEX-OLD which also appear in INDEX-ALL
2240 comm -23 $1 $2 > $1.tmp
2243 # Remove lines from INDEX-ALL which have a file name not appearing
2244 # anywhere in INDEX-OLD (since these must be files which haven't
2245 # changed -- if they were new, there would be an entry of type "-").
2246 cut -f 1 -d '|' < $1 |
2248 sort -k 1,1 -t '|' < $2 |
2249 join -t '|' - $1.paths |
2254 # Rename INDEX-ALL to INDEX-NEW.
2258 # Helper for upgrade_merge: Return zero true iff the two files differ only
2259 # in the contents of their $FreeBSD$ tags.
2261 X=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $1 | ${SHA256}`
2262 Y=`sed -E 's/\\$FreeBSD.*\\$/\$FreeBSD\$/' < $2 | ${SHA256}`
2264 if [ $X = $Y ]; then
2271 # From the list of "old" files in $1, merge changes in $2 with those in $3,
2272 # and update $3 to reflect the hashes of merged files.
2274 # We only need to do anything if $1 is non-empty.
2276 cut -f 1 -d '|' $1 |
2279 # Create staging area for merging files
2283 mkdir -p merge/old/${D}
2284 mkdir -p merge/${OLDRELNUM}/${D}
2285 mkdir -p merge/${RELNUM}/${D}
2286 mkdir -p merge/new/${D}
2291 # Currently installed file
2292 V=`look "${F}|" $2 | cut -f 7 -d '|'`
2293 gunzip < files/${V}.gz > merge/old/${F}
2296 if look "${F}|" $1 | fgrep -q "|f|"; then
2297 V=`look "${F}|" $1 | cut -f 3 -d '|'`
2298 gunzip < files/${V}.gz \
2299 > merge/${OLDRELNUM}/${F}
2303 if look "${F}|" $3 | cut -f 1,2,7 -d '|' |
2304 fgrep -q "|f|"; then
2305 V=`look "${F}|" $3 | cut -f 7 -d '|'`
2306 gunzip < files/${V}.gz \
2307 > merge/${RELNUM}/${F}
2311 # Attempt to automatically merge changes
2312 echo -n "Attempting to automatically merge "
2313 echo -n "changes in files..."
2316 # If the file doesn't exist in the new release,
2317 # the result of "merging changes" is having the file
2319 if ! [ -f merge/${RELNUM}/${F} ]; then
2323 # If the file didn't exist in the old release, we're
2324 # going to throw away the existing file and hope that
2325 # the version from the new release is what we want.
2326 if ! [ -f merge/${OLDRELNUM}/${F} ]; then
2327 cp merge/${RELNUM}/${F} merge/new/${F}
2331 # Some files need special treatment.
2333 /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db)
2334 # Don't merge these -- we're rebuild them
2335 # after updates are installed.
2336 cp merge/old/${F} merge/new/${F}
2339 if ! merge -p -L "current version" \
2340 -L "${OLDRELNUM}" -L "${RELNUM}" \
2342 merge/${OLDRELNUM}/${F} \
2343 merge/${RELNUM}/${F} \
2344 > merge/new/${F} 2>/dev/null; then
2345 echo ${F} >> failed.merges
2352 # Ask the user to handle any files which didn't merge.
2354 # If the installed file differs from the version in
2355 # the old release only due to $FreeBSD$ tag expansion
2356 # then just use the version in the new release.
2357 if samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2358 cp merge/${RELNUM}/${F} merge/new/${F}
2364 The following file could not be merged automatically: ${F}
2365 Press Enter to edit this file in ${EDITOR} and resolve the conflicts
2368 read dummy </dev/tty
2369 ${EDITOR} `pwd`/merge/new/${F} < /dev/tty
2370 done < failed.merges
2373 # Ask the user to confirm that he likes how the result
2376 # Skip files which haven't changed except possibly
2377 # in their $FreeBSD$ tags.
2378 if [ -f merge/old/${F} ] && [ -f merge/new/${F} ] &&
2379 samef merge/old/${F} merge/new/${F}; then
2383 # Skip files where the installed file differs from
2384 # the old file only due to $FreeBSD$ tags.
2385 if [ -f merge/old/${F} ] &&
2386 [ -f merge/${OLDRELNUM}/${F} ] &&
2387 samef merge/old/${F} merge/${OLDRELNUM}/${F}; then
2391 # Warn about files which are ceasing to exist.
2392 if ! [ -f merge/new/${F} ]; then
2395 The following file will be removed, as it no longer exists in
2396 FreeBSD ${RELNUM}: ${F}
2398 continuep < /dev/tty || return 1
2402 # Print changes for the user's approval.
2405 The following changes, which occurred between FreeBSD ${OLDRELNUM} and
2406 FreeBSD ${RELNUM} have been merged into ${F}:
2408 diff -U 5 -L "current version" -L "new version" \
2409 merge/old/${F} merge/new/${F} || true
2410 continuep < /dev/tty || return 1
2413 # Store merged files.
2415 if [ -f merge/new/${F} ]; then
2416 V=`${SHA256} -q merge/new/${F}`
2418 gzip -c < merge/new/${F} > files/${V}.gz
2421 done < $1-paths > newhashes
2423 # Pull lines out from $3 which need to be updated to
2424 # reflect merged files.
2427 done < $1-paths > $3-oldlines
2429 # Update lines to reflect merged files
2430 join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \
2431 $3-oldlines newhashes > $3-newlines
2433 # Remove old lines from $3 and add new lines.
2436 sort - $3-newlines > $3.tmp
2440 rm $1-paths newhashes $3-oldlines $3-newlines
2444 # We're done with merging files.
2448 # Do the work involved in fetching upgrades to a new release
2450 workdir_init || return 1
2452 # Prepare the mirror list.
2453 fetch_pick_server_init && fetch_pick_server
2455 # Try to fetch the public key until we run out of servers.
2456 while ! fetch_key; do
2457 fetch_pick_server || return 1
2460 # Try to fetch the metadata index signature ("tag") until we run
2461 # out of available servers; and sanity check the downloaded tag.
2462 while ! fetch_tag; do
2463 fetch_pick_server || return 1
2465 fetch_tagsanity || return 1
2467 # Fetch the INDEX-OLD and INDEX-ALL.
2468 fetch_metadata INDEX-OLD INDEX-ALL || return 1
2470 # If StrictComponents is not "yes", generate a new components list
2471 # with only the components which appear to be installed.
2472 upgrade_guess_components INDEX-ALL || return 1
2474 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
2475 # the components we want and without anything marked as "Ignore".
2476 fetch_filter_metadata INDEX-OLD || return 1
2477 fetch_filter_metadata INDEX-ALL || return 1
2479 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD.
2480 sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp
2481 mv INDEX-OLD.tmp INDEX-OLD
2484 # Adjust variables for fetching files from the new release.
2486 RELNUM=${TARGETRELEASE}
2487 OLDFETCHDIR=${FETCHDIR}
2488 FETCHDIR=${RELNUM}/${ARCH}
2490 # Try to fetch the NEW metadata index signature ("tag") until we run
2491 # out of available servers; and sanity check the downloaded tag.
2492 while ! fetch_tag; do
2493 fetch_pick_server || return 1
2496 # Fetch the new INDEX-ALL.
2497 fetch_metadata INDEX-ALL || return 1
2499 # If StrictComponents is not "yes", COMPONENTS contains an entry
2500 # corresponding to the currently running kernel, and said kernel
2501 # does not exist in the new release, add "kernel/generic" to the
2502 # list of components.
2503 upgrade_guess_new_kernel INDEX-ALL || return 1
2505 # Filter INDEX-ALL to contain only the components we want and without
2506 # anything marked as "Ignore".
2507 fetch_filter_metadata INDEX-ALL || return 1
2509 # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into
2510 # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades).
2511 upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW
2513 # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR}
2514 fetch_filter_kernel_names INDEX-NEW ${NKERNCONF}
2515 fetch_filter_kernel_names INDEX-OLD ${KERNCONF}
2517 # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the
2518 # system and generate an INDEX-PRESENT file.
2519 fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2521 # Based on ${MERGECHANGES}, generate a file tomerge-old with the
2522 # paths and hashes of old versions of files to merge.
2523 fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old
2525 # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which
2526 # correspond to lines in INDEX-PRESENT with hashes not appearing
2527 # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in
2528 # INDEX-PRESENT has type - and there isn't a corresponding entry in
2529 # INDEX-OLD with type -.
2530 fetch_filter_unmodified_notpresent \
2531 INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old
2533 # For each entry in INDEX-PRESENT of type -, remove any corresponding
2534 # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries
2535 # of type - from INDEX-PRESENT.
2536 fetch_filter_allowadd INDEX-PRESENT INDEX-NEW
2538 # If ${ALLOWDELETE} != "yes", then remove any entries from
2539 # INDEX-PRESENT which don't correspond to entries in INDEX-NEW.
2540 fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW
2542 # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in
2543 # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD,
2544 # replace the corresponding line of INDEX-NEW with one having the
2545 # same metadata as the entry in INDEX-PRESENT.
2546 fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW
2548 # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical;
2549 # no need to update a file if it isn't changing.
2550 fetch_filter_uptodate INDEX-PRESENT INDEX-NEW
2552 # Fetch "clean" files from the old release for merging changes.
2553 fetch_files_premerge tomerge-old
2555 # Prepare to fetch files: Generate a list of the files we need,
2556 # copy the unmodified files we have into /files/, and generate
2557 # a list of patches to download.
2558 fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1
2560 # Fetch patches from to-${RELNUM}/${ARCH}/bp/
2561 PATCHDIR=to-${RELNUM}/${ARCH}/bp
2562 fetch_files || return 1
2564 # Merge configuration file changes.
2565 upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1
2567 # Create and populate install manifest directory; and report what
2568 # updates are available.
2569 fetch_create_manifest || return 1
2571 # Leave a note behind to tell the "install" command that the kernel
2572 # needs to be installed before the world.
2573 touch ${BDHASH}-install/kernelfirst
2575 # Remind the user that they need to run "freebsd-update install"
2576 # to install the downloaded bits, in case they didn't RTFM.
2577 echo "To install the downloaded upgrades, run \"$0 install\"."
2580 # Make sure that all the file hashes mentioned in $@ have corresponding
2581 # gzipped files stored in /files/.
2583 # Generate a list of hashes
2590 # Make sure all the hashes exist
2592 if ! [ -f files/${HASH}.gz ]; then
2593 echo -n "Update files missing -- "
2594 echo "this should never happen."
2595 echo "Re-run '$0 fetch'."
2604 # Remove the system immutable flag from files
2606 # Generate file list
2608 cut -f 1 -d '|' > filelist
2612 if ! [ -e ${BASEDIR}/${F} ]; then
2616 chflags noschg ${BASEDIR}/${F} || return 1
2623 # Decide which directory name to use for kernel backups.
2624 backup_kernel_finddir () {
2627 # Pathname does not exist, so it is OK use that name
2628 # for backup directory.
2629 if [ ! -e $BACKUPKERNELDIR ]; then
2633 # If directory do exist, we only use if it has our
2635 if [ -d $BACKUPKERNELDIR -a \
2636 -e $BACKUPKERNELDIR/.freebsd-update ]; then
2640 # We could not use current directory name, so add counter to
2641 # the end and try again.
2643 if [ $CNT -gt 9 ]; then
2644 echo "Could not find valid backup dir ($BACKUPKERNELDIR)"
2647 BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`"
2648 BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}"
2652 # Backup the current kernel using hardlinks, if not disabled by user.
2653 # Since we delete all files in the directory used for previous backups
2654 # we create a marker file called ".freebsd-update" in the directory so
2655 # we can determine on the next run that the directory was created by
2656 # freebsd-update and we then do not accidentally remove user files in
2657 # the unlikely case that the user has created a directory with a
2660 # Only make kernel backup is so configured.
2661 if [ $BACKUPKERNEL != yes ]; then
2665 # Decide which directory name to use for kernel backups.
2666 backup_kernel_finddir
2668 # Remove old kernel backup files. If $BACKUPKERNELDIR was
2669 # "not ours", backup_kernel_finddir would have exited, so
2670 # deleting the directory content is as safe as we can make it.
2671 if [ -d $BACKUPKERNELDIR ]; then
2672 rm -fr $BACKUPKERNELDIR
2675 # Create directories for backup.
2676 mkdir -p $BACKUPKERNELDIR
2677 mtree -cdn -p "${KERNELDIR}" | \
2678 mtree -Ue -p "${BACKUPKERNELDIR}" > /dev/null
2680 # Mark the directory as having been created by freebsd-update.
2681 touch $BACKUPKERNELDIR/.freebsd-update
2682 if [ $? -ne 0 ]; then
2683 echo "Could not create kernel backup directory"
2687 # Disable pathname expansion to be sure *.symbols is not
2691 # Use find to ignore symbol files, unless disabled by user.
2692 if [ $BACKUPKERNELSYMBOLFILES = yes ]; then
2695 FINDFILTER=-"a ! -name *.symbols"
2698 # Backup all the kernel files using hardlinks.
2699 (cd $KERNELDIR && find . -type f $FINDFILTER -exec \
2700 cp -pl '{}' ${BACKUPKERNELDIR}/'{}' \;)
2702 # Re-enable patchname expansion.
2707 install_from_index () {
2708 # First pass: Do everything apart from setting file flags. We
2709 # can't set flags yet, because schg inhibits hard linking.
2710 sort -k 1,1 -t '|' $1 |
2712 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2715 # Create a directory
2716 install -d -o ${OWNER} -g ${GROUP} \
2717 -m ${PERM} ${BASEDIR}/${FPATH}
2720 if [ -z "${LINK}" ]; then
2721 # Create a file, without setting flags.
2722 gunzip < files/${HASH}.gz > ${HASH}
2723 install -S -o ${OWNER} -g ${GROUP} \
2724 -m ${PERM} ${HASH} ${BASEDIR}/${FPATH}
2727 # Create a hard link.
2728 ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH}
2733 ln -sfh ${HASH} ${BASEDIR}/${FPATH}
2738 # Perform a second pass, adding file flags.
2740 while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do
2741 if [ ${TYPE} = "f" ] &&
2742 ! [ ${FLAGS} = "0" ]; then
2743 chflags ${FLAGS} ${BASEDIR}/${FPATH}
2748 # Remove files which we want to delete
2750 # Generate list of new files
2751 cut -f 1 -d '|' < $2 |
2754 # Generate subindex of old files we want to nuke
2755 sort -k 1,1 -t '|' $1 |
2756 join -t '|' -v 1 - newfiles |
2757 sort -r -k 1,1 -t '|' |
2759 tr '|' ' ' > killfiles
2761 # Remove the offending bits
2762 while read FPATH TYPE; do
2765 rmdir ${BASEDIR}/${FPATH}
2768 rm ${BASEDIR}/${FPATH}
2771 rm ${BASEDIR}/${FPATH}
2777 rm newfiles killfiles
2780 # Install new files, delete old files, and update linker.hints
2782 # If we haven't already dealt with the kernel, deal with it.
2783 if ! [ -f $1/kerneldone ]; then
2784 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2785 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
2787 # Backup current kernel before installing a new one
2788 backup_kernel || return 1
2791 install_from_index INDEX-NEW || return 1
2793 # Remove files which need to be deleted
2794 install_delete INDEX-OLD INDEX-NEW || return 1
2796 # Update linker.hints if necessary
2797 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2798 kldxref -R /boot/ 2>/dev/null
2801 # We've finished updating the kernel.
2804 # Do we need to ask for a reboot now?
2805 if [ -f $1/kernelfirst ] &&
2806 [ -s INDEX-OLD -o -s INDEX-NEW ]; then
2809 Kernel updates have been installed. Please reboot and run
2810 "$0 install" again to finish installing updates.
2816 # If we haven't already dealt with the world, deal with it.
2817 if ! [ -f $1/worlddone ]; then
2818 # Create any necessary directories first
2819 grep -vE '^/boot/' $1/INDEX-NEW |
2820 grep -E '^[^|]+\|d\|' > INDEX-NEW
2821 install_from_index INDEX-NEW || return 1
2823 # Install new runtime linker
2824 grep -vE '^/boot/' $1/INDEX-NEW |
2825 grep -vE '^[^|]+\|d\|' |
2826 grep -E '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2827 install_from_index INDEX-NEW || return 1
2829 # Install new shared libraries next
2830 grep -vE '^/boot/' $1/INDEX-NEW |
2831 grep -vE '^[^|]+\|d\|' |
2832 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2833 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2834 install_from_index INDEX-NEW || return 1
2836 # Deal with everything else
2837 grep -vE '^/boot/' $1/INDEX-OLD |
2838 grep -vE '^[^|]+\|d\|' |
2839 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2840 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2841 grep -vE '^/boot/' $1/INDEX-NEW |
2842 grep -vE '^[^|]+\|d\|' |
2843 grep -vE '^/libexec/ld-elf[^|]*\.so\.[0-9]+\|' |
2844 grep -vE '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2845 install_from_index INDEX-NEW || return 1
2846 install_delete INDEX-OLD INDEX-NEW || return 1
2848 # Rebuild /etc/spwd.db and /etc/pwd.db if necessary.
2849 if [ /etc/master.passwd -nt /etc/spwd.db ] ||
2850 [ /etc/master.passwd -nt /etc/pwd.db ]; then
2851 pwd_mkdb /etc/master.passwd
2854 # Rebuild /etc/login.conf.db if necessary.
2855 if [ /etc/login.conf -nt /etc/login.conf.db ]; then
2856 cap_mkdb /etc/login.conf
2859 # We've finished installing the world and deleting old files
2860 # which are not shared libraries.
2863 # Do we need to ask the user to portupgrade now?
2864 grep -vE '^/boot/' $1/INDEX-NEW |
2865 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2868 if grep -vE '^/boot/' $1/INDEX-OLD |
2869 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' |
2872 join -v 1 - newfiles |
2876 Completing this upgrade requires removing old shared object files.
2877 Please rebuild all installed 3rd party software (e.g., programs
2878 installed from the ports tree) and then run "$0 install"
2879 again to finish installing updates.
2887 # Remove old shared libraries
2888 grep -vE '^/boot/' $1/INDEX-NEW |
2889 grep -vE '^[^|]+\|d\|' |
2890 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-NEW
2891 grep -vE '^/boot/' $1/INDEX-OLD |
2892 grep -vE '^[^|]+\|d\|' |
2893 grep -E '^[^|]*/lib/[^|]*\.so\.[0-9]+\|' > INDEX-OLD
2894 install_delete INDEX-OLD INDEX-NEW || return 1
2896 # Remove old directories
2897 grep -vE '^/boot/' $1/INDEX-NEW |
2898 grep -E '^[^|]+\|d\|' > INDEX-NEW
2899 grep -vE '^/boot/' $1/INDEX-OLD |
2900 grep -E '^[^|]+\|d\|' > INDEX-OLD
2901 install_delete INDEX-OLD INDEX-NEW || return 1
2903 # Remove temporary files
2904 rm INDEX-OLD INDEX-NEW
2907 # Rearrange bits to allow the installed updates to be rolled back
2908 install_setup_rollback () {
2909 # Remove the "reboot after installing kernel", "kernel updated", and
2910 # "finished installing the world" flags if present -- they are
2911 # irrelevant when rolling back updates.
2912 if [ -f ${BDHASH}-install/kernelfirst ]; then
2913 rm ${BDHASH}-install/kernelfirst
2914 rm ${BDHASH}-install/kerneldone
2916 if [ -f ${BDHASH}-install/worlddone ]; then
2917 rm ${BDHASH}-install/worlddone
2920 if [ -L ${BDHASH}-rollback ]; then
2921 mv ${BDHASH}-rollback ${BDHASH}-install/rollback
2924 mv ${BDHASH}-install ${BDHASH}-rollback
2927 # Actually install updates
2929 echo -n "Installing updates..."
2931 # Make sure we have all the files we should have
2932 install_verify ${BDHASH}-install/INDEX-OLD \
2933 ${BDHASH}-install/INDEX-NEW || return 1
2935 # Remove system immutable flag from files
2936 install_unschg ${BDHASH}-install/INDEX-OLD \
2937 ${BDHASH}-install/INDEX-NEW || return 1
2939 # Install new files, delete old files, and update linker.hints
2940 install_files ${BDHASH}-install || return 1
2942 # Rearrange bits to allow the installed updates to be rolled back
2943 install_setup_rollback
2948 # Rearrange bits to allow the previous set of updates to be rolled back next.
2949 rollback_setup_rollback () {
2950 if [ -L ${BDHASH}-rollback/rollback ]; then
2951 mv ${BDHASH}-rollback/rollback rollback-tmp
2952 rm -r ${BDHASH}-rollback/
2953 rm ${BDHASH}-rollback
2954 mv rollback-tmp ${BDHASH}-rollback
2956 rm -r ${BDHASH}-rollback/
2957 rm ${BDHASH}-rollback
2961 # Install old files, delete new files, and update linker.hints
2963 # Install old shared library files which don't have the same path as
2964 # a new shared library file.
2965 grep -vE '^/boot/' $1/INDEX-NEW |
2966 grep -E '/lib/.*\.so\.[0-9]+\|' |
2968 sort > INDEX-NEW.libs.flist
2969 grep -vE '^/boot/' $1/INDEX-OLD |
2970 grep -E '/lib/.*\.so\.[0-9]+\|' |
2971 sort -k 1,1 -t '|' - |
2972 join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD
2973 install_from_index INDEX-OLD || return 1
2975 # Deal with files which are neither kernel nor shared library
2976 grep -vE '^/boot/' $1/INDEX-OLD |
2977 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
2978 grep -vE '^/boot/' $1/INDEX-NEW |
2979 grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
2980 install_from_index INDEX-OLD || return 1
2981 install_delete INDEX-NEW INDEX-OLD || return 1
2983 # Install any old shared library files which we didn't install above.
2984 grep -vE '^/boot/' $1/INDEX-OLD |
2985 grep -E '/lib/.*\.so\.[0-9]+\|' |
2986 sort -k 1,1 -t '|' - |
2987 join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD
2988 install_from_index INDEX-OLD || return 1
2990 # Delete unneeded shared library files
2991 grep -vE '^/boot/' $1/INDEX-OLD |
2992 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD
2993 grep -vE '^/boot/' $1/INDEX-NEW |
2994 grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW
2995 install_delete INDEX-NEW INDEX-OLD || return 1
2997 # Deal with kernel files
2998 grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD
2999 grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW
3000 install_from_index INDEX-OLD || return 1
3001 install_delete INDEX-NEW INDEX-OLD || return 1
3002 if [ -s INDEX-OLD -o -s INDEX-NEW ]; then
3003 kldxref -R /boot/ 2>/dev/null
3006 # Remove temporary files
3007 rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist
3010 # Actually rollback updates
3012 echo -n "Uninstalling updates..."
3014 # If there are updates waiting to be installed, remove them; we
3015 # want the user to re-run 'fetch' after rolling back updates.
3016 if [ -L ${BDHASH}-install ]; then
3017 rm -r ${BDHASH}-install/
3018 rm ${BDHASH}-install
3021 # Make sure we have all the files we should have
3022 install_verify ${BDHASH}-rollback/INDEX-NEW \
3023 ${BDHASH}-rollback/INDEX-OLD || return 1
3025 # Remove system immutable flag from files
3026 install_unschg ${BDHASH}-rollback/INDEX-NEW \
3027 ${BDHASH}-rollback/INDEX-OLD || return 1
3029 # Install old files, delete new files, and update linker.hints
3030 rollback_files ${BDHASH}-rollback || return 1
3032 # Remove the rollback directory and the symlink pointing to it; and
3033 # rearrange bits to allow the previous set of updates to be rolled
3035 rollback_setup_rollback
3040 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences.
3042 # Get all the lines which mismatch in something other than file
3043 # flags. We ignore file flags because sysinstall doesn't seem to
3044 # set them when it installs FreeBSD; warning about these adds a
3045 # very large amount of noise.
3046 cut -f 1-5,7-8 -d '|' $1 > $1.noflags
3047 sort -k 1,1 -t '|' $1.noflags > $1.sorted
3048 cut -f 1-5,7-8 -d '|' $2 |
3049 comm -13 $1.noflags - |
3050 fgrep -v '|-|||||' |
3051 sort -k 1,1 -t '|' |
3052 join -t '|' $1.sorted - > INDEX-NOTMATCHING
3054 # Ignore files which match IDSIGNOREPATHS.
3055 for X in ${IDSIGNOREPATHS}; do
3056 grep -E "^${X}" INDEX-NOTMATCHING
3059 comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp
3060 mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING
3062 # Go through the lines and print warnings.
3064 FPATH=`echo "${LINE}" | cut -f 1 -d '|'`
3065 TYPE=`echo "${LINE}" | cut -f 2 -d '|'`
3066 OWNER=`echo "${LINE}" | cut -f 3 -d '|'`
3067 GROUP=`echo "${LINE}" | cut -f 4 -d '|'`
3068 PERM=`echo "${LINE}" | cut -f 5 -d '|'`
3069 HASH=`echo "${LINE}" | cut -f 6 -d '|'`
3070 LINK=`echo "${LINE}" | cut -f 7 -d '|'`
3071 P_TYPE=`echo "${LINE}" | cut -f 8 -d '|'`
3072 P_OWNER=`echo "${LINE}" | cut -f 9 -d '|'`
3073 P_GROUP=`echo "${LINE}" | cut -f 10 -d '|'`
3074 P_PERM=`echo "${LINE}" | cut -f 11 -d '|'`
3075 P_HASH=`echo "${LINE}" | cut -f 12 -d '|'`
3076 P_LINK=`echo "${LINE}" | cut -f 13 -d '|'`
3078 # Warn about different object types.
3079 if ! [ "${TYPE}" = "${P_TYPE}" ]; then
3080 echo -n "${FPATH} is a "
3082 f) echo -n "regular file, "
3084 d) echo -n "directory, "
3086 L) echo -n "symlink, "
3089 echo -n "but should be a "
3091 f) echo -n "regular file."
3093 d) echo -n "directory."
3095 L) echo -n "symlink."
3100 # Skip other tests, since they don't make sense if
3101 # we're comparing different object types.
3105 # Warn about different owners.
3106 if ! [ "${OWNER}" = "${P_OWNER}" ]; then
3107 echo -n "${FPATH} is owned by user id ${P_OWNER}, "
3108 echo "but should be owned by user id ${OWNER}."
3111 # Warn about different groups.
3112 if ! [ "${GROUP}" = "${P_GROUP}" ]; then
3113 echo -n "${FPATH} is owned by group id ${P_GROUP}, "
3114 echo "but should be owned by group id ${GROUP}."
3117 # Warn about different permissions. We do not warn about
3118 # different permissions on symlinks, since some archivers
3119 # don't extract symlink permissions correctly and they are
3121 if ! [ "${PERM}" = "${P_PERM}" ] &&
3122 ! [ "${TYPE}" = "L" ]; then
3123 echo -n "${FPATH} has ${P_PERM} permissions, "
3124 echo "but should have ${PERM} permissions."
3127 # Warn about different file hashes / symlink destinations.
3128 if ! [ "${HASH}" = "${P_HASH}" ]; then
3129 if [ "${TYPE}" = "L" ]; then
3130 echo -n "${FPATH} is a symlink to ${P_HASH}, "
3131 echo "but should be a symlink to ${HASH}."
3133 if [ "${TYPE}" = "f" ]; then
3134 echo -n "${FPATH} has SHA256 hash ${P_HASH}, "
3135 echo "but should have SHA256 hash ${HASH}."
3139 # We don't warn about different hard links, since some
3140 # some archivers break hard links, and as long as the
3141 # underlying data is correct they really don't matter.
3142 done < INDEX-NOTMATCHING
3145 rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING
3148 # Do the work involved in comparing the system to a "known good" index
3150 workdir_init || return 1
3152 # Prepare the mirror list.
3153 fetch_pick_server_init && fetch_pick_server
3155 # Try to fetch the public key until we run out of servers.
3156 while ! fetch_key; do
3157 fetch_pick_server || return 1
3160 # Try to fetch the metadata index signature ("tag") until we run
3161 # out of available servers; and sanity check the downloaded tag.
3162 while ! fetch_tag; do
3163 fetch_pick_server || return 1
3165 fetch_tagsanity || return 1
3167 # Fetch INDEX-OLD and INDEX-ALL.
3168 fetch_metadata INDEX-OLD INDEX-ALL || return 1
3170 # Generate filtered INDEX-OLD and INDEX-ALL files containing only
3171 # the components we want and without anything marked as "Ignore".
3172 fetch_filter_metadata INDEX-OLD || return 1
3173 fetch_filter_metadata INDEX-ALL || return 1
3175 # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL.
3176 sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp
3177 mv INDEX-ALL.tmp INDEX-ALL
3180 # Translate /boot/${KERNCONF} to ${KERNELDIR}
3181 fetch_filter_kernel_names INDEX-ALL ${KERNCONF}
3183 # Inspect the system and generate an INDEX-PRESENT file.
3184 fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1
3186 # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any
3188 IDS_compare INDEX-ALL INDEX-PRESENT
3191 #### Main functions -- call parameter-handling and core functions
3193 # Using the command line, configuration file, and defaults,
3194 # set all the parameters which are needed later.
3202 # Fetch command. Make sure that we're being called
3203 # interactively, then run fetch_check_params and fetch_run
3206 echo -n "`basename $0` fetch should not "
3207 echo "be run non-interactively."
3208 echo "Run `basename $0` cron instead."
3215 # Cron command. Make sure the parameters are sensible; wait
3216 # rand(3600) seconds; then fetch updates. While fetching updates,
3217 # send output to a temporary file; only print that file if the
3221 sleep `jot -r 1 0 3600`
3223 TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1
3224 if ! fetch_run >> ${TMPFILE} ||
3225 ! grep -q "No updates needed" ${TMPFILE} ||
3226 [ ${VERBOSELEVEL} = "debug" ]; then
3227 mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE}
3233 # Fetch files for upgrading to a new release.
3235 upgrade_check_params
3236 upgrade_run || exit 1
3239 # Install downloaded updates.
3241 install_check_params
3242 install_run || exit 1
3245 # Rollback most recently installed updates.
3247 rollback_check_params
3248 rollback_run || exit 1
3251 # Compare system against a "known good" index.
3259 # Make sure we find utilities from the base system
3260 export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH}
3262 # Set a pager if the user doesn't
3263 if [ -z "$PAGER" ]; then
3267 # Set LC_ALL in order to avoid problems with character ranges like [A-Z].
3271 for COMMAND in ${COMMANDS}; do