From 1b5e9609ce649fbd17c2fc478ce248db954bf2ea Mon Sep 17 00:00:00 2001 From: Daniel Llewellyn Date: Mon, 16 Dec 2019 16:16:31 +0000 Subject: [PATCH] Add ld-cache and reduce snap size Signed-off-by: Daniel Llewellyn --- scripts/build-ld-cache | 20 ++++++++++++++++++ scripts/check-ld-cache | 32 +++++++++++++++++++++++++++++ scripts/makemkv-launch | 23 +++++++++++++++++++++ snap/hooks/install | 3 +++ snap/hooks/post-refresh | 3 +++ snap/snapcraft.yaml | 45 +++++++++++++++++------------------------ 6 files changed, 99 insertions(+), 27 deletions(-) create mode 100755 scripts/build-ld-cache create mode 100755 scripts/check-ld-cache create mode 100755 scripts/makemkv-launch create mode 100755 snap/hooks/install create mode 100755 snap/hooks/post-refresh diff --git a/scripts/build-ld-cache b/scripts/build-ld-cache new file mode 100755 index 0000000..e6c7571 --- /dev/null +++ b/scripts/build-ld-cache @@ -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" \ No newline at end of file diff --git a/scripts/check-ld-cache b/scripts/check-ld-cache new file mode 100755 index 0000000..1d12736 --- /dev/null +++ b/scripts/check-ld-cache @@ -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 "$@" \ No newline at end of file diff --git a/scripts/makemkv-launch b/scripts/makemkv-launch new file mode 100755 index 0000000..0f5e916 --- /dev/null +++ b/scripts/makemkv-launch @@ -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 < makemkv-launch - #!/bin/sh - if [ ! -f \$SNAP_USER_DATA/.MakeMKV/settings.conf ]; then - mkdir -p \$SNAP_USER_DATA/.MakeMKV - cat < \$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: