-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·136 lines (108 loc) · 3.84 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·136 lines (108 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
# OpenWrt 固件构建脚本
# 用法: ./build.sh [架构配置文件] [线程数]
# 示例: ./build.sh x86_64 8
set -e
# 颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 默认参数
CONFIG_FILE="${1:-x86_64}"
THREADS="${2:-$(nproc)}"
OPENWRT_DIR="/workspace/openwrt-build"
OUTPUT_DIR="/workspace/output"
log_info "开始 OpenWrt 固件构建"
log_info "配置文件: $CONFIG_FILE"
log_info "使用线程数: $THREADS"
# 检查 OpenWrt 源码
if [ ! -d "$OPENWRT_DIR" ]; then
log_info "OpenWrt 源码不存在,开始克隆..."
git clone --depth=1 https://github.com/openwrt/openwrt.git "$OPENWRT_DIR"
fi
cd "$OPENWRT_DIR"
# 清理旧的配置
log_info "清理旧的构建配置..."
rm -rf tmp .config
# 更新 feeds
# log_info "更新 feeds..."
# ./scripts/feeds update -a
# ./scripts/feeds install -a
# 添加自定义包
log_info "添加自定义包..."
rm -rf package/feeds/openwrt-passwall2 package/feeds/openwrt-passwall-packages 2>/dev/null || true
git clone --depth=1 https://github.com/jerrykuku/luci-app-argon-config.git \
package/feeds/luci/luci-app-argon-config 2>/dev/null || true
git clone --depth=1 https://github.com/jerrykuku/luci-theme-argon.git \
package/feeds/luci/luci-theme-argon 2>/dev/null || true
git clone --depth=1 https://github.com/xiaorouji/openwrt-passwall2.git \
package/feeds/openwrt-passwall2 2>/dev/null || true
git clone --depth=1 https://github.com/xiaorouji/openwrt-passwall-packages.git \
package/feeds/openwrt-passwall-packages 2>/dev/null || true
# 删除冲突的包
rm -rf feeds/packages/net/{microsocks,sing-box,v2ray-geodata,xray-core} 2>/dev/null || true
# 再次更新 feeds
./scripts/feeds update -a
./scripts/feeds install -a
# 加载配置文件
if [ -f "/workspace/openwrt/$CONFIG_FILE" ]; then
log_info "加载配置: /workspace/openwrt/$CONFIG_FILE"
cp "/workspace/openwrt/$CONFIG_FILE" .config
else
log_error "配置文件不存在: $CONFIG_FILE"
log_error "请确保配置文件在 /workspace/openwrt/ 目录下"
exit 1
fi
# 启用 ccache 和开发者选项
echo -e 'CONFIG_DEVEL=y\nCONFIG_CCACHE=y' >> .config
# 生成完整配置
log_info "生成默认配置..."
make defconfig
# 修复 Rust LLVM 设置 (download-ci-llvm=true 在 CI 上被拒绝,且预编译 artifact 可能已过期 404)
log_info "修复 Rust LLVM 配置..."
sed -i 's/download-ci-llvm=true/download-ci-llvm=false/g' \
feeds/packages/lang/rust/Makefile 2>/dev/null || true
# 显示磁盘空间
log_info "当前磁盘空间:"
df -h | grep -E '(Filesystem|/$|/workspace)'
# 开始编译
log_info "开始编译 (使用 $THREADS 线程)..."
log_info "首次尝试多线程编译..."
if make -j${THREADS} V=s; then
log_info "多线程编译成功!"
else
log_warn "多线程编译失败,回退到单线程编译..."
make -j1 V=99
fi
# 显示编译后磁盘空间
log_info "编译后磁盘空间:"
df -h | grep -E '(Filesystem|/$|/workspace)'
# 准备输出
log_info "准备输出文件..."
mkdir -p "$OUTPUT_DIR"/{images,packages}
# 复制固件镜像
if [ -d "bin/targets" ]; then
find bin/targets -name "openwrt-*" -type f -exec cp {} "$OUTPUT_DIR/images/" \;
find bin/targets -name "sha256sums" -type f -exec cp {} "$OUTPUT_DIR/images/" \;
log_info "固件镜像已复制到: $OUTPUT_DIR/images/"
fi
# 复制软件包
if [ -d "bin/packages" ]; then
cp -r bin/packages/* "$OUTPUT_DIR/packages/" 2>/dev/null || true
log_info "软件包已复制到: $OUTPUT_DIR/packages/"
fi
# 列出生成的文件
log_info "生成的固件文件:"
ls -lh "$OUTPUT_DIR/images/" 2>/dev/null || log_warn "没有找到固件文件"
log_info "构建完成!"
log_info "输出目录: $OUTPUT_DIR"