mirror of
https://github.com/bin456789/reinstall.git
synced 2025-12-10 15:37:43 +08:00
core: 默认使用随机密码
This commit is contained in:
49
reinstall.sh
49
reinstall.sh
@ -7,9 +7,6 @@ confhome=https://raw.githubusercontent.com/bin456789/reinstall/main
|
|||||||
confhome_cn=https://cnb.cool/bin456789/reinstall/-/git/raw/main
|
confhome_cn=https://cnb.cool/bin456789/reinstall/-/git/raw/main
|
||||||
# confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
|
# confhome_cn=https://www.ghproxy.cc/https://raw.githubusercontent.com/bin456789/reinstall/main
|
||||||
|
|
||||||
# 默认密码
|
|
||||||
DEFAULT_PASSWORD=123@@@
|
|
||||||
|
|
||||||
# 用于判断 reinstall.sh 和 trans.sh 是否兼容
|
# 用于判断 reinstall.sh 和 trans.sh 是否兼容
|
||||||
SCRIPT_VERSION=4BACD833-A585-23BA-6CBB-9AA4E08E0004
|
SCRIPT_VERSION=4BACD833-A585-23BA-6CBB-9AA4E08E0004
|
||||||
|
|
||||||
@ -126,6 +123,16 @@ error_and_exit() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
show_dd_password_tips() {
|
||||||
|
warn false "
|
||||||
|
This password is only used for SSH access to view logs during the installation.
|
||||||
|
Password of the image will NOT modify.
|
||||||
|
|
||||||
|
密码仅用于安装过程中通过 SSH 查看日志。
|
||||||
|
镜像的密码不会被修改。
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
curl() {
|
curl() {
|
||||||
is_have_cmd curl || install_pkg curl
|
is_have_cmd curl || install_pkg curl
|
||||||
|
|
||||||
@ -2297,16 +2304,23 @@ trim() {
|
|||||||
|
|
||||||
prompt_password() {
|
prompt_password() {
|
||||||
info "prompt password"
|
info "prompt password"
|
||||||
|
warn false "Leave blank to use a random password."
|
||||||
|
warn false "不填写则使用随机密码"
|
||||||
while true; do
|
while true; do
|
||||||
IFS= read -r -p "Password [$DEFAULT_PASSWORD]: " password
|
# 特殊字符列表
|
||||||
IFS= read -r -p "Retype password [$DEFAULT_PASSWORD]: " password_confirm
|
# https://learn.microsoft.com/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh994562(v=ws.11)
|
||||||
password=${password:-$DEFAULT_PASSWORD}
|
chars=\''A-Za-z0-9~!@#$%^&*_=+`|(){}[]:;"<>,.?/-'
|
||||||
password_confirm=${password_confirm:-$DEFAULT_PASSWORD}
|
random_password=$(tr -dc "$chars" </dev/random | head -c16)
|
||||||
if [ -z "$password" ]; then
|
IFS= read -r -p "Password: " password
|
||||||
error "Passwords is empty. Try again."
|
if [ -n "$password" ]; then
|
||||||
elif [ "$password" != "$password_confirm" ]; then
|
IFS= read -r -p "Retype password: " password_confirm
|
||||||
error "Passwords don't match. Try again."
|
if [ "$password" = "$password_confirm" ]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
error "Passwords don't match. Try again."
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
|
password=$random_password
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -4088,13 +4102,7 @@ fi
|
|||||||
# 密码
|
# 密码
|
||||||
if ! is_netboot_xyz && [ -z "$ssh_keys" ] && [ -z "$password" ]; then
|
if ! is_netboot_xyz && [ -z "$ssh_keys" ] && [ -z "$password" ]; then
|
||||||
if is_use_dd; then
|
if is_use_dd; then
|
||||||
echo "
|
show_dd_password_tips
|
||||||
This password is only used for SSH access to view logs during the installation.
|
|
||||||
Password of the image will NOT modify.
|
|
||||||
|
|
||||||
密码仅用于安装过程中通过 SSH 查看日志。
|
|
||||||
镜像的密码不会被修改。
|
|
||||||
"
|
|
||||||
fi
|
fi
|
||||||
prompt_password
|
prompt_password
|
||||||
fi
|
fi
|
||||||
@ -4544,8 +4552,8 @@ echo "$distro $releasever"
|
|||||||
|
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
windows) username=administrator ;;
|
windows) username=administrator ;;
|
||||||
dd | netboot.xyz) username= ;;
|
netboot.xyz) username= ;;
|
||||||
*) username=root ;;
|
dd | *) username=root ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -n "$username" ]; then
|
if [ -n "$username" ]; then
|
||||||
@ -4562,6 +4570,7 @@ if is_netboot_xyz; then
|
|||||||
elif is_alpine_live; then
|
elif is_alpine_live; then
|
||||||
echo 'Reboot to start Alpine Live OS.'
|
echo 'Reboot to start Alpine Live OS.'
|
||||||
elif is_use_dd; then
|
elif is_use_dd; then
|
||||||
|
show_dd_password_tips
|
||||||
echo 'Reboot to start DD.'
|
echo 'Reboot to start DD.'
|
||||||
elif [ "$distro" = fnos ]; then
|
elif [ "$distro" = fnos ]; then
|
||||||
echo "Special note for FNOS:"
|
echo "Special note for FNOS:"
|
||||||
|
|||||||
Reference in New Issue
Block a user