117 lines
3.4 KiB
Bash
117 lines
3.4 KiB
Bash
#!/bin/bash -e
|
||
|
||
# 颜色变量定义
|
||
export RED_COLOR='\e[1;31m'
|
||
export GREEN_COLOR='\e[1;32m'
|
||
export YELLOW_COLOR='\e[1;33m'
|
||
export BLUE_COLOR='\e[1;34m'
|
||
export PINK_COLOR='\e[1;35m'
|
||
export SHAN='\e[1;33;5m'
|
||
export RES='\e[0m'
|
||
|
||
# GitHub 变量
|
||
export github="github.com"
|
||
|
||
# $CURL_BAR
|
||
if curl --help | grep progress-bar >/dev/null 2>&1; then
|
||
CURL_BAR="--progress-bar";
|
||
fi
|
||
|
||
# 分组函数(GitHub Actions 支持)
|
||
GROUP=
|
||
group() {
|
||
endgroup
|
||
echo "::group:: $1"
|
||
GROUP=1
|
||
}
|
||
endgroup() {
|
||
if [ -n "$GROUP" ]; then
|
||
echo "::endgroup::"
|
||
fi
|
||
GROUP=
|
||
}
|
||
|
||
# 开始时间
|
||
starttime=$(date +'%Y-%m-%d %H:%M:%S')
|
||
startsec=$(date +%s)
|
||
|
||
#####################################
|
||
# Mediatek OpenWrt Build Script #
|
||
#####################################
|
||
|
||
# 设置平台变量
|
||
group "设置平台变量"
|
||
if [ "$1" = "Mediatek_mt7981" ]; then
|
||
export platform="Mediatek_mt7981"
|
||
elif [ "$1" = "Mediatek_mt7986" ]; then
|
||
export platform="Mediatek_mt7986"
|
||
else
|
||
echo -e "${RED_COLOR}错误:未指定正确的平台参数(Mediatek_mt7981 或 Mediatek_mt7986)${RES}"
|
||
exit 1
|
||
fi
|
||
endgroup
|
||
|
||
# 克隆源码
|
||
group "克隆源码"
|
||
git clone --depth=1 https://$github/zhiern/immortalwrt-mt798x -b openwrt-21.02
|
||
cd immortalwrt-mt798x || { echo -e "${RED_COLOR}进入源码目录失败${RES}"; exit 1; }
|
||
endgroup
|
||
|
||
# 更新 feeds
|
||
group "更新和安装 feeds"
|
||
./scripts/feeds update -a
|
||
./scripts/feeds install -a
|
||
endgroup
|
||
|
||
# 加载 .config 配置文件
|
||
group "加载对应配置文件"
|
||
if [ "$platform" = "Mediatek_mt7981" ]; then
|
||
curl -s https://git.kejizero.online/zhao/scripts/raw/branch/main/Mediatek/21-config-mediatek_mt7981 > .config
|
||
elif [ "$platform" = "Mediatek_mt7986" ]; then
|
||
curl -s https://git.kejizero.online/zhao/scripts/raw/branch/main/Mediatek/21-config-mediatek_mt7986 > .config
|
||
fi
|
||
endgroup
|
||
|
||
# 更换软件源
|
||
group "更换软件源"
|
||
mkdir -p files/etc/opkg
|
||
cat > files/etc/opkg/distfeeds.conf <<EOF
|
||
src/gz openwrt_base https://mirrors.cernet.edu.cn/immortalwrt/releases/21.02-SNAPSHOT/packages/aarch64_cortex-a53/base
|
||
src/gz openwrt_luci https://mirrors.cernet.edu.cn/immortalwrt/releases/21.02-SNAPSHOT/packages/aarch64_cortex-a53/luci
|
||
src/gz openwrt_packages https://mirrors.cernet.edu.cn/immortalwrt/releases/21.02-SNAPSHOT/packages/aarch64_cortex-a53/packages
|
||
src/gz openwrt_routing https://mirrors.cernet.edu.cn/immortalwrt/releases/21.02-SNAPSHOT/packages/aarch64_cortex-a53/routing
|
||
src/gz openwrt_telephony https://mirrors.cernet.edu.cn/immortalwrt/releases/21.02-SNAPSHOT/packages/aarch64_cortex-a53/telephony
|
||
EOF
|
||
endgroup
|
||
|
||
# 加载缓存
|
||
# group "加载缓存"
|
||
# curl -L https://$github/oppen321/openwrt_caches/releases/download/OpenWrt_Toolchain_Cache/toolchain_gcc8_mediatek.tar.zst -o toolchain.tar.zst $CURL_BAR
|
||
# tar -I "zstd" -xf toolchain.tar.zst
|
||
# rm -f toolchain.tar.zst
|
||
# mkdir bin
|
||
# find ./staging_dir/ -name '*' -exec touch {} \; >/dev/null 2>&1
|
||
# find ./tmp/ -name '*' -exec touch {} \; >/dev/null 2>&1
|
||
# endgroup
|
||
|
||
# 生成默认配置
|
||
group "生成默认配置"
|
||
make defconfig
|
||
endgroup
|
||
|
||
# 开始编译
|
||
group "开始编译固件"
|
||
echo -e "${GREEN_COLOR}使用 $(nproc) 线程进行编译...${RES}"
|
||
make -j$(nproc)
|
||
endgroup
|
||
|
||
# 显示耗时
|
||
endtime=$(date +'%Y-%m-%d %H:%M:%S')
|
||
endsec=$(date +%s)
|
||
duration=$((endsec - startsec))
|
||
echo -e "${BLUE_COLOR}构建开始时间: $starttime${RES}"
|
||
echo -e "${BLUE_COLOR}构建结束时间: $endtime${RES}"
|
||
echo -e "${GREEN_COLOR}总共耗时: ${duration} 秒${RES}"
|
||
|
||
|