freebsd-update tell the user to run 'fetch' first even though we're using the fetch command. # freebsd-update fetch install Looking up update.FreeBSD.org mirrors... 5 mirrors found. Fetching metadata signature for 10.0-RELEASE from update4.freebsd.org... done. Fetching metadata index... done. Inspecting system... done. Preparing to download files... done. No updates needed to update system to 10.0-RELEASE-p5. No updates are available to install. Run '/usr/sbin/freebsd-update fetch' first.
Additionally, the exit code is 1 in this case. As far as I can tell this is a non-error (simply that no updates are needed), but this makes scripting annoying since the exit code is a failure. (Same use and error as OP for me.)
Created attachment 166733 [details] Remove erroneous message when "fetch install" used Exiting with zero status here when "fetch" has no updates seems reasonable, instead of attempting to execute an "install" which will abort due to lack of updates*. * unless there are already updates pending that were previously fetched by the user. This feels like unexpected behaviour to me, though. freebsd-update's ability to chain commands seems like a design mistake to me. For example it allows the admin to issue the commands: freebsd-update install rollback freebsd-update fetch rollback Or even: freebsd-update fetch fetch fetch fetch fetch fetch fetch fetch fetch fetch
I read recently that freebsd-update will be obsoleted by pkg(8) for FreeBSD 11, so it seems safe to assume that there's no incentive to fix this or any other problems freebsd-update(8) has. Which is fair enough.
Regardless of what happens in FreeBSD 11 and later we still need to support FreeBSD-update for 10.x, and some usability improvements are warranted.
In my opinion, the approach of the proposed patch is not clean enough, since the behaviors of compound statements should always be equivalent to running it separately, for example: freebsd-update fetch install should have the same effect as freebsd-update fetch freebsd-update install The real question here is, should `install` return 0 or 1 (currently 1) if there's nothing to install?
> The real question here is, should `install` return 0 or 1 (currently 1) if > there's nothing to install? In my opinion doing nothing when there's nothing to install is not an error, so should return 0. It would be nice to omit the "Run '/usr/sbin/freebsd-update fetch' first." message when run as a a single freebsd-update invocation. The "no updates" messages are still accurate and fine, IMO.
Submitted a review to fix this bug. Differential Revision: https://reviews.freebsd.org/D12037
A commit references this bug: Author: ygy Date: Mon Oct 9 16:33:37 UTC 2017 New revision: 324441 URL: https://svnweb.freebsd.org/changeset/base/324441 Log: Fix freebsd-update(8) erroneous message and exit status when "fetch install" used. PR: 190660 Reviewed by: allanjude Approved by: emaste Differential Revision: https://reviews.freebsd.org/D12037 Changes: head/usr.sbin/freebsd-update/freebsd-update.sh
A commit references this bug: Author: eadler Date: Thu Mar 15 10:13:25 UTC 2018 New revision: 330985 URL: https://svnweb.freebsd.org/changeset/base/330985 Log: MFC r324441: Fix freebsd-update(8) erroneous message and exit status when "fetch install" used. PR: 190660 Changes: _U stable/11/ stable/11/usr.sbin/freebsd-update/freebsd-update.sh
Created attachment 194742 [details] patch to revert return code back to 1 Switching the return code to 0 broke my refresh script logic: freebsd-update fetch install >/dev/null 2>&1 && \ echo "done. Rebooting system in three (3) seconds." && \ sleep 3 && shutdown -r now && exit 1 ||\ echo "no updates to install." Can we please revert just that one change back to "exit 1"? See attached mini patch.
There
(Please ignore the last message - my Chromium crashed) IMO there are 3 possible results of freebsd-update install: Installed successfully => exit 0; Nothing to install => exit 0; - fetch was run in a chain of commands right before install, exit 0 - fetch was not run immediately before - additional message displayed, still exit 0 Installed unsuccessfully => exit 1; We decided to change "Nothing to install" from 1 to 0 since it seems reasonable to think of it as "did nothing successfully". But if you interpret the return code as "is freebsd-update actually installed *something* successfully", then the version before this PR is correct. I can see that you are using the error code to decide if a restart is needed. I don't think just revert it back is a good idea, since exitting 0 cause there's nothing to install makes sense to me. I would hope there's another way of telling that, or we could do something like this: Nothing to install => exit 0; - fetch was run in a chain of commands right before install, exit 0 - fetch was not run immediately before - additional message displayed, exit 1
(In reply to Guangyuan Yang from comment #12) Hi, There are four possible outcomes to running "install" so I believe we need to differentiate the return codes: 1. Installed successfully: 0 2. Nothing to install (and fetch was run): 2 3. Nothing to install (and fetch was not run): 1 4. Install ran and failed: 1
(In reply to Kenneth Salerno from comment #13) I don't think it makes sense to conflate option 3 and 4 here. 'Nothing to install' is not really an error, and 'install failed' is an important error to catch
Created attachment 194762 [details] patch to return 1 if install is run without fetch and nothing to install This patch is a compromise: return 1 if "install" is run without "fetch" and nothing to install, consistent with error message "run fetch first", therefore should return an error code 1 as before. Maintains the return code of 0 (no error) if user uses both parameters "fetch install" and nothing to install.