@@ -322,6 +322,140 @@ assemble() {
322322 esac
323323}
324324
325+ # Universal library filter - removes system-critical libraries from any directory
326+ filter_critical_system_libraries () {
327+ local target_dir=" $1 "
328+ local filter_type=" ${2:- lib} " # 'lib' for directory filtering, 'list' for text file filtering
329+
330+ log i " �️ Filtering critical system libraries from: $target_dir (type: $filter_type )" " $logfile "
331+
332+ # List of system-critical library patterns to exclude/remove
333+ local critical_patterns=(
334+ " libc.so*"
335+ " libdl.so*"
336+ " libpthread.so*"
337+ " librt.so*"
338+ " libm.so*"
339+ " ld-linux*"
340+ " linux-vdso*"
341+ " libgcc_s.so*"
342+ " libstdc++.so*"
343+ " libresolv.so*"
344+ " libnss_*"
345+ " libutil.so*"
346+ " libcrypt.so*"
347+ " libelf.so*"
348+ " libz.so*"
349+ " libbz2.so*"
350+ " liblzma.so*"
351+ " libexpat.so*"
352+ " libffi.so*"
353+ " libpcre*"
354+ " libselinux.so*"
355+ " libcap.so*"
356+ " libacl.so*"
357+ " libattr.so*"
358+ )
359+
360+ if [[ " $filter_type " == " lib" ]]; then
361+ # Filter actual library files in directories
362+ if [[ -d " $target_dir " ]]; then
363+ for lib_file in " $target_dir " /* .so* " $target_dir " /** /lib* .so* ; do
364+ if [[ -f " $lib_file " ]]; then
365+ local lib_name=$( basename " $lib_file " )
366+
367+ # Check if this library matches any critical pattern
368+ for pattern in " ${critical_patterns[@]} " ; do
369+ if [[ " $lib_name " == $pattern ]]; then
370+ log w " 🚫 Removing critical system library: $lib_name " " $logfile "
371+ rm -f " $lib_file "
372+ break
373+ fi
374+ done
375+
376+ # Set executable permissions for remaining libraries
377+ if [[ -f " $lib_file " ]]; then
378+ chmod +x " $lib_file "
379+ log d " ✅ Kept and set permissions: $lib_name " " $logfile "
380+ fi
381+ fi
382+ done
383+
384+ # Handle subdirectories recursively
385+ find " $target_dir " -type d -mindepth 1 | while read -r subdir; do
386+ filter_critical_system_libraries " $subdir " " lib"
387+ done
388+ fi
389+
390+ elif [[ " $filter_type " == " list" ]]; then
391+ # Filter text files (for required_libraries processing)
392+ local input_file=" $target_dir "
393+ local output_file=" $3 " # Third parameter is output file for list filtering
394+
395+ if [[ ! -f " $input_file " ]]; then
396+ log e " Input file not found: $input_file " " $logfile "
397+ return 1
398+ fi
399+
400+ # Clear output file
401+ > " $output_file "
402+
403+ while IFS= read -r line; do
404+ # Skip empty lines and comments
405+ [[ -z " $line " || " $line " =~ ^[[:space:]]* # ]] && continue
406+
407+ local skip_line= false
408+
409+ # Check if line contains any critical library pattern
410+ for pattern in " ${critical_patterns[@]} " ; do
411+ if [[ " $line " == * " $pattern " * ]]; then
412+ log w " 🚫 Filtering out critical library: $line " " $logfile "
413+ skip_line=true
414+ break
415+ fi
416+ done
417+
418+ # Add to output if not critical
419+ if [[ " $skip_line " == false ]]; then
420+ echo " $line " >> " $output_file "
421+ log d " ✅ Keeping library: $line " " $logfile "
422+ fi
423+
424+ done < " $input_file "
425+
426+ log i " ✅ Library list filtering complete" " $logfile "
427+ fi
428+ }
429+
430+ # Filter AppImage libraries to exclude system-critical ones
431+ filter_appimage_libs () {
432+ local source_dir=" $1 "
433+ local dest_dir=" $2 "
434+
435+ log i " 🔍 Filtering AppImage libraries from: $source_dir " " $logfile "
436+
437+ # Copy all non-lib directories first
438+ for item in " $source_dir " /* ; do
439+ if [[ -d " $item " && " $( basename " $item " ) " != " lib" ]]; then
440+ log d " 📁 Copying directory: $( basename " $item " ) " " $logfile "
441+ cp -rL " $item " " $dest_dir /"
442+ elif [[ -f " $item " ]]; then
443+ log d " 📄 Copying file: $( basename " $item " ) " " $logfile "
444+ cp -L " $item " " $dest_dir /"
445+ fi
446+ done
447+
448+ # Handle lib directory - copy first, then filter
449+ if [[ -d " $source_dir /lib" ]]; then
450+ log i " 🔧 Processing lib directory..." " $logfile "
451+ mkdir -p " $dest_dir /lib"
452+ cp -rL " $source_dir /lib/" * " $dest_dir /lib/" 2> /dev/null || true
453+
454+ # Apply unified filtering
455+ filter_critical_system_libraries " $dest_dir /lib" " lib"
456+ fi
457+ }
458+
325459manage_appimage () {
326460 log d " Starting manage_appimage function" " $logfile "
327461
@@ -408,8 +542,13 @@ manage_appimage() {
408542 rm -f " $file "
409543 done
410544
411- # Move only if dirs exist
412- [[ -d " $WORK_DIR /squashfs-root/usr" ]] && mv " $WORK_DIR /squashfs-root/usr" /* " $component /artifacts/" || log w " No usr/ content found" " $logfile "
545+ # Move only if dirs exist, but filter out system-critical libraries
546+ if [[ -d " $WORK_DIR /squashfs-root/usr" ]]; then
547+ log i " Filtering AppImage contents to exclude system-critical libraries..." " $logfile "
548+ filter_appimage_libs " $WORK_DIR /squashfs-root/usr" " $component /artifacts/"
549+ else
550+ log w " No usr/ content found" " $logfile "
551+ fi
413552 [[ -d " $WORK_DIR /squashfs-root/share" ]] && mv " $WORK_DIR /squashfs-root/share" " $component /artifacts/"
414553 [[ -d " $WORK_DIR /squashfs-root/apprun-hooks" ]] && mv " $WORK_DIR /squashfs-root/apprun-hooks" " $component /artifacts/"
415554
@@ -526,10 +665,10 @@ manage_flatpak_id() {
526665 log e " Failed to copy $target from $found_path " " $logfile "
527666 exit 1
528667 }
529- # Set executable permissions for shared libraries if we copied lib directory
668+ # Filter and set executable permissions for shared libraries if we copied lib directory
530669 if [[ " $target " == " lib" ]]; then
531- log i " Setting executable permissions for shared libraries..." " $logfile "
532- find " $component /artifacts/lib" -name " *.so* " -type f -exec chmod +x {} \;
670+ log i " Filtering and setting permissions for Flatpak libraries..." " $logfile "
671+ filter_critical_system_libraries " $component /artifacts/lib" " lib "
533672 fi
534673 local need_to_ls=" true"
535674 else
@@ -628,9 +767,9 @@ manage_flatpak_artifacts() {
628767 if [[ -d " $WORK_DIR /files/lib" ]]; then
629768 mkdir -p " $component /artifacts/lib"
630769 cp -rL " $WORK_DIR /files/lib/" * " $component /artifacts/lib/" 2> /dev/null || true
631- # Set executable permissions for shared libraries
632- log i " Setting executable permissions for shared libraries..." " $logfile "
633- find " $component /artifacts/lib" -name " *.so* " -type f -exec chmod +x {} \;
770+ # Filter and set executable permissions for shared libraries
771+ log i " Filtering and setting permissions for Flatpak artifacts libraries..." " $logfile "
772+ filter_critical_system_libraries " $component /artifacts/lib" " lib "
634773 log i " Copied lib directory contents to artifacts" " $logfile "
635774 fi
636775
@@ -855,6 +994,29 @@ process_required_libraries() {
855994 local temp_lib_file=$( mktemp)
856995 process_library_file " $required_libs_file " " $temp_lib_file "
857996
997+ # Filter out critical system libraries before processing
998+ local filtered_lib_file=$( mktemp)
999+ filter_critical_system_libraries " $temp_lib_file " " list" " $filtered_lib_file "
1000+
1001+ # Use search_libs to copy libraries
1002+ if [[ -s " $filtered_lib_file " ]]; then
1003+ log i " 🔧 Using search_libs to copy component-specific libraries..." " $logfile "
1004+ search_libs " $filtered_lib_file "
1005+
1006+ # Apply post-copy filtering to remove any critical libs that slipped through
1007+ if [[ -d " $component /artifacts/lib" ]]; then
1008+ filter_critical_system_libraries " $component /artifacts/lib" " lib"
1009+ fi
1010+ else
1011+ log i " No component-specific libraries to process after filtering" " $logfile "
1012+ fi
1013+
1014+ # Clean up
1015+ rm -f " $temp_lib_file " " $filtered_lib_file "
1016+ }
1017+ local temp_lib_file= $( mktemp)
1018+ process_library_file " $required_libs_file " " $temp_lib_file "
1019+
8581020 # Use search_libs to copy libraries
8591021 if [[ -s " $temp_lib_file " ]]; then
8601022 log i " 🔧 Using search_libs to copy component-specific libraries..." " $logfile "
@@ -867,7 +1029,7 @@ process_required_libraries() {
8671029 rm -f " $temp_lib_file "
8681030}
8691031
870- # Process the library file to extract library names
1032+ # Filter AppImage libraries to exclude system-critical ones
8711033process_library_file () {
8721034 local input_file=" $1 "
8731035 local output_file=" $2 "
@@ -956,6 +1118,11 @@ process_libraries_manual() {
9561118 fi
9571119 fi
9581120 done < " $required_libs_file "
1121+
1122+ # Apply filtering to remove any critical libraries that were copied
1123+ if [[ -d " $lib_dir " ]]; then
1124+ filter_critical_system_libraries " $lib_dir " " lib"
1125+ fi
9591126}
9601127
9611128finalize () {
0 commit comments