函数里的变量, 改为局部变量

This commit is contained in:
Olia Lisa 2026-01-15 14:02:40 +08:00
parent 6ef7ad5744
commit f85766154c
5 changed files with 8 additions and 5 deletions

View File

@ -66,6 +66,7 @@ create_config(){
echo "请选择配置文件类型:" echo "请选择配置文件类型:"
echo "1. 创建reality配置" echo "1. 创建reality配置"
echo "2. 创建xhttp_reality配置" echo "2. 创建xhttp_reality配置"
local choice
read -p "请输入选择 (1 或 2): " choice read -p "请输入选择 (1 或 2): " choice
case $choice in case $choice in
1) create_reality_config ;; 1) create_reality_config ;;

View File

@ -3,7 +3,7 @@
update_docker_images(){ update_docker_images(){
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径 local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # 脚本文件绝对路径
docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径 local docker_compose_file="$script_dir/../docker-compose.yml" # docker-compose.yml文件路径
# 检查是否存在 docker-compose.yml 文件 # 检查是否存在 docker-compose.yml 文件
if [ ! -f $docker_compose_file ]; then if [ ! -f $docker_compose_file ]; then

View File

@ -8,7 +8,7 @@ update_key(){
docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt docker run --rm teddysun/xray:latest /usr/bin/xray x25519 > $config_dir/key.txt
# 获取私钥 # 获取私钥
private_key=$(grep "Private" $config_dir/key.txt | awk -F ': ' '{print $2}') local private_key=$(grep "Private" $config_dir/key.txt | awk -F ': ' '{print $2}')
# 修改config.json密钥属性 # 修改config.json密钥属性
modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.privateKey" "$private_key" modify_json_file "$config_dir/config.json" ".inbounds[0].streamSettings.realitySettings.privateKey" "$private_key"

View File

@ -6,6 +6,7 @@ update_xhttp_path(){
local config_dir="$script_dir/../conf" local config_dir="$script_dir/../conf"
local path_length="$(( RANDOM % 4 + 8 ))" local path_length="$(( RANDOM % 4 + 8 ))"
local uuid=$(cat /proc/sys/kernel/random/uuid)
local xhttp_path="/"$(docker run --rm teddysun/xray:latest xray uuid | tr -d '-' | cut -c 1-$path_length) local xhttp_path="/"$(docker run --rm teddysun/xray:latest xray uuid | tr -d '-' | cut -c 1-$path_length)
# 修改config.json的xhttp_path # 修改config.json的xhttp_path

View File

@ -75,7 +75,7 @@ install_package() {
fi fi
echo "安装 $package_name..." echo "安装 $package_name..."
package_manager=$(get_package_manager) local package_manager=$(get_package_manager)
if [ "$package_manager" == "apt-get" ]; then if [ "$package_manager" == "apt-get" ]; then
sudo apt-get update sudo apt-get update
sudo apt-get install -y "$package_name" sudo apt-get install -y "$package_name"
@ -98,7 +98,7 @@ check_config(){
fi fi
# 如果配置未初始化 # 如果配置未初始化
uuid=$(jq -r '.inbounds[0].settings.clients[0].id' "$config_file") local uuid=$(jq -r '.inbounds[0].settings.clients[0].id' "$config_file")
if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ]; then if [ "$uuid" = "你的UUID" ] || [ -z "$uuid" ]; then
echo "请先'创建配置'" echo "请先'创建配置'"
exit 1 exit 1
@ -117,6 +117,7 @@ restart_docker() {
# 如果容器未运行,提示启动 # 如果容器未运行,提示启动
local running_count=$(docker-compose -f $script_dir/../docker-compose.yml ps -q | wc -l) local running_count=$(docker-compose -f $script_dir/../docker-compose.yml ps -q | wc -l)
if [ "$running_count" -eq 0 ]; then if [ "$running_count" -eq 0 ]; then
local choice
read -p "容器未启动,是否启动容器?(y/n): " choice read -p "容器未启动,是否启动容器?(y/n): " choice
case "$choice" in case "$choice" in
Y|y) Y|y)