#!/bin/sh # "anonymize-svg" removes export paths and document names from all the SVG files # in a directory, saving the original versions. # 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. # Copyright (C) 2014 Thérèse Godefroy # You may redistribute this script and/or modify it under the terms of the # Creative Commons CC0 license # (http://creativecommons.org/publicdomain/zero/1.0/legalcode). set -e close_term () { printf '\n%s' '*** Close the terminal window or press Return.'; read OK test -z "$OK" && exit $1 } [ -d saved-svg ] || mkdir saved-svg for svg in *.svg; do cp -b -S '.bak' "$svg" saved-svg/"$svg" 2>/dev/null \ || (echo "*** This directory doesn't contain any SVG."; close_term '1') sed -i 's,sodipodi:docname="[^"]*",sodipodi:docname="",' "$svg" sed -i 's,inkscape:export-filename="[^"]*",inkscape:export-filename="",' "$svg" echo $svg done close_term '0'