Sunday, November 16, 2025

Automating NetBeans Debian Package with Bash and GitHub Actions: The Deep Dive

 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.

Command(s)Purpose
export NETBEANS_VERSION=$1Captures the version number passed as an argument (e.g., from the GitHub Action) and makes it a global environment variable for the script.
cd src / curl / unzipDownloads the official NetBeans binary ZIP file into the src directory and extracts its contents, providing the application files.
envsubst < ... > debian/controlUses the envsubst utility to read a template file (like control.tpl) and replace placeholders (e.g., $NETBEANS_VERSION) with their actual values, generating the final control file. This is essential for dynamic versioning.
mkdir -p ... / cp ...Creates the standard Linux file hierarchy (e.g., /usr/bin/, /usr/share/icons/) inside the source directory and copies the NetBeans application files and icons into these paths. This structure dictates where the files will be installed on the target system.

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 as debian/control and debian/changelog.

  • -p apache-netbeans_${NETBEANS_VERSION}: Forces the package name and version format to be packagename_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 tells debuild not to digitally sign the .dsc (Debian Source Control) file.

  • -uc: Means "unchanged package." It tells debuild not to digitally sign the final .changes file.

    • Note: For packages published in official repositories, signing is required, but for personal, automated builds, -us -uc simplifies the process by skipping the digital signature steps.

  • -b: Specifies a binary-only build. It only builds the final .deb binary 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.

StepCommand/ActionPurpose
Install dh-makesudo apt-get install -y dh-make devscripts build-essentialInstalls the essential Debian packaging utilities (dh-make, debuild, etc.) in the clean virtual machine environment.
Run the script./package.sh ${{ github.event.inputs.version }}Executes the package.sh script, passing the version entered by the user.
Upload Debian packageactions/upload-artifact@v5Uploads the newly created apache-netbeans*.deb file as a downloadable artifact, making it easy to retrieve and share the final package.

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

Your Friendly Guide to Mastering the Linux Kernel with kernel-update

If you have ever explored the inner workings of Linux, you probably know that the kernel is the heart of your operating system. While most u...