#!/bin/bash # # strip-cr-file file [--preserve-mtime] # # Uses strip-cr on a file. # To convert an entire directory of files, use something like: # # find target/ -type f -exec strip-cr-file {} \; # # --preserve-mtime # # Leaves the modification time untouched. # Unfortunately, the change time (per stat) must change, # because there are no tools (neither Linux's touch, nor Perl) that can correct it. # if [ -f /tmp/strip ]; then rm /tmp/strip || exit 1 # clean up early, after previous mess fi if [ $2 ]; then if [ $2 == --preserve-mtime ]; then preserve=1 else echo unrecognized option: $2 exit 1 fi fi is-text $1 || exit; # mv -f $1 /tmp/strip ## but changes attributes when the file is later recreated ## also fails between # this is better: cp --preserve $1 /tmp/strip || exit 1; ## though it still stats with a different "Change" time strip-cr < /tmp/strip > $1 [ $preserve ] && touch -r /tmp/strip $1 rm /tmp/strip # don't block other users