Path: blob/master/scripts/packaging/appimage/make-appimage.sh
4251 views
#!/usr/bin/env bash12# SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]>3# SPDX-License-Identifier: CC-BY-NC-ND-4.045SCRIPTDIR=$(dirname "${BASH_SOURCE[0]}")67function retry_command {8# Package servers tend to be unreliable at times..9# Retry a bunch of times.10local RETRIES=101112for i in $(seq 1 "$RETRIES"); do13"$@" && break14if [ "$i" == "$RETRIES" ]; then15echo "Command \"$@\" failed after ${RETRIES} retries."16exit 117fi18done19}2021if [ "$#" -ne 4 ]; then22echo "Syntax: $0 <path to duckstation directory> <path to build directory> <deps prefix> <output name>"23exit 124fi2526ROOTDIR=$127BUILDDIR=$228DEPSDIR=$329NAME=$43031BINARY=duckstation-qt32APPDIRNAME=DuckStation.AppDir33STRIP=strip3435declare -a MANUAL_LIBS=(36"libz.so.1"37"libavcodec.so.61"38"libavformat.so.61"39"libavutil.so.59"40"libswscale.so.8"41"libswresample.so.5"42"libdiscord-rpc.so"43"libfreetype.so.6"44"libshaderc_ds.so"45"libspirv-cross-c-shared.so.0"46)4748declare -a MANUAL_QT_LIBS=(49"libQt6WaylandEglClientHwIntegration.so.6"50)5152declare -a MANUAL_QT_PLUGINS=(53"wayland-decoration-client"54"wayland-graphics-integration-client"55"wayland-shell-integration"56)5758declare -a REMOVE_LIBS=(59'libwayland-client.so*'60'libwayland-cursor.so*'61'libwayland-egl.so*'62)6364set -e6566LINUXDEPLOY=./linuxdeploy-x86_6467LINUXDEPLOY_PLUGIN_QT=./linuxdeploy-plugin-qt-x86_6468APPIMAGETOOL=./appimagetool-x86_6469APPIMAGERUNTIME=./runtime-x86_6470PATCHELF=patchelf7172if [ ! -f "$LINUXDEPLOY" ]; then73retry_command wget -O "$LINUXDEPLOY" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-x86_64.AppImage74chmod +x "$LINUXDEPLOY"75fi7677if [ ! -f "$LINUXDEPLOY_PLUGIN_QT" ]; then78retry_command wget -O "$LINUXDEPLOY_PLUGIN_QT" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/linuxdeploy-plugin-qt-x86_64.AppImage79chmod +x "$LINUXDEPLOY_PLUGIN_QT"80fi8182if [ ! -f "$APPIMAGETOOL" ]; then83retry_command wget -O "$APPIMAGETOOL" https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/appimagetool-x86_64.AppImage84chmod +x "$APPIMAGETOOL"85fi8687if [ ! -f "$APPIMAGERUNTIME" ]; then88retry_command wget -O "$APPIMAGERUNTIME" https://github.com/stenzek/type2-runtime/releases/download/continuous/runtime-x86_6489fi9091OUTDIR=$(realpath "./$APPDIRNAME")92rm -fr "$OUTDIR"9394echo "Locating extra libraries..."95EXTRA_LIBS_ARGS=()96for lib in "${MANUAL_LIBS[@]}"; do97srcpath=$(find "$DEPSDIR" -name "$lib")98if [ ! -f "$srcpath" ]; then99echo "Missinge extra library $lib. Exiting."100exit 1101fi102103echo "Found $lib at $srcpath."104EXTRA_LIBS_ARGS+=("--library=$srcpath")105done106107# Why the nastyness? linuxdeploy strips our main binary, and there's no option to turn it off.108# It also doesn't strip the Qt libs. We can't strip them after running linuxdeploy, because109# patchelf corrupts the libraries (but they still work), but patchelf+strip makes them crash110# on load. So, make a backup copy, strip the original (since that's where linuxdeploy finds111# the libs to copy), then swap them back after we're done.112# Isn't Linux packaging amazing?113114rm -fr "$DEPSDIR.bak"115cp -a "$DEPSDIR" "$DEPSDIR.bak"116IFS="117"118for i in $(find "$DEPSDIR" -iname '*.so'); do119echo "Stripping deps library ${i}"120strip "$i"121done122123echo "Running linuxdeploy to create AppDir..."124EXTRA_QT_PLUGINS="core;gui;svg;waylandclient;widgets;xcbqpa" \125EXTRA_PLATFORM_PLUGINS="libqwayland-egl.so;libqwayland-generic.so" \126DEPLOY_PLATFORM_THEMES="1" \127QMAKE="$DEPSDIR/bin/qmake" \128NO_STRIP="1" \129$LINUXDEPLOY --plugin qt --appdir="$OUTDIR" --executable="$BUILDDIR/bin/duckstation-qt" ${EXTRA_LIBS_ARGS[@]} \130--desktop-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.desktop" \131--icon-file="$ROOTDIR/scripts/packaging/org.duckstation.DuckStation.png" \132133echo "Copying resources into AppDir..."134cp -a "$BUILDDIR/bin/resources" "$OUTDIR/usr/bin"135136# LinuxDeploy's Qt plugin doesn't include Wayland support. So manually copy in the additional Wayland libraries.137echo "Copying Qt Wayland libraries..."138for lib in "${MANUAL_QT_LIBS[@]}"; do139srcpath="$DEPSDIR/lib/$lib"140dstpath="$OUTDIR/usr/lib/$lib"141echo " $srcpath -> $dstpath"142cp "$srcpath" "$dstpath"143$PATCHELF --set-rpath '$ORIGIN' "$dstpath"144done145146# .. and plugins.147echo "Copying Qt Wayland plugins..."148for GROUP in "${MANUAL_QT_PLUGINS[@]}"; do149srcpath="$DEPSDIR/plugins/$GROUP"150dstpath="$OUTDIR/usr/plugins/$GROUP"151echo " $srcpath -> $dstpath"152mkdir -p "$dstpath"153154for srcsopath in $(find "$DEPSDIR/plugins/$GROUP" -iname '*.so'); do155# This is ../../ because it's usually plugins/group/name.so156soname=$(basename "$srcsopath")157dstsopath="$dstpath/$soname"158echo " $srcsopath -> $dstsopath"159cp "$srcsopath" "$dstsopath"160$PATCHELF --set-rpath '$ORIGIN/../../lib:$ORIGIN' "$dstsopath"161done162done163164# Why do we have to manually remove these libs? Because the linuxdeploy Qt plugin165# copies them, not the "main" linuxdeploy binary, and plugins don't inherit the166# include list...167for lib in "${REMOVE_LIBS[@]}"; do168for libpath in $(find "$OUTDIR/usr/lib" -name "$lib"); do169echo " Removing problematic library ${libpath}."170rm -f "$libpath"171done172done173174# Restore unstripped deps (for cache).175rm -fr "$DEPSDIR"176mv "$DEPSDIR.bak" "$DEPSDIR"177178# Fix up translations.179rm -fr "$OUTDIR/usr/bin/translations"180mv "$OUTDIR/usr/translations" "$OUTDIR/usr/bin"181cp -a "$BUILDDIR/bin/translations" "$OUTDIR/usr/bin"182183# Generate AppStream meta-info.184echo "Generating AppStream metainfo..."185mkdir -p "$OUTDIR/usr/share/metainfo"186"$SCRIPTDIR/../generate-metainfo.sh" "$OUTDIR/usr/share/metainfo"187188echo "Generating AppImage..."189rm -f "$NAME.AppImage"190"$APPIMAGETOOL" -v --runtime-file "$APPIMAGERUNTIME" "$OUTDIR" "$NAME.AppImage"191192193