-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·114 lines (95 loc) · 3.35 KB
/
build.sh
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
#!/bin/bash
S2_APP_ID="lnx"
# Check if conda is available
if ! command -v conda &> /dev/null; then
echo "Conda is not installed or not in the PATH. Please install Conda and try again."
exit 1
fi
# Function to find the highest Minecraft version
find_highest_version() {
local game_dir="data/game"
local versions=()
local snapshots=()
local other_versions=()
# Collect all version directories
for dir in "$game_dir"/*; do
if [ -d "$dir" ]; then
version=$(basename "$dir")
# Check if it's a regular version (like 1.21.5)
if [[ $version =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
versions+=("$version")
# Check if it's a snapshot
elif [[ $version =~ ^[0-9]+w[0-9]+[a-z]$ ]] || [[ $version == *"snapshot"* ]]; then
snapshots+=("$version")
# Other versions (beta, etc.)
else
other_versions+=("$version")
fi
fi
done
# Sort versions in descending order
if [ ${#versions[@]} -gt 0 ]; then
# Sort regular versions and return the highest
IFS=$'\n' sorted_versions=($(sort -t. -k1,1nr -k2,2nr -k3,3nr <<<"${versions[*]}"))
unset IFS
echo "${sorted_versions[0]}"
return
fi
# If no regular versions, check snapshots
if [ ${#snapshots[@]} -gt 0 ]; then
# For snapshots, we'll do a simple string sort which should work for the format described
IFS=$'\n' sorted_snapshots=($(sort -r <<<"${snapshots[*]}"))
unset IFS
echo "${sorted_snapshots[0]}"
return
fi
# If no regular or snapshot versions, return the first other version
if [ ${#other_versions[@]} -gt 0 ]; then
echo "${other_versions[0]}"
return
fi
# If no versions found
echo "No Minecraft versions found in $game_dir"
exit 1
}
# Activate the Anaconda environment
source $(conda info --base)/etc/profile.d/conda.sh
conda activate S2RM
# Check if the environment activation was successful
if [ $? -ne 0 ]; then
echo "Failed to activate the Conda environment 'S2RM'. Please ensure it exists and try again."
exit 1
fi
# Find the highest Minecraft version
selected_version=$(find_highest_version)
echo "Selected Minecraft version: $selected_version"
# Delete previous zip build folder
if [ -d "S2RM_${S2_APP_ID}" ]; then
rm -rf "S2RM_${S2_APP_ID}"
fi
# Build with PyInstaller --windowed to remove terminal
python -m PyInstaller \
--name "S2RM_$S2_APP_ID" \
--add-data "src/*.py:src" \
--add-data "src/*.json:src" \
--add-data "src/icon.ico:src" \
--add-data "data/*.py:data" \
--add-data "data/game/$selected_version/limited_stack_items.json:data/game/$selected_version" \
--add-data "data/game/$selected_version/raw_materials_table.json:data/game/$selected_version" \
--distpath "." \
--noconfirm \
main.py
# Check if PyInstaller was successful
if [ $? -ne 0 ]; then
echo "PyInstaller build failed. Exiting."
exit 1
fi
# Compress the output folder and rename the zip using the app identifier
zip -r "S2RM_${S2_APP_ID}.zip" "S2RM_${S2_APP_ID}"
# Check if compression was successful
if [ $? -ne 0 ]; then
echo "Compression failed. Exiting."
exit 1
fi
mv "S2RM_${S2_APP_ID}.zip" "S2RM_lnx/"
echo "Build and compression completed successfully."