Browse Source

read-magic and look follow symbolic links

main
deicidus 2 years ago
parent
commit
343470652f
  1. 11
      spells/read-magic

11
spells/read-magic

@ -23,16 +23,17 @@ fi
# Define a function to read the attribute value using the available commands # Define a function to read the attribute value using the available commands
read_attribute_value() { read_attribute_value() {
# Try to read the attribute using the 'attr' command # Try to read the attribute using the 'attr' command
attribute_value=$(attr -g "$1" "$2" 2> /dev/null | cut -d ":" -f 2 | xargs) real_path=$(readlink -f "$file")
attribute_value=$(attr -g "$attribute" "$real_path" 2> /dev/null | cut -d ":" -f 2 | xargs)
# If the 'attr' command is not available, try using the 'xattr' command # If the 'attr' command is not available, try using the 'xattr' command
if [ -z "$attribute_value" ]; then if [ -z "$attribute_value" ]; then
attribute_value=$(xattr -p "$1" "$2" 2> /dev/null | cut -d ":" -f 2 | xargs) attribute_value=$(xattr -p "$attribute" "$real_path" 2> /dev/null | cut -d ":" -f 2 | xargs)
fi fi
# If the 'xattr' command is not available, try using the 'getfattr' command # If the 'xattr' command is not available, try using the 'getfattr' command
if [ -z "$attribute_value" ]; then if [ -z "$attribute_value" ]; then
attribute_value=$(getfattr -n "$1" --only-values "$2" 2> /dev/null) attribute_value=$(getfattr -h -n "$attribute" --only-values "$file" 2> /dev/null)
fi fi
# Return the attribute value # Return the attribute value
@ -46,7 +47,7 @@ if [ -z "$attribute" ]; then
# Define a function to process each attribute # Define a function to process each attribute
process_attribute() { process_attribute() {
# Read the attribute value using the read_attribute_value function # Read the attribute value using the read_attribute_value function
value=$(read_attribute_value "$1" "$file") value=$(read_attribute_value "$attribute" "$file")
# Check if the attribute value was set # Check if the attribute value was set
if [ -n "$value" ]; then if [ -n "$value" ]; then
@ -57,7 +58,7 @@ if [ -z "$attribute" ]; then
} }
# Call the process_attribute function for each attribute # Call the process_attribute function for each attribute
for attribute in $(getfattr -m ".*" -e hex "$file" | cut -d ":" -f 1 | cut -d "." -f 2 | tr -d ' '); do for attribute in $(getfattr -h -m ".*" -e hex "$file" | cut -d ":" -f 1 | cut -d "." -f 2 | tr -d ' '); do
process_attribute "$attribute" process_attribute "$attribute"
done done

Loading…
Cancel
Save