Add ld-cache and reduce snap size

Signed-off-by: Daniel Llewellyn <daniel@bowlhat.net>
This commit is contained in:
Daniel Llewellyn
2019-12-16 16:16:31 +00:00
committed by Daniel Llewellyn
parent 962147eee8
commit 1b5e9609ce
6 changed files with 99 additions and 27 deletions

20
scripts/build-ld-cache Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash -ex
# copying the conf dir from real /etc into $SNAP_DATA
mkdir -p "$SNAP_DATA/etc/ld.so.conf.d"
cp -r /etc/ld.so.conf.d/* "$SNAP_DATA/etc/ld.so.conf.d"
cp /etc/ld.so.conf "$SNAP_DATA/etc/ld.so.conf"
# delete empty entries in the LD_LIBRARY_PATH
# i.e. change "/a/b/c:/1/2/3::/other" into "/a/b/c:/1/2/3:/other"
# if we don't do this, then ldconfig gets confused with "" as arguments of dirs
# to add to the cache
LD_LIBRARY_PATH="${LD_LIBRARY_PATH//::/:}"
# run ldconfig on our LD_LIBRARY_PATH lib dirs
IFS=':' read -ra PATHS <<< "$LD_LIBRARY_PATH"
mkdir -p "$SNAP_DATA/fake-etc"
ldconfig -v -C "$SNAP_DATA/fake-etc/ld.so.cache" -f "$SNAP_DATA/etc/ld.so.conf" "${PATHS[@]}"
# install the new ld.so.cache to the global location by just copying it
cp "$SNAP_DATA/fake-etc/ld.so.cache" "$SNAP_DATA/etc/ld.so.cache"

32
scripts/check-ld-cache Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/sh -e
# save the original LD_LIBRARY_PATH, and unset it to check the cache
ORIGINAL_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
LD_LIBRARY_PATH=""
export LD_LIBRARY_PATH
# FINAL_BINARY should be set and exported to what the "real" final executable
# that's run is so we can check that
# an alternative would be to always run the "real" final executable immediately
# after this script in the chain, and then check "$1" here, but that is probably
# fragile
if [ -z "$FINAL_BINARY" ]; then
echo "FINAL_BINARY unset, can't check the dynamic linker cache for correctness"
else
# this is a bit tricky, we want to exit 0 if we didn't find a library, but
# exit 1 if we didn't _not_ find a library, so use the output phrase
# "=> not found" as what to look for from ldd
# TODO: make this less of a hack?
if ldd "$FINAL_BINARY" | grep "=> not found" | grep -q "=> not found"; then
# regenerate the cache first
LD_LIBRARY_PATH=$ORIGINAL_LD_LIBRARY_PATH
export LD_LIBRARY_PATH
# "$SNAP/bin/build-ld-cache"
# # unset to continue executing the next command in the chain
# LD_LIBRARY_PATH=""
# export LD_LIBRARY_PATH
fi
fi
# execute the next command in the chain
exec "$@"

23
scripts/makemkv-launch Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/sh
if [ ! -f $SNAP_USER_DATA/.MakeMKV/settings.conf ]; then
mkdir -p $SNAP_USER_DATA/.MakeMKV
cat > $SNAP_USER_DATA/.MakeMKV/settings.conf <<SEOF
#
# MakeMKV settings file, written by MakeMKV v1.14.5 linux(x64-release)
#
app_DestinationDir = ""
app_Java = ""
app_Key = ""
app_PreferredLanguage = ""
app_ccextractor = "/snap/makemkv/current/usr/bin/ccextractor"
dvd_MinimumTitleLength = "300"
sdf_Stop = ""
SEOF
elif grep 'app_ccextractor = ""' $SNAP_USER_DATA/.MakeMKV/settings.conf; then
sed -i -E 's|(app_ccextractor = )""|\1"/snap/makemkv/current/usr/bin/ccextractor"|' $SNAP_USER_DATA/.MakeMKV/settings.conf
fi
exec $@

3
snap/hooks/install Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash -ex
exec "$SNAP/snap/command-chain/desktop-launch" "$SNAP/bin/build-ld-cache"

3
snap/hooks/post-refresh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
exec "$(dirname "$0")/install"

View File

@@ -29,11 +29,13 @@ apps:
command-chain:
- bin/desktop-launch
- bin/makemkv-launch
- bin/check-ld-cache
- bin/snapcraft-preload
desktop: usr/share/applications/makemkv.desktop
environment:
MAKEMKVCON: $SNAP/usr/bin/makemkvcon
JAVA_HOME: $SNAP/usr
FINAL_BINARY: $SNAP/usr/bin/makemkv
plugs:
- desktop
- desktop-legacy
@@ -51,9 +53,14 @@ apps:
- x11
makemkvcon:
command: snapcraft-preload $SNAP/usr/bin/makemkvcon.real
command: usr/bin/makemkvcon.real
command-chain:
- bin/makemkv-launch
- bin/check-ld-cache
- bin/snapcraft-preload
environment:
JAVA_HOME: $SNAP/usr
FINAL_BINARY: $SNAP/usr/bin/makemkvcon.real
plugs:
- hardware-observe
- home
@@ -65,33 +72,11 @@ apps:
parts:
scripts:
source: .
source: scripts
plugin: dump
override-pull: |
cat <<EOF > makemkv-launch
#!/bin/sh
if [ ! -f \$SNAP_USER_DATA/.MakeMKV/settings.conf ]; then
mkdir -p \$SNAP_USER_DATA/.MakeMKV
cat <<SEOF > \$SNAP_USER_DATA/.MakeMKV/settings.conf
#
# MakeMKV settings file, written by MakeMKV v1.14.5 linux(x64-release)
#
app_DestinationDir = ""
app_Java = ""
app_Key = ""
app_PreferredLanguage = ""
app_ccextractor = "/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/bin/ccextractor"
dvd_MinimumTitleLength = "300"
sdf_Stop = ""
SEOF
elif grep 'app_ccextractor = ""' \$SNAP_USER_DATA/.MakeMKV/settings.conf; then
sed -i -E 's|(app_ccextractor = )""|\1"/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/bin/ccextractor"|' \$SNAP_USER_DATA/.MakeMKV/settings.conf
fi
exec \$@
EOF
chmod +x makemkv-launch
organize:
build-ld-cache: bin/build-ld-cache
check-ld-cache: bin/check-ld-cache
makemkv-launch: bin/makemkv-launch
libav:
@@ -109,6 +94,8 @@ parts:
stage-packages:
- libfdk-aac1
- libxcb-shape0
prime:
- -**/*.a
snapcraft-preload:
source: https://github.com/diddledan/snapcraft-preload.git
@@ -140,6 +127,7 @@ parts:
- libqt5gui5
- libgdk-pixbuf2.0-0
- libqt5svg5 # for loading icon themes which are svg
- qtwayland5
- locales-all
ccextractor:
@@ -206,9 +194,12 @@ parts:
- libwayland-cursor0
- libx11-6
- lsscsi
- qtwayland5
- zlib1g
prime:
- -bin/ffmpeg
- -bin/ffprobe
- -lib/$SNAPCRAFT_ARCH_TRIPLET/libfdisk.so*
- -sbin
- -version
makemkv-bin: