Auto-upgrade: Check kernel version before switching
This commit is contained in:
parent
2b4264d32d
commit
70454613d1
|
@ -30,10 +30,6 @@ in
|
|||
in ''
|
||||
set -o pipefail
|
||||
|
||||
upgrade() {
|
||||
${nixos-rebuild} ${cfg.operation} ${toString (cfg.flags ++ upgradeFlag)}
|
||||
}
|
||||
|
||||
indent()
|
||||
{
|
||||
while read -r line ; do
|
||||
|
@ -43,6 +39,7 @@ in
|
|||
|
||||
start_time="$(${date})"
|
||||
reboot_allowed="no"
|
||||
activate_configuration="yes"
|
||||
do_reboot="no"
|
||||
exit_code=0
|
||||
|
||||
|
@ -74,9 +71,7 @@ in
|
|||
''}
|
||||
|
||||
output_file="$(mktemp)"
|
||||
upgrade 2>&1 | tee "$output_file" || exit_code=$?
|
||||
upgrade_output="$(cat "$output_file")"
|
||||
rm -f "$output_file"
|
||||
${nixos-rebuild} boot ${toString (cfg.flags ++ upgradeFlag)} 2>&1 | tee "$output_file" || exit_code=$?
|
||||
|
||||
send_email=no
|
||||
email_subject="Upgrade succeeded"
|
||||
|
@ -87,21 +82,6 @@ in
|
|||
email_body="The system upgrade started at $start_time has failed with exit code $exit_code."
|
||||
fi
|
||||
|
||||
possible_warnings="$(${grep} -e "^trace:" <<<"$upgrade_output" || true)"
|
||||
if [ "$possible_warnings" != "" ] ; then
|
||||
send_email=yes
|
||||
email_subject="$email_subject with warnings"
|
||||
email_body="$(cat <<-EOF
|
||||
$email_body
|
||||
|
||||
|
||||
These trace messages and warnings were encountered:
|
||||
---------------------------------------------------
|
||||
$possible_warnings
|
||||
EOF
|
||||
)"
|
||||
fi
|
||||
|
||||
booted_version="$(${readlink} /run/booted-system/{initrd,kernel,kernel-modules})"
|
||||
built_version="$(${readlink} /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
|
||||
|
||||
|
@ -109,7 +89,7 @@ in
|
|||
version_comparison="$(cat <<-EOF
|
||||
The booted kernel version
|
||||
$(indent "$booted_version")
|
||||
does not match currently active
|
||||
does not match the newly built
|
||||
$(indent "$built_version")
|
||||
.
|
||||
EOF
|
||||
|
@ -126,12 +106,41 @@ in
|
|||
$version_comparison
|
||||
EOF
|
||||
)"
|
||||
activate_configuration="no"
|
||||
if [ "$reboot_allowed" = "yes" ] && [ $exit_code -eq 0 ] ; then
|
||||
email_body="$(printf "%s\n%s" "$email_body" "The system will reboot now.")"
|
||||
do_reboot="yes"
|
||||
activate_configuration="yes"
|
||||
else
|
||||
email_body="$(printf "%s\n%s" "$email_body" "The upgraded configuration will be activated on the next reboot.")"
|
||||
fi
|
||||
fi
|
||||
|
||||
${optionalString (cfg.operation == "switch") ''
|
||||
if [ "$activate_configuration" = "yes" ] ; then
|
||||
echo "Activating new configuration."
|
||||
${nixos-rebuild} switch ${toString cfg.flags} 2>&1 | tee -a "$output_file" || exit_code=$?
|
||||
fi
|
||||
''}
|
||||
|
||||
upgrade_output="$(cat "$output_file")"
|
||||
rm -f "$output_file"
|
||||
|
||||
possible_warnings="$(${grep} -e "^trace:" <<<"$upgrade_output" || true)"
|
||||
if [ "$possible_warnings" != "" ] ; then
|
||||
send_email=yes
|
||||
email_subject="$email_subject with warnings"
|
||||
email_body="$(cat <<-EOF
|
||||
$email_body
|
||||
|
||||
|
||||
These trace messages and warnings were encountered:
|
||||
---------------------------------------------------
|
||||
$possible_warnings
|
||||
EOF
|
||||
)"
|
||||
fi
|
||||
|
||||
${optionalString cfg.sendEmail ''
|
||||
if [ "$send_email" = "yes" ] ; then
|
||||
${sendmail} -t -X - <<-EOF
|
||||
|
|
Loading…
Reference in a new issue