refactor: 迁移函数到新的文件
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
update_key(){
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
|
||||
local config_dir="$script_dir/../conf"
|
||||
|
||||
# 使用docker运行xray镜像生成密钥文件
|
||||
docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt
|
||||
|
||||
# 获取私钥
|
||||
local private_key=$(grep "Private" $config_dir/key.txt | awk -F ': ' '{print $2}')
|
||||
|
||||
# 修改config.json密钥属性
|
||||
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.privateKey" "$private_key"
|
||||
|
||||
echo "生成和设置密钥成功."
|
||||
|
||||
}
|
||||
|
||||
|
||||
update_reality_dest(){
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
local config_dir="$script_dir/../conf"
|
||||
|
||||
# 获取当前dest值
|
||||
local old_dest=$(jq -r '.inbounds[0].streamSettings.realitySettings.dest' "$config_dir/config.json")
|
||||
old_dest="${old_dest%:*}"
|
||||
# 输入新的dest地址
|
||||
local dest
|
||||
read -p "请输入新的dest地址[当前地址: $old_dest]: " dest
|
||||
|
||||
# 如果输入为空, 不修改直接退出
|
||||
if [[ -z "$dest" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 如果未指定端口号,默认加上 :443
|
||||
if [[ "$dest" != *:* ]]; then
|
||||
dest="${dest}:443"
|
||||
fi
|
||||
|
||||
# 提取域名部分,去掉端口号
|
||||
local domain=$(echo "$dest" | cut -d: -f1)
|
||||
|
||||
# 修改配置文件中的dest
|
||||
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.dest" "$dest"
|
||||
|
||||
# 修改配置文件中的serverNames,不带端口号
|
||||
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.serverNames" "[\"$domain\"]"
|
||||
|
||||
echo "修改reality_dest成功"
|
||||
}
|
||||
|
||||
update_short_id(){
|
||||
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
|
||||
local config_dir="$script_dir/../conf"
|
||||
|
||||
# 生成 shortId
|
||||
local short_id=$(openssl rand -hex 8)
|
||||
|
||||
#修改 shortId
|
||||
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.shortIds[0]" "$short_id"
|
||||
|
||||
echo "设置shortId成功."
|
||||
}
|
||||
Reference in New Issue
Block a user