From 7546fb7dba3cfdd6fea5b99e8da2627f408c6575 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Th=C3=A9r=C3=A8se=20Godefroy?= Date: Wed, 6 Aug 2014 18:49:33 +0200 Subject: [PATCH] =?utf8?q?fr:=20add=20"detect-svg-leakage"=20by=20Donatas?= =?utf8?q?=20Klima=C5=A1auskas;=20fix=20"anonymize-svg"=20(catch=20errors,?= =?utf8?q?=20leave=20the=20terminal=20open,=20etc.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- svg/fr/anonymize-svg | 55 +++++++++++++++++++++++++-------------- svg/fr/detect-svg-leakage | 27 +++++++++++++++++++ 2 files changed, 62 insertions(+), 20 deletions(-) create mode 100755 svg/fr/detect-svg-leakage diff --git a/svg/fr/anonymize-svg b/svg/fr/anonymize-svg index bc8144e..65afc5a 100755 --- a/svg/fr/anonymize-svg +++ b/svg/fr/anonymize-svg @@ -1,24 +1,39 @@ -#!/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' diff --git a/svg/fr/detect-svg-leakage b/svg/fr/detect-svg-leakage new file mode 100755 index 0000000..9e0b877 --- /dev/null +++ b/svg/fr/detect-svg-leakage @@ -0,0 +1,27 @@ +#!/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' -- 2.25.1