|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# SPDX-FileCopyrightText: 2025 Project516 <138796702+Project516@users.noreply.github.com> |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 | + |
| 7 | +# Script to create a Fedora/RPM package (.rpm) for Number Guessing Game |
| 8 | +# This package can be installed on Fedora, RHEL, CentOS, and other RPM-based distributions |
| 9 | +# Usage: ./package-rpm.sh |
| 10 | +# Output: numberguessinggame-1.0.0-1.noarch.rpm |
| 11 | + |
| 12 | +# Exit immediately if any command fails |
| 13 | +set -e |
| 14 | + |
| 15 | +echo "Building Number Guessing Game RPM package..." |
| 16 | + |
| 17 | +# Check if rpmbuild is installed |
| 18 | +if ! command -v rpmbuild >/dev/null 2>&1; then |
| 19 | + echo "Error: rpmbuild not found. Please install rpm-build:" |
| 20 | + echo " Fedora/RHEL: sudo dnf install rpm-build" |
| 21 | + echo " Ubuntu/Debian: sudo apt install rpm" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +# Clean up any previous build artifacts |
| 26 | +echo "Cleaning up previous builds..." |
| 27 | +rm -rf ~/rpmbuild/RPMS/noarch/numberguessinggame-*.rpm |
| 28 | +rm -rf ~/rpmbuild/BUILD/numberguessinggame-* |
| 29 | +rm -rf ~/rpmbuild/BUILDROOT/numberguessinggame-* |
| 30 | +rm -f numberguessinggame-*.rpm |
| 31 | + |
| 32 | +# Build the application using Gradle |
| 33 | +echo "Building application..." |
| 34 | +./gradlew build |
| 35 | + |
| 36 | +# Create RPM build directory structure |
| 37 | +echo "Setting up RPM build environment..." |
| 38 | +mkdir -p ~/rpmbuild/BUILD |
| 39 | +mkdir -p ~/rpmbuild/RPMS |
| 40 | +mkdir -p ~/rpmbuild/SOURCES |
| 41 | +mkdir -p ~/rpmbuild/SPECS |
| 42 | +mkdir -p ~/rpmbuild/SRPMS |
| 43 | + |
| 44 | +# Copy the spec file to the SPECS directory |
| 45 | +echo "Copying spec file..." |
| 46 | +cp fedora-package/SPECS/numberguessinggame.spec ~/rpmbuild/SPECS/numberguessinggame.spec |
| 47 | + |
| 48 | +# Copy the JAR file to the SOURCES directory |
| 49 | +echo "Copying JAR file..." |
| 50 | +cp app/build/libs/app-all.jar ~/rpmbuild/SOURCES/game.jar |
| 51 | + |
| 52 | +# Build the RPM package |
| 53 | +echo "Building RPM package..." |
| 54 | +rpmbuild -bb ~/rpmbuild/SPECS/numberguessinggame.spec |
| 55 | + |
| 56 | +# Copy the built RPM to the current directory |
| 57 | +echo "Copying RPM package to current directory..." |
| 58 | +cp ~/rpmbuild/RPMS/noarch/numberguessinggame-*.rpm . |
| 59 | + |
| 60 | +# Display success message with installation instructions |
| 61 | +echo "" |
| 62 | +echo "✓ RPM package created: $(ls numberguessinggame-*.rpm)" |
| 63 | +echo "" |
| 64 | +echo "To install on Fedora/RHEL/CentOS, run:" |
| 65 | +echo " sudo dnf install ./numberguessinggame-*.rpm" |
| 66 | +echo "" |
| 67 | +echo "Or on older systems:" |
| 68 | +echo " sudo yum install ./numberguessinggame-*.rpm" |
| 69 | +echo "" |
| 70 | +echo "After installation, run the game with:" |
| 71 | +echo " numberguessinggame" |
| 72 | +echo "" |
0 commit comments