-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertNew.sh
executable file
·67 lines (58 loc) · 1.29 KB
/
convertNew.sh
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
#!/bin/sh
#echo syntaxe : $0 repertoire_cible fichiers
#could optimize by making a list of all files, and at the end check if it's not empty, and call it all at once
getSuffix(){
echo $1 | rev | cut -d"." -f1 | rev
}
convert(){
libreoffice --headless --convert-to pdf --outdir $1 $2
}
#test for the flag.
#if the first arg is a directory, then do the script normally
#otherwise, it means a flag could be present
#and the first argument is the filename of the flag
if test -f $1 #is a file
then
fsize=$(wc -c $1 | awk '{print $1}')
if test $fsize -le 10 #size small enough for a simple flag file
then
echo found a flag, commencing check + convertion
rm $1
shift
else
echo that is way too big for a flag file!
exit
fi
elif test -d $1 #is a dir
then
echo normal behaviour
else
echo no flag found
exit
fi
#end of the search for a flag, start of the normal check+convert
cible=$1
shift
for f in $*
do
for i in doc docx pdf rtf xls txt docm xlsx ppt pptx csv
do
if test `getSuffix $f` = $i
then
fbase=`basename -s".$i" $f`
t=$cible/$fbase".pdf"
if test -e $t
then
if test $f -nt $t #is $f more recent than $t
then
echo $f is more recent than $t
convert $cible/ $f
else
echo $f is older than $t
fi
else
convert $cible/ $f
fi
fi
done
done