跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

00-check-rtc-and-wait-ntp.sh

67 行 · 2.7 KB历史下载
1#!/bin/sh
2
3# SPDX-FileCopyrightText: Copyright The Lima Authors
4# SPDX-License-Identifier: Apache-2.0
5
6set -eu
7
8# In vz, the VM lacks an RTC when booting with a kernel image (see: https://developer.apple.com/forums/thread/760344).
9# This causes incorrect system time until NTP synchronizes it, leading to TLS errors.
10# To avoid TLS errors, this script waits for NTP synchronization if RTC is unavailable.
11test ! -c /dev/rtc0 || exit 0
12
13# This script is intended for services running with systemd.
14command -v systemctl >/dev/null 2>&1 || exit 0
15
16echo_with_time_usec() {
17 time_usec=$(timedatectl show --property=TimeUSec)
18 echo "${time_usec}, ${1}"
19}
20
21# For the first boot, where the above setting is not yet active, wait for NTP synchronization here.
22max_retry=60 retry=0
23until ntp_synchronized=$(timedatectl show --property=NTPSynchronized --value) && [ "${ntp_synchronized}" = "yes" ] ||
24 [ "${retry}" -gt "${max_retry}" ]; do
25 if [ "${retry}" -eq 0 ]; then
26 # If /dev/rtc is not available, the system time set during the Linux kernel build is used.
27 # The larger the difference between this system time and the NTP server time, the longer the NTP synchronization will take.
28 # By setting the system time to the modification time of the reference file, which is likely to be closer to the actual time,
29 reference_file="${LIMA_CIDATA_MNT:-/mnt/lima-cidata}/user-data"
30 [ -f "${reference_file}" ] || reference_file="${0}"
31
32 # the NTP synchronization time can be shortened.
33 echo_with_time_usec "Setting the system time to the modification time of ${reference_file}."
34
35 # To set the time to a specified time, it is necessary to stop systemd-timesyncd.
36 systemctl stop systemd-timesyncd
37
38 # Since `timedatectl set-time` fails if systemd-timesyncd is not stopped,
39 # ensure that it is completely stopped before proceeding.
40 until pid_of_timesyncd=$(systemctl show systemd-timesyncd --property=MainPID --value) && [ "${pid_of_timesyncd}" -eq 0 ]; do
41 echo_with_time_usec "Waiting for systemd-timesyncd to stop..."
42 sleep 1
43 done
44
45 # Set the system time to the modification time of the reference file.
46 modification_time=$(stat -c %y "${reference_file}")
47 echo_with_time_usec "Setting the system time to ${modification_time}."
48 timedatectl set-time "${modification_time}"
49
50 # Restart systemd-timesyncd
51 systemctl start systemd-timesyncd
52 else
53 echo_with_time_usec "Waiting for NTP synchronization..."
54 fi
55 retry=$((retry + 1))
56 sleep 1
57done
58# Print the result of NTP synchronization
59ntp_message=$(timedatectl show-timesync --property=NTPMessage)
60if [ "${ntp_synchronized}" = "yes" ]; then
61 echo_with_time_usec "NTP synchronization complete."
62 echo "${ntp_message}"
63else
64 echo_with_time_usec "NTP synchronization timed out."
65 echo "${ntp_message}"
66 exit 1
67fi