Last active
April 22, 2025 08:02
-
-
Save muink/6363ea7136fff1252315b7d239498586 to your computer and use it in GitHub Desktop.
Openwrt本地源构建
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set "path=%path%;%~dp0cwRsync_5.5.0_x86_Free\bin" | |
start cmd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. /www/packages/synclede.sh | |
URLPREFIX=rsync://downloads.openwrt.org/downloads/ | |
BWLIMIT=500K | |
PRUNE='--delete' | |
COMPAC='zz' | |
PROGR='--progress' | |
SyncAll "$BWLIMIT" 19.07.0 x86_64 x86 64 all none | |
SyncAll "$BWLIMIT" 19.07.2 x86_64 x86 64 all none | |
SyncPackage "$BWLIMIT" 19.07.2 mips_24kc | |
SyncTarget "$BWLIMIT" 19.07.2 ar71xx nand | |
SyncModule "$BWLIMIT" 19.07.2 ar71xx nand all | |
SyncModule "$BWLIMIT" 19.07.2 ath79 nand wndr4300 | |
SyncTarget "$BWLIMIT" 19.07.2 ath79 generic | |
SyncModule "$BWLIMIT" 19.07.2 ath79 generic ex6400 | |
SyncModule "$BWLIMIT" 19.07.2 ath79 generic ex7300 | |
PRUNE= | |
COMPAC='zz' | |
PROGR='--progress' | |
SyncAll "$BWLIMIT" snapshots x86_64 x86 64 x86 4.19.91-1-0b3dff97a9c6f0730b67aeb33483aec1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OpenWrt制作本地源 | |
## 爬取所有包 | |
首先需要把当前内核对应的所有包都下载下来,下载地址可以在`/etc/opkg/distfeeds.conf`找到。 | |
我把里面的每个链接的内容都全部下载到一个单独的文件夹内。(本文使用的方法) | |
或者使用官方推荐的rsyanc同步法(推荐) | |
## 挂载U盘 | |
1. 安装所需要的包`fdisk` `e2fsprogs` `kmod-fs-ext4`(可能有遗漏) | |
2. 通过**fdisk**和**mkfs.ext4**和**mount**像普通LINUX那样挂载U盘即可,我挂到了`/root/sda1` | |
3. 然后再把源全部拉到这个U盘上 | |
由于我还想这个U盘里能装一点别的东西,便于做离线下载或者暂存一点别的东西,所以接下将在路由器上搭建一个HFS。 | |
## 搭建“本地”源 | |
搭建本地http服务器(有两种方法) | |
PC使用hfs搭建本地http服务器 | |
官方地址:https://www.rejetto.com/hfs/?f=dl | |
使用hfs 的原因是无需安装,双击即用。 | |
将第一步下载到本地的所有ipk都拖到hfs里面,hfs会自动生成一个本地地址。 | |
由于OpenWrt的luci就有网页服务器,所以我们直接把东西丢到`/www`这个目录下就行。 | |
我的把所有的包都已经放到`/root/sda1/openwrt`目录下。 | |
所以直接`ln -s /root/sda1/openwrt /www/openwrt`,再把`/etc/opkg.conf`刚刚添加的内容修改为如下 | |
``` | |
src/gz openwrt_core http://127.0.0.1/openwrt/openwrt_core | |
src/gz openwrt_kmods http://127.0.0.1/openwrt/openwrt_kmods | |
src/gz openwrt_base http://127.0.0.1/openwrt/openwrt_base | |
src/gz openwrt_luci http://127.0.0.1/openwrt/openwrt_luci | |
src/gz openwrt_packages http://127.0.0.1/openwrt/openwrt_packages | |
src/gz openwrt_routing http://127.0.0.1/openwrt/openwrt_routing | |
src/gz openwrt_telephony http://127.0.0.1/openwrt/openwrt_telephony | |
``` | |
## 成果 | |
``` | |
opkg install iperf3 | |
Installing iperf3 (3.7-1) to root... | |
Downloading http://127.0.0.1/openwrt/openwrt_base/iperf3_3.7-1_mipsel_24kc.ipk | |
Configuring iperf3. | |
``` | |
可以看到就从本地拉取安装包了 | |
## crontab 定期备份 | |
通常如果要在本地端进行备份,就可以在**crontab**中定期执行这样的指令 | |
将重要的资料定期备份至指定目录: | |
``` | |
# m h day mon wek command | |
0 5 * * 1 rsync -a /path/to/folder /path/to/backup/ | |
``` | |
这样系统就会在每周一的早上 5 点执行 rsync 备份档案。 | |
## 参考 | |
[搭建openwrt本地源(8.7更新,使用openwrt的http服务)](https://www.right.com.cn/forum/thread-170135-1-1.html) | |
[OpenWrt制作本地源](http://blog.sysu.tech/%E7%BD%91%E7%BB%9C/%E8%B7%AF%E7%94%B1%E5%99%A8/OpenWrt/OpenWrt%E5%88%B6%E4%BD%9C%E6%9C%AC%E5%9C%B0%E6%BA%90/) | |
[Linux 使用 rsync 遠端檔案同步與備份工具教學與範例](https://blog.gtwang.org/linux/rsync-local-remote-file-synchronization-commands/) | |
[crontab 定时任务](https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set "path=%path%;%~dp0bin" | |
call%~1 %~2 %~3 %~4 %~5 %~6 %~7 | |
goto :eof | |
:SyncRes | |
set Mod=%~1 | |
set Ver=%~2 | |
set Arch=%~3 | |
set Mem=%~4 | |
set Pak=%~5 | |
set KVer=%~6 | |
if defined PRUNE set Del=--delete | |
if defined PROGR set Prg=--progress | |
if defined COMPAC set z=z | |
md %Ver:/=\%\targets\%Arch%\%Mem%\>nul 2>nul | |
md %Ver:/=\%\targets\%Arch%\%Mem%\kmods\>nul 2>nul | |
md %Ver:/=\%\targets\%Arch%\%Mem%\packages\>nul 2>nul | |
md %Ver:/=\%\packages\>nul 2>nul | |
if not "%Mod%" == "none" ( | |
if "%Mod%" == "all" (call:GetModImg) else ( | |
call:Supplementary | |
if "%Arch%" == "x86" (call:x86) else call:GetModImg "" "--include '*%Mod%*' --exclude '*'" | |
) | |
) | |
rsync -arvhi%z% %Del% %Prg% --bwlimit=%BWLIMIT% %URLPREFIX%%Rel%%Ver%/targets/%Arch%/%Mem%/packages %Ver%\targets\%Arch%\%Mem%\ | |
rsync -arvhi%z% %Del% %Prg% --bwlimit=%BWLIMIT% %URLPREFIX%%Rel%%Ver%/targets/%Arch%/%Mem%/kmods/%KVer% %Ver%\targets\%Arch%\%Mem%\kmods\ | |
rsync -arvhi%z% %Del% %Prg% --bwlimit=%BWLIMIT% %URLPREFIX%%Rel%%Ver%/packages/%Pak% %Ver%\packages\ | |
goto :eof | |
:GetModImg | |
rsync -avhi%z% %~2 %Del% %Prg% --bwlimit=%BWLIMIT% %URLPREFIX%%Rel%%Ver%/targets/%Arch%/%Mem%/%~1 %Ver%\targets\%Arch%\%Mem%\ | |
goto :eof | |
:Supplementary | |
call:GetModImg config.buildinfo | |
call:GetModImg feeds.buildinfo | |
call:GetModImg kernel-debug.tar.bz2 | |
call:GetModImg sha256sums | |
call:GetModImg sha256sums.asc | |
call:GetModImg sha256sums.sig | |
call:GetModImg version.buildinfo | |
call:GetModImg "" "--include '*.manifest' --exclude '*'" | |
call:GetModImg "" "--include 'openwrt-imagebuilder*' --exclude '*'" | |
call:GetModImg "" "--include 'openwrt-sdk*' --exclude '*'" | |
goto :eof | |
:x86 | |
call:GetModImg combined-ext4.img.gz | |
call:GetModImg combined-squashfs.img.gz | |
call:GetModImg generic-rootfs.tar.gz | |
call:GetModImg rootfs-ext4.img.gz | |
call:GetModImg rootfs-squashfs.img.gz | |
call:GetModImg vmlinuz | |
goto :eof |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set URLPREFIX=rsync://downloads.openwrt.org/downloads/ | |
set BWLIMIT=300K | |
set PRUNE=1 | |
set COMPAC=1 | |
set PROGR=1 | |
call Script.cmd :SyncRes all releases/18.06.6 x86 64 x86_64 | |
call Script.cmd :SyncRes all releases/18.06.6 ar71xx nand mips_24kc | |
call Script.cmd :SyncRes r7500 releases/18.06.6 ipq806x generic arm_cortex-a15_neon-vfpv4 | |
call Script.cmd :SyncRes all releases/19.07.0 x86 64 x86_64 | |
call Script.cmd :SyncRes all releases/19.07.0 ar71xx nand mips_24kc | |
call Script.cmd :SyncRes wndr3800 releases/19.07.0 ath79 generic mips_24kc | |
call Script.cmd :SyncRes wndr4300 releases/19.07.0 ath79 nand mips_24kc | |
call Script.cmd :SyncRes none releases/19.07.0 ipq806x generic arm_cortex-a15_neon-vfpv4 | |
set PRUNE= | |
set COMPAC=1 | |
set PROGR=1 | |
call Script.cmd :SyncRes all snapshots x86 64 x86_64 4.19.91-1-0b3dff97a9c6f0730b67aeb33483aec1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# WorkDir | |
WORKDIR='/www/packages/' | |
cd $WORKDIR | |
# Src URL | |
URLPREFIX='rsync://downloads.openwrt.org/downloads/' | |
BWLIMIT=500K | |
PRUNE='--delete' | |
COMPAC='zz' | |
PROGR='--progress' | |
function GetImage() { | |
eval "rsync -lptrvhi$COMPAC $PRUNE $PROGR $2 ${URLPREFIX}${VER}/targets/${TARGET}/${MEM}/$1 ${VER}/targets/${TARGET}/${MEM}/" | |
} | |
function Supplementary() { | |
GetImage config.buildinfo | |
GetImage feeds.buildinfo | |
GetImage kernel-debug.tar.bz2 | |
GetImage sha256sums | |
GetImage sha256sums.asc | |
GetImage sha256sums.sig | |
GetImage version.buildinfo | |
GetImage '' "--include={'*.manifest','openwrt-imagebuilder*','openwrt-sdk*'} --exclude='*'" | |
} | |
function x86() { | |
GetImage combined-ext4.img.gz | |
GetImage combined-squashfs.img.gz | |
GetImage generic-rootfs.tar.gz | |
GetImage rootfs-ext4.img.gz | |
GetImage rootfs-squashfs.img.gz | |
GetImage vmlinuz | |
} | |
# Usage: | |
# SyncPackage <Bandwidth limit> <Version> <Architecture> | |
# e.g. 1M 19.07.2 mips_24kc | |
# e.g. 0 snapshots mips_24kc | |
function SyncPackage() { | |
# Init Parameters | |
if [ -n "$1" ]; then if [ "$1" == "0" ]; then local BWLIMIT=; else local BWLIMIT="--bwlimit=$1"; fi; shift 1; else echo 'SyncPackage: <Bandwidth limit> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local VER="${1%/*}"; shift 1; else echo 'SyncPackage: <Version> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local ARCH="$1"; shift 1; else echo 'SyncPackage: <Architecture> Requires a parameter'; return 1; fi | |
# Sync Packages | |
if [ -n "$(echo "$VER" | sed -n '/^[.0-9]\+$/ p')" ]; then | |
VER="releases/$VER" | |
mkdir -p releases >/dev/null 2>/dev/null | |
rsync -lptrvhi$COMPAC $PRUNE $PROGR $BWLIMIT --include 'packages' --exclude '*' ${URLPREFIX}${VER}/ ${VER}/ | |
sleep 5 | |
mkdir -p "${VER}/$(ls -l "${VER}/packages" | sed "s|.*->[ ]*\(.*\)[ ]*$|\1|")" >/dev/null 2>/dev/null | |
rsync -lptrvhi$COMPAC $PRUNE $PROGR $BWLIMIT ${URLPREFIX}${VER}/packages/$ARCH ${VER}/packages/ | |
elif [ "$VER" == "snapshots" ]; then | |
mkdir -p snapshots/packages >/dev/null 2>/dev/null | |
rsync -lptrvhi$COMPAC $PRUNE $PROGR $BWLIMIT ${URLPREFIX}${VER}/packages/$ARCH ${VER}/packages/ | |
else | |
echo 'SyncPackage: Parameter <Version> is invalid' | |
return 1 | |
fi | |
} | |
# Usage: | |
# SyncTarget <Bandwidth limit> <Version> <Target> <Memory tech> [Kernel version] | |
# e.g. 1M 19.07.2 ath79 nand | |
# e.g. 0 19.07.2 ath79 nand | |
function SyncTarget() { | |
# Init Parameters | |
if [ -n "$1" ]; then if [ "$1" == "0" ]; then local BWLIMIT=; else local BWLIMIT="--bwlimit=$1"; fi; shift 1; else echo 'SyncPackage: <Bandwidth limit> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local VER="${1%/*}"; shift 1; else echo 'SyncTarget: <Version> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local TARGET="$1"; shift 1; else echo 'SyncTarget: <Target> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local MEM="$1"; shift 1; else echo 'SyncTarget: <Memory tech> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local KVER="$1"; shift 1; fi | |
# Sync Target | |
if [ -n "$(echo "$VER" | sed -n '/^[.0-9]\+$/ p')" ]; then | |
VER="releases/$VER" | |
else | |
echo 'SyncTarget: Parameter <Version> is invalid' | |
return 1 | |
fi | |
mkdir -p ${VER}/targets/${TARGET}/${MEM}/kmods >/dev/null 2>/dev/null | |
rsync -lptrvhi$COMPAC $PRUNE $PROGR $BWLIMIT ${URLPREFIX}${VER}/targets/${TARGET}/${MEM}/packages ${VER}/targets/${TARGET}/${MEM}/ | |
rsync -lptrvhi$COMPAC $PRUNE $PROGR $BWLIMIT ${URLPREFIX}${VER}/targets/${TARGET}/${MEM}/kmods/$KVER ${VER}/targets/${TARGET}/${MEM}/kmods/ | |
} | |
# Usage: | |
# SyncModule <Bandwidth limit> <Version> <Target> <Memory tech> <Module> | |
# e.g. 1M 19.07.2 ath79 nand wndr4300 | |
# e.g. 0 19.07.2 ath79 nand all | |
function SyncModule() { | |
# Init Parameters | |
if [ -n "$1" ]; then if [ "$1" == "0" ]; then local BWLIMIT=; else local BWLIMIT="--bwlimit=$1"; fi; shift 1; else echo 'SyncPackage: <Bandwidth limit> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local VER="${1%/*}"; shift 1; else echo 'SyncModule: <Version> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local TARGET="$1"; shift 1; else echo 'SyncModule: <Target> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local MEM="$1"; shift 1; else echo 'SyncModule: <Memory tech> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local MODULE="$1"; shift 1; else echo 'SyncModule: <Module> Requires a parameter'; return 1; fi | |
# Sync Module | |
if [ -n "$(echo "$VER" | sed -n '/^[.0-9]\+$/ p')" ]; then | |
VER="releases/$VER" | |
else | |
echo 'SyncModule: Parameter <Version> is invalid' | |
return 1 | |
fi | |
if [ "${MODULE,,}" == "all" ]; then GetImage '' "--include='*' --exclude='*/'"; | |
else | |
Supplementary | |
if [ "$TARGET" == "x86" ]; then x86; | |
else GetImage '' "--include='*${MODULE}*' --exclude='*'"; | |
fi | |
fi | |
} | |
# Usage: | |
# SyncAll <Bandwidth limit> <Version> <Architecture> <Target> <Memory tech> <Module> <Kernel version> | |
# e.g. 1M 19.07.2 mips_24kc ath79 nand wndr4300 4.19.91-1-4e92f69bcf94fcc1ca5afc513ab5f2b6 | |
# e.g. 0 19.07.2 mips_24kc ath79 nand none none | |
function SyncAll() { | |
# Init Parameters | |
if [ -n "$1" ]; then local BWLIMIT="$1"; shift 1; else echo 'SyncPackage: <Bandwidth limit> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local VER="$1"; shift 1; else echo 'SyncPackage: <Version> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local ARCH="$1"; shift 1; else echo 'SyncPackage: <Architecture> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local TARGET="$1"; shift 1; else echo 'SyncModule: <Target> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local MEM="$1"; shift 1; else echo 'SyncModule: <Memory tech> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local MODULE="$1"; shift 1; else echo 'SyncModule: <Module> Requires a parameter'; return 1; fi | |
if [ -n "$1" ]; then local KVER="$1"; shift 1; else echo 'SyncModule: <Kernel version> Requires a parameter'; return 1; fi | |
if [ "$KVER" == "none" ]; then local KVER=; fi | |
SyncPackage "$BWLIMIT" "$VER" "$ARCH" | |
SyncTarget "$BWLIMIT" "$VER" "$TARGET" "$MEM" "$KVER" | |
if [ "$MODULE" != "none" ]; then SyncModule "$BWLIMIT" "$VER" "$TARGET" "$MEM" "$MODULE"; fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment