generated from P3TERX/Actions-OpenWrt
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcompile.sh
72 lines (67 loc) · 1.87 KB
/
compile.sh
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
#!/bin/bash
# 设置工作目录变量
WORK_DIR=~/immortalwrt
# 判断是否传入了 -c 参数
FORCE_COMPILE=false
while getopts ":c" opt; do
case ${opt} in
c )
FORCE_COMPILE=true
;;
\? )
echo "无效的选项" 1>&2
exit 1
;;
esac
done
# 进入工作目录
cd "$WORK_DIR" || { echo "无法切换到目录 $WORK_DIR"; exit 1; }
# 拉取最新代码
git fetch origin
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse origin/master)
# 检查本地和远程代码是否一致或是否强制编译
if [ "$LOCAL" != "$REMOTE" ] || [ "$FORCE_COMPILE" = true ]; then
if [ "$FORCE_COMPILE" = true ]; then
echo "检测到强制编译选项,即使代码是最新的也会重新编译。"
else
echo "源码已更新,开始重新编译。"
fi
# 开始计时
start=$(date +%s)
# 拉取最新代码并重新编译
if ! git pull origin master; then
echo "从 origin/master 拉取最新代码失败。"
exit 1
fi
if ! ./scripts/feeds update -a; then
echo "更新 feeds 失败。"
exit 1
fi
if ! ./scripts/feeds install -a; then
echo "安装 feeds 失败。"
exit 1
fi
if ! make -j${NPROC:-$(nproc)} download; then
echo "下载软件包失败。"
exit 1
fi
# 新增:运行 make defconfig
if ! make defconfig; then
echo "执行 make defconfig 失败。"
exit 1
fi
if ! make -j${NPROC:-$(nproc --ignore=1)}; then
echo "编译失败。"
exit 1
fi
# 结束计时
end=$(date +%s)
# 输出编译总耗时
echo "总编译时间:$(((end - start) / 60)) 分 $(((end - start) % 60)) 秒"
# 记录完成时间
echo "$(date '+%Y-%m-%d %H:%M:%S'): 编译完成"
else
# 本地代码是最新的,无需重新编译
echo "源码已是最新,无需重新编译。"
fi