update
This commit is contained in:
parent
8885a814d6
commit
46a8b059c0
@ -1,8 +1,13 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 当前脚本所在目录的绝对路径
|
||||
script_dir="$(dirname "$(realpath "$0")")"
|
||||
|
||||
# 导入utils文件夹中的jq_util.sh脚本
|
||||
source "$script_dir/utils/jq_util.sh"
|
||||
|
||||
gen_cert() {
|
||||
local domain="$1"
|
||||
local script_dir="$(dirname "$(realpath "$0")")" # 当前脚本所在目录的绝对路径
|
||||
local key_dir="$script_dir/../key" # key目录绝对路径
|
||||
# 使用openssl生成自签名证书,设置密钥和有效期,并指定域名信息
|
||||
openssl req -x509 -nodes -newkey ec:<(openssl ecparam -name prime256v1) -keyout "$key_dir/server.key" -out "$key_dir/server.crt" -subj "/CN=$domain" -days 36500
|
||||
@ -10,11 +15,9 @@ gen_cert() {
|
||||
|
||||
update_config() {
|
||||
local domain="$1"
|
||||
local script_dir="$(dirname "$(realpath "$0")")" # 当前脚本所在目录的绝对路径
|
||||
local config_file="$script_dir/../config.json" # config.json文件路径
|
||||
# 使用jq命令修改文件conifg.json中的masquerade.proxy.url
|
||||
new_config=$(jq --arg new_url "https://$domain" '.masquerade.proxy.url = $new_url' "$config_file")
|
||||
echo "$new_config" > "$config_file"
|
||||
# 使用jq_util.sh脚本中的modify_json_file函数修改config.json文件中的域名信息
|
||||
modify_json_file $config_file "masquerade.proxy.url" "https://$domain"
|
||||
}
|
||||
|
||||
domain="${1:-bing.com}" # 域名, 默认为"bing.com"
|
||||
|
||||
@ -1,5 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 检查是否安装了jq命令
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "Error: jq command not found. Please install jq first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 当前脚本所在目录的绝对路径
|
||||
script_dir="$(dirname "$(realpath "$0")")"
|
||||
|
||||
# 加载jq_util.sh脚本
|
||||
source $script_dir/utils/jq_util.sh
|
||||
|
||||
# 函数生成随机密码
|
||||
gen_random_pass() {
|
||||
local pass_length=$1 # 密码长度作为第一个参数
|
||||
@ -11,24 +23,14 @@ gen_random_pass() {
|
||||
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"
|
||||
# 使用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."
|
||||
11
bin/utils/jq_util.sh
Normal file
11
bin/utils/jq_util.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 修改json文件的属性值
|
||||
function modify_json_file() {
|
||||
local json_file=$1 # json文件路径
|
||||
local key=$2 # 要修改的key
|
||||
local value=$3 # 要修改的value
|
||||
|
||||
jq ".${key} = \"${value}\"" ${json_file} > ${json_file}.tmp
|
||||
mv ${json_file}.tmp ${json_file}
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
},
|
||||
"auth": {
|
||||
"type": "password",
|
||||
"password": "设置你的密码"
|
||||
"password": "La4AdWOoE57OdtwY"
|
||||
},
|
||||
"masquerade": {
|
||||
"type": "proxy",
|
||||
@ -15,4 +15,4 @@
|
||||
"rewriteHost": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user