OpenWrt搭建私有源
1. 使用官方构建的软件包
使用下面的脚本爬取ipk包:
#!/usr/bin/env python
#coding=utf-8
#
# Openwrt Package Grabber
#
# Copyright (C) 2016 sohobloo.me
#import urllib.request
import re
import os
import time
import argparsepattern = r'<a href="([^\?].*?)">'
def fetch(url, dir, path = ''):if not os.path.exists(dir + path):os.makedirs(dir + path)print('fetching package list from ' + url[:-1] + path)content = urllib.request.urlopen(url[:-1] + path, timeout=15).read().decode('utf-8')# print('content = ' + content.decode('utf-8'))content = content[content.index('<table>'):]# print content# returnitems = re.findall(pattern, content)for item in items:# print "current item : " + itemif item == '../' or item == '/':continueelif item.endswith('/'):fetch(url, path + item)else:print('downloading item : ' + path + item)if os.path.isfile(dir + path + item):print('file exists, ignored.')else:rfile = urllib.request.urlopen(url + path + item)with open(dir + path + item, "wb") as code:code.write(rfile.read())if __name__ =='__main__':parser = argparse.ArgumentParser()parser.add_argument('-c', type=str, default="distfeeds.conf")parser.add_argument('-d', type=str, default="./openwrt/")parser.add_argument('-l', type=int, default=0)args = parser.parse_args()with open(args.c, 'r', encoding='gb2312') as fd:lines = fd.readlines()fd.close()line = lines[args.l]strlist = line.split(' ')fetch(strlist[2].rstrip()+'/', args.d+strlist[1]+'/')
python3 openwrt_ipk_crawler.py -c ./distfeeds.conf -d /var/www/html/openwrt_src/ipq40xx/ -l 0distfeeds.conf文件可以在目标机器的/etc/opkg/目标下找到,-d表示下载的包存放的路径,-l表示下载配置文件中的第几项,便于多线程下载。
2. 使用源码构建的软件包
源码构建的软件包在bin/packages/arm_cortex-a7_neon-vfpv4下。
如果要编译所有的包,按如下步骤操作:
删除.config,然后在worldbit.config中添加 CONFIG_ALL=y ,注意要先把.config删除,不然后未设置的项不会覆盖。
如果用第一步的方法,可能有些包编译不过,所以把仓库中的worldbit.config复制为.config,然后在menuconfig中选择Global build settings ---> Select all userspace packages by default,这样可以排除编译不过的包。
编译, make -j8 IGNORE_ERRORS=m 编译的时候忽略所有的错误。
如果编译的时候有的包编译失败,是不会生成Packages索引文件的(如果按第二步操作,不会有这个问题,忽略这一步),按如下操作:
# 将要用的命令加到环境变量中
export PATH="/home/sy/github/ipq4019-openwrt/staging_dir/host/bin:$PATH"# 然后在packages的每个子目录生成索引
cd bin/packages/arm_cortex-a7_neon-vfpv4/base
../../../../scripts/ipkg-make-index.sh ./ > ./Packages
gzip -9c ./Packages > ./Packages.gz因为没有生成Packages.sig,需要禁用包校验,在opkg.conf中去掉了check_signature选项。
3. 安装http服务器
在服务器上安装http服务器: sudo apt-get install apache2 ,启动http服务器: sudo /etc/init.d/apache2 restart 。
修改http服务器端口: /etc/apache2/ports.conf 中的 Listen 。
然后把软件包放到 /var/www/html 下。
3. 替换源
修改目标机器上/etc/opkg/distfeeds.conf中的内容:
ipq4019的源:
src/gz openwrt_core http://openwrt.usb7.net:8090/openwrt_src/worldbit.hp_1/generic/packages
src/gz openwrt_base http://openwrt.usb7.net:8090/openwrt_src/worldbit.hp_1/base
src/gz openwrt_luci http://openwrt.usb7.net:8090/openwrt_src/worldbit.hp_1/luci
src/gz openwrt_packages http://openwrt.usb7.net:8090/openwrt_src/worldbit.hp_1/packages
src/gz openwrt_routing http://openwrt.usb7.net:8090/openwrt_src/worldbit.hp_1/routing
src/gz openwrt_telephony http://openwrt.usb7.net:8090/openwrt_src/worldbit.hp_1/telephony然后在目标机器上运行 opkg update ,然后就可以 opkg install xxx 安装包了。
4. 制作自已的ipk包
顶层makefile:
include $(TOPDIR)/rules.mkPKG_NAME:=ipk_test_1
PKG_VERSION:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)include $(INCLUDE_DIR)/package.mkdefine Package/$(PKG_NAME)SECTION:=my_packageCATEGORY:=my_packageTITLE:=ipk_test_1
endefdefine Package/$(PKG_NAME)/descriptionIf you can't figure out what this program does, you're probablybrain-dead and need immediate medical attention.
endefdefine Build/Preparemkdir -p $(PKG_BUILD_DIR)$(CP) ./src/* $(PKG_BUILD_DIR)/
endefdefine Package/$(PKG_NAME)/install$(INSTALL_DIR) $(1)/bin$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/bin/
endef$(eval $(call BuildPackage,$(PKG_NAME)))
编译生成ipk: make package/ipk_test_1/compile
