From 115d2912489985230e61d64afaf9e01d0cee692a Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 16 May 2024 00:35:10 +0800 Subject: [PATCH] update --- bin/init.sh | 10 ++++++++++ bin/update_password.sh | 34 ++++++++++++++++++++++++++++++++++ config.json | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 bin/init.sh create mode 100644 bin/update_password.sh diff --git a/bin/init.sh b/bin/init.sh new file mode 100644 index 0000000..53bb13a --- /dev/null +++ b/bin/init.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd) # 脚本绝对路径 + +# 更新密码 +bash "$SCRIPT_DIR/update_password.sh" + +# 更新证书 +bash "$SCRIPT_DIR/gen_cert.sh" + diff --git a/bin/update_password.sh b/bin/update_password.sh new file mode 100644 index 0000000..1989016 --- /dev/null +++ b/bin/update_password.sh @@ -0,0 +1,34 @@ +#!/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" +} + +# 检查是否安装了jq命令 +if ! command -v jq &> /dev/null; then + echo "Error: jq command not found. Please install jq first." + exit 1 +fi + +# 生成一个长度为16的随机密码 +new_password=$(gen_random_pass 16) + +# 更新config.json文件中的auth.password字段 +script_dir="$(dirname "$(realpath "$0")")" # 当前脚本所在目录的绝对路径 +config_file="$script_dir/../config.json" + +# 使用jq命令修改auth.password字段的值 +new_config=$(jq --arg new_password "$new_password" '.auth.password = $new_password' "$config_file") + +# 将修改后的JSON写回config.json文件 +echo "$new_config" > "$config_file" + +echo "New password: $new_password" +echo "config.json file updated with new password." \ No newline at end of file diff --git a/config.json b/config.json index ed6cd8d..c2598d8 100644 --- a/config.json +++ b/config.json @@ -6,7 +6,7 @@ }, "auth": { "type": "password", - "password": "JitvTPJZp3TeeVS" + "password": "设置你的密码" }, "masquerade": { "type": "proxy",