Path: blob/master/scripts/appimage/make-appimage.sh
10595 views
#!/usr/bin/env bash12# SPDX-FileCopyrightText: 2019-2025 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 3 ]; then22echo "Syntax: $0 <path to duckstation directory> <path to build directory> <output name>"23exit 124fi2526ROOTDIR=$127BUILDDIR=$228ASSETNAME=$32930BINARY=duckstation-qt31APPDIRNAME=DuckStation.AppDir32STRIP=strip3334declare -a MANUAL_LIBS=(35"libz.so.1"36"libavcodec.so.62"37"libavformat.so.62"38"libavutil.so.60"39"libswscale.so.9"40"libswresample.so.6"41"libdiscord-rpc.so"42"libharfbuzz.so"43"libfreetype.so.6"44"libshaderc_shared.so"45"libspirv-cross-c-shared.so.0"46)4748set -e4950DEPSDIR=$(realpath "$SCRIPTDIR/../../dep/prebuilt/linux-x64")51LINUXDEPLOY=./linuxdeploy-x86_6452LINUXDEPLOY_PLUGIN_QT=./linuxdeploy-plugin-qt-x86_6453APPIMAGETOOL=./appimagetool-x86_6454APPIMAGERUNTIME=./runtime-x86_6455PATCHELF=patchelf5657if [ ! -f "$LINUXDEPLOY" ]; then58retry_command wget -O "$LINUXDEPLOY" https://github.com/duckstation/dependencies/releases/download/appimage-tools/linuxdeploy-x86_64.AppImage59chmod +x "$LINUXDEPLOY"60fi6162if [ ! -f "$LINUXDEPLOY_PLUGIN_QT" ]; then63retry_command wget -O "$LINUXDEPLOY_PLUGIN_QT" https://github.com/duckstation/dependencies/releases/download/appimage-tools/linuxdeploy-plugin-qt-x86_64.AppImage64chmod +x "$LINUXDEPLOY_PLUGIN_QT"65fi6667if [ ! -f "$APPIMAGETOOL" ]; then68retry_command wget -O "$APPIMAGETOOL" https://github.com/duckstation/dependencies/releases/download/appimage-tools/appimagetool-x86_64.AppImage69chmod +x "$APPIMAGETOOL"70fi7172if [ ! -f "$APPIMAGERUNTIME" ]; then73retry_command wget -O "$APPIMAGERUNTIME" https://github.com/stenzek/type2-runtime/releases/download/continuous/runtime-x86_6474fi7576OUTDIR=$(realpath "./$APPDIRNAME")77rm -fr "$OUTDIR"7879echo "Locating extra libraries..."80EXTRA_LIBS_ARGS=()81for lib in "${MANUAL_LIBS[@]}"; do82srcpath=$(find "$DEPSDIR" -name "$lib")83if [ ! -f "$srcpath" ]; then84echo "Missinge extra library $lib. Exiting."85exit 186fi8788echo "Found $lib at $srcpath."89EXTRA_LIBS_ARGS+=("--library=$srcpath")90done9192# Why the nastyness? linuxdeploy strips our main binary, and there's no option to turn it off.93# It also doesn't strip the Qt libs. We can't strip them after running linuxdeploy, because94# patchelf corrupts the libraries (but they still work), but patchelf+strip makes them crash95# on load. So, make a backup copy, strip the original (since that's where linuxdeploy finds96# the libs to copy), then swap them back after we're done.97# Isn't Linux packaging amazing?9899rm -fr "$DEPSDIR.bak"100cp -a "$DEPSDIR" "$DEPSDIR.bak"101IFS="102"103for i in $(find "$DEPSDIR" -iname '*.so'); do104echo "Stripping deps library ${i}"105strip "$i"106done107108echo "Running linuxdeploy to create AppDir..."109EXTRA_QT_MODULES="core;gui;svg;widgets;xcbqpa;waylandcompositor" \110EXTRA_PLATFORM_PLUGINS="libqwayland.so" \111DEPLOY_PLATFORM_THEMES="1" \112LINUXDEPLOY_EXCLUDED_LIBRARIES="libwayland-cursor*;libwayland-egl*" \113QMAKE="$DEPSDIR/bin/qmake" \114NO_STRIP="1" \115$LINUXDEPLOY --plugin qt --appdir="$OUTDIR" --executable="$BUILDDIR/bin/duckstation-qt" ${EXTRA_LIBS_ARGS[@]} \116--desktop-file="$ROOTDIR/scripts/appimage/org.duckstation.DuckStation.desktop" \117--icon-file="$ROOTDIR/scripts/appimage/org.duckstation.DuckStation.png" \118119echo "Copying resources into AppDir..."120cp -a "$BUILDDIR/bin/resources" "$OUTDIR/usr/bin"121122# Restore unstripped deps (for cache).123rm -fr "$DEPSDIR"124mv "$DEPSDIR.bak" "$DEPSDIR"125126# Fix up translations.127rm -fr "$OUTDIR/usr/bin/translations"128mv "$OUTDIR/usr/translations" "$OUTDIR/usr/bin"129cp -a "$BUILDDIR/bin/translations" "$OUTDIR/usr/bin"130131# Generate AppStream meta-info.132echo "Generating AppStream metainfo..."133mkdir -p "$OUTDIR/usr/share/metainfo"134"$SCRIPTDIR/generate-metainfo.sh" "$OUTDIR/usr/share/metainfo"135136echo "Generating AppImage..."137rm -f "$ASSETNAME"138"$APPIMAGETOOL" -v --runtime-file "$APPIMAGERUNTIME" "$OUTDIR" "$ASSETNAME"139140141