chore:actions

This commit is contained in:
dichgrem
2026-01-18 15:51:42 +08:00
parent 15e1df01f5
commit 130a2298f2
2 changed files with 168 additions and 10 deletions

View File

@@ -9,7 +9,6 @@ on:
default: "immortalwrt"
type: choice
options:
- lede
- openwrt
- immortalwrt
- immortalwrt-mt798x
@@ -57,6 +56,48 @@ on:
required: false
default: true
type: boolean
custom_shell:
description: "默认 shell"
required: false
default: "ash"
type: choice
options:
- ash
- bash
luci_theme:
description: "LuCI 主题"
required: false
default: "argon"
type: choice
options:
- argon
- bootstrap
- material
enable_bbr:
description: "启用 BBR 拥塞控制"
required: false
default: true
type: boolean
custom_hostname:
description: "自定义 hostname留空则跳过"
required: false
default: "Dwrt"
type: string
custom_ip:
description: "自定义 IP 地址(留空则跳过)"
required: false
default: "192.168.1.1"
type: string
root_password:
description: "自定义 root 密码(留空则跳过)"
required: false
default: ""
type: string
custom_banner:
description: "自定义 SSH 横幅(留空则默认)"
required: false
default: ""
type: string
env:
CCACHE_DIR: ${{ github.workspace }}/wrt/.ccache
@@ -197,9 +238,6 @@ jobs:
openwrt)
echo "url=https://git.openwrt.org/openwrt/openwrt.git" >> $GITHUB_OUTPUT
;;
lede)
echo "url=https://github.com/coolsnowwolf/lede.git" >> $GITHUB_OUTPUT
;;
*)
echo "❌ 未知项目: ${{ inputs.project }}" >&2
exit 1
@@ -213,13 +251,134 @@ jobs:
(git clone "${{ steps.projectinfo.outputs.url }}" wrt && cd wrt && git checkout "${{ steps.refinfo.outputs.ref }}")
echo "🔖 当前版本:$(cd wrt && git describe --tags --always || git rev-parse --short HEAD)"
- name: Apply custom configurations
working-directory: wrt
run: |
echo "⚙️ 应用自定义配置..."
# 检测项目类型
DETECT_TARGET_FILE="package/base-files/files/etc/openwrt_release"
if [ -f "$DETECT_TARGET_FILE" ]; then
if grep -qi "immortalwrt" "$DETECT_TARGET_FILE"; then
TARGET_TYPE="ImmortalWrt"
else
TARGET_TYPE="OpenWrt"
fi
else
if [ -d "feeds/packages" ]; then
TARGET_TYPE="ImmortalWrt"
else
TARGET_TYPE="OpenWrt"
fi
fi
echo "📋 检测到目标类型:$TARGET_TYPE"
# 1. 设置自定义 hostname
if [ -n "${{ inputs.custom_hostname }}" ]; then
CONFIG_GEN_FILE="package/base-files/files/bin/config_generate"
if [ -f "$CONFIG_GEN_FILE" ]; then
if [ "$TARGET_TYPE" = "ImmortalWrt" ]; then
sed -i "s/ImmortalWrt/${{ inputs.custom_hostname }}/g" "$CONFIG_GEN_FILE"
else
sed -i "s/OpenWrt/${{ inputs.custom_hostname }}/g" "$CONFIG_GEN_FILE"
fi
echo "✅ Hostname 已设置为:${{ inputs.custom_hostname }}"
fi
fi
# 2. 设置自定义 IP 地址
if [ -n "${{ inputs.custom_ip }}" ]; then
CONFIG_GEN_FILE="package/base-files/files/bin/config_generate"
if [ -f "$CONFIG_GEN_FILE" ]; then
sed -i 's/192\.168\.[0-9]*\.[0-9]*/${{ inputs.custom_ip }}/g' "$CONFIG_GEN_FILE"
echo "✅ 默认 IP 已设置为:${{ inputs.custom_ip }}"
fi
fi
# 3. 设置 root 密码
if [ -n "${{ inputs.root_password }}" ]; then
SHADOW_FILE="package/base-files/files/etc/shadow"
if [ -f "$SHADOW_FILE" ]; then
HASH=$(openssl passwd -1 '${{ inputs.root_password }}')
if grep -q "^root:" "$SHADOW_FILE"; then
sed -i "s|^root:[^:]*:|root:${HASH}:|" "$SHADOW_FILE"
elif grep -q "^root::" "$SHADOW_FILE"; then
sed -i "s|root::|root:${HASH}:|" "$SHADOW_FILE"
fi
echo "✅ root 密码已设置"
fi
fi
# 4. 设置 LuCI 主题
mkdir -p package/base-files/files/etc/uci-defaults
cat >package/base-files/files/etc/uci-defaults/99_set_theme <<'EOF'
uci set luci.main.mediaurlbase=/luci-static/${{ inputs.luci_theme }}
uci commit luci
EOF
chmod +x package/base-files/files/etc/uci-defaults/99_set_theme
echo "✅ LuCI 主题已设置为:${{ inputs.luci_theme }}"
# 5. 启用/禁用 BBR
if [ "${{ inputs.enable_bbr }}" = "true" ]; then
mkdir -p package/base-files/files/etc/sysctl.d
cat >package/base-files/files/etc/sysctl.d/99-bbr.conf <<'EOF'
net.core.default_qdisc=fq_codel
net.ipv4.tcp_congestion_control=bbr
EOF
echo "✅ BBR 拥塞控制算法已启用"
else
rm -f package/base-files/files/etc/sysctl.d/99-bbr.conf || true
echo " BBR 拥塞控制算法已禁用"
fi
# 6. 设置默认 shell
PASSWD_FILE="package/base-files/files/etc/passwd"
if [ -f "$PASSWD_FILE" ]; then
if [ "${{ inputs.custom_shell }}" = "bash" ]; then
if grep -q "/bin/ash" "$PASSWD_FILE"; then
sed -i "s|/bin/ash|/bin/bash|g" "$PASSWD_FILE"
echo "✅ 默认 shell 已设置为 bash"
fi
else
if grep -q "/bin/bash" "$PASSWD_FILE"; then
sed -i "s|/bin/bash|/bin/ash|g" "$PASSWD_FILE"
echo "✅ 默认 shell 已设置为 ash"
fi
fi
fi
# 7. 设置自定义 SSH 横幅
mkdir -p package/base-files/files/etc
if [ -n "${{ inputs.custom_banner }}" ]; then
cat >package/base-files/files/etc/banner <<'EOF'
${{ inputs.custom_banner }}
EOF
echo "✅ 使用自定义 banner"
else
cat >package/base-files/files/etc/banner <<'EOF'
| | _____ _____ ____________/ |______ | |
| |/ \ / \ / _ \_ __ \ __\__ \ | |
| | Y Y \ Y Y ( <_> ) | \/| | / __ \| |__
|___|__|_| /__|_| /\____/|__| |__| (____ /____/
\/ \/ By Dich \/
-----------------------------------------------------
EOF
echo "✅ 默认 banner 已设置"
fi
echo "✅ 自定义配置完成"
- name: Copy and Run diy.sh
run: |
echo "📂 复制 diy.sh 到 wrt 目录并执行"
cp diy.sh wrt/diy.sh
cd wrt
chmod +x diy.sh
./diy.sh
echo "📂 复制 diy.sh 到 wrt 目录并执行(可选)"
if [ -f diy.sh ]; then
cp diy.sh wrt/diy.sh
cd wrt
chmod +x diy.sh
./diy.sh || echo "⚠️ diy.sh 执行失败,继续构建..."
else
echo " diy.sh 不存在,跳过"
fi
- name: Update and install feeds
working-directory: wrt