Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add freebsd pkg #539

Merged
merged 18 commits into from
Sep 29, 2024
37 changes: 37 additions & 0 deletions .github/workflows/build_pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: FreeBSD pkg Package Build

on:
workflow_call:
jobs:
pkg:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: java_info
uses: YunaBraska/java-info-action@main
- uses: actions/download-artifact@v4
with:
name: maven-dist
path: target/
Comment on lines +9 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Pin the Java info action to a specific version.

While using the latest version of actions/checkout is good practice, it's recommended to pin the YunaBraska/java-info-action to a specific version to ensure reproducibility and prevent unexpected changes in your workflow.

Consider updating the Java info action step as follows:

 - id: java_info
-  uses: YunaBraska/java-info-action@main
+  uses: YunaBraska/[email protected]

Replace v1.12.0 with the latest stable version available at the time of implementation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: actions/checkout@v4
- id: java_info
uses: YunaBraska/java-info-action@main
- uses: actions/download-artifact@v4
with:
name: maven-dist
path: target/
- uses: actions/checkout@v4
- id: java_info
uses: YunaBraska/java-info-action@v1.12.0
- uses: actions/download-artifact@v4
with:
name: maven-dist
path: target/

- name: Replace pkg version
run: |
calculatedSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$calculatedSha" >> $GITHUB_ENV
sed -i "s/<version>/${{ env.PBH_VERSION }}/g" pkg/pkg/MANIFEST
env:
PBH_VERSION: ${{ steps.java_info.outputs.project_version }}
- name: Build FreeBSD pkg
uses: vmactions/freebsd-vm@v1
with:
usesh: true
run: |
mkdir -p pkg/pkg/work-dir/usr/local/lib/peerbanhelper
cp target/PeerBanHelper.jar pkg/pkg/work-dir/usr/local/lib/peerbanhelper/
pkg create -M pkg/pkg/MANIFEST -r pkg/pkg/work-dir -p pkg/pkg/pkg-plist -o pkg/
pkg info -F pkg/peerbanhelper-${{ env.PBH_VERSION }}.pkg
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: pkg-dist
path: |
pkg/*.pkg
3 changes: 3 additions & 0 deletions .github/workflows/jvm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
Build_DEB:
needs: CI
uses: ./.github/workflows/build_deb.yml
Build_PKG:
needs: CI
uses: ./.github/workflows/build_pkg.yml
Build_Docker:
needs: CI
runs-on: ubuntu-latest
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/jvm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ jobs:
with:
name: deb-dist
path: target/media
- uses: actions/download-artifact@v4
with:
name: pkg-dist
path: target/media
- uses: alexellis/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
asset_paths: '["target/PeerBanHelper.jar", "target/media/PeerBanHelper_*", "target/media/peerbanhelper_*", "target/media/*.spk"]'
asset_paths: '["target/PeerBanHelper.jar", "target/media/PeerBanHelper_*", "target/media/peerbanhelper_*", "target/media/peerbanhelper-*"'
Build_Docker:
permissions:
contents: write
Expand Down
6 changes: 0 additions & 6 deletions install4j/project.install4j
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,6 @@ return console.askYesNo(message, true);
<jreBundle installOnlyIfNecessary="true" />
</windows>
<macosFolder name="macOS Folder" id="98" mediaFileName="${compiler:sys.shortName}_${compiler:sys.platform}_universal_${compiler:sys.version}" architecture="universal" />
<unixInstaller name="Unix Installer" id="103" mediaFileName="${compiler:sys.shortName}_${compiler:sys.platform}_glibc_${compiler:sys.version}" require64BitVm="true">
<jreBundle installOnlyIfNecessary="true" />
</unixInstaller>
<linuxRPM name="Linux RPM" id="106" mediaFileName="${compiler:sys.shortName}_${compiler:sys.platform}_glibc_${compiler:sys.version}" installDir="/usr/local/${compiler:sys.shortName}" require64BitVm="true" arch="x86_64" />
<windows name="Windows x64 NoJava" id="109" mediaFileName="${compiler:sys.shortName}_${compiler:sys.platform}_${compiler:sys.version}_nojava" architecture="64">
<jreBundle jreBundleSource="none" />
Expand All @@ -677,8 +674,5 @@ return console.askYesNo(message, true);
<macosFolder name="macOS Folder NoJava" id="120" mediaFileName="${compiler:sys.shortName}_${compiler:sys.platform}_universal_${compiler:sys.version}_nojava" architecture="universal">
<jreBundle jreBundleSource="none" />
</macosFolder>
<unixInstaller name="Unix Installer NoJava" id="124" mediaFileName="${compiler:sys.shortName}_${compiler:sys.platform}_glibc_${compiler:sys.version}_nojava" require64BitVm="true">
<jreBundle jreBundleSource="none" />
</unixInstaller>
</mediaSets>
</install4j>
24 changes: 24 additions & 0 deletions pkg/pkg/MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "peerbanhelper",
"version": "<version>",
"origin": "net/peerbanhelper",
"comment": "Tool to auto ban peers on the bittorrent network",
"desc": "PeerBanHelper is a tool to auto ban peers on the bittorrent network",
"maintainer": "[email protected]",
"www": "https://github.com/PBH-BTN/PeerBanHelper",
Comment on lines +1 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace version placeholder and verify maintainer email

  1. The version field contains a placeholder "". Please replace this with the actual version number of the package.
  2. The maintainer's email domain (111.com) seems unusual. Please verify if this is the correct email address or if it needs to be updated.

Apply this diff to fix the version placeholder (replace X.Y.Z with the actual version number):

-    "version": "<version>",
+    "version": "X.Y.Z",

Committable suggestion was skipped due to low confidence.

"deps": {
"openjdk21": {
"origin": "java/openjdk21",
"version": "21.0"
}
},
"categories": ["net"],
"prefix":"/usr/local",
"licenselogic": "single",
"licenses": [
"BSD"
],
"scripts": {
"post-install": "post-install"
}
Comment on lines +21 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Post-install script requires enhancements

The post-install script exists but currently only echoes informational messages. It does not perform any post-installation tasks. Additionally, there's a typo in the first echo statement ("Thansk" should be "Thanks"). Please update the script to include necessary setup actions and correct the typo to ensure it follows best practices for FreeBSD package post-install scripts.

🔗 Analysis chain

Verify post-install script

A post-install script is specified, but its contents are not visible in this manifest. Please ensure that:

  1. The "post-install" script file exists in the appropriate location.
  2. The script performs the necessary post-installation tasks.
  3. The script follows best practices for FreeBSD package post-install scripts.

Run the following script to check for the existence of the post-install script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the existence of the post-install script

# Test: Search for the post-install script. Expect: File exists and is not empty.
fd -t f 'post-install' | xargs -I {} sh -c 'if [ -s "{}" ]; then echo "Found non-empty post-install script: {}"; else echo "Error: post-install script not found or empty: {}"; fi'

Length of output: 239


Script:

#!/bin/bash
# Description: Display the contents of the post-install script

# Test: Output the contents of pkg/pkg/post-install
cat pkg/pkg/post-install

Length of output: 218

}
2 changes: 2 additions & 0 deletions pkg/pkg/pkg-plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/usr/local/lib/peerbanhelper/PeerBanHelper.jar
/usr/local/etc/rc.d/peerbanhelper
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Issues Detected: Missing Files and Dependencies

  • /usr/local/lib/peerbanhelper/PeerBanHelper.jar not found.
  • /usr/local/etc/rc.d/peerbanhelper rc script not found.
  • Configuration file /usr/local/etc/peerbanhelper.conf not found.
  • Java is not installed on the system.

These issues indicate that the pkg-plist references files that are missing and necessary dependencies are not specified.

🔗 Analysis chain

LGTM! Consider adding configuration and specifying dependencies.

The pkg-plist file correctly lists the JAR file and the rc script for the PeerBanHelper. However, there are a few suggestions to improve the package:

  1. Consider adding a configuration file (e.g., /usr/local/etc/peerbanhelper.conf) if the application requires one.
  2. Ensure that any required dependencies (such as Java runtime) are specified in the package metadata.
  3. Consider specifying file permissions in the pkg-plist, especially for the rc script.

You might want to add the following lines to the pkg-plist:

@sample /usr/local/etc/peerbanhelper.conf.sample
@(root,wheel,555) /usr/local/etc/rc.d/peerbanhelper

This will add a sample configuration file and set appropriate permissions for the rc script.

To ensure the package is set up correctly, you can run the following script:

This script will help verify the presence and permissions of the package files, as well as check for Java installation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the PeerBanHelper package setup

# Check if the JAR file exists
if [ -f /usr/local/lib/peerbanhelper/PeerBanHelper.jar ]; then
    echo "PeerBanHelper.jar found"
else
    echo "PeerBanHelper.jar not found"
fi

# Check if the rc script exists and has correct permissions
if [ -f /usr/local/etc/rc.d/peerbanhelper ]; then
    echo "peerbanhelper rc script found"
    ls -l /usr/local/etc/rc.d/peerbanhelper
else
    echo "peerbanhelper rc script not found"
fi

# Check for a configuration file
if [ -f /usr/local/etc/peerbanhelper.conf ]; then
    echo "Configuration file found"
else
    echo "Configuration file not found"
fi

# Check if Java is installed
if command -v java >/dev/null 2>&1; then
    echo "Java is installed"
else
    echo "Java is not installed"
fi

Length of output: 433

4 changes: 4 additions & 0 deletions pkg/pkg/post-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
echo "Thansk for using peerbanhelper. Your config file will be placed at /usr/local/etc/peerbanhelper"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in the echo statement

There's a typo in the word "Thanks" at the beginning of the echo statement.

Please apply the following correction:

-echo "Thansk for using peerbanhelper. Your config file will be placed at /usr/local/etc/peerbanhelper"
+echo "Thanks for using peerbanhelper. Your config file will be placed at /usr/local/etc/peerbanhelper"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
echo "Thansk for using peerbanhelper. Your config file will be placed at /usr/local/etc/peerbanhelper"
echo "Thanks for using peerbanhelper. Your config file will be placed at /usr/local/etc/peerbanhelper"

echo "To auto start peerbanhelper, please run: sysrc peerbanhelper_enable=YES"
mkdir -p /usr/local/var/db/peerbanhelper
23 changes: 23 additions & 0 deletions pkg/pkg/work-dir/usr/local/etc/rc.d/peerbanhelper
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
#
# PROVIDE: peerbanhelper
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="peerbanhelper"
rcvar=peerbanhelper_enable

load_rc_config $name

: ${peerbanhelper_enable:=NO}
: ${peerbanhelper_user:="root"}
: ${peerbanhelper_dir:="/usr/local/var/db/peerbanhelper"}
: ${peerbanhelper_classpath:="/usr/local/lib/peerbanhelper/PeerBanHelper.jar"}
: ${peerbanhelper_jvm_flags:="-Dpbh.datadir=${peerbanhelper_dir} -Xmx386M -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+ShrinkHeapInSteps"}
: ${peerbanhelper_command:="/usr/local/bin/java ${peerbanhelper_jvm_flags} -jar ${peerbanhelper_classpath}"}

command="/usr/sbin/daemon"
command_args="-f -p /var/run/${name}.pid -u ${peerbanhelper_user} ${peerbanhelper_command}"
run_rc_command "$1"
Loading