OPNsense Forum

English Forums => General Discussion => Topic started by: hsing on July 05, 2024, 05:28:57 AM

Title: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 05, 2024, 05:28:57 AM
Hi, Community

I am having some difficulties understanding the steps for version updates and creating plugins, specifically how to create the Helloworld plugin. Additionally, I am not quite sure how the make command in OPNsense tools works. I have read the README and tried to follow the instructions, but I always encounter errors. Therefore, I would like to ask if anyone can kindly provide some advice.

Currently, I am unable to resolve this issue:

Installed pkg version '1.21' does not match required version '1.19'
*** Error code 1

Stop.
make: stopped in /usr/tools
root@freebsd:/usr/tools # pkg -v
1.21.3
root@freebsd:/usr/tools # uname -r
13.2-RELEASE


I have tried to downgrade pkg to version 1.19, but it seems unsuccessful.
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Monviech (Cedrik) on July 05, 2024, 07:27:13 AM
Do you want to build the package of the hello world plugin from their source files?

For that you go to "/usr/plugins/devel/" and go into the helloworld folder and invoke "make package".
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 05, 2024, 07:47:55 AM
So, is my understanding of this document incorrect?
https://github.com/opnsense/tools

Because I thought I needed to set up a FreeBSD system and then install OPNsense tools according to the document.

According to your explanation, if I want to package a plugin, I just need to go to the plugin directory on the OPNsense system and run make package?

But if I want to package my own system, I follow the document and run make dvd in /usr/tools. The location will be in make print-IMAGESDIR. Is this correct?
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Monviech (Cedrik) on July 05, 2024, 08:01:45 AM
Well you can use a freebsd system. But you can also just install an opnsense vm, install the build tools in it, and then use "make dvd" in there.

Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 05, 2024, 08:16:29 AM
Quote from: hsing on July 05, 2024, 05:28:57 AM

Installed pkg version '1.21' does not match required version '1.19'
*** Error code 1

Stop.
make: stopped in /usr/tools
root@freebsd:/usr/tools # pkg -v
1.21.3
root@freebsd:/usr/tools # uname -r
13.2-RELEASE



This is the issue I encountered on the FreeBSD system, the incompatibility of the pkg version.

So if I run make dvd on the OPNsense system, should it be executed in the /usr/tools directory? Or, like with the plugins, should it be done under /usr/plugins/devel/?

I just tried to run make package in /usr/plugins/devel/helloworld. Initially, I saw a folder and two files (src/, Makefile, pkg-descr). After execution, an additional folder work/ appeared, and I noticed that there is always a src/ folder. If I want to create other plugins, should I also copy the plugin's files into the src/ directory?
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Monviech (Cedrik) on July 05, 2024, 08:59:12 AM
You can remove pkg on freebsd and manually install the matching version.

But its easier just to use an OPNsense cause it has the matching pkg version needed.

To make the DVD you just do exactly the steps as they are explained in the opnsense/tools readme.

Going into /usr/plugins/devel/ is for when you want to build single plugins, you just copy them into a folder there, e.g. /usr/plugins/devel/caddy and then invoke "make package" to build the single plugin package. The src and work get created automatically.

Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 05, 2024, 09:22:39 AM
OK, I think I should directly operate on OPNsense.

However, I don't quite understand the initial TL;DR in the documentation. When I run make dvd in /usr/tools, I encounter a lot of errors. If I need to specify the build, where should I set those parameters?

Sorry, I'm not very clear on the documentation...
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Patrick M. Hausen on July 05, 2024, 09:35:52 AM
Why would you "make dvd" if you only want to build a plugin? The "make dvd" command builds install media. You need the source of OPNsense, not only plugins, for that.
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 05, 2024, 10:04:40 AM
I want to understand how make works. It seems different from FreeBSD's port or pkg, so I want to try and see how it works.
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Patrick M. Hausen on July 05, 2024, 10:13:43 AM
Yes, but different make targets do different things. If you want to "make dvd" you need to setup your environment for a complete build of all of OPNsense, because that's what "make dvd" does.
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 08, 2024, 04:36:41 AM
Hi,

Last week, I attempted to follow the step "How to run individual or composite build steps." The initial steps for base and kernel went smoothly. However, when I reached the make ports step, it took a considerable amount of time. Is this normal?

Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Patrick M. Hausen on July 08, 2024, 08:45:44 AM
Quote from: hsing on July 08, 2024, 04:36:41 AM
However, when I reached the make ports step, it took a considerable amount of time. Is this normal?
Yes.
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 10, 2024, 04:31:51 AM
Hi,
These past few days, I tried using make ports and successfully generated packages-24.1.9_72-amd64.tar. However, I noticed something: does make ports require an internet connection? Can anyone explain the reason for this? Isn't it supposed to package the system's own ports and those packages? Why does it need an internet connection? Is it to fetch updates?
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: Patrick M. Hausen on July 10, 2024, 06:16:00 AM
The ports system consists of a tree of Makefiles that fetch and build third party tools which are not part of FreeBSD. The source code for these third party tools is downloaded from the Internet.

https://docs.freebsd.org/en/books/handbook/ports/
Title: Re: How to Create a Helloworld Plugin and Use OPNsense Tools
Post by: hsing on July 10, 2024, 08:12:40 AM
Understood, but I encountered an issue when running make plugins. The error message is as follows:

make[1]: "/usr/obj/usr/tools/config/24.1/amd64/usr/plugins/Mk/plugins.mk" line 75: Plugin variant 'zabbix7' does not exist
*** Error code 1


Does this error mean that I do not have the 'zabbix7' plugin?

When running make plugins, should it be executed under /usr/local, or should each plugin be copied to /usr/plugins/devel/ before execution? The issue mentioned above occurred because I ran make plugins under /usr/local.