#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" BUILD_DIR="${BUILD_DIR:-$ROOT/build/linux-gcc-release}" DIST_DIR="${DIST_DIR:-$ROOT/dist}" QT_ROOT="${QT_ROOT:-/home/misaki/Qt6.3/6.6.3/gcc_64}" VERSION="${VERSION:-0.1.0}" ARCH="${ARCH:-x86_64}" CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/schedule-appimage-tools" if [[ -n "${TOOLS_DIR:-}" ]]; then CACHE_DIR="$TOOLS_DIR" fi mkdir -p "$CACHE_DIR" "$DIST_DIR" download_tool() { local name="$1" local url="$2" local target="$CACHE_DIR/$name" if [[ ! -x "$target" ]]; then echo "Downloading $name..." curl -fL --retry 3 --max-time 300 -o "$target" "$url" chmod +x "$target" fi } download_tool linuxdeploy-x86_64.AppImage \ "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage" download_tool appimagetool-x86_64.AppImage \ "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" LINUXDEPLOY="$CACHE_DIR/linuxdeploy-x86_64.AppImage" APPIMAGETOOL="$CACHE_DIR/appimagetool-x86_64.AppImage" export PATH="$CACHE_DIR:$PATH" export APPIMAGE_EXTRACT_AND_RUN=1 export QMAKE="$QT_ROOT/bin/qmake" export LD_LIBRARY_PATH="$QT_ROOT/lib:${LD_LIBRARY_PATH:-}" export VERSION export ARCH if [[ ! -x "$QT_ROOT/bin/qmake" ]]; then echo "Qt qmake not found: $QT_ROOT/bin/qmake" >&2 echo "Set QT_ROOT to the Qt 6.6.3 gcc_64 directory." >&2 exit 1 fi echo "Configuring release build..." cmake --preset linux-gcc-release -DCMAKE_BUILD_TYPE=Release cmake --build --preset linux-gcc-release -j"$(nproc)" APPDIR="$BUILD_DIR/AppDir" rm -rf "$APPDIR" mkdir -p "$APPDIR" echo "Installing application files..." DESTDIR="$APPDIR" cmake --install "$BUILD_DIR" --prefix /usr mkdir -p "$APPDIR/usr/bin" if [[ -f "$APPDIR/usr/Schedule" ]]; then mv "$APPDIR/usr/Schedule" "$APPDIR/usr/bin/Schedule" fi if command -v strip >/dev/null 2>&1; then strip --strip-unneeded "$APPDIR/usr/bin/Schedule" || true fi install -Dm644 "$ROOT/packaging/linux/Schedule.desktop" \ "$APPDIR/usr/share/applications/Schedule.desktop" install -Dm644 "$ROOT/packaging/linux/schedule.png" \ "$APPDIR/usr/share/icons/hicolor/256x256/apps/schedule.png" install -Dm644 "$ROOT/packaging/linux/schedule.svg" \ "$APPDIR/usr/share/icons/hicolor/scalable/apps/schedule.svg" install -Dm644 "$ROOT/packaging/linux/com.misaki.Schedule.appdata.xml" \ "$APPDIR/usr/share/metainfo/com.misaki.Schedule.appdata.xml" cp "$ROOT/packaging/linux/Schedule.desktop" "$APPDIR/Schedule.desktop" cp "$ROOT/packaging/linux/schedule.png" "$APPDIR/schedule.png" cp "$ROOT/packaging/linux/schedule.png" "$APPDIR/.DirIcon" echo "Copying required Qt plugins..." copy_plugin_dir() { local name="$1" if [[ -d "$QT_ROOT/plugins/$name" ]]; then mkdir -p "$APPDIR/usr/plugins/$name" cp -a "$QT_ROOT/plugins/$name/." "$APPDIR/usr/plugins/$name/" fi } for plugin_dir in \ platforms \ platformthemes \ platforminputcontexts \ imageformats \ iconengines \ styles \ tls \ xcbglintegrations \ wayland-shell-integration \ wayland-decoration-client \ accessible; do copy_plugin_dir "$plugin_dir" done mkdir -p "$APPDIR/usr/plugins/sqldrivers" if [[ -e "$QT_ROOT/plugins/sqldrivers/libqsqlite.so" ]]; then cp "$QT_ROOT/plugins/sqldrivers/libqsqlite.so" "$APPDIR/usr/plugins/sqldrivers/" fi find "$APPDIR/usr/plugins" -name '*.debug' -delete # Copy Qt libraries required by the X11/Wayland platform plugins. The core # deployment handles the application's direct Qt dependencies, but not these # plugin-only modules. mkdir -p "$APPDIR/usr/lib" for lib in \ libQt6XcbQpa \ libQt6OpenGL \ libQt6WaylandClient \ libQt6WaylandEglClientHwIntegration \ libQt6WlShellIntegration; do cp -a "$QT_ROOT/lib/$lib.so"* "$APPDIR/usr/lib/" 2>/dev/null || true done echo "Deploying shared library dependencies..." "$LINUXDEPLOY" \ --appdir "$APPDIR" \ --executable "$APPDIR/usr/bin/Schedule" \ --desktop-file "$APPDIR/usr/share/applications/Schedule.desktop" \ --icon-file "$ROOT/packaging/linux/schedule.png" cat > "$APPDIR/usr/bin/qt.conf" <<'QT_CONF' [Paths] Prefix=.. Plugins=plugins Libraries=lib QT_CONF # Bundle a few newer xcb helpers that are not guaranteed on older desktops. copy_system_library() { local soname="$1" local path path="$(ldconfig -p 2>/dev/null | awk -v name="$soname" '$1 == name { print $NF; exit }')" if [[ -n "$path" && -f "$path" ]]; then cp -L "$path" "$APPDIR/usr/lib/" fi } for lib in \ libxcb-cursor.so.0 \ libxcb-icccm.so.4 \ libxcb-image.so.0 \ libxcb-keysyms.so.1 \ libxcb-render-util.so.0 \ libxcb-xinerama.so.0 \ libxcb-util.so.1 \ libxkbcommon-x11.so.0; do copy_system_library "$lib" done rm -f "$APPDIR/AppRun" cat > "$APPDIR/AppRun" <<'APPRUN' #!/bin/sh HERE="$(dirname "$(readlink -f "$0")")" export LD_LIBRARY_PATH="$HERE/usr/lib:${LD_LIBRARY_PATH:-}" export QT_PLUGIN_PATH="$HERE/usr/plugins" exec "$HERE/usr/bin/Schedule" "$@" APPRUN chmod +x "$APPDIR/AppRun" OUTPUT="$DIST_DIR/AI-Schedule-${VERSION}-${ARCH}.AppImage" echo "Creating $OUTPUT..." ARCH="$ARCH" VERSION="$VERSION" "$APPIMAGETOOL" "$APPDIR" "$OUTPUT" chmod +x "$OUTPUT" echo "AppImage created: $OUTPUT"