-
Notifications
You must be signed in to change notification settings - Fork 3
/
slacheckimages
89 lines (78 loc) · 1.97 KB
/
slacheckimages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# set -x
filename=""
filenameoption="--include=*.sla"
folderexcludeoption="--exclude-dir=archives"
recurseoption="-r"
stopoption=""
. shellcolors
while [ "$stopoptions" = "" ] && [ "$1" != "" ]
do
case $1 in
"-h" | "-?" )
echo "usage : slacheckimages [-h] [-r] [-e pattern] [scribusfile]"
echo "checks whether all used images are stored in scribusfile's 'images' subfolder"
echo options :
echo -h or -? : displays this help
echo "-r : recurse folders (default)"
echo "-e pattern : exclude files matching pattern (default : archives)"
echo "scribusfile : specific file to check. Dont use with -r"
echo "-v : verbose (displays more details)"
echo
exit
;;
"-v")
shift
verbose=oui
;;
"-r" )
shift
recurseoption="-r"
filenameoption="--include=*.sla"
;;
"-e" )
if [ "$2" = "" ]
then
echo Error : -e option without pattern to exclude folders
exit
fi
folderexcludeoption="--exclude-dir=$2"
shift
shift
;;
*) if [ ! -f "$1.sla" ]
then
if [ ${1##*\.} = "sla" ] # ${parameter##pattern} : enleve le début jusqu'au dernier pattern
then
echo "Error : you should not specify the sla extension in the filename"
fi
echo "Error : file \"$1.sla\" doesn't exist"
exit
fi
filename="$1.sla"
filenameoption=""
folderexcludeoption=""
recurseoption=""
stopoptions=true
shift
;;
esac
done
if [ "$1" != "" ]
then
echo "${ESC_error} too many parameters$ESC_normal"
exit
fi
if [ "$verbose" = "oui" ]
then
# verbose shell + expand variables (set -v : verbose with no expand)
set -x
fi
# PFILES="images/ : image is stored in correct images subfolder
# PFILES="" : empty image frame OR inline image
alloptions="-H $recurseoption $folderexcludeoption $filenameoption"
err=`grep $alloptions -- PFILE= "$filename" | grep -v 'PFILE="images/\|PFILE=""' | sed 's/^\(.*\.sla\).* PFILE="\([^"]*\)".*$/In \1, image has source file outside \/images : \2/'`
if [ "$err" != "" ]
then
echo -e "${ESC_error}$err$ESC_normal"
fi