Repository navigation
Expand file tree
/
Copy pathpackage_linux.sh
More file actions
executable file
·334 lines (280 loc) · 10.3 KB
/
Copy pathpackage_linux.sh
File metadata and controls
executable file
·334 lines (280 loc) · 10.3 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/usr/bin/env bash
# Helper script to package PSD2Live for Linux distribution.
# This script does NOT include proprietary Cubism SDK binaries by default.
# Developers must build and deploy the SDK locally if they want Cubism preview.
#
# Packaging approach:
# Prefer Compose Desktop packageUberJarForCurrentOS (runnable fat jar with
# Main-Class). Falls back to packageReleaseUberJarForCurrentOS, then to
# installDist + the generated start script if uber-jar packaging fails.
# Default Gradle builds exclude src/main/resources/cubism/** from jars
# unless -Ppsd2live.includeCubism=true (see build.gradle.kts).
#
# Usage:
# ./native/package_linux.sh [--include-local-cubism]
#
# Options:
# --include-local-cubism: Opt into Cubism for this package (personal use only):
# passes -Ppsd2live.includeCubism=true to Gradle, and
# copies deployed binaries beside the jar with
# CUBISM_SDK_PATH set by the launcher.
# WARNING: Do NOT distribute packages created with this flag!
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Cubism binaries are deployed per architecture (native/build_live2d_renderer.sh --deploy).
case "$(uname -m)" in
aarch64|arm64) CUBISM_PLATFORM="linux-arm64" ;;
*) CUBISM_PLATFORM="linux-x86_64" ;;
esac
INCLUDE_CUBISM=0
# Parse arguments
for arg in "$@"; do
case "$arg" in
--include-local-cubism)
INCLUDE_CUBISM=1
;;
*)
echo "Unknown argument: $arg" >&2
echo "Usage: $0 [--include-local-cubism]" >&2
exit 1
;;
esac
done
echo "=================================================="
echo " PSD2Live Linux Package Helper"
echo "=================================================="
# Check if we're in the right directory
if [[ ! -f "$REPO_ROOT/build.gradle.kts" ]]; then
echo "[ERROR] Cannot find build.gradle.kts. Run from repository root." >&2
exit 1
fi
cd "$REPO_ROOT"
# Opt-in Gradle property so processResources/jar/uber-jar may embed cubism/**
# when --include-local-cubism is set. Default builds keep jars Cubism-free.
GRADLE_EXTRA_ARGS=()
if [[ "$INCLUDE_CUBISM" == "1" ]]; then
GRADLE_EXTRA_ARGS+=(-Ppsd2live.includeCubism=true)
fi
run_gradle() {
# Invoke via bash so packaging works even when gradlew is not +x.
bash ./gradlew "$@"
}
# Locate a Compose Desktop uber jar under build/compose/jars/.
find_uber_jar() {
local candidate=""
shopt -s nullglob
for candidate in "$REPO_ROOT/build/compose/jars"/*-linux-*.jar \
"$REPO_ROOT/build/compose/jars"/*.jar; do
if [[ -f "$candidate" ]]; then
echo "$candidate"
shopt -u nullglob
return 0
fi
done
shopt -u nullglob
return 1
}
# Locate the Gradle application-plugin start script from installDist.
find_install_start_script() {
local candidate=""
shopt -s nullglob
for candidate in "$REPO_ROOT/build/install"/*/bin/psd2live \
"$REPO_ROOT/build/install"/*/bin/*; do
# Prefer non-.bat launcher
if [[ -f "$candidate" && "$candidate" != *.bat ]]; then
echo "$candidate"
shopt -u nullglob
return 0
fi
done
shopt -u nullglob
return 1
}
LAUNCH_MODE="" # "uberjar" or "installdist"
JAR_PATH=""
INSTALL_BIN=""
INSTALL_ROOT=""
echo "[1/3] Building runnable Linux artifact with Gradle..."
# Prefer Compose Desktop uber jar (Main-Class + deps) for java -jar.
if run_gradle clean packageUberJarForCurrentOS -x test "${GRADLE_EXTRA_ARGS[@]}"; then
if JAR_PATH="$(find_uber_jar)"; then
LAUNCH_MODE="uberjar"
echo " Built uber jar via packageUberJarForCurrentOS"
fi
fi
if [[ -z "$LAUNCH_MODE" ]]; then
echo " packageUberJarForCurrentOS did not produce a jar; trying packageReleaseUberJarForCurrentOS..."
if run_gradle packageReleaseUberJarForCurrentOS -x test "${GRADLE_EXTRA_ARGS[@]}"; then
if JAR_PATH="$(find_uber_jar)"; then
LAUNCH_MODE="uberjar"
echo " Built uber jar via packageReleaseUberJarForCurrentOS"
fi
fi
fi
# Fallback: application installDist start script (starts MainKt via classpath).
if [[ -z "$LAUNCH_MODE" ]]; then
echo " Uber jar packaging unavailable; falling back to installDist..."
run_gradle installDist -x test "${GRADLE_EXTRA_ARGS[@]}"
if INSTALL_BIN="$(find_install_start_script)"; then
INSTALL_ROOT="$(cd "$(dirname "$INSTALL_BIN")/.." && pwd)"
LAUNCH_MODE="installdist"
echo " Built installDist at $INSTALL_ROOT"
else
echo "[ERROR] Could not build a runnable artifact (uber jar or installDist)." >&2
exit 1
fi
fi
if [[ "$LAUNCH_MODE" == "uberjar" ]]; then
echo " Found runnable JAR: $JAR_PATH"
fi
# Create distribution directory
DIST_DIR="$REPO_ROOT/dist/linux-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$DIST_DIR"
echo "[2/3] Packaging..."
if [[ "$LAUNCH_MODE" == "uberjar" ]]; then
cp "$JAR_PATH" "$DIST_DIR/psd2live.jar"
else
# Copy the full installDist tree (bin/ + lib/) so the start script works.
cp -a "$INSTALL_ROOT/." "$DIST_DIR/"
fi
# Also copy Cubism binaries beside the artifact (for personal use only) before writing
# the launcher, so CUBISM_SDK_PATH is exported BEFORE exec (matches runtime loader).
CUBISM_INCLUDED=0
if [[ "$INCLUDE_CUBISM" == "1" ]]; then
CUBISM_SRC="$REPO_ROOT/src/main/resources/cubism/$CUBISM_PLATFORM"
if [[ -d "$CUBISM_SRC" ]]; then
echo " Including local Cubism SDK binaries (PERSONAL USE ONLY)..."
mkdir -p "$DIST_DIR/cubism/$CUBISM_PLATFORM"
cp -r "$CUBISM_SRC"/* "$DIST_DIR/cubism/$CUBISM_PLATFORM/"
CUBISM_INCLUDED=1
cat > "$DIST_DIR/CUBISM_NOTICE.txt" << 'NOTICE_EOF'
WARNING: This package includes locally built Live2D Cubism SDK binaries.
The Cubism SDK is proprietary software owned by Live2D Inc.
These binaries are provided for your PERSONAL USE ONLY under the
Live2D Proprietary Software License.
DO NOT REDISTRIBUTE this package publicly.
DO NOT share this package with others.
If you want to distribute PSD2Live, use the version WITHOUT Cubism
binaries and instruct users to build and deploy the SDK themselves
following the instructions in docs/*/guide/CUBISM_SDK_SETUP.md.
For Cubism SDK licensing, visit: https://www.live2d.com/
NOTICE_EOF
else
echo " WARNING: Cubism binaries not found at $CUBISM_SRC"
echo " Run './native/build_live2d_renderer.sh --deploy' first."
INCLUDE_CUBISM=0
fi
fi
# Create launcher script (Cubism env must come before exec — exec never returns).
if [[ "$LAUNCH_MODE" == "uberjar" ]]; then
if [[ "$CUBISM_INCLUDED" == "1" ]]; then
cat > "$DIST_DIR/psd2live.sh" << 'LAUNCHER_EOF'
#!/bin/bash
# PSD2Live launcher for Linux (Compose Desktop uber jar)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Check for Java
if ! command -v java &> /dev/null; then
echo "Error: Java not found. Please install JDK 21 or later." >&2
exit 1
fi
# Note: This package includes locally built Cubism SDK binaries (personal use only).
export CUBISM_SDK_PATH="$(ls -d "$SCRIPT_DIR"/cubism/linux-* | head -1)"
# Launch PSD2Live (fat jar with Main-Class)
exec java -jar psd2live.jar "$@"
LAUNCHER_EOF
else
cat > "$DIST_DIR/psd2live.sh" << 'LAUNCHER_EOF'
#!/bin/bash
# PSD2Live launcher for Linux (Compose Desktop uber jar)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Check for Java
if ! command -v java &> /dev/null; then
echo "Error: Java not found. Please install JDK 21 or later." >&2
exit 1
fi
# Launch PSD2Live (fat jar with Main-Class)
exec java -jar psd2live.jar "$@"
LAUNCHER_EOF
fi
else
# installDist: wrap the generated start script (bin/psd2live).
START_REL="bin/$(basename "$INSTALL_BIN")"
if [[ "$CUBISM_INCLUDED" == "1" ]]; then
cat > "$DIST_DIR/psd2live.sh" << LAUNCHER_EOF
#!/bin/bash
# PSD2Live launcher for Linux (Gradle installDist start script)
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
cd "\$SCRIPT_DIR"
# Note: This package includes locally built Cubism SDK binaries (personal use only).
export CUBISM_SDK_PATH="\$SCRIPT_DIR/cubism/$CUBISM_PLATFORM"
exec "\$SCRIPT_DIR/$START_REL" "\$@"
LAUNCHER_EOF
else
cat > "$DIST_DIR/psd2live.sh" << LAUNCHER_EOF
#!/bin/bash
# PSD2Live launcher for Linux (Gradle installDist start script)
SCRIPT_DIR="\$(cd "\$(dirname "\${BASH_SOURCE[0]}")" && pwd)"
cd "\$SCRIPT_DIR"
exec "\$SCRIPT_DIR/$START_REL" "\$@"
LAUNCHER_EOF
fi
# Ensure the nested start script is executable
chmod +x "$DIST_DIR/$START_REL" 2>/dev/null || true
fi
chmod +x "$DIST_DIR/psd2live.sh"
# Create README reflecting whether Cubism was included
if [[ "$CUBISM_INCLUDED" == "1" ]]; then
cat > "$DIST_DIR/README.txt" << 'README_EOF'
PSD2Live for Linux
==================
Launch:
./psd2live.sh
Requirements:
- JDK 21 or later
- OpenGL / GLX (Mesa or vendor drivers) and an X11 display
Headless: use xvfb-run ./psd2live.sh (see CUBISM_SDK_SETUP.md)
Cubism SDK Preview:
This package INCLUDES locally built Cubism SDK binaries for PERSONAL USE ONLY.
See CUBISM_NOTICE.txt — do NOT redistribute this package.
The launcher sets CUBISM_SDK_PATH automatically.
For more information, visit:
https://github.com/tsunehimatoi/psd2live
License: GNU GPL v3
README_EOF
else
cat > "$DIST_DIR/README.txt" << 'README_EOF'
PSD2Live for Linux
==================
Launch:
./psd2live.sh
Requirements:
- JDK 21 or later
- OpenGL / GLX (Mesa or vendor drivers) and an X11 display (for Cubism preview)
Optional Cubism SDK Preview:
This package does NOT include Live2D Cubism SDK binaries.
The application will use its built-in software renderer.
To enable native Cubism preview:
1. Download Cubism SDK for Native (5-r.5) from Live2D
2. Build the native library following docs/en/guide/CUBISM_SDK_SETUP.md
3. Set CUBISM_SDK_PATH environment variable to the deployed directory
4. On headless hosts, run under Xvfb (e.g. xvfb-run ./psd2live.sh)
For more information, visit:
https://github.com/tsunehimatoi/psd2live
License: GNU GPL v3
README_EOF
fi
echo "[3/3] Package complete!"
echo ""
echo " Output: $DIST_DIR"
echo " Mode: $LAUNCH_MODE"
echo " Launch: cd $DIST_DIR && ./psd2live.sh"
if [[ "$CUBISM_INCLUDED" == "1" ]]; then
echo ""
echo " ⚠️ WARNING: This package includes Cubism SDK binaries!"
echo " FOR PERSONAL USE ONLY - DO NOT REDISTRIBUTE"
echo " See CUBISM_NOTICE.txt for details"
fi
echo "=================================================="