rstrip.sh 800 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2006 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. SELF=${0##*/}
  9. [ -z "$STRIP" ] && {
  10. echo "$SELF: strip command not defined (STRIP variable not set)"
  11. exit 1
  12. }
  13. TARGETS=$*
  14. [ -z "$TARGETS" ] && {
  15. echo "$SELF: no directories / files specified"
  16. echo "usage: $SELF [PATH...]"
  17. exit 1
  18. }
  19. find $TARGETS -type f -a -exec file {} \; | \
  20. sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.* stripped/\1:\2/p' | \
  21. (
  22. IFS=":"
  23. while read F S; do
  24. echo "$SELF: $F:$S"
  25. [ "${S}" = "relocatable" ] && {
  26. eval "$STRIP_KMOD $F"
  27. } || {
  28. b=$(stat -c '%a' $F)
  29. eval "$STRIP $F"
  30. a=$(stat -c '%a' $F)
  31. [ "$a" = "$b" ] || chmod $b $F
  32. }
  33. done
  34. true
  35. )