2025-01-06 00:45:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2025-01-07 05:39:28 +00:00
|
|
|
# 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"
|
|
|
|
|
2025-01-06 12:00:51 +00:00
|
|
|
|
2025-01-06 11:07:52 +00:00
|
|
|
echo "Worry not, LibMan is here!"
|
2025-01-06 06:26:15 +00:00
|
|
|
|
2025-01-06 00:45:59 +00:00
|
|
|
# Set default destination if FLATPAK_DEST is not set
|
|
|
|
if [ -z "$FLATPAK_DEST" ]; then
|
2025-01-07 05:39:28 +00:00
|
|
|
export FLATPAK_DEST="/app"
|
2025-01-06 00:45:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if source directory is provided
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "Usage: $0 <source_directory>"
|
2025-01-06 11:07:52 +00:00
|
|
|
exit 0
|
2025-01-06 00:45:59 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Ensure the target directory exists
|
2025-01-06 06:26:15 +00:00
|
|
|
if ! mkdir -p "$target_dir"; then
|
|
|
|
echo "Error: Failed to create target directory $target_dir"
|
|
|
|
exit 0
|
|
|
|
fi
|
2025-01-06 00:45:59 +00:00
|
|
|
|
2025-01-07 05:39:28 +00:00
|
|
|
# Function to check if a file is in the excluded libraries list
|
|
|
|
is_excluded() {
|
|
|
|
local file="$1"
|
|
|
|
for excluded in "${excluded_libraries[@]}"; do
|
|
|
|
if [[ "$excluded" == "$file" ]]; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
2025-01-06 11:07:52 +00:00
|
|
|
|
2025-01-06 00:45:59 +00:00
|
|
|
# Find and copy files
|
2025-01-06 11:07:52 +00:00
|
|
|
copied_files=()
|
|
|
|
failed_files=()
|
|
|
|
|
2025-01-07 00:16:35 +00:00
|
|
|
for file in $(find "$1" -type f -name "*.so*"); do
|
2025-01-06 06:26:15 +00:00
|
|
|
# Define destination file path
|
|
|
|
dest_file="$target_dir/$(basename "$file")"
|
|
|
|
|
|
|
|
# Skip if the destination file already exists
|
|
|
|
if [ -e "$dest_file" ]; then
|
|
|
|
echo "Skipped $file as $dest_file already exists"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2025-01-07 05:39:28 +00:00
|
|
|
# Skip if the file is in the list of excluded libraries
|
|
|
|
if is_excluded "$(basename "$file")"; then
|
|
|
|
reason="library is in the exclusion list"
|
|
|
|
echo "Skipped $file as it is $reason"
|
|
|
|
failed_files+=("$file, $reason")
|
2025-01-06 11:07:52 +00:00
|
|
|
continue
|
|
|
|
fi
|
2025-01-06 06:26:15 +00:00
|
|
|
# Attempt to copy the file
|
2025-01-06 11:07:52 +00:00
|
|
|
if install -D "$file" "$dest_file" 2>error_log; then
|
2025-01-06 06:26:15 +00:00
|
|
|
echo "Copied $file to $dest_file"
|
2025-01-06 11:07:52 +00:00
|
|
|
copied_files+=("$file")
|
2025-01-06 06:26:15 +00:00
|
|
|
else
|
2025-01-06 11:07:52 +00:00
|
|
|
error_message=$(<error_log)
|
2025-01-06 14:30:18 +00:00
|
|
|
echo "Warning: Failed to copy $file. Skipping. Error: $error_message"
|
2025-01-06 11:07:52 +00:00
|
|
|
failed_files+=("$file, $error_message")
|
2025-01-06 06:26:15 +00:00
|
|
|
fi
|
2025-01-06 14:14:13 +00:00
|
|
|
done
|
2025-01-06 06:26:15 +00:00
|
|
|
|
2025-01-06 11:07:52 +00:00
|
|
|
# Output the lists of copied and failed files
|
2025-01-07 00:54:17 +00:00
|
|
|
if [ ${#copied_files[@]} -ne 0 ]; then
|
2025-01-07 00:54:50 +00:00
|
|
|
echo "Imported libraries:"
|
2025-01-07 00:54:17 +00:00
|
|
|
for file in "${copied_files[@]}"; do
|
|
|
|
echo "$file"
|
|
|
|
done
|
|
|
|
fi
|
2025-01-06 11:07:52 +00:00
|
|
|
|
2025-01-06 14:14:13 +00:00
|
|
|
# Output failed files only if the list is not empty
|
|
|
|
if [ ${#failed_files[@]} -ne 0 ]; then
|
2025-01-07 00:54:50 +00:00
|
|
|
echo "Failed library files:"
|
2025-01-06 14:14:13 +00:00
|
|
|
for file in "${failed_files[@]}"; do
|
|
|
|
echo "$file"
|
2025-01-06 14:30:18 +00:00
|
|
|
done
|
2025-01-06 14:14:13 +00:00
|
|
|
fi
|
2025-01-07 05:39:28 +00:00
|
|
|
|
|
|
|
echo "LibMan is flying away"
|