-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.sh
More file actions
executable file
·85 lines (71 loc) · 2.5 KB
/
package.sh
File metadata and controls
executable file
·85 lines (71 loc) · 2.5 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
#!/bin/bash -xe
set -euo pipefail
if [[ -z "${JAVA_HOME:-}" ]]; then
JAVA_BIN=$(command -v java) || {
echo "Error: Java not found. Please install JDK or set JAVA_HOME." >&2
exit 1
}
JAVA_HOME=$(dirname "$(dirname "$JAVA_BIN")")
echo "Detected JAVA_HOME: $JAVA_HOME"
fi
PROGRAM=${PROGRAM:?PROGRAM must be set (e.g. PROGRAM=wml ./build.sh)}
PROGRAM_NAME=${PROGRAM_NAME:-$PROGRAM}
JAR_DIR=${JAR_DIR:-jar}
INPUT=${INPUT:-${JAR_DIR}/${PROGRAM}.jar}
OUTPUT=${OUTPUT:-${PROGRAM_NAME}.AppImage}
PROGRAM_ICON=${PROGRAM_ICON:-${PROGRAM}.png}
PROGRAM_DESKTOP_FILE=${PROGRAM_DESKTOP_FILE:-${PROGRAM}.desktop}
MODULES=$(jdeps --ignore-missing-deps --multi-release 17 --print-module-deps "${INPUT}")
APPIMAGE_DOWNLOAD_URL="https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage"
APPRUN_DOWNLOAD_URL="https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-x86_64"
APPIMAGETOOL="/tmp/appimagetool-x86_64.AppImage"
run_jlink() {
jlink \
--module-path "$JAVA_HOME/jmods" \
--add-modules ${MODULES} \
--output ${PROGRAM_NAME}.AppDir/usr \
--strip-debug \
--no-header-files \
--no-man-pages
}
make_launcher() {
local PROGRAM="$1"
local OUTFILE="$2"
cat > "$OUTFILE" <<EOF
#!/bin/sh
HERE="\$(dirname "\$(readlink -f "\${0}")")"
cd "\$HERE"
"\$HERE/java" -Djava.library.path=./lib -Dsun.java2d.xrender=false -Dsun.java2d.d3d=false \
-splash:images/splashJV.png -jar "\$HERE/../share/${PROGRAM}/${PROGRAM}.jar" "\$@"
EOF
chmod +x "$OUTFILE"
}
# Run jlink to create runtime
run_jlink
# download AppRun
wget -nc --verbose -O AppRun ${APPRUN_DOWNLOAD_URL}
chmod +x ./AppRun
# make launcher
make_launcher ${PROGRAM} "./${PROGRAM}"
# create directory structure
mkdir -p ${PROGRAM_NAME}.AppDir/usr/share/${PROGRAM}
cp ${INPUT} ${PROGRAM_NAME}.AppDir/usr/share/${PROGRAM}/
cp ${PROGRAM} ${PROGRAM_NAME}.AppDir/usr/bin/
cp AppRun ${PROGRAM_NAME}.AppDir/
if [[ -n "$PROGRAM_ICON" && -f "$PROGRAM_ICON" && "$PROGRAM_ICON" == *.png ]]; then
echo "Setting icon: $PROGRAM_ICON"
cp ${PROGRAM_ICON} ${PROGRAM_NAME}.AppDir/
else
echo "Icon missing or invalid (.png not found), skipping."
fi
cp ${PROGRAM_DESKTOP_FILE} ${PROGRAM_NAME}.AppDir/
# download appimagetool
pwd && ls -lh
wget -nc --verbose -O ${APPIMAGETOOL} ${APPIMAGE_DOWNLOAD_URL}
file ${APPIMAGETOOL}
pwd && ls -lh /tmp
chmod +x ${APPIMAGETOOL}
${APPIMAGETOOL} --appimage-extract
# run appimagetool
ARCH=x86_64 squashfs-root/AppRun "${PROGRAM_NAME}.AppDir" ${OUTPUT}
echo "AppImage created successfully! Path: ${OUTPUT}"