From c4c383204beb8f693404e873b0cd87737a91a794 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Wed, 1 Jan 2025 17:38:32 +0800 Subject: [PATCH] =?UTF-8?q?core:=20trans=20=E5=85=88=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=97=B6=E9=97=B4=EF=BC=8C=E9=81=BF=E5=85=8D=20ubuntu=20apt=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B4=A2=E5=BC=95=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #223 --- trans.sh | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/trans.sh b/trans.sh index 329137e..f002e01 100644 --- a/trans.sh +++ b/trans.sh @@ -4944,6 +4944,43 @@ refind_main_disk() { fi } +sync_time() { + if false; then + # arm要手动从硬件同步时间,避免访问https出错 + # do 机器第二次运行会报错 + hwclock -s || true + fi + + # ntp 时间差太多会无法同步? + # http 时间可能不准确,毕竟不是专门的时间服务器 + # 也有可能没有 date header? + method=http + + case "$method" in + ntp) + if is_in_china; then + ntp_server=ntp.aliyun.com + else + ntp_server=pool.ntp.org + fi + # -d[d] Verbose + # -n Run in foreground + # -q Quit after clock is set + # -p PEER + ntpd -d -n -q -p "$ntp_server" + ;; + http) + url=$(grep -m1 ^http /etc/apk/repositories) + # 可能有多行,取第一行 + date_header=$(wget -S --no-check-certificate --spider "$url" 2>&1 | grep -m1 '^ Date:') + # gnu date 不支持 -D + busybox date -u -D " Date: %a, %d %b %Y %H:%M:%S GMT" -s "$date_header" + ;; + esac + + hwclock -w +} + get_ubuntu_kernel_flavor() { # 20.04/22.04 kvm 内核 vnc 没显示 # 24.04 kvm = virtual @@ -5230,9 +5267,14 @@ fi # 允许 ramdisk 使用所有内存,默认是 50% mount / -o remount,size=100% -# arm要手动从硬件同步时间,避免访问https出错 -# do 机器第二次运行会报错 -hwclock -s || true +# 同步时间 +# 1. 可以防止访问 https 出错 +# 2. 可以防止 https://github.com/bin456789/reinstall/issues/223 +# E: Release file for http://security.ubuntu.com/ubuntu/dists/noble-security/InRelease is not valid yet (invalid for another 5h 37min 18s). +# Updates for this repository will not be applied. +# 3. 不能直接读取 rtc,因为默认情况 windows rtc 是本地时间,linux rtc 是 utc 时间 +# 4. 允许同步失败,因为不是关键步骤 +sync_time || true # 设置密码,安装并打开 ssh echo "root:$(get_password_linux_sha512)" | chpasswd -e