Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/cidata/cidata.TEMPLATE.d/boot/00-reboot-if-required.sh
2678 views
1
#!/bin/bash
2
3
# SPDX-FileCopyrightText: Copyright The Lima Authors
4
# SPDX-License-Identifier: Apache-2.0
5
6
set -eux
7
8
[ "$LIMA_CIDATA_UPGRADE_PACKAGES" = "1" ] || exit 0
9
10
# Check if cloud-init forgot to reboot_if_required
11
# (only implemented for apt at the moment, not dnf)
12
13
if command -v dnf >/dev/null 2>&1; then
14
# dnf-utils needs to be installed, for needs-restarting
15
if dnf -h needs-restarting >/dev/null 2>&1; then
16
# check-update returns "false" (100) if updates (!)
17
set +e
18
dnf check-update >/dev/null
19
if [ "$?" != "1" ]; then
20
# needs-restarting messages are translated _()
21
export LC_ALL=C.UTF-8
22
logfile=$(mktemp)
23
# needs-restarting returns "false" if needed (!)
24
set -o pipefail
25
dnf needs-restarting -r | tee "$logfile"
26
if [ "$?" = "1" ]; then
27
if grep -q "Reboot is required" "$logfile"; then
28
systemctl reboot
29
fi
30
fi
31
rm "$logfile"
32
fi
33
fi
34
fi
35
36