Last active
April 30, 2017 03:10
-
-
Save kurahaupo/230dca8b32823e7d2f4fcf3137eeafd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
shopt -s globstar | |
sdir=$HOME/Documents/website | |
tdir=$HOME/tmp/transcoded-website | |
scode=WINDOWS-1252 | |
tcode=UTF-8 | |
mkdir -vp "$tdir" | |
cp -al "$sdir/." "$tdir" || exit | |
for f in "$tdir"/**/*.shtml \ | |
"$tdir"/**/*.txt \ | |
"$tdir"/**/*.p[lm] | |
do | |
# if you want to do some tests, put those here, e.g.: | |
# [[ -s $f ]] || continue # skip things that aren't plain files | |
# file "$f" | grep -qs "Text" || continue # skip things that don't contain text | |
# file "$f" | grep -qsE "Unicode|UTF" && continue # skip things that are already Unicode or UTF-something | |
g=$f.NEW$$ | |
iconv --from-code=$sc --to-code=$tc <"$f" >"$g" || exit | |
if cmp -s "$f" "$g" ; then | |
# the transcoded file is identical to the original, so don't replace it | |
rm "$g" | |
else | |
touch --ref="$f" "$g" # optional -- set timestamp to match original file | |
chmod --ref="$f" "$g" # optional -- set permissions to match original file | |
mv -T "$g" "$f" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment