Files
download/panel/public.sh
耗子 a65d23f05b
Some checks failed
Generate Checksums / checksums (push) Has been cancelled
feat: 移除协议
2025-08-22 06:19:40 +08:00

93 lines
3.0 KiB (Stored with Git LFS)
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
export LC_ALL=C
export HR="+----------------------------------------------------"
export ARCH=$(uname -m)
# hce Huawei Cloud EulerOS
# openEuler openEuler
export OS=$(source /etc/os-release && { [[ "$ID" == "debian" ]] || [[ "$ID_LIKE" =~ "debian" ]] && echo "debian"; } || { [[ "$ID" == "ubuntu" ]] || [[ "$ID_LIKE" =~ "ubuntu" ]] && echo "ubuntu"; } || { [[ "$ID" == "tencentos" ]] || [[ "$ID" == "opencloudos" ]] || [[ "$ID" == "hce" ]] || [[ "$ID" == "openEuler" ]] || [[ "$ID" == "rhel" ]] || [[ "$ID_LIKE" =~ "rhel" ]] && echo "rhel"; } || echo "unknown")
export CORES=$(nproc)
export MEM=$(LC_ALL=C free -m | grep Mem | awk '{print $2}')
export SWAP=$(LC_ALL=C free -m | grep Swap | awk '{print $2}')
export download_url="https://dl.cdn.haozi.net/panel"
export setup_path="/www"
# 从配置文件中读取 setup_path
if [ -f /usr/local/etc/panel/config.yml ]; then
setup_path=$(grep root /usr/local/etc/panel/config.yml | awk '{print $2}')
fi
# 计算 j 值(通用)
calculate_j() {
total=$((MEM + SWAP))
j_value=$((total / 1024))
[ "$j_value" -eq 0 ] && j_value=1
[ "$j_value" -gt "$CORES" ] && j_value=$CORES
[ "$j_value" -gt 1 ] && j_value=$((j_value - 1)) # 大于1则减1
echo "$j_value"
}
# 计算 j 值2倍内存
calculate_j2() {
total=$((MEM + SWAP))
j_value=$((total / 2024))
[ "$j_value" -eq 0 ] && j_value=1
[ "$j_value" -gt "$CORES" ] && j_value=$CORES
[ "$j_value" -gt 1 ] && j_value=$((j_value - 1)) # 大于1则减1
echo "$j_value"
}
# 系统信息
sys_info() {
dir=$(pwd)
cd /tmp || cd /
if [ -f /etc/os-release ]; then
system_version=$(grep PRETTY_NAME /etc/os-release | awk -F '"' '{print $2}')
else
system_version="unknown"
fi
kernel_version=$(uname -a)
bitness=$(getconf LONG_BIT)-bit
cpu_name=$(lscpu | grep "^Model name:" | awk -F: '{print $2}' | sed 's/^[ \t]*//')
cpu_flags=$(lscpu | grep "^Flags:" | awk -F: '{print $2}' | sed 's/^[ \t]*//' | sed 's/ /,/g')
if command -v gcc >/dev/null 2>&1; then
gcc_version=$(gcc -v 2>&1 | tail -n1 | awk '{print $3}')
else
gcc_version="no gcc"
fi
if command -v cmake >/dev/null 2>&1; then
cmake_version=$(cmake --version | head -n1 | awk '{print $3}')
else
cmake_version="no cmake"
fi
echo -e $HR
echo -e "| Kernel: $kernel_version"
echo -e "| CPU: $cpu_name | Arch: $ARCH | Core: $CORES"
echo -e "| OS: $system_version | Bit: $bitness | Mem: $MEM | Swap: $SWAP | gcc: $gcc_version | cmake: $cmake_version"
echo -e $HR
[ -d "$dir" ] && cd "$dir"
}
# 错误输出
error() {
echo -e $HR
echo -e "| 错误:$1"
echo -e "| Error: $1"
echo -e "| 可截图错误信息寻求帮助,或者联系面板官方支持。"
echo -e "| Take a screenshot of the error message for help, or contact the panel official support."
sys_info
exit 1
}