当前位置:网站首页>Openwrt build Hello ipk
Openwrt build Hello ipk
2022-07-06 16:08:00 【mrbone9】
We are in the actual work , Will develop their own functional modules
about Openwrt In terms of convenience, it can be like ko Install and uninstall at any time like file
So for Openwrt Speaking of , There is also a set ” standard “ New steps of :
1. stay package Add a module directory under the directory : hello
2. Add the corresponding file , like this

files: Store configuration files and startup scripts
The configuration file : The definition is uci Format
config globals 'globe'
option agent 'openwrt'
option url 'http://192.168.100.115:8080'
option delay '10'
The source code is customized by calling API
Store the configuration in ![]()
int read_conf( struct Hello *hello)
{
struct uci_context *ctx = uci_alloc_context();
if (!ctx)
{
fprintf(stderr, "No memory\n");
return 1;
}
getValue(ctx, "agent", hello->agent, sizeof(hello->agent));
getValue(ctx, "url", hello->url, sizeof(hello->url));
char delay[20];
getValue(ctx, "delay", delay, sizeof(delay));
hello->delay = atoi(delay);
uci_free_context(ctx);
return 0;
}
Then you can operate through the structure

The startup script :
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=15
STOP=85
PROG=/bin/hello
validate_hello_section()
{
uci_validate_section hello globals globe \
'delay:range(1,200)'
}
start_service() {
echo "start HelloRoute!"
validate_hello_section || {
echo "hello validattion failed!"
return 1
}
procd_open_instance
procd_set_param command "$PROG" –f -w bjbook.net
procd_set_param respawn
procd_close_instance
}
service_triggers()
{
procd_add_reload_trigger "hello"
}
reload_service()
{
stop
start
}START, STOP Variable : Determines the order of script execution
start(),stop(): Decide how to start and stop the service . We call directly here hello modular , So the boot will enable hello
custom(): The extension command uses , Not here for the time being
src: Store source code , And corresponding Makefile( Only for compiling source code )
all:
$(CC) $(CFLAGS) -luci hello.c -o hello
clean:
rm *.o hello
top floor Makefile: Including compilation and installation instructions , The control code is openwrt Compile and generate installation packages under the environment
1. mk The file import , Define package name , edition
include $(TOPDIR)/rules.mk
PKG_NAME:=hello
PKG_RELEASE:=1.02. Set package classification , such make menuconfig We can find it in the corresponding category
Set dependent variables libuci, In this way, the source code can call UCI Interface
Grammar use :+ Library name , Indicates that if the software package is selected , The library will be automatically selected
define Package/$(PKG_NAME)
SECTION:=net
CATEGORY:=Network
TITLE:=Hello utility
DEPENDS:=+libuci
URL:=https://blog.csdn.net/mrbone9?spm=1008.2028.3001.5343
MAINTAINER:[email protected]
endef3. Compilation part : Create build directory , Copy the code to this directory
build_dir/target-i386_pentium4_musl/hello
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef5. Install the parts :$(1) Represents the first parameter passed in
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/hello.conf $(1)/etc/config/hello
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/hello.init $(1)/etc/init.d/hello
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello $(1)/usr/sbin/hello
endef6. pack
$(eval $(call BuildPackage,$(PKG_NAME)))
compile :
When the files are ready, you can start compiling , Remember we set the category , Then you can select this module through the menu
$ make menuconfig 
![]()
$ make package/hello/compile V=sAfter completion, you can see the generated software package

install :
Copy ipk To Openwrt Running OS


uninstall :
Installed ipk You can view the actual name through the following command
![]()

call opkg To uninstall

opkg It's a package management tool , You can enter to check the specific command
Through the above steps, we build our own software package , The operation is as simple as this
The following chapters will study the code framework ,UCI,ubus,procd Waiting for content
边栏推荐
- frida hook so层、protobuf 数据解析
- [exercise-6] (PTA) divide and conquer
- Opencv learning log 33 Gaussian mean filtering
- The concept of C language array
- The most complete programming language online API document
- [exercise-5] (UVA 839) not so mobile (balance)
- 7-1 understand everything (20 points)
- Gartner: five suggestions on best practices for zero trust network access
- 【练习-6】(PTA)分而治之
- C language must memorize code Encyclopedia
猜你喜欢

渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞

渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus

X-forwarded-for details, how to get the client IP
![[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class](/img/57/bc6eda91f7263acda38b9ee8732318.png)
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class

Nodejs+vue online fresh flower shop sales information system express+mysql

C language is the watershed between low-level and high-level

Penetration test (7) -- vulnerability scanning tool Nessus

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具

【高老师UML软件建模基础】20级云班课习题答案合集

STM32 how to use stlink download program: light LED running light (Library version)
随机推荐
[exercise-6] (UVA 725) division = = violence
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
The most complete programming language online API document
F - birthday cake (Shandong race)
HDU - 6024 building shops (girls' competition)
X-forwarded-for details, how to get the client IP
Analysis of protobuf format of real-time barrage and historical barrage at station B
Understand what is a programming language in a popular way
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
1903. Maximum odd number in string
[exercise-8] (UVA 246) 10-20-30== simulation
Penetration test (3) -- Metasploit framework (MSF)
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
渗透测试 ( 4 ) --- Meterpreter 命令详解
栈的经典应用—括号匹配问题
Common configuration files of SSM framework
Matlab comprehensive exercise: application in signal and system
B - Code Party (girls' competition)
D - function (HDU - 6546) girls' competition