Created
November 25, 2019 18:12
-
-
Save anonymouse64/5647d8e585d9514e75d58f67240b0879 to your computer and use it in GitHub Desktop.
Script to ensure ld.so.cache is usable and updated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/meta/hooks/install" | |
# 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 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment