浏览文件
00-reboot-if-required.sh
35 行 · 929 B历史下载| 1 | |
| 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 | touch "$LIMA_REBOOT_REQUIRED" |
| 29 | systemctl reboot |
| 30 | fi |
| 31 | fi |
| 32 | rm "$logfile" |
| 33 | fi |
| 34 | fi |
| 35 | fi |

