When the latest Netbeans skipped providing a native Debian package, I just went and decided to roll my own. This article breaks my automated solution using a simple Bash script (package.sh) and a GitHub Actions workflow (main.yml) to reliably package Apache NetBeans into a distribution-ready .deb file. This approach is highly repeatable, ensuring you can generate a package for any new NetBeans version with a single click.
You can fin all sources here: https://github.com/aliedperezmartinez/netbeans-deb-packager
Contributions are welcome 😉
Part 1: The Core Packaging Script (package.sh)
The package.sh script is the engine that handles everything from downloading the source to generating the final package. It performs three main phases: setup, file preparation, and final build.
1. Setup and File Preparation
The first part of the script dynamically acquires the source and prepares the package metadata.
2. The Packaging Boilerplate: dh_make
Once the source files and the basic metadata files (like control) are ready, the next step is to generate the comprehensive set of required Debian packaging files. This is where dh_make comes in.
dh_make --createorig -y -s -e aliedperezmartinez@gmail.com -p apache-netbeans_${NETBEANS_VERSION}
The dh_make command is a tool that creates the boilerplate structure for a new Debian package, populating the critical debian/ subdirectory with template files (like changelog, copyright, rules, etc.).
Let's break down the flags:
--createorig: Creates the original source archive (.orig.tar.gz). Debian requires this file to track changes between the upstream source and the Debian package.-y: Automatically answers "yes" to all interactive questions, making the script non-interactive for automation.-s: Specifies a "single binary" package, which means the package will only contain one final binary package (in this case,apache-netbeans).-e aliedperezmartinez@gmail.com: Sets the Maintainer email address in the generated files, such asdebian/controlanddebian/changelog.-p apache-netbeans_${NETBEANS_VERSION}: Forces the package name and version format to bepackagename_version. This is crucial for naming the resulting files correctly.
3. The Final Build: debuild
The last step is to run the build process itself using debuild. This command orchestrates the entire process of turning the prepared directory structure and metadata into a final, installable .deb file.
DEB_BUILD_OPTIONS=nostrip debuild -us -uc -b
DEB_BUILD_OPTIONS=nostrip: This sets an environment variable for the build process. When packaging certain applications (especially those written in Java, like NetBeans, or containing pre-built binaries), the default Debian build process might attempt to strip debugging symbols from executable files. This option prevents that stripping, which is often necessary to avoid breaking non-standard executables or pre-compiled applications like NetBeans.debuild: This is a wrapper script that runs the necessary commands (dpkg-buildpackage) to build the Debian package.-us: Means "unsigned source." It tellsdebuildnot to digitally sign the.dsc(Debian Source Control) file.-uc: Means "unchanged package." It tellsdebuildnot to digitally sign the final.changesfile.Note: For packages published in official repositories, signing is required, but for personal, automated builds,
-us -ucsimplifies the process by skipping the digital signature steps.
-b: Specifies a binary-only build. It only builds the final.debbinary package and skips creating the full source package. Since the script uses the NetBeans binary ZIP as the "source," this is the simplest and most efficient option.
The output of this final command is the distribution-ready .deb package file (e.g., apache-netbeans_21-1_all.deb), which can be installed on any Debian-based system (like Ubuntu) using sudo dpkg -i <package-name.deb>.
Part 2: The GitHub Actions Automation (main.yml)
The GitHub Actions workflow turns the local script into a repeatable, cloud-based Continuous Integration (CI) pipeline.
The workflow is configured to run on a manual trigger (workflow_dispatch), allowing you to input the desired NetBeans version (e.g., 22) directly on GitHub's interface.
This setup ensures that the entire process—from setting up the environment to building the package—is fully automated and version-controlled, providing a reliable source for your custom NetBeans packages.
No comments:
Post a Comment