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 initial support for RPM packaging #120

Closed
wants to merge 10 commits into from
Closed
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ else()
set(SUNSHINE_EXECUTABLE_PATH "sunshine")
endif()
configure_file(gen-deb.in gen-deb @ONLY)
configure_file(gen-rpm.in gen-rpm @ONLY)
configure_file(sunshine.desktop.in sunshine.desktop @ONLY)
configure_file(sunshine.service.in sunshine.service @ONLY)
endif()
Expand Down
1 change: 1 addition & 0 deletions assets/85-sunshine-rules.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KERNEL=="uinput", GROUP="input", MODE="0660"
162 changes: 162 additions & 0 deletions gen-rpm.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/sh

# Export filepaths
export BUILDDIR=@CMAKE_CURRENT_SOURCE_DIR@/build
export BUILDROOT=~/rpmbuild/
export RPMSRC=~/rpmbuild/SOURCES
export RPMSPEC=~/rpmbuild/SPECS
export RPMBUILD=~/rpmbuild/BUILD

# Check if user's rpmbuild folder is there, if so, temoprairly rename it.
if [ -f ~/rpmbuild ]; then
echo "Backing up rpmbuild"
~/rpmbuild ~/rpmbuild.bkp
export RPMBUILDEXISTS=TRUE
fi

# Create rpmbuild folder structure
mkdir ~/rpmbuild
mkdir ~/rpmbuild/BUILD
mkdir ~/rpmbuild/BUILDROOT
mkdir ~/rpmbuild/RPMS
mkdir ~/rpmbuild/SOURCES
mkdir ~/rpmbuild/SPECS
mkdir ~/rpmbuild/SRPMS

# Create sunshine .spec file with preinstall and postinstall scripts
cat << 'EOF' > $RPMSPEC/sunshine.spec
Name: sunshine
Version: 0.13.0
Release: 1%{?dist}
Summary: An NVIDIA Gamestream-compatible hosting server
BuildArch: x86_64

License: GPLv3
URL: https://github.com/SunshineStream/Sunshine
Source0: sunshine-@PROJECT_VERSION@_bin.tar.gz

Requires: systemd

%description
An NVIDIA Gamestream-compatible hosting server

%pre
#!/bin/sh

# Sunshine Pre-Install Script
# Store backup for old config files to prevent it from being overwritten
if [ -f /etc/sunshine/sunshine.conf ]; then
cp /etc/sunshine/sunshine.conf /etc/sunshine/sunshine.conf.old
fi

if [ -f /etc/sunshine/apps_linux.json ]; then
cp /etc/sunshine/apps_linux.json /etc/sunshine/apps_linux.json.old
fi

%post
#!/bin/sh

# Sunshine Post-Install Script
export GROUP_INPUT=input

if [ -f /etc/group ]; then
if ! grep -q $GROUP_INPUT /etc/group; then
echo "Creating group $GROUP_INPUT"

groupadd $GROUP_INPUT
fi
else
echo "Warning: /etc/group not found"
fi

if [ -f /etc/sunshine/sunshine.conf.old ]; then
echo "Restoring old sunshine.conf"
mv /etc/sunshine/sunshine.conf.old /etc/sunshine/sunshine.conf
fi

if [ -f /etc/sunshine/apps_linux.json.old ]; then
echo "Restoring old apps_linux.json"
mv /etc/sunshine/apps_linux.json.old /etc/sunshine/apps_linux.json
fi

# Update permissions on config files for Web Manager
if [ -f /etc/sunshine/apps_linux.json ]; then
echo "chmod 666 /etc/sunshine/apps_linux.json"
chmod 666 /etc/sunshine/apps_linux.json
fi

if [ -f /etc/sunshine/sunshine.conf ]; then
echo "chmod 666 /etc/sunshine/sunshine.conf"
chmod 666 /etc/sunshine/sunshine.conf
fi

# Ensure Sunshine can grab images from KMS
path_to_setcap=$(which setcap)
if [ -x "$path_to_setcap" ] ; then
echo "$path_to_setcap cap_sys_admin+p /usr/bin/sunshine"
$path_to_setcap cap_sys_admin+p /usr/bin/sunshine
fi

%prep
%setup -q

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
mkdir -p $RPM_BUILD_ROOT/etc/sunshine
mkdir -p $RPM_BUILD_ROOT/usr/lib/systemd/user
mkdir -p $RPM_BUILD_ROOT/usr/share/applications
mkdir -p $RPM_BUILD_ROOT/etc/udev/rules.d

