Skip to content

Commit

Permalink
DEB/RPM packages support (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
phnzb committed Apr 19, 2024
1 parent cc6fb8b commit 1de712a
Show file tree
Hide file tree
Showing 11 changed files with 554 additions and 2 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ jobs:
build-qnap:
uses: ./.github/workflows/qnap.yml

build-linux-pkg:
uses: ./.github/workflows/linux-pkg.yml
with:
external_call: true
needs: [build-linux]
permissions:
actions: write

repack-qnap:
uses: ./.github/workflows/qnap-repack.yml
with:
Expand Down Expand Up @@ -54,6 +62,8 @@ jobs:
mv nzbget-synology-packages/* builds || true
mv nzbget-qnap-packages/* builds || true
mv nzbget-qnap-native-packages/* builds || true
mv nzbget-deb-packages/* builds || true
mv nzbget-rpm-packages/* builds || true
cd builds
VERSION=$(ls | grep bin-windows-setup | cut -d - -f 2)
if [ "$GITHUB_REF_NAME" != "main" ]; then VERSION="$VERSION-testing"; fi
Expand All @@ -65,7 +75,7 @@ jobs:
echo "nzbget_signatures({" | tee $SIGS_FILE
echo | tee -a $SIGS_FILE
for FILE in *.exe *.run *.zip *.spk *.qpkg; do
for FILE in *.exe *.run *.zip *.spk *.qpkg *.deb *.rpm; do
[ -f $FILE ] || continue
MD5=$(openssl dgst -md5 $FILE | cut -d ' ' -f 2)
Expand Down Expand Up @@ -105,8 +115,15 @@ jobs:
nzbget-qnap-packages
nzbget-qnap-native-packages
- name: Delete unneded linux packages artifacts
uses: geekyeggo/delete-artifact@v4
with:
name: |
nzbget-deb-packages
nzbget-rpm-packages
make-testing-release:
runs-on: [self-hosted, linux]
runs-on: [self-hosted, nzbget-linux]
needs: [generate-signatures]
permissions:
contents: write
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/linux-pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: linux packages

on:
workflow_call:
inputs:
external_call:
description: 'To distinguish workflow_call from regular push / workflow_dispatch'
type: boolean
required: false
default: false
workflow_dispatch:

jobs:
build-linux:
uses: ./.github/workflows/linux.yml
if: ${{ inputs.external_call == false }}

build-pkg:
runs-on: [self-hosted, nzbget-linux]
needs: [build-linux]
if: always()
permissions:
actions: write

steps:

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download build artifacts
uses: actions/download-artifact@v4

- name: Build DEB and RPM packages
run: |
sudo apt-get update && sudo apt-get install rpm -y
bash linux/pkg/build-pkg.sh
- name: Upload DEB build artifacts
uses: actions/upload-artifact@v4
with:
name: nzbget-deb-packages
path: build/deb/*.deb
retention-days: 5

- name: Upload RPM build artifacts
uses: actions/upload-artifact@v4
with:
name: nzbget-rpm-packages
path: build/rpm/*.rpm
retention-days: 5

- name: Delete unneded linux artifacts
if: ${{ inputs.external_call == false }}
uses: geekyeggo/delete-artifact@v4
with:
name: |
nzbget-linux-installers
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ More information available at https://nzbget.com
We provide a easy-to-use installer for each platform we support.
Please download binaries from our [releases](https://github.com/nzbgetcom/nzbget/tags) page.

Linux DEB/RPM packages are available from [releases](https://github.com/nzbgetcom/nzbget/tags) page or from DEB/RPM [repositories](https://nzbgetcom.github.io).

Docker images are available for x86-64 / arm64 / armv7 architectures. [Docker readme](docker/README.md)

Synology packages are available as SynoCommunity packages and SPK packages. [Synology readme](synology/README.md)
Expand Down
28 changes: 28 additions & 0 deletions linux/pkg/build-info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# About

"build-pkg.sh" is a bash script which is used to build nzbget Linux DEB/RPM packages.


# Prerequisites

- linux x86_64 host (Ubuntu 22.04 LTS for example)
- installed packages:
```
sudo apt install rpm dpkg fakeroot
```

# Building NZBGet Linux packages

From cloned repository run
```
bash linux/pkg/build-pkg.sh [type] [arch]
```

Optional arguments:
- type: can be `deb` / `rpm`
- arch: can be `i686` / `x86_64` / `armel` / `armhf` / `aarch64` / `riscv64`

# Output files

- `build/deb` - Debian packages
- `build/rpm` - RPM packages
182 changes: 182 additions & 0 deletions linux/pkg/build-pkg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/bin/sh
#
# This file is part of nzbget. See <https://nzbget.com>.
#
# Copyright (C) 2024 phnzb <pavel@nzbget.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# stop on error
set -e

NZBGET_ROOT=$PWD

# $1 - installer
# if empty - find installer file in artifacts dir
INSTALLER="$1"
if [ -z $INSTALLER ]; then
INSTALLER=$(find $NZBGET_ROOT/nzbget-linux-installers/ -name *linux.run 2>/dev/null) || true
fi
if [ -z $INSTALLER ]; then
echo "Cannot find linux installer file. Exitig."
exit 1
fi

# $2 - type of package(s) deb/rpm
# if empty - build deb and rpm
PKG_TYPE="$2"
if [ -z $PKG_TYPE ]; then
DEB=yes
RPM=yes
fi
if [ "$PKG_TYPE" == "deb" ]; then
DEB=yes
RPM=no
fi
if [ "$PKG_TYPE" == "rpm" ]; then
DEB=no
RPM=yes
fi

# $3 - architectures
# if empty - use all available architectures
ARCHS="$3"
if [ -z $ARCHS ]; then
ARCHS="i686 x86_64 armel armhf aarch64 riscv64"
fi

# prepare directories
mkdir -p build
cd build
if [ "$DEB" == "yes" ]; then
rm -rf deb
mkdir -p deb
fi
if [ "$RPM" == "yes" ]; then
rm -rf rpm
mkdir -p rpm
fi

# extract version
VERSION=$(bash "$INSTALLER" --help | grep 'Installer for' | cut -d ' ' -f 3 | sed -r 's/nzbget-//')
RPM_VERSION=${VERSION//-/}

for ARCH in $ARCHS; do
rm -rf $PWD/$ARCH
bash "$INSTALLER" --arch "$ARCH" --destdir "$PWD/$ARCH" --silent
case $ARCH in
i686)
DPKG_ARCH=i386
RPM_ARCH=i386
;;
x86_64)
DPKG_ARCH=amd64
RPM_ARCH=x86_64
;;
aarch64)
DPKG_ARCH=arm64
RPM_ARCH=aarch64
;;
armhf)
DPKG_ARCH=armhf
RPM_ARCH=armv7l
;;
armel)
DPKG_ARCH=armel
RPM_ARCH=armv6l
;;
*)
DPKG_ARCH=$ARCH
RPM_ARCH=$ARCH
;;
esac

# prepare files
CONTENTS="$PWD/$ARCH/CONTENTS/"
SHARE="$CONTENTS/usr/share/nzbget/"
SHAREDOC="$CONTENTS/usr/share/doc/nzbget/"
mkdir -p $CONTENTS/usr/bin
mkdir -p $CONTENTS/usr/share/doc/nzbget
mkdir -p $CONTENTS/usr/share/nzbget
cp $PWD/$ARCH/nzbget $CONTENTS/usr/bin
for DOCFILE in ChangeLog COPYING; do
cp $PWD/$ARCH/$DOCFILE $SHAREDOC
done
mv $PWD/$ARCH/scripts $SHARE
mv $PWD/$ARCH/webui $SHARE
cp $PWD/$ARCH/nzbget.conf $SHARE
cp $PWD/$ARCH/cacert.pem $SHARE

# tweak nzbget.conf
sed -i \
-e "s|^MainDir=.*|MainDir=/var/lib/nzbget/downloads|g" \
-e "s|^ScriptDir=.*|ScriptDir=/var/lib/nzbget/scripts|g" \
-e "s|^WebDir=.*|WebDir=/usr/share/nzbget/webui|g" \
-e "s|^TempDir=.*|TempDir=/var/lib/nzbget/tmp|g" \
-e "s|^ConfigTemplate=.*|ConfigTemplate=/usr/share/nzbget/nzbget.conf|g" \
-e "s|^UnrarCmd=.*|UnrarCmd=unrar|g" \
-e "s|^SevenZipCmd=.*|SevenZipCmd=7zz|g" \
-e "s|^CertStore=.*|CertStore=/usr/share/nzbget/cacert.pem|g" \
-e "s|^CertCheck=.*|CertCheck=yes|g" \
-e "s|^DestDir=.*|DestDir=$\{MainDir\}/completed|g" \
-e "s|^InterDir=.*|InterDir=$\{MainDir\}/intermediate|g" \
-e "s|^AuthorizedIP=.*|AuthorizedIP=127.0.0.1|g" \
-e 's|^UpdateCheck=.*|UpdateCheck=none|g' \
-e 's|^UMask=.*|UMask=0002|g' \
"${SHARE}nzbget.conf"

# build debian package
if [ "$DEB" == "yes" ]; then
mkdir -p $CONTENTS/DEBIAN/
cp $NZBGET_ROOT/linux/pkg/deb/DEBIAN/* "$CONTENTS/DEBIAN/"
# copy additional CONTENTS files
cp -r $NZBGET_ROOT/linux/pkg/deb/CONTENTS "$PWD/$ARCH/" 2>/dev/null || true
eval "echo \"$(cat ../linux/pkg/deb/DEBIAN/control)\"" > "$CONTENTS/DEBIAN/control"
mkdir -p "$CONTENTS/lib/systemd/system/"
cp ../linux/pkg/nzbget.service "$CONTENTS/lib/systemd/system/"
# fix permissions
chmod -R u+rwX,go+rX,go-w "$CONTENTS/usr"
chmod -R u+rwX,go+rX,go-w "$CONTENTS/lib"
# remove unneeded files
find $PWD/$ARCH/ -maxdepth 1 -type f -delete
fakeroot dpkg-deb -Zxz --build $CONTENTS $PWD/deb/nzbget-$VERSION-$DPKG_ARCH.deb
fi

# build rpm package
if [ "$RPM" == "yes" ]; then
if [ "$ARCH" == "riscv64" ]; then continue; fi
# prepare spec
cat ../linux/pkg/rpm/nzbget.spec | sed "s|^Version:.*|Version: $RPM_VERSION|" > "$ARCH/nzbget.spec"
# prepare directories
if [ "$ARCH" == "armel" ] || [ "$ARCH" == "armhf" ]; then
ARCH_PATH="arm"
else
ARCH_PATH=$RPM_ARCH
fi
RPM_SRC="$PWD/$ARCH/BUILDROOT/nzbget-$RPM_VERSION-1.$ARCH_PATH"
mkdir -p $RPM_SRC
cp -r $CONTENTS/usr/ $RPM_SRC
# replace 7zz with 7za (p7zip-full)
sed -i -e "s|^SevenZipCmd=.*|SevenZipCmd=7za|g" "$RPM_SRC/usr/share/nzbget/nzbget.conf"
mkdir -p "$RPM_SRC/usr/lib/systemd/system/"
cp ../linux/pkg/nzbget.service "$RPM_SRC/usr/lib/systemd/system/"
# remove unneeded files
find $PWD/$ARCH/ -maxdepth 1 -type f ! -name "nzbget.spec" -delete
rpmbuild --define "_topdir $PWD/$ARCH" -bb $PWD/$ARCH/nzbget.spec --target $RPM_ARCH
cp $PWD/$ARCH/RPMS/$RPM_ARCH/*.rpm rpm/
fi
# cleanup
rm -rf $PWD/$ARCH
done
14 changes: 14 additions & 0 deletions linux/pkg/deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Package: nzbget
Version: $VERSION
Architecture: $DPKG_ARCH
Maintainer: nzbget.com <nzbget@nzbget.com>
Depends: adduser, init-system-helpers, systemd
Recommends: python3, 7zip, unrar
Section: net
Priority: optional
Homepage: https://nzbget.com
Description: Command-line based binary newsgrabber for nzb files, written in C++
NZBGet is a command-line based binary newsgrabber for nzb files,
written in C++.
It supports client/server mode, automatic par-check/-repair,
unpack and web-interface. NZBGet requires low system resources.
Loading

0 comments on commit 1de712a

Please sign in to comment.