Add iso8859-to-utf8.sh
authorHugo Villeneuve <hugo@hugovil.com>
Fri, 3 Dec 2021 19:05:23 +0000 (14:05 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Fri, 3 Dec 2021 19:05:23 +0000 (14:05 -0500)
scripts/Makefile.am
scripts/iso8859-to-utf8.sh [new file with mode: 0755]

index b885496..0be64ab 100644 (file)
@@ -12,6 +12,7 @@ dist_bin_SCRIPTS = \
     gztobz2 tarbz2 \
     hv-backup \
     hv-video-dvd \
+    iso8859-to-utf8.sh \
     mail-files mail-if-fail mail-statistics \
     replace.pl \
     rotatelogs \
diff --git a/scripts/iso8859-to-utf8.sh b/scripts/iso8859-to-utf8.sh
new file mode 100755 (executable)
index 0000000..6937e9f
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+TMPFILE=/tmp/iso8859-to-utf8.tmp
+
+if [ ${#} -eq 0 ]; then
+    echo "Erreur: aucun fichier(s) à traiter."
+    exit 1
+fi
+
+for f in ${*} ; do
+    if [ ! -f "${f}" ]; then
+        echo "Erreur: fichier introuvable: ${f}"
+        exit 1
+    fi
+    if file -i "${f}" | grep -q "iso-8859-1"; then
+        echo "[ISO-8859 -> UTF8] ${f}"
+        iconv -f iso-8859-1 -t utf-8 "${f}" > ${TMPFILE}
+        mv ${TMPFILE} "${f}"
+    fi
+done
+
+rm -f ${TMPFILE}