Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
stenzek
GitHub Repository: stenzek/duckstation
Path: blob/master/scripts/packaging/appimage/inject-libc.sh
4251 views
1
#!/usr/bin/env bash
2
3
set -e
4
5
function retry_command {
6
# Package servers tend to be unreliable at times..
7
# Retry a bunch of times.
8
local RETRIES=10
9
10
for i in $(seq 1 "$RETRIES"); do
11
"$@" && break
12
if [ "$i" == "$RETRIES" ]; then
13
echo "Command \"$@\" failed after ${RETRIES} retries."
14
exit 1
15
fi
16
done
17
}
18
19
this_dir="$(readlink -f "$(dirname "$0")")"
20
21
if [ "$#" -ne 4 ]; then
22
echo "Syntax: $0 <path to AppDir> <.deb arch> <triple> <ubuntu mirror> <binary to run>"
23
echo "e.g. $0 DuckStation.AppDir amd64 x86_64-linux-gnu duckstation-qt"
24
exit 1
25
fi
26
27
28
APPDIR=$1
29
DEBARCH=$2
30
TRIPLE=$3
31
APPNAME=$4
32
33
GLIBC_VERSION=2.35
34
35
if [ ! -f "libc.deb" ]; then
36
retry_command wget -O "libc.deb" "https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/libc6_2.35-0ubuntu3.9_${DEBARCH}.deb"
37
fi
38
if [ ! -f "libgccs.deb" ]; then
39
retry_command wget -O "libgccs.deb" "https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/libgcc-s1_12.3.0-1ubuntu1.22.04_${DEBARCH}.deb"
40
fi
41
if [ ! -f "libstdc++.deb" ]; then
42
retry_command wget -O "libstdc++.deb" "https://github.com/stenzek/duckstation-ext-qt-minimal/releases/download/linux/libstdc++6_12.3.0-1ubuntu1.22.04_${DEBARCH}.deb"
43
fi
44
45
rm -fr "temp"
46
mkdir "temp"
47
cd "temp"
48
dpkg -x "../libc.deb" .
49
dpkg -x "../libgccs.deb" .
50
dpkg -x "../libstdc++.deb" .
51
52
# Copy everything into AppDir
53
RUNTIME="${APPDIR}/libc-runtime"
54
mkdir -p "${RUNTIME}"
55
56
# libc.so.6 and friends
57
cd "lib/${TRIPLE}"
58
cp -v * "${RUNTIME}"
59
cd ../../
60
61
# libstdc++
62
cd "usr/lib/${TRIPLE}"
63
cp -v * "${RUNTIME}" || true
64
cd ../../..
65
66
# done with temps now
67
cd ..
68
rm -fr temp
69
70
# Not risking mixing resolvers...
71
cd "${RUNTIME}"
72
rm -vf libnss_*
73
74
# Move ld-linux.so.2 into the binary directory so we can preserve arg0's directory
75
mv -v "ld-linux-"*.so.* "${APPDIR}/usr/bin/ld-linux"
76
77
# Set up the replacement apprun script
78
cd "${APPDIR}"
79
rm -f AppRun.wrapped
80
cp "${this_dir}/inject-libc-apprun.sh" AppRun.wrapped
81
sed -i -e "s/__APPNAME__/${APPNAME}/" AppRun.wrapped
82
sed -i -e "s/__REQ_GLIBC_VERSION__/${GLIBC_VERSION}/" AppRun.wrapped
83
84
echo Done.
85
86
87