| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -e |
| 4 |
|
| 5 |
SKIP_DEPS="${SKIP_DEPS:-0}" |
| 6 |
|
| 7 |
ARCH=$(uname -m) |
| 8 |
ARCHDASH=$(echo "$ARCH"|tr '_' '-') |
| 9 |
APPIMAGETOOL="https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-${ARCH}.AppImage" |
| 10 |
|
| 11 |
curl -Ls "$APPIMAGETOOL" > appimagetool |
| 12 |
if [ $? -ne 0 ];then |
| 13 |
echo "failed to retrieve appimagetool. bailing out." |
| 14 |
exit 1 |
| 15 |
fi |
| 16 |
chmod -f +x appimagetool |
| 17 |
|
| 18 |
#unused but must exist |
| 19 |
DESKTOP_ENTRY='[Desktop Entry] |
| 20 |
Comment=A modern QuakeWorld client focused on competitive online play |
| 21 |
Name=ezQuake |
| 22 |
Exec=ezquake-linux-'$ARCH' |
| 23 |
Icon=io.github.ezQuake |
| 24 |
Type=Application |
| 25 |
StartupNotify=true |
| 26 |
Terminal=false |
| 27 |
Categories=Game; |
| 28 |
Keywords=quake;first;person;shooter;multiplayer;' |
| 29 |
|
| 30 |
TESTPROGRAM=' |
| 31 |
#include "curl/curl.h" |
| 32 |
int main(){ |
| 33 |
curl_easy_init(); |
| 34 |
return 0; |
| 35 |
} |
| 36 |
' |
| 37 |
|
| 38 |
QUAKE_SCRIPT='#!/usr/bin/env bash |
| 39 |
export LD_LIBRARY_PATH="${APPIMAGE_LIBRARY_PATH}:${APPDIR}/usr/lib:${LD_LIBRARY_PATH}" |
| 40 |
if [ ! -e "$OWD/id1" ];then |
| 41 |
cd "$(dirname "$APPIMAGE")" |
| 42 |
else |
| 43 |
cd "$OWD" |
| 44 |
fi |
| 45 |
"${APPDIR}/usr/bin/test" >/dev/null 2>&1 |: |
| 46 |
FAIL=${PIPESTATUS[0]} |
| 47 |
if [ $FAIL -eq 0 ];then |
| 48 |
echo "executing with native libc" |
| 49 |
"${APPDIR}/usr/bin/ezquake-linux-'$ARCH'" $* |
| 50 |
else |
| 51 |
echo "executing with appimage libc" |
| 52 |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${APPDIR}/usr/lib-override" |
| 53 |
"${APPDIR}/usr/lib-override/ld-linux-'$ARCHDASH'.so.2" "${APPDIR}/usr/bin/ezquake-linux-'$ARCH'" $* |
| 54 |
fi |
| 55 |
exitstatus=$? |
| 56 |
if [ $exitstatus -eq 0 ];then |
| 57 |
#fix qwurl association if set for appimage |
| 58 |
grep -q "^Exec=/tmp/.mount_" "${HOME}/.local/share/applications/qw-url-handler.desktop" >/dev/null 2>&1 && \ |
| 59 |
sed -i "s|^Exec=.*|Exec=${APPIMAGE} +qwurl %u|g" "${HOME}/.local/share/applications/qw-url-handler.desktop" |
| 60 |
fi |
| 61 |
exit $exitstatus |
| 62 |
' |
| 63 |
|
| 64 |
unset CC |
| 65 |
if [ "$ARCH" == "x86_64" ];then |
| 66 |
march="-march=nehalem" |
| 67 |
fi |
| 68 |
export CFLAGS="$march -O3 -pipe -flto=$(nproc)" |
| 69 |
export LDFLAGS="$CFLAGS" |
| 70 |
|
| 71 |
DIR="$(pwd)" |
| 72 |
|
| 73 |
if [ -d AppDir ];then |
| 74 |
rm -rf AppDir |
| 75 |
fi |
| 76 |
mkdir -p "$DIR/AppDir/usr/bin" || exit 1 |
| 77 |
mkdir -p "$DIR/AppDir/usr/lib" || exit 1 |
| 78 |
mkdir -p "$DIR/AppDir/usr/lib-override" || exit 1 |
| 79 |
|
| 80 |
VERSION=$(sed -n 's/.*VERSION_NUMBER.*"\(.*\)".*/\1/p' src/version.h) |
| 81 |
REVISION=$(git log -n 1|head -1|awk '{print $2}'|cut -c1-6) |
| 82 |
|
| 83 |
#build ezquake unless executable set |
| 84 |
if ! [[ -x "$EXECUTABLE" ]]; then |
| 85 |
export SKIP_DEPS |
| 86 |
chmod +x ./build-linux.sh && nice ./build-linux.sh || exit 3 |
| 87 |
EXECUTABLE="build/ezquake-linux-$ARCH" |
| 88 |
fi |
| 89 |
|
| 90 |
#build test program |
| 91 |
echo "$TESTPROGRAM" > "$DIR/test.c" || exit 2 |
| 92 |
gcc "$DIR/test.c" -o "$DIR/AppDir/usr/bin/test" -lcurl || exit 2 |
| 93 |
rm -f "$DIR/AppDir/test.c" || exit 2 |
| 94 |
|
| 95 |
cp -f $EXECUTABLE "$DIR/AppDir/usr/bin/." || exit 4 |
| 96 |
rm -f "$DIR/AppDir/AppRun" |
| 97 |
echo "$QUAKE_SCRIPT" > "$DIR/AppDir/AppRun" || exit 4 |
| 98 |
chmod +x "$DIR/AppDir/AppRun" || exit 4 |
| 99 |
echo "$DESKTOP_ENTRY" > "$DIR/AppDir/io.github.ezQuake.desktop" || exit 4 |
| 100 |
cp "$DIR/dist/linux/io.github.ezQuake.128.png" "$DIR/AppDir/io.github.ezQuake.png"||true #copy over quake png if it exists |
| 101 |
mkdir -p "$DIR/AppDir/usr/share/metainfo" |
| 102 |
sed 's,EZQUAKE_VERSION,'$VERSION-$REVISION',g;s,EZQUAKE_DATE,'$(date +%F)',g' "$DIR/misc/appimage/ezquake.appdata.xml.template" > "$DIR/AppDir/usr/share/metainfo/ezquake.appdata.xml" |
| 103 |
ldd "$DIR/AppDir/usr/bin/ezquake-linux-$ARCH" | \ |
| 104 |
grep --color=never -v libGL| \ |
| 105 |
grep --color=never -v libdrm.so | \ |
| 106 |
grep --color=never -v libgbm.so | \ |
| 107 |
awk '{print $3}'| \ |
| 108 |
xargs -I% cp -Lf "%" "$DIR/AppDir/usr/lib/." || exit 5 |
| 109 |
strip -s "$DIR/AppDir/usr/lib/"* || exit 5 |
| 110 |
strip -s "$DIR/AppDir/usr/bin/"* || exit 5 |
| 111 |
mv -f "$DIR/AppDir/usr/lib/libc.so.6" "$DIR/AppDir/usr/lib-override/." |
| 112 |
mv -f "$DIR/AppDir/usr/lib/libm.so.6" "$DIR/AppDir/usr/lib-override/." |
| 113 |
cp -f "$(ldconfig -Np|grep --color=never libpthread.so.0$|grep --color=never $(uname -m)|awk '{print $NF}')" "$DIR/AppDir/usr/lib-override/." |
| 114 |
cp -Lf "/lib64/ld-linux-${ARCHDASH}.so.2" "$DIR/AppDir/usr/lib-override/." || exit 6 |
| 115 |
|
| 116 |
cd "$DIR" || exit 5 |
| 117 |
./appimagetool AppDir ezQuake-$ARCH.AppImage || exit 7 |