~优化setconfig函数,修复部分因系统兼容导致的bug

This commit is contained in:
juewuy
2025-12-12 17:40:19 +08:00
parent a1eb072fa7
commit afb3a806af
4 changed files with 38 additions and 27 deletions

View File

@@ -145,10 +145,14 @@ setdir() {
[ "$res" = "1" ] && CRASHDIR=$dir/ShellCrash || setdir
fi
}
setconfig() {
setconfig() { #脚本配置工具
#参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=${CRASHDIR}/configs/ShellCrash.cfg || configpath="${3}"
[ -n "$(grep "${1}=" "$configpath")" ] && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || echo "${1}=${2}" >>$configpath
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
if grep -q "^${1}=" "$configpath";then
sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
else
printf '%s=%s\n' "$1" "$2" >> "$configpath"
fi
}
#特殊固件识别及标记
[ -f "/etc/storage/started_script.sh" ] && {

View File

@@ -17,8 +17,12 @@ JSONSDIR=${CRASHDIR}/jsons
#读取配置相关
setconfig() {
#参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath=${CFG_PATH} || configpath="${3}"
grep -q "${1}=" "$configpath" && sed -i "s#${1}=.*#${1}=${2}#g" $configpath || sed -i "\$a\\${1}=${2}" $configpath
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
if grep -q "^${1}=" "$configpath";then
sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
else
printf '%s=%s\n' "$1" "$2" >> "$configpath"
fi
}
ckcmd() {
command -v sh >/dev/null 2>&1 && command -v $1 >/dev/null 2>&1 || type $1 >/dev/null 2>&1
@@ -607,7 +611,7 @@ setport() { #端口设置
else
authentication=$(echo $input | grep :)
if [ -n "$authentication" ]; then
setconfig authentication \'$authentication\'
setconfig authentication "'$authentication'"
echo -e "\033[32m设置成功\033[0m"
else
echo -e "\033[31m输入有误请重新输入\033[0m"
@@ -723,7 +727,7 @@ setdns() { #DNS详细设置
read -p "请输入新的DNS > " dns_nameserver
dns_nameserver=$(echo $dns_nameserver | sed 's#|#\,\ #g')
if [ -n "$dns_nameserver" ]; then
setconfig dns_nameserver \'"$dns_nameserver"\'
setconfig dns_nameserver "'$dns_nameserver'"
echo -e "\033[32m设置成功\033[0m"
fi
sleep 1
@@ -733,7 +737,7 @@ setdns() { #DNS详细设置
read -p "请输入新的DNS > " dns_fallback
dns_fallback=$(echo $dns_fallback | sed 's/|/\,\ /g')
if [ -n "$dns_fallback" ]; then
setconfig dns_fallback \'"$dns_fallback"\'
setconfig dns_fallback "'$dns_fallback'"
echo -e "\033[32m设置成功\033[0m"
fi
sleep 1
@@ -745,7 +749,7 @@ setdns() { #DNS详细设置
echo -e "\033[31m此选项暂不支持ipv6加密DNS\033[0m"
elif [ -n "$text" ]; then
dns_resolver=$(echo $text | sed 's/|/\,\ /g')
setconfig dns_resolver \'"$dns_resolver"\'
setconfig dns_resolver "'$dns_resolver'"
echo -e "\033[32m设置成功\033[0m"
fi
sleep 1
@@ -758,9 +762,9 @@ setdns() { #DNS详细设置
dns_nameserver='https://doh.360.cn/dns-query, https://dns.alidns.com/dns-query, https://doh.pub/dns-query'
dns_fallback='https://cloudflare-dns.com/dns-query, https://dns.google/dns-query, https://doh.opendns.com/dns-query'
dns_resolver='https://223.5.5.5/dns-query, 2400:3200::1'
setconfig dns_nameserver \'"$dns_nameserver"\'
setconfig dns_fallback \'"$dns_fallback"\'
setconfig dns_resolver \'"$dns_resolver"\'
setconfig dns_nameserver "'$dns_nameserver'"
setconfig dns_fallback "'$dns_fallback'"
setconfig dns_resolver "'$dns_resolver'"
echo -e "\033[32m已设置加密DNS如出现DNS解析问题请尝试重置DNS配置\033[0m"
else
echo -e "\033[31m找不到根证书文件无法启用加密DNSLinux系统请自行搜索安装OpenSSL的方式\033[0m"
@@ -974,7 +978,7 @@ setfirewall() { #防火墙设置
)" ]; then
reserve_ipv4="$text"
echo -e "已将保留地址网段设为:\033[32m$reserve_ipv4\033[0m"
setconfig reserve_ipv4 "\'$reserve_ipv4\'"
setconfig reserve_ipv4 "'$reserve_ipv4'"
else
echo -e "\033[31m输入有误操作已取消\033[0m"
fi
@@ -1447,7 +1451,7 @@ set_firewall_area() { #防火墙模式设置
*) ;;
esac
setconfig vm_redir $vm_redir
setconfig vm_ipv4 "\'$vm_ipv4\'"
setconfig vm_ipv4 "'$vm_ipv4'"
sleep 1
set_firewall_area
;;

View File

@@ -69,7 +69,11 @@ getconfig() { #读取配置及全局变量
setconfig() { #脚本配置工具
#参数1代表变量名参数2代表变量值,参数3即文件路径
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
grep -q "${1}=" "$configpath" && sed -i "s#${1}=.*#${1}=${2}#g" "$configpath" || sed -i "\$a\\${1}=${2}" $configpath
if grep -q "^${1}=" "$configpath";then
sed -i "s#${1}=.*#${1}=${2}#g" "$configpath"
else
printf '%s=%s\n' "$1" "$2" >> "$configpath"
fi
}
ckcmd() { #检查命令是否存在
command -v sh >/dev/null 2>&1 && command -v "$1" >/dev/null 2>&1 || type "$1" >/dev/null 2>&1
@@ -709,7 +713,6 @@ EOF
{
"tag": "cn",
"type": "remote",
"format": "binary",
"path": "./ruleset/cn.srs",
"url": "https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@update/bin/geodata/srs_geosite_cn.srs"
}
@@ -2171,7 +2174,7 @@ webget)
[ "$result" = "200" ] && exit 0 || exit 1
;;
*)
$1 $2 $3 $4 $5 $6 $7
"$1" "$2" "$3" "$4" "$5" "$6" "$7"
;;
esac

View File

@@ -880,7 +880,7 @@ gen_link_flt(){ #在线生成节点过滤
exclude=''
echo -e "\033[31m 已删除节点过滤关键字!!!\033[0m"
fi
setconfig exclude \'$exclude\'
setconfig exclude "'$exclude'"
}
gen_link_ele(){ #在线生成节点筛选
[ -z "$include" ] && include="未设置"
@@ -900,7 +900,7 @@ gen_link_ele(){ #在线生成节点筛选
include=''
echo -e "\033[31m 已删除节点匹配关键字!!!\033[0m"
fi
setconfig include \'$include\'
setconfig include "'$include'"
}
get_core_config(){ #调用工具下载
${CRASHDIR}/start.sh get_core_config
@@ -954,7 +954,7 @@ gen_core_config_link(){ #在线生成工具
i=100
#将用户链接写入配置
setconfig Https
setconfig Url \'$Url_link\'
setconfig Url "'$Url_link'"
#获取在线yaml文件
get_core_config
else
@@ -1008,7 +1008,7 @@ set_core_config_link(){ #直接导入配置
if [ "$res" = '1' ]; then
#将用户链接写入配置
sed -i '/Url=*/'d $CFG_PATH
setconfig Https \'$link\'
setconfig Https "'$link'"
setconfig Url
#获取在线yaml文件
get_core_config
@@ -1827,7 +1827,7 @@ getdb(){ #下载Dashboard文件
#sed -i "s/7892/${db_port}/g" $dbdir/app*.js
fi
#写入配置文件
setconfig hostdir \'$hostdir\'
setconfig hostdir "'$hostdir'"
echo -----------------------------------------------
echo -e "\033[32m面板安装成功\033[36m如未生效请使用【Ctrl+F5】强制刷新浏览器\033[0m"
rm -rf ${TMPDIR}/clashdb.tar.gz
@@ -2007,7 +2007,7 @@ setserver(){
[ -n "$url_id" ] && url_name=$(grep "$url_id" ${CRASHDIR}/configs/servers.list 2>/dev/null | awk '{print $2}') || url_name=$update_url
saveserver(){
#写入配置文件
setconfig update_url \'$update_url\'
setconfig update_url "'$update_url'"
setconfig url_id $url_id
setconfig release_type $release_type
echo -----------------------------------------------
@@ -2335,9 +2335,9 @@ userguide(){
dns_nameserver='https://doh.360.cn/dns-query, https://dns.alidns.com/dns-query, https://doh.pub/dns-query'
dns_fallback='https://cloudflare-dns.com/dns-query, https://dns.google/dns-query, https://doh.opendns.com/dns-query'
dns_resolver='https://223.5.5.5/dns-query, 2400:3200::1'
setconfig dns_nameserver \'"$dns_nameserver"\'
setconfig dns_fallback \'"$dns_fallback"\'
setconfig dns_resolver \'"$dns_resolver"\'
setconfig dns_nameserver "'$dns_nameserver'"
setconfig dns_fallback "'$dns_fallback'"
setconfig dns_resolver "'$dns_resolver'"
fi
#开启公网访问
sethost(){
@@ -2369,7 +2369,7 @@ userguide(){
setconfig mix_port $mix_port
setconfig host $host
setconfig public_support $public_support
setconfig authentication \'$authentication\'
setconfig authentication "'$authentication'"
fi
fi
#启用推荐的自动任务配置