if [ "$FREETZ_STRIP_SCRIPTS" == "y" ]; then
echo0 "stripping shell scripts"
# This is (necessarily) slow because it checks *all* files
for f in $(find ${FILESYSTEM_MOD_DIR} -type f); do
# Syntax check. Use ash (not bash) because on target we also have ash.
# This is the first step because it is faster than 'file'.
$BUSYBOX ash -n "$f" 2>/dev/null &&
# Sometimes the ash syntax check succeeds on binaries.
# So we need to check we really have a text file here.
file -b --mime-type "$f" | grep -sq '^text/' &&
# Only strip scripts (possibly also stuff like awk or perl) with
# shebang. This excludes dot-included files without shebang, but
# anything else would be too unsafe. We do not want plain text
# files stripped.
grep -sq '#[^!]' "$f" ||
# continue the loop with the next file if one of the conditions above is false
continue
# Strip ...
STRIP_SCRIPTS_SED_SCRIPT='/^[ \t]*$/d;' # blank lines
# TODO: doesn't work because of multiline IFS definitions, i.e. IFS='\t\n'
#STRIP_SCRIPTS_SED_SCRIPT+='s/[ \t]+$//;' # trailing white spaces
STRIP_SCRIPTS_SED_SCRIPT+='/^[ \t]*#[^!].*/d;' # shell comments (not shebangs)
if [ "${f: -3:3}" != ".py" ]; then
STRIP_SCRIPTS_SED_SCRIPT+='s/^[ \t]*//g;' # and indentation if it's not a python script
fi
sed -i -r "${STRIP_SCRIPTS_SED_SCRIPT}" "$f" &&
echo2 "${f##${FILESYSTEM_MOD_DIR}}"
done
fi