github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/redhat/test-fixtures/image-minimal/remove.sh (about) 1 #!/bin/bash 2 3 ESSENTIAL_PACKAGES=( 4 "basesystem" 5 "filesystem" 6 "bash" 7 ) 8 9 ESSENTIALS_PATTERN=$(IFS='|'; echo "${ESSENTIAL_PACKAGES[*]}") 10 ALL_PACKAGES=$(rpm -qa --queryformat '%{NAME}\n') 11 PACKAGES_TO_REMOVE=() 12 13 for package in $ALL_PACKAGES; do 14 if ! [[ "$package" =~ ^($ESSENTIALS_PATTERN)$ ]]; then 15 PACKAGES_TO_REMOVE+=("$package") 16 else 17 echo "Skipping essential package: $package" 18 fi 19 done 20 21 if [ ${#PACKAGES_TO_REMOVE[@]} -gt 0 ]; then 22 echo "Removing non-essential packages..." 23 rpm -e --nodeps "${PACKAGES_TO_REMOVE[@]}" 24 else 25 echo "No non-essential packages to remove." 26 fi 27 28 # since we are still in the same terminal and the shell is loaded we can still echo :) 29 echo "Cleanup complete."