From bad2ba164423406bd32f6ff6af3c55f64f39c46c Mon Sep 17 00:00:00 2001 From: bin456789 Date: Fri, 18 Oct 2024 23:58:04 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=B8=8D=E9=87=8D=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cloud-init.yaml | 3 +- reinstall.sh | 75 ++++++++++++++++++++++++++----------------------- trans.sh | 7 ++++- 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/cloud-init.yaml b/cloud-init.yaml index c06b683..87aa11b 100644 --- a/cloud-init.yaml +++ b/cloud-init.yaml @@ -32,4 +32,5 @@ runcmd: - sed -i -e '/^[[:space:]]*password:/d' -e '/[[:space:]]*root:/d' /etc/cloud/cloud.cfg.d/99_fallback.cfg - touch /etc/cloud/cloud-init.disabled # ubuntu 镜像运行 echo -e '\nDone' ,-e 会被显示出来 - - printf '\n%s\n' 'reinstall done' >/dev/tty0 || true + # 加 true 因为有的 tty 不可写 + - for tty in tty0 ttyS0 ttyAMA0; do [ -c /dev/$tty ] && printf '\n%s\n' 'reinstall done' >/dev/$tty || true; done diff --git a/reinstall.sh b/reinstall.sh index 433a827..3013caa 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -33,37 +33,37 @@ trap_err() { usage_and_exit() { if is_in_windows; then - reinstall____=' reinstall.bat' + reinstall_____='.\reinstall.bat' else - reinstall____='./reinstall.sh' + reinstall_____=' ./reinstall.sh' fi cat <&2 } warn() { - echo_color_text '\e[33m' "Warning: $*" + echo_color_text '\e[33m' "Warning: $*" >&2 } error() { - echo_color_text '\e[31m' "Error: $*" + echo_color_text '\e[31m' "***** ERROR *****" >&2 + echo_color_text '\e[31m' "Error: $*" >&2 } echo_color_text() { @@ -1848,12 +1849,16 @@ save_password() { # alpine 这两个包有冲突 # apk add expect mkpasswd + # 不要用 echo "$password" 保存密码,原因: + # password="-n" + # echo "$password" # 空白 + # 明文密码 - # 假如用户运行 alpine live 直接打包硬盘镜像,则会暴露明文密码,因为 netboot initrd 在里面 + # 假如用户运行 alpine live 直接打包硬盘镜像,如果保存了明文密码,则会暴露明文密码,因为 netboot initrd 在里面 # 通过 --password 传入密码,history 有记录,也会暴露明文密码 - # /reinstall.log 也会暴露明文密码 + # /reinstall.log 也会暴露明文密码(已处理) if false; then - echo "$password" >>"$dir/password-plaintext" + printf '%s' "$password" >>"$dir/password-plaintext" fi # sha512 @@ -3319,12 +3324,12 @@ fi # 密码 if ! is_netboot_xyz && [ -z "$password" ]; then if is_use_dd; then - warn " + echo " This password is only used for SSH access to view logs during the DD process. Password of the image will NOT modify. 密码仅用于 DD 过程中通过 SSH 查看日志。 -镜像的密码将不会被修改。 +镜像的密码不会被修改。 " fi diff --git a/trans.sh b/trans.sh index cc3fd84..9173bb7 100644 --- a/trans.sh +++ b/trans.sh @@ -706,7 +706,6 @@ to_lower() { } del_empty_lines() { - # grep . sed '/^[[:space:]]*$/d' } @@ -4559,6 +4558,12 @@ get_ubuntu_kernel_flavor() { echo generic-hwe-$releasever fi else + # 这里有坑 + # $(get_cloud_vendor) 调用了 cache_dmi_and_virt + # 但是 $(get_cloud_vendor) 运行在 subshell 里面 + # subshell 运行结束后里面的变量就消失了 + # 因此先运行 cache_dmi_and_virt + cache_dmi_and_virt vendor="$(get_cloud_vendor)" case "$vendor" in aws | gcp | oracle | azure | ibm) echo $vendor ;;