/
gen-rpm.in
executable file
·179 lines (148 loc) · 5.45 KB
/
gen-rpm.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/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 for Docker switch
if [ "$1" == "-d" ]; then
export DOCKERSTATUS=TRUE
else
export DOCKERSTATUS=FALSE
fi
# Check if user's rpmbuild folder is there, if so, temoprairly rename it.
if [ -d ~/rpmbuild ]; then
echo "Backing up rpmbuild"
~/rpmbuild ~/rpmbuild.bkp
export RPMBUILDEXISTS=TRUE
else
export RPMBUILDEXISTS=FALSE
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: @PROJECT_VERSION@
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 <65380846+thatsysadmin@users.noreply.github.com>
- 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
# Check if running in a CT
if [ "$DOCKERSTATUS" == "FALSE" ]; then
# Move the completed RPM into the cmake build folder
mv ~/rpmbuild/RPMS/x86_64/sunshine-@PROJECT_VERSION@-1.fc*.x86_64.rpm @CMAKE_CURRENT_BINARY_DIR@/
echo "Moving completed RPM package into CMake build folder."
elif [ "$DOCKERSTATUS" == "TRUE" ]; then
# Move into pickup location
mkdir -p /root/sunshine-build/package-rpm/
mv ~/rpmbuild/RPMS/x86_64/sunshine-@PROJECT_VERSION@-1.fc*.x86_64.rpm /root/sunshine-build/package-rpm/sunshine.rpm
echo "Moving completed RPM package for pickup."
fi
# 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
exit 0