cp sunshine $RPM_BUILD_ROOT/%{_bindir}/sunshine
cp sunshine.conf $RPM_BUILD_ROOT/etc/sunshine/sunshine.conf
cp apps_linux.json $RPM_BUILD_ROOT/etc/sunshine/apps_linux.json
cp sunshine.service $RPM_BUILD_ROOT/usr/lib/systemd/user/sunshine.service
cp sunshine.desktop $RPM_BUILD_ROOT/usr/share/applications/sunshine.desktop
cp 85-sunshine-rules.rules $RPM_BUILD_ROOT/etc/udev/rules.d/85-sunshine-rules.rules

%clean
rm -rf $RPM_BUILD_ROOT

%files
%{_bindir}/sunshine
/usr/lib/systemd/user/sunshine.service
/etc/sunshine/sunshine.conf
/etc/sunshine/apps_linux.json
/usr/share/applications/sunshine.desktop
/etc/udev/rules.d/85-sunshine-rules.rules

%changelog
* Sat Mar 12 2022 h <[email protected]>
- Initial packaging of Sunshine.
EOF

# Copy over sunshine binary and supplemental files into rpmbuild/BUILD/
mkdir genrpm
mkdir genrpm/sunshine-@PROJECT_VERSION@
cp sunshine-@PROJECT_VERSION@ genrpm/sunshine-@PROJECT_VERSION@/sunshine
cp sunshine.service genrpm/sunshine-@PROJECT_VERSION@/sunshine.service
cp sunshine.desktop genrpm/sunshine-@PROJECT_VERSION@/sunshine.desktop
cp @CMAKE_CURRENT_SOURCE_DIR@/assets/sunshine.conf genrpm/sunshine-@PROJECT_VERSION@/sunshine.conf
cp @CMAKE_CURRENT_SOURCE_DIR@/assets/apps_linux.json genrpm/sunshine-@PROJECT_VERSION@/apps_linux.json
cp @CMAKE_CURRENT_SOURCE_DIR@/assets/85-sunshine-rules.rules genrpm/sunshine-@PROJECT_VERSION@/85-sunshine-rules.rules
cd genrpm

# tarball everything as if it was a source file for rpmbuild
tar --create --file sunshine-@PROJECT_VERSION@_bin.tar.gz sunshine-@PROJECT_VERSION@/
cp sunshine-@PROJECT_VERSION@_bin.tar.gz ~/rpmbuild/SOURCES

# Use rpmbuild to build the RPM package.
rpmbuild -bb $RPMSPEC/sunshine.spec

# Move the completed RPM into the cmake build folder
mv ~/rpmbuild/RPMS/x86_64/sunshine-@[email protected]_64.rpm @CMAKE_CURRENT_BINARY_DIR@/

# Clean up; delete the rpmbuild folder we created and move back the original one
if [ $RPMBUILDEXISTS=TRUE ]; then
echo "Removing and replacing original rpmbuild folder."
rm -rf ~/rpmbuild
mv ~/rpmbuild.bkp ~/rpmbuild
fi

# Done.
3 changes: 2 additions & 1 deletion scripts/Dockerfile-fedora_33
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ RUN dnf -y update && \
openssl-devel \
opus-devel \
pulseaudio-libs-devel \
&& dnf install rpm-build
&& dnf clean all \
&& rm -rf /var/cache/yum

COPY build-private.sh /root/build.sh


ENTRYPOINT ["/root/build.sh"]
ENTRYPOINT ["/root/build.sh -rpm"]
3 changes: 2 additions & 1 deletion scripts/Dockerfile-fedora_35
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ RUN dnf -y update && \
openssl-devel \
opus-devel \
pulseaudio-libs-devel \
&& dnf install rpm-build
&& dnf clean all \
&& rm -rf /var/cache/yum

COPY build-private.sh /root/build.sh


ENTRYPOINT ["/root/build.sh"]
ENTRYPOINT ["/root/build.sh -rpm"]
10 changes: 9 additions & 1 deletion scripts/build-private.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ cmake "-DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE" "-DSUNSHINE_EXECUTABLE_PATH=$SUNSHI

make -j ${nproc}

./gen-deb
# Get preferred package format
if [ "$1" == "-rpm" ]
then
echo "Packaging in .rpm format."
./gen-rpm
else
echo "Pagkaging in .deb format."
./gen-deb
fi