-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathpackage-rlbot.sh
More file actions
executable file
·244 lines (195 loc) · 5.52 KB
/
Copy pathpackage-rlbot.sh
File metadata and controls
executable file
·244 lines (195 loc) · 5.52 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/env bash
set -euo pipefail
# package-rlbot.sh - Package RLBotServer binary for multiple Linux distributions
#
# Usage: ./package-rlbot.sh <binary_path> [distro_list]
#
# If no distribution list is provided, it defaults to packaging for ubuntu and fedora
# Supported distributions: ubuntu, fedora
#
# Examples:
# ./package-rlbot.sh ./RLBotServer ubuntu
# ./package-rlbot.sh ./RLBotServer # Defaults to ubuntu and fedora
#
# This script packages the RLBotServer binary for various Linux distributions,
# creating appropriate metadata and package structures.
DEFAULT_DISTROS=("ubuntu" "fedora")
usage() {
cat <<'EOF'
Usage: ./package-rlbot.sh <binary_path> [distro_list]
If no distribution list is provided, it defaults to packaging all supported distributions.
Supported distributions: ubuntu, fedora.
Examples:
./package-rlbot.sh ./RLBotServer ubuntu
./package-rlbot.sh ./RLBotServer # Defaults to ubuntu and fedora
Environment overrides:
OUTPUT_DIR Output directory for packages (default: ./dist)
EOF
}
require_cmd() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "Missing required command: $1" >&2
return 1
fi
}
get_git_version() {
require_cmd git
local repo_root="$1"
local latest_tag
latest_tag="$(git -C "$repo_root" describe --tags --abbrev=0 2>/dev/null || true)"
if [[ -z "$latest_tag" ]]; then
echo "Unable to determine version: no git tags found in $repo_root" >&2
return 1
fi
echo "${latest_tag#v}"
}
normalize_rpm_version() {
local input="$1"
if [[ -z "$input" ]]; then
echo "RPM version is empty" >&2
return 1
fi
echo "${input//-/.}"
}
resolve_path() {
local input_path="$1"
local dir
dir="$(cd "$(dirname "$input_path")" && pwd)"
echo "${dir}/$(basename "$input_path")"
}
ensure_x86_64() {
local arch_raw="$1"
case "$arch_raw" in
x86_64|amd64)
return 0
;;
*)
echo "Unsupported architecture: ${arch_raw}. Only x86-64 is supported." >&2
return 1
;;
esac
}
package_deb() {
require_cmd dpkg-deb
local pkg_name="rlbotserver"
local pkg_dir="${tmp_root}/deb/${pkg_name}_${version}"
local deb_path="${out_dir}/${pkg_name}_${version}_${deb_arch}.deb"
rm -rf "$pkg_dir"
mkdir -p "$pkg_dir/DEBIAN" "$pkg_dir/usr/bin"
install -m 0755 "$binary_path" "$pkg_dir/usr/bin/$binary_name"
cat > "$pkg_dir/DEBIAN/control" <<EOF
Package: ${pkg_name}
Version: ${version}
Section: utils
Priority: optional
Architecture: ${deb_arch}
Maintainer: RLBot Contributors
Description: RLBotServer binary
RLBotServer is the backend server for RLBot v5, allowing custom bots and scripts to interface with Rocket League.
EOF
dpkg-deb --build "$pkg_dir" "$deb_path" >/dev/null
echo "Created ${deb_path}"
}
package_rpm() {
require_cmd rpmbuild
require_cmd tar
local pkg_name="rlbotserver"
local rpm_root="${tmp_root}/rpm"
local src_dir="${tmp_root}/${pkg_name}-${rpm_version}"
local spec_file="${rpm_root}/SPECS/${pkg_name}.spec"
mkdir -p "${rpm_root}"/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
rm -rf "$src_dir"
mkdir -p "$src_dir"
install -m 0755 "$binary_path" "$src_dir/$binary_name"
tar -C "$tmp_root" -czf "$rpm_root/SOURCES/${pkg_name}-${rpm_version}.tar.gz" "${pkg_name}-${rpm_version}"
cat > "$spec_file" <<EOF
Name: ${pkg_name}
Version: ${rpm_version}
Release: 1%{?dist}
Summary: RLBotServer binary
License: MIT
BuildArch: ${rpm_arch}
Source0: %{name}-%{version}.tar.gz
%description
RLBotServer is the backend server for RLBot v5, allowing custom bots and scripts to interface with Rocket League.
%prep
%setup -q
%build
%install
mkdir -p %{buildroot}/usr/bin
install -m 0755 ${binary_name} %{buildroot}/usr/bin/${binary_name}
%files
/usr/bin/${binary_name}
%changelog
* $(date -u "+%a %b %d %Y") RLBot Contributors - ${version}-1
- Packaged RLBotServer binary
EOF
rpmbuild --define "_topdir ${rpm_root}" -bb "$spec_file" >/dev/null 2>&1
local rpm_file
rpm_file="$(find "$rpm_root/RPMS" -type f -name "*.rpm" | head -n 1)"
if [[ -z "$rpm_file" ]]; then
echo "RPM build failed: no package found in ${rpm_root}/RPMS" >&2
return 1
fi
cp "$rpm_file" "$out_dir/"
echo "Created ${out_dir}/$(basename "$rpm_file")"
}
main() {
if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
usage
exit 0
fi
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
binary_path="$1"
shift
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [[ $# -eq 0 ]]; then
distros=("${DEFAULT_DISTROS[@]}")
else
if [[ $# -eq 1 && "$1" == *","* ]]; then
IFS=',' read -r -a distros <<< "$1"
else
distros=("$@")
fi
fi
binary_path="$(resolve_path "$binary_path")"
if [[ ! -f "$binary_path" ]]; then
echo "Binary not found: $binary_path" >&2
exit 1
fi
if [[ ! -x "$binary_path" ]]; then
echo "Binary is not executable: $binary_path" >&2
exit 1
fi
binary_name="$(basename "$binary_path")"
version="$(get_git_version "$script_dir")"
rpm_version="$(normalize_rpm_version "$version")"
out_dir="${OUTPUT_DIR:-dist}"
mkdir -p "$out_dir"
arch_raw="$(uname -m)"
ensure_x86_64 "$arch_raw"
deb_arch="amd64"
rpm_arch="x86_64"
tmp_root="$(mktemp -d)"
trap 'rm -rf "$tmp_root"' EXIT
for distro in "${distros[@]}"; do
distro="${distro,,}"
case "$distro" in
ubuntu)
package_deb
;;
fedora)
package_rpm
;;
*)
echo "Unknown distribution: $distro" >&2
echo "Supported distributions: ubuntu, fedora" >&2
exit 1
;;
esac
done
}
main "$@"