-#!/bin/bash
+#!/bin/sh
-# "anonymize-svg" removes export paths (+ import URLs and/or document names as needed)
-# from all the SVG files in a directory, saving the original version. Subdirectories
-# are not affected.
+# "anonymize-svg" removes export paths and document names from all the SVG files
+# in a directory, saving the original versions.
-# Usage:
-# - Close Inkscape.
-# - Place the script in the directory containing the SVGs you want to clean.
-# - Uncomment the docname line if you need to remove the document names.
-# - Uncomment the xlink line only if you are absolutely sure that none of the
-# linked documents will be needed again.
-# - cd to the directory and run:
-# ./anonymize-svg
+# The script should be in the same directory as the SVGs. It can be launched from
+# the graphical user interface or called from the command line without argument.
+
+# Detailed method:
+# - make sure the first line (#!/bin/sh) wasn't lost during copy-pasting;
+# - make the script executable (this can usually be done from the contextual
+# menu);
+# - place it (or a softlink to it) in the directory containing the SVGs you
+# want to clean;
+# - make sure none of the SVGs is open in Inskape;
+# - open the SVG directory in the file browser (do not just unfold the parent
+# directory), then double-click on the script or launch it from the contextual
+# menu.
+
+# A terminal will open and list the files which have been cleaned, and a
+# subdirectory named saved-svg/ will be created to save the non-anonymized files.
+# If the script is run twice in the same directory, backups of the non-anonymized
+# files will be made in saved-svg/, but a third run will overwrite them.
+
+set -e
+EXIT () {
+ printf '\n%s' '*** Close the terminal window or press Return.'; read OK
+ test -z "$OK" && exit $1
+}
-find . -maxdepth 1 -name '*.svg' | sed 's,\./,,' > list
[ -d saved-svg ] || mkdir saved-svg
-while read f; do
- cp -b -S '.bak' $f saved-svg/$f
- sed -i 's,inkscape:export-filename="[^"]*",inkscape:export-filename="",' $f
- sed -i 's,xlink:href="file:///[^"]*",xlink:href="",' $f
- sed -i 's,sodipodi:docname="[^"]*",sodipodi:docname="",' $f
-done < list
-rm -f list
+for svg in *.svg; do
+ cp -b -S '.bak' "$svg" saved-svg/"$svg" 2>/dev/null \
+ || (echo "*** This directory doesn't contain any SVG."; EXIT '1')
+ sed -i 's,sodipodi:docname="[^"]*",sodipodi:docname="",' "$svg"
+ sed -i 's,inkscape:export-filename="[^"]*",inkscape:export-filename="",' "$svg"
+ echo $svg
+done
+EXIT '0'
--- /dev/null
+#!/bin/sh
+
+# "detect-svg-leakage" detects whether SVG files in the working
+# directory have attributes with local path name values, and prints
+# such attributes and their values.
+
+# The script (or a soft link to it) should be placed in the directory
+# containing the SVG files. It may be run either from the graphical user
+# interface (see "anonymize-svg"), or from the command line without argument.
+# In both cases, it will examine the SVG files in the directory and will
+# print their names, and the attributes whose value may be a local file
+# system path or a sensitive file name.
+
+set -e
+EXIT () {
+ printf '\n%s' '*** Close the terminal window or press Return.'; read OK
+ test -z "$OK" && exit $1
+}
+
+for svg in *.svg; do
+ test -s "$svg" \
+ || (echo "*** This directory doesn't contain any SVG."; EXIT '1')
+ printf '\n%s\n\n' "=== $svg"
+ perl -Twe 'while (<>) { print "$1\n" if
+ m/([\w\-:]+="([\/\.]+|file:).+?"|[\w:]+docname=".+")/i; }' <"$svg";
+done
+EXIT '0'