update update_password.sh and base.sh
This commit is contained in:
parent
be91ff8272
commit
40b8135701
@ -1,16 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 函数生成随机密码
|
|
||||||
gen_random_pass() {
|
|
||||||
local pass_length=$1 # 密码长度作为第一个参数
|
|
||||||
local chars='[:alnum:]' # 只允许出现字母和数字
|
|
||||||
|
|
||||||
local rand
|
|
||||||
rand=$(< /dev/urandom tr -dc "$chars" | head -c "$pass_length")
|
|
||||||
|
|
||||||
echo "$rand"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 更新密码的函数
|
# 更新密码的函数
|
||||||
update_password() {
|
update_password() {
|
||||||
local script_dir="$(dirname "$(realpath "$0")")"
|
local script_dir="$(dirname "$(realpath "$0")")"
|
||||||
@ -24,13 +13,12 @@ update_password() {
|
|||||||
check_jq
|
check_jq
|
||||||
|
|
||||||
# 生成一个长度为16的随机密码
|
# 生成一个长度为16的随机密码
|
||||||
local new_password=$(gen_random_pass 16)
|
local new_password=$(gen_password 16)
|
||||||
|
|
||||||
# 使用jq_util.sh中的modify_json_file函数修改config.json文件中的auth.password字段
|
# 使用jq_util.sh中的modify_json_file函数修改config.json文件中的auth.password字段
|
||||||
modify_json_file "$config_file" 'auth.password' "$new_password"
|
modify_json_file "$config_file" 'auth.password' "$new_password"
|
||||||
|
|
||||||
echo "New password: $new_password"
|
echo "设置密码成功"
|
||||||
echo "config.json file updated with new password."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 调用函数
|
# 调用函数
|
||||||
|
|||||||
@ -48,3 +48,15 @@ check_bash_installed() {
|
|||||||
return 1 # 返回 1 表示 Bash 未安装
|
return 1 # 返回 1 表示 Bash 未安装
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 生成密码
|
||||||
|
gen_password() {
|
||||||
|
local pass_length=$1 # 密码长度作为第一个参数
|
||||||
|
local chars='[:alnum:]' # 只允许出现字母和数字
|
||||||
|
|
||||||
|
local rand
|
||||||
|
rand=$(< /dev/urandom tr -dc "$chars" | head -c "$pass_length")
|
||||||
|
|
||||||
|
echo "$rand"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user