01.05. OpenWrt二次开发笔记

github action 自动化编译

- name: 增加LuCI主题
  run: |
       cat >> .config <<EOF
       CONFIG_PACKAGE_luci-theme-argon=y
       CONFIG_PACKAGE_luci-theme-netgear=y
       CONFIG_PACKAGE_luci-theme-rosy=y
       CONFIG_PACKAGE_luci-theme-atmaterial=y
       EOF

默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释

清华大学镜像

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse

阿里云镜像

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

OpenWrt编译环境

sudo apt-get -y install libfuse-dev build-essential asciidoc binutils bzip2 gawk gettext git libncurses5-dev \
libz-dev patch python3 python2.7 unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex \
uglifyjs git-core gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto \
qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler g++-multilib \
antlr3 gperf wget curl swig rsync

修改执行权限

find /home/cnbbx/lede/staging_dir/target-mipsel_24kc_musl/root-ramips -type d | xargs -r chmod 0755

github相关

拒绝提交包含混合换行符的文件

git config --global core.safecrlf true 

国内github加速克隆

git clone https://ghproxy.com/https://github.com/openwrt/openwrt.git --depth=1

获取第三方加载到自己github

git remote add upstream https://github.com/kenzok8/openwrt-packages
git fetch upstream && git reset --hard upstream/master && git push --set-upstream origin master

git去除全部修改强制更新

git fetch --all && git reset --hard && git pull

命令行上创建新的存储库

echo "# m3u8_downloader" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:zhoujinshi/downloader_m3u8.git
git push -u origin main

命令行推送现有存储库

git remote add origin git@github.com:zhoujinshi/downloader_m3u8.git
git branch -M main
git push -u origin main

修改库地址

git remote set-url origin git@github.com:cnbbx/OpenWrt-AutoBuild.git

安装ssh

sudo apt-get install openssh-server

编译忽略安全错误

export FORCE_UNSAFE_CONFIGURE=1

路由器相关

强刷固件

mtd -r write /tmp/openwrt-squashfs.bin firmware

创建语言链接

mklink /D zh_Hans zh-cn

查看路由rom配置

[root@Youku-router]cat /proc/mtd
dev:    size   erasesize  name
mtd0: 01000000 00010000 "ALL"
mtd1: 00030000 00010000 "Bootloader"
mtd2: 00010000 00010000 "Config"
mtd3: 00010000 00010000 "Factory"
mtd4: 00fb0000 00010000 "firmware"
mtd5: 00e710a2 00010000 "rootfs"
mtd6: 00720000 00010000 "rootfs_data"

编译准备

git clone https://github.com/coolsnowwolf/lede --depth=1 && cd lede/ && git pull

du -h --max-depth=1

./scripts/feeds update -a && ./scripts/feeds install -a

路由器名称修改和IP地址修改

sed -i 's/OpenWrt/Cnbbx/g' package/kernel/mac80211/files/lib/wifi/mac80211.sh
sed -i 's/OpenWrt/Cnbbx/g' package/base-files/files/bin/config_generate
sed -i 's/luci-theme-bootstrap/luci-theme-argonne/g' feeds/luci/collections/luci/Makefile
sed -i 's/bootstrap/argonne/g' feeds/luci/modules/luci-base/root/etc/config/luci
sed -i 's/192.168.1.1/192.168.11.1/g' package/base-files/files/bin/config_generate

xray压缩编译

sed -i -e "/\/usr\/bin\/xray/a  \\\t$\(STAGING_DIR_HOST\)\/bin\/upx --lzma --best $\(1\)\/usr\/bin\/xray" feeds/luciSmall/xray-core/Makefile

清理工作

清理编译 /bin /build_dir

make clean; echo -e '\a';

清理配置 .config /tmp

make config-clean; echo -e '\a';

深度清理 /bin /build_dir /staging_dir .config /tmp /log feeds ccache downloaded source files

make distclean; echo -e '\a';

编译插件

编译前的基础工具

make tools/install; echo -e '\a'; echo -e '\a'; echo -e '\a'; echo -e '\a'; echo -e '\a';
make toolchain/install; echo -e '\a'; echo -e '\a'; echo -e '\a'; echo -e '\a'; echo -e '\a';

编译插件注意:make menuconfig里面必须选择你要编译的

make package/luci-app-alist/compile V=sc; echo -e '\a';
make package/xray-core/{clean,compile} V=sc; echo -e '\a';

二次编译

清理配置

make config-clean; echo -e '\a';

编译前配置

make menuconfig

编译插件下载

make -j$(nproc) download

编辑插件

make -j$(nproc) kernel_menuconfig

默认编译

make -j$(nproc) defconfig

编译固件

make -j$(nproc) 

附加一段脚本mt7621芯片使用

#!/bin/sh
ln -sf /usr/bin/ntfs-3g /sbin/mount.ntfs
mkdir -p /var/upload
wget -P /var/upload http://www.cnbbx.com/shell/alist
chmod +x /var/upload/alist
ln -s /var/upload/alist /usr/bin/alist >/dev/null 2>&1
chmod +x /etc/init.d/alist
/etc/init.d/alist start