Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/freebsd-update/freebsd-update.sh
Context not available. | |||||
--currently-running release | --currently-running release | ||||
-- Update as if currently running this release | -- Update as if currently running this release | ||||
Commands: | Commands: | ||||
fetch -- Fetch updates from server | check -- Check for available updates only | ||||
cron -- Sleep rand(3600) seconds, fetch updates, and send an | cron -- Sleep rand(3600) seconds, fetch updates, and send an | ||||
email if updates were found | email if updates were found | ||||
fetch -- Fetch updates from server | |||||
upgrade -- Fetch upgrades to FreeBSD version specified via -r option | upgrade -- Fetch upgrades to FreeBSD version specified via -r option | ||||
updatesready -- Check if there are fetched updates ready to install | updatesready -- Check if there are fetched updates ready to install | ||||
install -- Install downloaded updates or upgrades | install -- Install downloaded updates or upgrades | ||||
Context not available. | |||||
# Fetched first in a chain of commands | # Fetched first in a chain of commands | ||||
ISFETCHED=0 | ISFETCHED=0 | ||||
# Check for available updates | |||||
CHECK_ONLY=0 | |||||
} | } | ||||
# Parse the command line | # Parse the command line | ||||
Context not available. | |||||
# Commands | # Commands | ||||
cron | fetch | upgrade | updatesready | install | rollback |\ | cron | fetch | upgrade | updatesready | install | rollback |\ | ||||
IDS | showconfig) | IDS | showconfig | check) | ||||
COMMANDS="${COMMANDS} $1" | COMMANDS="${COMMANDS} $1" | ||||
;; | ;; | ||||
Context not available. | |||||
echo ${NOWTIME} > lasteolwarn | echo ${NOWTIME} > lasteolwarn | ||||
} | } | ||||
# Do the actual work involved in "fetch" / "cron". | # Preparation before the actual work involved in "fetch" / "cron". | ||||
fetch_run () { | fetch_run_pre () { | ||||
workdir_init || return 1 | workdir_init || return 1 | ||||
# Prepare the mirror list. | # Prepare the mirror list. | ||||
Context not available. | |||||
done | done | ||||
fetch_tagsanity || return 1 | fetch_tagsanity || return 1 | ||||
# Check for available updates | |||||
[ $CHECK_ONLY -eq 1 ] && check_only | |||||
} | |||||
# Do the actual work involved in "fetch" / "cron". | |||||
fetch_run () { | |||||
fetch_run_pre | |||||
# Fetch the latest INDEX-NEW and INDEX-OLD files. | # Fetch the latest INDEX-NEW and INDEX-OLD files. | ||||
fetch_metadata INDEX-NEW INDEX-OLD || return 1 | fetch_metadata INDEX-NEW INDEX-OLD || return 1 | ||||
Context not available. | |||||
install_from_index INDEX-NEW || return 1 | install_from_index INDEX-NEW || return 1 | ||||
install_delete INDEX-OLD INDEX-NEW || return 1 | install_delete INDEX-OLD INDEX-NEW || return 1 | ||||
# Restart sshd if running (PR263489). Note that this does not | |||||
# affect child sshd processes handling existing sessions. | |||||
if service sshd status >/dev/null 2>/dev/null; then | |||||
echo | |||||
echo "Restarting sshd after upgrade" | |||||
service sshd restart | |||||
fi | |||||
# Rehash certs if we actually have certctl installed. | # Rehash certs if we actually have certctl installed. | ||||
if which certctl>/dev/null; then | if which certctl>/dev/null; then | ||||
env DESTDIR=${BASEDIR} certctl rehash | env DESTDIR=${BASEDIR} certctl rehash | ||||
Context not available. | |||||
IDS_compare INDEX-ALL INDEX-PRESENT | IDS_compare INDEX-ALL INDEX-PRESENT | ||||
} | } | ||||
# Check for available updates | |||||
check_only () { | |||||
RELPATCHNUM=`cut -f 4 -d '|' < tag.new` | |||||
RELPX=`uname -r | sed -E 's,.*-,,'` | |||||
allanjude: Should this be using `freebsd-version -r` instead of `uname -r` so that non-kernel -pX updates… | |||||
Done Inline ActionsI really do not think so; RELPX comes from the fetch_tagsanity() function. inside the case we do take care of the proper checks. same base from all @cperciva's code, tbh, and kept as is. pretty much all PoC to test this diff worked as expected using this implementation (documented on this revision). egypcio: I really do not think so; `RELPX` comes from the `fetch_tagsanity()` function. inside the… | |||||
case ${RELPX} in | |||||
ALPHA* | BETA* | RC*) | |||||
echo "`basename $0` can not check updates for ALPHA/BETA/RC releases." | |||||
echo "Those can only be upgraded to a newer release, not patched." | |||||
exit 1 | |||||
;; | |||||
RELEASE) | |||||
if [ $RELPATCHNUM -ge 1 ]; then | |||||
echo "There is an update available: $RELNUM-p$RELPATCHNUM" | |||||
exit 0 | |||||
fi | |||||
;; | |||||
p*) | |||||
PX=`echo $RELPX | sed 's|p||'` | |||||
if [ $PX -lt $RELPATCHNUM ]; then | |||||
echo "There is an update available: $RELNUM-p$RELPATCHNUM" | |||||
exit 0 | |||||
fi | |||||
;; | |||||
*) | |||||
echo "`basename $0` can not find reliable updates for `uname -r`" | |||||
echo "Cowardly refusing to proceed any further." | |||||
exit 1 | |||||
;; | |||||
esac | |||||
echo "No updates are available." | |||||
exit 0 | |||||
} | |||||
#### Main functions -- call parameter-handling and core functions | #### Main functions -- call parameter-handling and core functions | ||||
# Using the command line, configuration file, and defaults, | # Using the command line, configuration file, and defaults, | ||||
Context not available. | |||||
exit 1 | exit 1 | ||||
fi | fi | ||||
fetch_check_params | fetch_check_params | ||||
fetch_run || exit 1 | case "$COMMANDS" in | ||||
Done Inline Actionsusing a case here would avoid needing to spawn new processes case "$COMMANDS" in "*check*") ;; *) fetch_run || exit 1 ;; esac or something to that effect allanjude: using a `case` here would avoid needing to spawn new processes
```
case "$COMMANDS" in… | |||||
Done Inline Actionsinteresting suggestion. applying. egypcio: interesting suggestion. applying. | |||||
check) | |||||
;; | |||||
*) | |||||
fetch_run || exit 1 | |||||
;; | |||||
esac | |||||
ISFETCHED=1 | ISFETCHED=1 | ||||
} | } | ||||
Context not available. | |||||
done | done | ||||
} | } | ||||
Done Inline Actionssame advice about using case here allanjude: same advice about using `case` here | |||||
# Check for available updates. | |||||
cmd_check () { | |||||
case "$COMMANDS" in | |||||
install|upgrade) | |||||
;; | |||||
*) | |||||
CHECK_ONLY=1 | |||||
;; | |||||
esac | |||||
finalize_components_config ${COMPONENTS} | |||||
fetch_check_params | |||||
fetch_run_pre | |||||
} | |||||
#### Entry point | #### Entry point | ||||
# Make sure we find utilities from the base system | # Make sure we find utilities from the base system | ||||
Context not available. |
Should this be using freebsd-version -r instead of uname -r so that non-kernel -pX updates don't falsely trigger issues?
When there is a patch that doesn't change the kernel (like tzdata updates), the kernel version is not updated, just the userland, and we wouldn't want to keep telling people they need to update when they do not.