LIBMAN: added exclusion list + tweaks, removed LD_LIBRAY_PATH search as the runtime libraries are safe

This commit is contained in:
XargonWan 2025-01-07 14:39:28 +09:00
parent 86e8294c33
commit e0ae658383

View file

@ -1,12 +1,20 @@
#!/bin/bash #!/bin/bash
# Be aware that this script is deleting the source directory after copying the files and it's intended to be used only by flatpak builder # Be aware that this script deletes the source directory after copying the files. It is intended to be used only by the flatpak builder.
# List of user-defined libraries to exclude
excluded_libraries=("libselinux.so.1")
# Define target directory
target_dir="${FLATPAK_DEST}/lib"
echo "Worry not, LibMan is here!" echo "Worry not, LibMan is here!"
# Set default destination if FLATPAK_DEST is not set # Set default destination if FLATPAK_DEST is not set
if [ -z "$FLATPAK_DEST" ]; then if [ -z "$FLATPAK_DEST" ]; then
FLATPAK_DEST="/app" export FLATPAK_DEST="/app"
fi fi
# Check if source directory is provided # Check if source directory is provided
@ -15,25 +23,22 @@ if [ -z "$1" ]; then
exit 0 exit 0
fi fi
# Define target directory
target_dir="${FLATPAK_DEST}/lib"
# Ensure the target directory exists # Ensure the target directory exists
if ! mkdir -p "$target_dir"; then if ! mkdir -p "$target_dir"; then
echo "Error: Failed to create target directory $target_dir" echo "Error: Failed to create target directory $target_dir"
exit 0 exit 0
fi fi
# List all libraries in LD_LIBRARY_PATH and store them in an array # Function to check if a file is in the excluded libraries list
libraries=() is_excluded() {
IFS=: read -ra dirs <<< "$LD_LIBRARY_PATH" local file="$1"
for dir in "${dirs[@]}"; do for excluded in "${excluded_libraries[@]}"; do
if [ -d "$dir" ]; then if [[ "$excluded" == "$file" ]]; then
while IFS= read -r lib; do return 0
libraries+=("$lib") fi
done < <(find "$dir" -type f -name "*.so") done
fi return 1
done }
# Find and copy files # Find and copy files
copied_files=() copied_files=()
@ -49,13 +54,13 @@ for file in $(find "$1" -type f -name "*.so*"); do
continue continue
fi fi
# Skip if the file is already in the list of libraries # Skip if the file is in the list of excluded libraries
if [[ " ${libraries[*]} " == *" $file "* ]]; then if is_excluded "$(basename "$file")"; then
echo "Skipped $file as it is already present in the system" reason="library is in the exclusion list"
failed_files+=("$file, already present in the system") echo "Skipped $file as it is $reason"
failed_files+=("$file, $reason")
continue continue
fi fi
# Attempt to copy the file # Attempt to copy the file
if install -D "$file" "$dest_file" 2>error_log; then if install -D "$file" "$dest_file" 2>error_log; then
echo "Copied $file to $dest_file" echo "Copied $file to $dest_file"
@ -67,8 +72,6 @@ for file in $(find "$1" -type f -name "*.so*"); do
fi fi
done done
echo "LibMan is flying away"
# Output the lists of copied and failed files # Output the lists of copied and failed files
if [ ${#copied_files[@]} -ne 0 ]; then if [ ${#copied_files[@]} -ne 0 ]; then
echo "Imported libraries:" echo "Imported libraries:"
@ -84,3 +87,5 @@ if [ ${#failed_files[@]} -ne 0 ]; then
echo "$file" echo "$file"
done done
fi fi
echo "LibMan is flying away"