~统一缩进

This commit is contained in:
juewuy
2026-03-25 20:15:42 +08:00
parent ab29b5c036
commit 837f99727a
60 changed files with 2846 additions and 2846 deletions

View File

@@ -1,17 +1,17 @@
check_autostart(){
if [ "$start_old" = ON ];then
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
[ -n "$(find /etc/rc.d -name '*shellcrash')" ] && return 0
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif ckcmd systemctl; then
[ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && return 0
elif grep -q 's6' /proc/1/comm; then
[ -f /etc/s6-overlay/s6-rc.d/user/contents.d/afstart ] && return 0
elif rc-status -r >/dev/null 2>&1; then
rc-update show default | grep -q "shellcrash" && return 0
else
return 1
fi
return 1
if [ "$start_old" = ON ];then
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif [ -f /etc/rc.common -a "$(cat /proc/1/comm)" = "procd" ]; then
[ -n "$(find /etc/rc.d -name '*shellcrash')" ] && return 0
[ ! -f "$CRASHDIR"/.dis_startup ] && return 0
elif ckcmd systemctl; then
[ "$(systemctl is-enabled shellcrash.service 2>&1)" = enabled ] && return 0
elif grep -q 's6' /proc/1/comm; then
[ -f /etc/s6-overlay/s6-rc.d/user/contents.d/afstart ] && return 0
elif rc-status -r >/dev/null 2>&1; then
rc-update show default | grep -q "shellcrash" && return 0
else
return 1
fi
return 1
}

View File

@@ -1,14 +1,14 @@
check_cpucore(){ #自动获取内核架构
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5"
[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs ] && cpucore="armv7"
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="arm64"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
mipstype=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle
[ "$mipstype" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat"
fi
[ -n "$cpucore" ] && setconfig cpucore $cpucore
cputype=$(uname -ms | tr ' ' '_' | tr '[A-Z]' '[a-z]')
[ -n "$(echo $cputype | grep -E "linux.*armv.*")" ] && cpucore="armv5"
[ -n "$(echo $cputype | grep -E "linux.*armv7.*")" ] && [ -n "$(cat /proc/cpuinfo | grep vfp)" ] && [ ! -d /jffs ] && cpucore="armv7"
[ -n "$(echo $cputype | grep -E "linux.*aarch64.*|linux.*armv8.*")" ] && cpucore="arm64"
[ -n "$(echo $cputype | grep -E "linux.*86.*")" ] && cpucore="386"
[ -n "$(echo $cputype | grep -E "linux.*86_64.*")" ] && cpucore="amd64"
if [ -n "$(echo $cputype | grep -E "linux.*mips.*")" ];then
mipstype=$(echo -n I | hexdump -o 2>/dev/null | awk '{ print substr($2,6,1); exit}') #通过判断大小端判断mips或mipsle
[ "$mipstype" = "0" ] && cpucore="mips-softfloat" || cpucore="mipsle-softfloat"
fi
[ -n "$cpucore" ] && setconfig cpucore $cpucore
}

View File

@@ -1,5 +1,5 @@
#检查目录剩余空间——$1:目标路径 $2:-h参数
dir_avail() {
df -h >/dev/null 2>&1 && h="$2"
df -h >/dev/null 2>&1 && h="$2"
df -P $h "${1:-.}" 2>/dev/null | awk 'NR==2 {print $4}'
}

View File

@@ -1,8 +1,8 @@
if echo "$crashcore" | grep -q 'singbox'; then
target=singbox
format=json
target=singbox
format=json
else
target=clash
format=yaml
target=clash
format=yaml
fi
core_config="$CRASHDIR/${format}s/config.$format"

View File

@@ -3,7 +3,7 @@ compare() { #对比文件
return 1
elif ckcmd cmp; then
cmp -s "$1" "$2"
return $?
return $?
else
[ "$(cat "$1")" = "$(cat "$2")" ] && return 0 || return 1
fi

View File

@@ -3,87 +3,87 @@
[ -n "$(find --help 2>&1 | grep -o size)" ] && find_para=' -size +2000' #find命令兼容
core_unzip() { #$1:需要解压的文件 $2:目标文件名
if echo "$1" |grep -q 'tar.gz$' ;then
[ "$BINDIR" = "$TMPDIR" ] && rm -rf "$TMPDIR"/CrashCore #小闪存模式防止空间不足
[ -n "$(tar --help 2>&1 | grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容
mkdir -p "$TMPDIR"/core_tmp
tar -zxf "$1" ${tar_para} -C "$TMPDIR"/core_tmp/
for file in $(find "$TMPDIR"/core_tmp $find_para 2>/dev/null); do
[ -f "$file" ] && [ -n "$(echo $file | sed 's#.*/##' | grep -iE '(CrashCore|sing|meta|mihomo|clash|pre)')" ] && mv -f "$file" "$TMPDIR"/"$2"
done
rm -rf "$TMPDIR"/core_tmp
elif echo "$1" |grep -q '.gz$' ;then
gunzip -c "$1" > "$TMPDIR"/"$2"
elif echo "$1" |grep -q '.upx$' ;then
ln -sf "$1" "$TMPDIR"/"$2"
else
mv -f "$1" "$TMPDIR"/"$2"
fi
chmod +x "$TMPDIR"/"$2"
if echo "$1" |grep -q 'tar.gz$' ;then
[ "$BINDIR" = "$TMPDIR" ] && rm -rf "$TMPDIR"/CrashCore #小闪存模式防止空间不足
[ -n "$(tar --help 2>&1 | grep -o 'no-same-owner')" ] && tar_para='--no-same-owner' #tar命令兼容
mkdir -p "$TMPDIR"/core_tmp
tar -zxf "$1" ${tar_para} -C "$TMPDIR"/core_tmp/
for file in $(find "$TMPDIR"/core_tmp $find_para 2>/dev/null); do
[ -f "$file" ] && [ -n "$(echo $file | sed 's#.*/##' | grep -iE '(CrashCore|sing|meta|mihomo|clash|pre)')" ] && mv -f "$file" "$TMPDIR"/"$2"
done
rm -rf "$TMPDIR"/core_tmp
elif echo "$1" |grep -q '.gz$' ;then
gunzip -c "$1" > "$TMPDIR"/"$2"
elif echo "$1" |grep -q '.upx$' ;then
ln -sf "$1" "$TMPDIR"/"$2"
else
mv -f "$1" "$TMPDIR"/"$2"
fi
chmod +x "$TMPDIR"/"$2"
}
core_find(){
if [ ! -f "$TMPDIR"/CrashCore ];then
[ -n "$(find "$CRASHDIR"/CrashCore.* $find_para 2>/dev/null)" ] && [ "$CRASHDIR" != "$BINDIR" ] &&
mv -f "$CRASHDIR"/CrashCore.* "$BINDIR"/
core_dir=$(find "$BINDIR"/CrashCore.* $find_para 2>/dev/null | head -n 1)
[ -n "$core_dir" ] && core_unzip "$core_dir" CrashCore
fi
if [ ! -f "$TMPDIR"/CrashCore ];then
[ -n "$(find "$CRASHDIR"/CrashCore.* $find_para 2>/dev/null)" ] && [ "$CRASHDIR" != "$BINDIR" ] &&
mv -f "$CRASHDIR"/CrashCore.* "$BINDIR"/
core_dir=$(find "$BINDIR"/CrashCore.* $find_para 2>/dev/null | head -n 1)
[ -n "$core_dir" ] && core_unzip "$core_dir" CrashCore
fi
}
core_check(){
[ -n "$(pidof CrashCore)" ] && "$CRASHDIR"/start.sh stop #停止内核服务防止内存不足
core_unzip "$1" core_new
sbcheck=$(echo "$crashcore" | grep 'singbox')
v=''
if [ -n "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q 'sing-box'; then
v=$("$TMPDIR"/core_new version 2>/dev/null | grep version | awk '{print $3}')
COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"'
elif [ -z "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q '\-t';then
v=$("$TMPDIR"/core_new -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')
COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"'
fi
if [ -z "$v" ]; then
rm -rf "$1" "$TMPDIR"/core_new
return 2
else
rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx
if [ -z "$zip_type" ];then
gzip -c "$TMPDIR/core_new" > "$BINDIR/CrashCore.gz"
else
mv -f "$1" "$BINDIR/CrashCore.$zip_type"
fi
if [ "$zip_type" = 'upx' ];then
rm -f "$1" "$TMPDIR"/core_new
ln -sf "$TMPDIR/CrashCore.upx" "$TMPDIR/CrashCore"
else
mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore"
fi
core_v="$v"
setconfig COMMAND "$COMMAND" "$CRASHDIR"/configs/command.env && . "$CRASHDIR"/configs/command.env
setconfig crashcore "$crashcore"
setconfig core_v "$core_v"
setconfig custcorelink "$custcorelink"
return 0
fi
[ -n "$(pidof CrashCore)" ] && "$CRASHDIR"/start.sh stop #停止内核服务防止内存不足
core_unzip "$1" core_new
sbcheck=$(echo "$crashcore" | grep 'singbox')
v=''
if [ -n "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q 'sing-box'; then
v=$("$TMPDIR"/core_new version 2>/dev/null | grep version | awk '{print $3}')
COMMAND='"$TMPDIR/CrashCore run -D $BINDIR -C $TMPDIR/jsons"'
elif [ -z "$sbcheck" ] && "$TMPDIR"/core_new -h 2>&1 | grep -q '\-t';then
v=$("$TMPDIR"/core_new -v 2>/dev/null | head -n 1 | sed 's/ linux.*//;s/.* //')
COMMAND='"$TMPDIR/CrashCore -d $BINDIR -f $TMPDIR/config.yaml"'
fi
if [ -z "$v" ]; then
rm -rf "$1" "$TMPDIR"/core_new
return 2
else
rm -f "$BINDIR"/CrashCore.tar.gz "$BINDIR"/CrashCore.gz "$BINDIR"/CrashCore.upx
if [ -z "$zip_type" ];then
gzip -c "$TMPDIR/core_new" > "$BINDIR/CrashCore.gz"
else
mv -f "$1" "$BINDIR/CrashCore.$zip_type"
fi
if [ "$zip_type" = 'upx' ];then
rm -f "$1" "$TMPDIR"/core_new
ln -sf "$TMPDIR/CrashCore.upx" "$TMPDIR/CrashCore"
else
mv -f "$TMPDIR/core_new" "$TMPDIR/CrashCore"
fi
core_v="$v"
setconfig COMMAND "$COMMAND" "$CRASHDIR"/configs/command.env && . "$CRASHDIR"/configs/command.env
setconfig crashcore "$crashcore"
setconfig core_v "$core_v"
setconfig custcorelink "$custcorelink"
return 0
fi
}
core_webget(){
. "$CRASHDIR"/libs/web_get_bin.sh
. "$CRASHDIR"/libs/check_target.sh
if [ -z "$custcorelink" ];then
[ -z "$zip_type" ] && zip_type='tar.gz'
get_bin "$TMPDIR/Coretmp.$zip_type" "bin/$crashcore/${target}-linux-${cpucore}.$zip_type"
else
case "$custcorelink" in
*.tar.gz) zip_type="tar.gz" ;;
*.gz) zip_type="gz" ;;
*.upx) zip_type="upx" ;;
esac
[ -n "$zip_type" ] && webget "$TMPDIR/Coretmp.$zip_type" "$custcorelink"
fi
#校验内核
if [ "$?" = 0 ];then
core_check "$TMPDIR/Coretmp.$zip_type"
else
rm -f "$TMPDIR/Coretmp.$zip_type"
return 1
fi
. "$CRASHDIR"/libs/web_get_bin.sh
. "$CRASHDIR"/libs/check_target.sh
if [ -z "$custcorelink" ];then
[ -z "$zip_type" ] && zip_type='tar.gz'
get_bin "$TMPDIR/Coretmp.$zip_type" "bin/$crashcore/${target}-linux-${cpucore}.$zip_type"
else
case "$custcorelink" in
*.tar.gz) zip_type="tar.gz" ;;
*.gz) zip_type="gz" ;;
*.upx) zip_type="upx" ;;
esac
[ -n "$zip_type" ] && webget "$TMPDIR/Coretmp.$zip_type" "$custcorelink"
fi
#校验内核
if [ "$?" = 0 ];then
core_check "$TMPDIR/Coretmp.$zip_type"
else
rm -f "$TMPDIR/Coretmp.$zip_type"
return 1
fi
}

View File

@@ -1,26 +1,26 @@
#生成指定位数的加密秘钥符合ss2022协议
gen_random() {
if ckcmd openssl;then
openssl rand --base64 "$1"
elif ckcmd base64;then
head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then
head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif ckcmd uuencode;then
head -c "$1" /dev/urandom | uuencode -m - | sed -n '2p'
else
return 1
fi
openssl rand --base64 "$1"
elif ckcmd base64;then
head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then
head -c "$1" /dev/urandom | base64 | tr -d '\n'
elif ckcmd uuencode;then
head -c "$1" /dev/urandom | uuencode -m - | sed -n '2p'
else
return 1
fi
}
#对指定字符串进行base64转码
gen_base64() {
if ckcmd base64;then
echo -n "$1" | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then
echo -n "$1" | busybox base64 | tr -d '\n'
elif ckcmd openssl;then
echo -n "$1" | openssl base64 -A
else
return 1
fi
if ckcmd base64;then
echo -n "$1" | base64 | tr -d '\n'
elif busybox base64 --help >/dev/null 2>&1;then
echo -n "$1" | busybox base64 | tr -d '\n'
elif ckcmd openssl;then
echo -n "$1" | openssl base64 -A
else
return 1
fi
}

View File

@@ -15,8 +15,8 @@ routing_mark=$((fwmark + 2))
[ -z "$table" ] && table=100
[ -z "$dns_nameserver" ] && {
dns_nameserver='223.5.5.5, 1.2.4.8'
netstat -ntlup 2>/dev/null | grep -q '127.0.0.1:53' && dns_nameserver='127.0.0.1'
dns_nameserver='223.5.5.5, 1.2.4.8'
netstat -ntlup 2>/dev/null | grep -q '127.0.0.1:53' && dns_nameserver='127.0.0.1'
}
[ -z "$dns_fallback" ] && dns_fallback="1.1.1.1, 8.8.8.8"
[ -z "$dns_resolver" ] && dns_resolver="223.5.5.5, 2400:3200::1"

View File

@@ -5,11 +5,11 @@ get_ecs_address() {
ip=$(grep -A1 "^# Interface wan$" "$f" | grep nameserver | awk '{printf "%s ", $2}')
[ -n "$ip" ] && return
done
. "$CRASHDIR"/libs/web_get_lite.sh
for web in http://members.3322.org/dyndns/getip http://4.ipw.cn http://ipinfo.io/ip; do
ip=$(web_get_lite "$web" 0)
[ -n "$ip" ] && return
done
. "$CRASHDIR"/libs/web_get_lite.sh
for web in http://members.3322.org/dyndns/getip http://4.ipw.cn http://ipinfo.io/ip; do
ip=$(web_get_lite "$web" 0)
[ -n "$ip" ] && return
done
}
get_ecs_address
[ -n "$ip" ] && ecs_address="${ip%.*}.0/24"

View File

@@ -1,8 +1,8 @@
load_lang() {
i18n=$(cat "$CRASHDIR"/configs/i18n.cfg 2>/dev/null)
[ -z "$i18n" ] && i18n=chs
[ -z "$i18n" ] && i18n=chs
file="$CRASHDIR/lang/$i18n/$1.lang"
[ -s "$file" ] && . "$file"
}

View File

@@ -6,13 +6,13 @@ __IS_LIB_LOGGER=1
. "$CRASHDIR"/libs/web_json.sh
#$1日志内容$2显示颜色$3是否推送$4是否覆盖上一条
logger() {
TMPDIR=/tmp/ShellCrash
TMPDIR=/tmp/ShellCrash
[ -n "$2" -a "$2" != 0 ] && printf "\033[%sm%s\033[0m\n" "$2" "$1"
log_text="$(date "+%G-%m-%d_%H:%M:%S")~$1"
[ "$4" = on ] && sed -i "/$1/d" "$TMPDIR"/ShellCrash.log
[ "$4" = on ] && sed -i "/$1/d" "$TMPDIR"/ShellCrash.log
echo "$log_text" >>"$TMPDIR"/ShellCrash.log
[ "$(wc -l "$TMPDIR"/ShellCrash.log | awk '{print $1}')" -gt 199 ] && sed -i '1,20d' "$TMPDIR"/ShellCrash.log
#推送远程日志
#推送远程日志
[ "$3" != off ] && {
[ -n "$device_name" ] && log_text="$log_text($device_name)"
[ -n "$push_TG" ] && {
@@ -51,6 +51,6 @@ logger() {
url="${push_ChatURL}/webapi/entry.cgi?api=SYNO.Chat.External&method=chatbot&version=2&token=${push_ChatTOKEN}"
content="payload={\"text\":\"${log_text}\", \"user_ids\":[${push_ChatUSERID}]}"
web_json_post "$url" "$content" &
}
}
} &
}

View File

@@ -3,7 +3,7 @@
#meta内核vmess入站生成
[ "$vms_service" = ON ] && {
cat >>"$TMPDIR"/listeners.yaml <<EOF
cat >>"$TMPDIR"/listeners.yaml <<EOF
- name: "vmess-in"
type: vmess
port: $vms_port
@@ -16,7 +16,7 @@ EOF
}
#meta内核ss入站生成
[ "$sss_service" = ON ] && {
cat >>"$TMPDIR"/listeners.yaml <<EOF
cat >>"$TMPDIR"/listeners.yaml <<EOF
- name: "ss-in"
type: shadowsocks
port: $sss_port

View File

@@ -2,24 +2,24 @@
# Copyright (C) Juewuy
[ "$ts_service" = ON ] && ! grep -q '"tailscale"' "$CRASHDIR"/jsons/endpoints.json 2>/dev/null && {
[ "$ts_subnet" = true ] && {
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip
advertise_routes=$(echo "$host_ipv4"|sed 's/[[:space:]]\+/", "/g; s/^/"/; s/$/"/')
}
[ -z "$ts_exit_node" ] && ts_exit_node=false
[ -z "$ts_hostname" ] && ts_hostname='ShellCrash'
cat >"$TMPDIR"/jsons/tailscale.json <<EOF
[ "$ts_subnet" = true ] && {
. "$CRASHDIR"/starts/fw_getlanip.sh && getlanip
advertise_routes=$(echo "$host_ipv4"|sed 's/[[:space:]]\+/", "/g; s/^/"/; s/$/"/')
}
[ -z "$ts_exit_node" ] && ts_exit_node=false
[ -z "$ts_hostname" ] && ts_hostname='ShellCrash'
cat >"$TMPDIR"/jsons/tailscale.json <<EOF
{
"endpoints": [
{
"type": "tailscale",
"tag": "ts-ep",
"state_directory": "$CRASHDIR/tailscale",
"auth_key": "$ts_auth_key",
"hostname": "$ts_hostname",
"advertise_routes": [$advertise_routes],
"advertise_exit_node": $ts_exit_node,
"udp_timeout": "5m"
"type": "tailscale",
"tag": "ts-ep",
"state_directory": "$CRASHDIR/tailscale",
"auth_key": "$ts_auth_key",
"hostname": "$ts_hostname",
"advertise_routes": [$advertise_routes],
"advertise_exit_node": $ts_exit_node,
"udp_timeout": "5m"
}
]
}
@@ -27,27 +27,27 @@ EOF
}
[ "$wg_service" = ON ] && ! grep -q '"wireguard"' "$CRASHDIR"/jsons/endpoints.json 2>/dev/null && {
[ -n "$wg_ipv6" ] && wg_ipv6_add=", \"$wg_ipv6\""
cat >"$TMPDIR"/jsons/wireguard.json <<EOF
[ -n "$wg_ipv6" ] && wg_ipv6_add=", \"$wg_ipv6\""
cat >"$TMPDIR"/jsons/wireguard.json <<EOF
{
"endpoints": [
{
"type": "wireguard",
"tag": "wg-ep",
"system": true,
"mtu": 1420,
"address": [ "$wg_ipv4"$wg_ipv6_add ],
"private_key": "$wg_private_key",
"peers": [
{
"address": "$wg_server",
"port": $wg_port,
"public_key": "$wg_public_key",
"pre_shared_key": "$wg_pre_shared_key",
"allowed_ips": ["0.0.0.0/0", "::/0"]
}
]
}
{
"type": "wireguard",
"tag": "wg-ep",
"system": true,
"mtu": 1420,
"address": [ "$wg_ipv4"$wg_ipv6_add ],
"private_key": "$wg_private_key",
"peers": [
{
"address": "$wg_server",
"port": $wg_port,
"public_key": "$wg_public_key",
"pre_shared_key": "$wg_pre_shared_key",
"allowed_ips": ["0.0.0.0/0", "::/0"]
}
]
}
]
}
EOF

View File

@@ -2,8 +2,8 @@
# Copyright (C) Juewuy
[ "$vms_service" = ON ] && {
[ -n "$vms_ws_path" ] && transport=', "transport": { "type": "ws", "path": "'"$vms_ws_path"'" }'
cat >"$TMPDIR"/jsons/vmess-in.json <<EOF
[ -n "$vms_ws_path" ] && transport=', "transport": { "type": "ws", "path": "'"$vms_ws_path"'" }'
cat >"$TMPDIR"/jsons/vmess-in.json <<EOF
{
"inbounds": [
{
@@ -11,7 +11,7 @@
"tag": "vmess-in",
"listen": "::",
"listen_port": $vms_port,
"users": [
"users": [
{
"uuid": "$vms_uuid"
}
@@ -23,17 +23,17 @@ EOF
}
[ "$sss_service" = ON ] && {
cat >"$TMPDIR"/jsons/ss-in.json <<EOF
cat >"$TMPDIR"/jsons/ss-in.json <<EOF
{
"inbounds": [
{
"type": "shadowsocks",
"tag": "ss-in",
{
"type": "shadowsocks",
"tag": "ss-in",
"listen": "::",
"listen_port": $sss_port,
"method": "$sss_cipher",
"password": "$sss_pwd",
}
"method": "$sss_cipher",
"password": "$sss_pwd",
}
]
}
EOF

View File

@@ -1,6 +1,6 @@
#参数1代表变量名参数2代表变量值,参数3即文件路径
setconfig() {
[ -z "$3" ] && configpath="$CRASHDIR"/configs/ShellCrash.cfg || configpath="${3}"
sed -i "/^${1}=.*/d" "$configpath"
printf '%s=%s\n' "$1" "$2" >>"$configpath"
sed -i "/^${1}=.*/d" "$configpath"
printf '%s=%s\n' "$1" "$2" >>"$configpath"
}

View File

@@ -8,32 +8,32 @@ tmpcron=/tmp/cron_tmp
touch "$tmpcron"
cronadd() { #定时任务工具
if crontab -h 2>&1 | grep -q '\-l'; then
if crontab -h 2>&1 | grep -q '\-l'; then
crontab "$1"
elif [ -f "$crondir/$USER" ];then
cat "$1" >"$crondir"/"$USER" && cru a REFRESH "0 0 1 1 * /bin/true" 2>/dev/null
else
echo "找不到可用的crond或者crontab应用No available crond or crontab application can be found!"
fi
elif [ -f "$crondir/$USER" ];then
cat "$1" >"$crondir"/"$USER" && cru a REFRESH "0 0 1 1 * /bin/true" 2>/dev/null
else
echo "找不到可用的crond或者crontab应用No available crond or crontab application can be found!"
fi
}
cronload() { #定时任务工具
if crontab -h 2>&1 | grep -q '\-l'; then
if crontab -h 2>&1 | grep -q '\-l'; then
crontab -l
elif [ -f "$crondir/$USER" ];then
cat "$crondir"/"$USER" 2>/dev/null
else
return 1
fi
elif [ -f "$crondir/$USER" ];then
cat "$crondir"/"$USER" 2>/dev/null
else
return 1
fi
}
cronset() { #定时任务设置
# 参数1代表要移除的关键字,参数2代表要添加的任务语句
cronload | grep -v '^$' | grep -vF "$1" >"$tmpcron"
[ -n "$2" ] && echo "$2" >>"$tmpcron"
cronadd "$tmpcron"
#华硕/Padavan固件存档在本地,其他则删除
if [ -d /jffs ] || [ -d /etc/storage/ShellCrash ];then
mv -f "$tmpcron" "$CRASHDIR"/task/cron
else
rm -f "$tmpcron"
fi
cronadd "$tmpcron"
#华硕/Padavan固件存档在本地,其他则删除
if [ -d /jffs ] || [ -d /etc/storage/ShellCrash ];then
mv -f "$tmpcron" "$CRASHDIR"/task/cron
else
rm -f "$tmpcron"
fi
}

View File

@@ -5,5 +5,5 @@ set_profile() {
echo "alias ${my_alias}=\"$shtype $CRASHDIR/menu.sh\"" >>"$1" #设置快捷命令环境变量
sed -i '/export CRASHDIR=*/'d "$1"
echo "export CRASHDIR=\"$CRASHDIR\"" >>"$1" #设置路径环境变量
. "$1" >/dev/null 2>&1 || true
. "$1" >/dev/null 2>&1 || true
}

View File

@@ -1,9 +1,9 @@
setproxy(){
[ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@" || auth=""
[ -z "$mix_port" ] && mix_port=7890
export https_proxy="http://${auth}127.0.0.1:$mix_port"
export http_proxy="http://${auth}127.0.0.1:$mix_port"
}
[ -n "$(pidof CrashCore)" ] && {
[ -n "$authentication" ] && auth="$authentication@" || auth=""
[ -z "$mix_port" ] && mix_port=7890
export https_proxy="http://${auth}127.0.0.1:$mix_port"
export http_proxy="http://${auth}127.0.0.1:$mix_port"
}
}

View File

@@ -1,10 +1,10 @@
i=1
while [ -z "$test" -a "$i" -lt 30 ]; do
sleep 1
if curl --version >/dev/null 2>&1; then
test=$(curl -s -H "Authorization: Bearer $secret" http://127.0.0.1:${db_port}/proxies | grep -o proxies)
else
test=$(wget -q --header="Authorization: Bearer $secret" -O - http://127.0.0.1:${db_port}/proxies | grep -o proxies)
fi
i=$((i + 1))
sleep 1
if curl --version >/dev/null 2>&1; then
test=$(curl -s -H "Authorization: Bearer $secret" http://127.0.0.1:${db_port}/proxies | grep -o proxies)
else
test=$(wget -q --header="Authorization: Bearer $secret" -O - http://127.0.0.1:${db_port}/proxies | grep -o proxies)
fi
i=$((i + 1))
done

View File

@@ -1,77 +1,77 @@
. "$CRASHDIR"/libs/set_proxy.sh
webget(){
if pidof CrashCore >/dev/null; then
setproxy #设置临时代理,【$1】代表下载目录【$2】代表在线地址
url=$(printf '%s\n' "$2" |
sed -e 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' \
-e 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#')
else
url=$(printf '%s\n' "$2" |
sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#')
fi
# ===============================================
if pidof CrashCore >/dev/null; then
setproxy #设置临时代理,【$1】代表下载目录【$2】代表在线地址
url=$(printf '%s\n' "$2" |
sed -e 's#https://.*jsdelivr.net/gh/juewuy/ShellCrash[@|/]#https://raw.githubusercontent.com/juewuy/ShellCrash/#' \
-e 's#https://gh.jwsc.eu.org/#https://raw.githubusercontent.com/juewuy/ShellCrash/#')
else
url=$(printf '%s\n' "$2" |
sed 's#https://raw.githubusercontent.com/juewuy/ShellCrash/#https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@#')
fi
# ===============================================
#参数【$1】代表下载目录【$2】代表在线地址
#参数【$3】代表输出显示【$4】不启用重定向
#参数【$5】代表验证证书【$6】使用自定义UA
[ -n "$6" ] && agent="--user-agent $6"
if wget --help 2>&1 | grep -q 'show-progress' >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
certificate=''
else
certificate='--no-check-certificate'
fi
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$1" "$url" && return 0 #成功则退出否则重试
wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$1" "$2"
return $?
elif curl --version >/dev/null 2>&1; then
if [ "$3" = "echooff" ];then
progress='-s'
elif echo "$url" | grep -q 'jsdelivr.net';then
progress='-#'
. "$CRASHDIR"/libs/web_get_curlbar.sh && curl_fsize
else
progress='-#'
fi
[ "$4" = "rediroff" ] && redirect='' || redirect='-L'
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
certificate=''
else
certificate='-k'
fi
# curl 特殊版本兼容
auth_arg=""
if curl --version | grep -q '^curl 8.' && ckcmd base64; then
auth_b64=$(printf '%s' "$authentication" | base64)
[ -n "$auth_b64" ] && auth_arg="--proxy-header Proxy-Authorization:Basic $auth_b64"
fi
if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then
result=$(execute_curl "$1" "$url" "$fsize_raw" "$agent $auth_arg $redirect $certificate")
else
result=$(curl $agent $auth_arg -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$1" "$url")
fi
#参数【$1】代表下载目录【$2】代表在线地址
#参数【$3】代表输出显示【$4】不启用重定向
#参数【$5】代表验证证书【$6】使用自定义UA
[ -n "$6" ] && agent="--user-agent $6"
if wget --help 2>&1 | grep -q 'show-progress' >/dev/null 2>&1; then
[ "$3" = "echooff" ] && progress='-q' || progress='-q --show-progress'
[ "$4" = "rediroff" ] && redirect='--max-redirect=0' || redirect=''
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
certificate=''
else
certificate='--no-check-certificate'
fi
wget -Y on $agent $progress $redirect $certificate --timeout=3 -O "$1" "$url" && return 0 #成功则退出否则重试
wget -Y off $agent $progress $redirect $certificate --timeout=5 -O "$1" "$2"
return $?
elif curl --version >/dev/null 2>&1; then
if [ "$3" = "echooff" ];then
progress='-s'
elif echo "$url" | grep -q 'jsdelivr.net';then
progress='-#'
. "$CRASHDIR"/libs/web_get_curlbar.sh && curl_fsize
else
progress='-#'
fi
[ "$4" = "rediroff" ] && redirect='' || redirect='-L'
if [ "$5" = "skipceroff" ] || [ "$skip_cert" = OFF ];then
certificate=''
else
certificate='-k'
fi
# curl 特殊版本兼容
auth_arg=""
if curl --version | grep -q '^curl 8.' && ckcmd base64; then
auth_b64=$(printf '%s' "$authentication" | base64)
[ -n "$auth_b64" ] && auth_arg="--proxy-header Proxy-Authorization:Basic $auth_b64"
fi
if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then
result=$(execute_curl "$1" "$url" "$fsize_raw" "$agent $auth_arg $redirect $certificate")
else
result=$(curl $agent $auth_arg -w '%{http_code}' --connect-timeout 3 $progress $redirect $certificate -o "$1" "$url")
fi
[ "$result" = "200" ] && return 0 #成功则退出否则重试
export https_proxy=""
export http_proxy=""
if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then
result=$(execute_curl "$1" "$2" "$fsize_raw" "$agent $redirect $certificate")
else
result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$1" "$2")
fi
[ "$result" = "200" ]
return $?
elif ckcmd wget;then
[ "$3" = "echooff" ] && progress='-q'
wget -Y on $progress -O "$1" "$url" && return 0 #成功则退出否则重试
wget -Y off $progress -O "$1" "$2"
return $?
else
echo "No Curl or Wget"
return 1
fi
[ "$result" = "200" ] && return 0 #成功则退出否则重试
export https_proxy=""
export http_proxy=""
if [ -n "$fsize_raw" ] && [ "$fsize_raw" -gt 204800 ]; then
result=$(execute_curl "$1" "$2" "$fsize_raw" "$agent $redirect $certificate")
else
result=$(curl $agent -w '%{http_code}' --connect-timeout 5 $progress $redirect $certificate -o "$1" "$2")
fi
[ "$result" = "200" ]
return $?
elif ckcmd wget;then
[ "$3" = "echooff" ] && progress='-q'
wget -Y on $progress -O "$1" "$url" && return 0 #成功则退出否则重试
wget -Y off $progress -O "$1" "$2"
return $?
else
echo "No Curl or Wget"
return 1
fi
}

View File

@@ -3,7 +3,7 @@
get_bin() { #专用于项目内部文件的下载
[ -z "$update_url" ] && update_url=https://testingcf.jsdelivr.net/gh/juewuy/ShellCrash@master
if [ -n "$url_id" ]; then
[ -n "$release_type" ] && rt="$release_type" || rt=master
[ -n "$release_type" ] && rt="$release_type" || rt=master
echo "$2" | grep -q '^bin/' && rt=update #/bin文件改为在update分支下载
echo "$2" | grep -qE '^public/|^rules/' && rt=dev #/public和/rules文件改为在dev分支下载
if [ "$url_id" = 101 -o "$url_id" = 104 ]; then

View File

@@ -2,46 +2,46 @@
bar_max=42 #进度条长度
curl_fsize(){ # 获取文件大小
fsize_raw=0
header=$(curl -sIL --connect-timeout 2 "$url")
# 代理容错
[ -z "$header" ] && { export https_proxy=""; export http_proxy=""; header=$(curl -sIL --connect-timeout 2 "$url"); }
# 提取大小 (优先 Content-Length其次 ETag)
fsize_raw=$(echo "$header" | grep -i 'Content-Length' | tail -n 1 | awk '{print $2}' | tr -d '\r' | awk '{print int($1)}')
if [ -z "$fsize_raw" ] || [ "$fsize_raw" -eq 0 ]; then
etag=$(echo "$header" | grep -i 'etag' | tail -n 1 | cut -d '"' -f2 | cut -d '-' -f1)
[ -n "$etag" ] && fsize_raw=$(printf "%d" 0x$etag 2>/dev/null)
fi
fsize_raw=0
header=$(curl -sIL --connect-timeout 2 "$url")
# 代理容错
[ -z "$header" ] && { export https_proxy=""; export http_proxy=""; header=$(curl -sIL --connect-timeout 2 "$url"); }
# 提取大小 (优先 Content-Length其次 ETag)
fsize_raw=$(echo "$header" | grep -i 'Content-Length' | tail -n 1 | awk '{print $2}' | tr -d '\r' | awk '{print int($1)}')
if [ -z "$fsize_raw" ] || [ "$fsize_raw" -eq 0 ]; then
etag=$(echo "$header" | grep -i 'etag' | tail -n 1 | cut -d '"' -f2 | cut -d '-' -f1)
[ -n "$etag" ] && fsize_raw=$(printf "%d" 0x$etag 2>/dev/null)
fi
}
execute_curl(){ # 手搓curl进度条
local path="$1" target_url="$2" total_size="$3" extra_args="$4"
rm -f /tmp/webget_res
# 后台静默下载,状态码写入临时文件
curl $extra_args -s -L -w '%{http_code}' "$target_url" -o "$path" > /tmp/webget_res &
local pid=$!
# 循环监控
while kill -0 $pid 2>/dev/null; do
if [ -f "$path" ]; then
local curr=$(wc -c < "$path")
local pct=$(awk -v c=$curr -v t=$total_size 'BEGIN {p=(c*100/t); if(p>100)p=100; printf "%.1f", p}')
local num=$(awk -v p=$pct -v w=$bar_max 'BEGIN {printf "%d", p*w/100}')
local bar=$(printf "%${num}s" | tr ' ' '#'); local spc_n=$((bar_max - num))
local spc=""; [ "$spc_n" -gt 0 ] && spc=$(printf "%${spc_n}s")
local size=$(( fsize_raw * 100 / 1048576 ))
local fs="$((size / 100)).$((size % 100)) MB"
printf "\r\033[2K%s%s %6s%%(%s)" "$bar" "$spc" "$pct" "$fs" >&2
fi
usleep 200000 2>/dev/null || sleep 1
done
local code=$(cat /tmp/webget_res 2>/dev/null)
if [ "$code" = "200" ] || [ "$code" = "206" ]; then
local full=$(printf "%${bar_max}s" | tr ' ' '#')
printf "\r\033[2K%s 100.0%%(%s)\n" "$full" "$fs" >&2
else
printf "\r\033[2K" >&2; [ -f "$path" ] && rm -f "$path"
fi
echo "$code"
local path="$1" target_url="$2" total_size="$3" extra_args="$4"
rm -f /tmp/webget_res
# 后台静默下载,状态码写入临时文件
curl $extra_args -s -L -w '%{http_code}' "$target_url" -o "$path" > /tmp/webget_res &
local pid=$!
# 循环监控
while kill -0 $pid 2>/dev/null; do
if [ -f "$path" ]; then
local curr=$(wc -c < "$path")
local pct=$(awk -v c=$curr -v t=$total_size 'BEGIN {p=(c*100/t); if(p>100)p=100; printf "%.1f", p}')
local num=$(awk -v p=$pct -v w=$bar_max 'BEGIN {printf "%d", p*w/100}')
local bar=$(printf "%${num}s" | tr ' ' '#'); local spc_n=$((bar_max - num))
local spc=""; [ "$spc_n" -gt 0 ] && spc=$(printf "%${spc_n}s")
local size=$(( fsize_raw * 100 / 1048576 ))
local fs="$((size / 100)).$((size % 100)) MB"
printf "\r\033[2K%s%s %6s%%(%s)" "$bar" "$spc" "$pct" "$fs" >&2
fi
usleep 200000 2>/dev/null || sleep 1
done
local code=$(cat /tmp/webget_res 2>/dev/null)
if [ "$code" = "200" ] || [ "$code" = "206" ]; then
local full=$(printf "%${bar_max}s" | tr ' ' '#')
printf "\r\033[2K%s 100.0%%(%s)\n" "$full" "$fs" >&2
else
printf "\r\033[2K" >&2; [ -f "$path" ] && rm -f "$path"
fi
echo "$code"
}

View File

@@ -1,10 +1,10 @@
. "$CRASHDIR"/libs/set_proxy.sh
#$1:目标地址 $2:禁用proxy
web_get_lite() {
[ -z "$2" ] && setproxy
if curl --version >/dev/null 2>&1; then
curl -ksSl --connect-timeout 3 "$1" 2>/dev/null
else
wget -Y on -q --timeout=3 -O - "$1"
fi
[ -z "$2" ] && setproxy
if curl --version >/dev/null 2>&1; then
curl -ksSl --connect-timeout 3 "$1" 2>/dev/null
else
wget -Y on -q --timeout=3 -O - "$1"
fi
}

View File

@@ -1,10 +1,10 @@
. "$CRASHDIR"/libs/set_proxy.sh
#$1:目标地址 $2:json字符串
web_json_post() {
setproxy
if curl --version >/dev/null 2>&1; then
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json" "$1" -d "$2" >/dev/null 2>&1
else
wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json" --body-data="$2" "$1"
fi
setproxy
if curl --version >/dev/null 2>&1; then
curl -kfsSl -X POST --connect-timeout 3 -H "Content-Type: application/json" "$1" -d "$2" >/dev/null 2>&1
else
wget -Y on -q --timeout=3 --method=POST --header="Content-Type: application/json" --body-data="$2" "$1"
fi
}

View File

@@ -9,12 +9,12 @@ put_save() { #推送面板选择
fi
}
web_restore() { #还原面板选择
num=$(cat "$CRASHDIR"/configs/web_save | wc -l)
i=1
while [ "$i" -le "$num" ]; do
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' "$CRASHDIR"/configs/web_save | sed 's/ /%20/g')
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' "$CRASHDIR"/configs/web_save)
put_save "http://127.0.0.1:${db_port}/proxies/${group_name}" "{\"name\":\"${now_name}\"}"
i=$((i + 1))
done
num=$(cat "$CRASHDIR"/configs/web_save | wc -l)
i=1
while [ "$i" -le "$num" ]; do
group_name=$(awk -F ',' 'NR=="'${i}'" {print $1}' "$CRASHDIR"/configs/web_save | sed 's/ /%20/g')
now_name=$(awk -F ',' 'NR=="'${i}'" {print $2}' "$CRASHDIR"/configs/web_save)
put_save "http://127.0.0.1:${db_port}/proxies/${group_name}" "{\"name\":\"${now_name}\"}"
i=$((i + 1))
done
}

View File

@@ -9,7 +9,7 @@ get_save() { #获取面板信息
}
web_save() { #最小化保存面板节点选择
#使用get_save获取面板节点设置
get_save "http://127.0.0.1:${db_port}/proxies" | sed 's/{}//g' | sed 's/:{/\
get_save "http://127.0.0.1:${db_port}/proxies" | sed 's/{}//g' | sed 's/:{/\
/g'| grep -aE '"Selector"' >"$TMPDIR"/web_proxies
[ -s "$TMPDIR"/web_proxies ] && while read line; do
def=$(echo $line | grep -oE '"all".*",' | awk -F "[\"]" '{print $4}')
@@ -25,8 +25,8 @@ web_save() { #最小化保存面板节点选择
if [ -s "$TMPDIR/$file" ]; then
. "$CRASHDIR"/libs/compare.sh && compare "$TMPDIR/$file" "$CRASHDIR/configs/$file"
[ "$?" = 0 ] && rm -f "$TMPDIR/$file" || mv -f "$TMPDIR/$file" "$CRASHDIR/configs/$file"
else
> "$CRASHDIR/configs/$file" #空文件时移除旧文件
else
> "$CRASHDIR/configs/$file" #空文件时移除旧文件
fi
done
}