|
1 | | -#!/bin/sh |
2 | | -# Script to create a Linux package with bundled JRE for Number Guessing Game |
3 | | -# This creates a self-contained package that doesn't require Java to be installed |
4 | | -# Output: NumberGuessingGame-linux.tar.xz |
5 | | - |
6 | | -# Exit immediately if any command fails |
7 | | -set -e |
8 | | - |
9 | | -echo "Building Number Guessing Game for Linux with bundled JRE..." |
10 | | - |
11 | | -# Configuration |
12 | | -PACKAGE_NAME="NumberGuessingGame-linux" |
13 | | -JRE_DIR="jre-linux" |
14 | | -ADOPTIUM_BASE_URL="https://api.adoptium.net/v3/binary/latest/8/ga" |
15 | | - |
16 | | -# Clean up any previous builds |
17 | | -rm -rf ${PACKAGE_NAME} |
18 | | -rm -rf ${JRE_DIR} |
19 | | -rm -f ${PACKAGE_NAME}.tar.xz |
20 | | -rm -f ${PACKAGE_NAME}.tar.gz |
21 | | - |
22 | | -# Build the application using Gradle |
23 | | -echo "Building application..." |
24 | | -./gradlew build |
25 | | - |
26 | | -# Download JRE for Linux from Eclipse Adoptium |
27 | | -echo "Downloading JRE for Linux..." |
28 | | -mkdir -p ${JRE_DIR} |
29 | | -curl -L "${ADOPTIUM_BASE_URL}/linux/x64/jre/hotspot/normal/eclipse?project=jdk" -o ${JRE_DIR}/jre-linux.tar.gz |
30 | | - |
31 | | -# Extract the downloaded JRE |
32 | | -echo "Extracting JRE..." |
33 | | -cd ${JRE_DIR} |
34 | | -tar -xzf jre-linux.tar.gz |
35 | | -JRE_EXTRACTED=$(ls -d jdk* 2>/dev/null || ls -d jre* 2>/dev/null) |
36 | | -cd .. |
37 | | - |
38 | | -# Create package directory structure |
39 | | -echo "Creating package structure..." |
40 | | -mkdir -p ${PACKAGE_NAME} |
41 | | -cp app/build/libs/app-all.jar ${PACKAGE_NAME}/game.jar |
42 | | -cp README.md ${PACKAGE_NAME}/README.txt |
43 | | -cp LICENSE ${PACKAGE_NAME}/LICENSE |
44 | | - |
45 | | -# Copy the JRE into the package |
46 | | -echo "Copying JRE into package..." |
47 | | -cp -r ${JRE_DIR}/${JRE_EXTRACTED} ${PACKAGE_NAME}/jre |
48 | | - |
49 | | -# Create a shell script that uses the bundled JRE |
50 | | -cat > ${PACKAGE_NAME}/run.sh << 'EOF' |
51 | | -#!/bin/sh |
52 | | -
|
53 | | -# Get the directory where the script is located |
54 | | -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
55 | | -
|
56 | | -"${SCRIPT_DIR}/jre/bin/java" -jar "${SCRIPT_DIR}/game.jar" |
57 | | -EOF |
58 | | - |
59 | | -# Make the run script executable |
60 | | -chmod +x ${PACKAGE_NAME}/run.sh |
61 | | - |
62 | | -# Create the final tar.xz archive with maximum compression |
63 | | -echo "Creating tar.xz archive..." |
64 | | -tar -cJf ${PACKAGE_NAME}.tar.xz ${PACKAGE_NAME}/ |
65 | | - |
66 | | -# Clean up temporary directories |
67 | | -rm -rf ${PACKAGE_NAME} |
68 | | -rm -rf ${JRE_DIR} |
69 | | - |
70 | | -echo "" |
71 | | -echo "✓ Linux package with bundled JRE created: ${PACKAGE_NAME}.tar.xz" |
72 | | -echo "" |
| 1 | +#!/bin/sh |
| 2 | +# Script to create a Linux package with bundled JRE for Number Guessing Game |
| 3 | +# This creates a self-contained package that doesn't require Java to be installed |
| 4 | +# Output: NumberGuessingGame-linux.tar.xz |
| 5 | + |
| 6 | +# Exit immediately if any command fails |
| 7 | +set -e |
| 8 | + |
| 9 | +echo "Building Number Guessing Game for Linux with bundled JRE..." |
| 10 | + |
| 11 | +# Configuration |
| 12 | +PACKAGE_NAME="NumberGuessingGame-linux" |
| 13 | +JRE_DIR="jre-linux" |
| 14 | +ADOPTIUM_BASE_URL="https://api.adoptium.net/v3/binary/latest/8/ga" |
| 15 | + |
| 16 | +# Clean up any previous builds |
| 17 | +rm -rf ${PACKAGE_NAME} |
| 18 | +rm -rf ${JRE_DIR} |
| 19 | +rm -f ${PACKAGE_NAME}.tar.xz |
| 20 | +rm -f ${PACKAGE_NAME}.tar.gz |
| 21 | + |
| 22 | +# Build the application using Gradle |
| 23 | +echo "Building application..." |
| 24 | +./gradlew build |
| 25 | + |
| 26 | +# Download JRE for Linux from Eclipse Adoptium |
| 27 | +echo "Downloading JRE for Linux..." |
| 28 | +mkdir -p ${JRE_DIR} |
| 29 | +curl -L "${ADOPTIUM_BASE_URL}/linux/x64/jre/hotspot/normal/eclipse?project=jdk" -o ${JRE_DIR}/jre-linux.tar.gz |
| 30 | + |
| 31 | +# Extract the downloaded JRE |
| 32 | +echo "Extracting JRE..." |
| 33 | +cd ${JRE_DIR} |
| 34 | +tar -xzf jre-linux.tar.gz |
| 35 | +JRE_EXTRACTED=$(ls -d jdk* 2>/dev/null || ls -d jre* 2>/dev/null) |
| 36 | +cd .. |
| 37 | + |
| 38 | +# Create package directory structure |
| 39 | +echo "Creating package structure..." |
| 40 | +mkdir -p ${PACKAGE_NAME} |
| 41 | +cp app/build/libs/app-all.jar ${PACKAGE_NAME}/game.jar |
| 42 | +cp README.md ${PACKAGE_NAME}/README.txt |
| 43 | +cp LICENSE ${PACKAGE_NAME}/LICENSE |
| 44 | + |
| 45 | +# Copy the JRE into the package |
| 46 | +echo "Copying JRE into package..." |
| 47 | +cp -r ${JRE_DIR}/${JRE_EXTRACTED} ${PACKAGE_NAME}/jre |
| 48 | + |
| 49 | +# Create a shell script that uses the bundled JRE |
| 50 | +cat > ${PACKAGE_NAME}/run.sh << 'EOF' |
| 51 | +#!/bin/sh |
| 52 | +
|
| 53 | +# Get the directory where the script is located |
| 54 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 55 | +
|
| 56 | +"${SCRIPT_DIR}/jre/bin/java" -jar "${SCRIPT_DIR}/game.jar" |
| 57 | +EOF |
| 58 | + |
| 59 | +# Make the run script executable |
| 60 | +chmod +x ${PACKAGE_NAME}/run.sh |
| 61 | + |
| 62 | +# Create the final tar.xz archive with maximum compression |
| 63 | +echo "Creating tar.xz archive..." |
| 64 | +tar -cJf ${PACKAGE_NAME}.tar.xz ${PACKAGE_NAME}/ |
| 65 | + |
| 66 | +# Clean up temporary directories |
| 67 | +rm -rf ${PACKAGE_NAME} |
| 68 | +rm -rf ${JRE_DIR} |
| 69 | + |
| 70 | +echo "" |
| 71 | +echo "✓ Linux package with bundled JRE created: ${PACKAGE_NAME}.tar.xz" |
| 72 | +echo "" |
0 commit comments