hysteria_docker/bin/update_password.sh
2025-02-08 22:43:16 +08:00

35 lines
920 B
Bash

#!/bin/bash
# 当前脚本所在目录的绝对路径
script_dir="$(dirname "$(realpath "$0")")"
# 加载jq_util.sh脚本
source $script_dir/utils/jq_util.sh
source $script_dir/utils/base.sh
# 检查jq是否安装
check_jq
# 函数生成随机密码
gen_random_pass() {
local pass_length=$1 # 密码长度作为第一个参数
local chars='[:alnum:]' # 只允许出现字母和数字
local rand
rand=$(< /dev/urandom tr -dc "$chars" | head -c "$pass_length")
echo "$rand"
}
# 生成一个长度为16的随机密码
new_password=$(gen_random_pass 16)
# 更新config.json文件中的auth.password字段
config_file="$script_dir/../config.json"
# 使用jq_util.sh中的modify_json_file函数修改config.json文件中的auth.password字段
modify_json_file "$config_file" 'auth.password' "$new_password"
echo "New password: $new_password"
echo "config.json file updated with new password."