Repository navigation
Expand file tree
/
Copy paththumbnizedir
More file actions
executable file
·179 lines (139 loc) · 3.59 KB
/
Copy paththumbnizedir
File metadata and controls
executable file
·179 lines (139 loc) · 3.59 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
#
############################################
# create thumbnail for cloudsx
#
# dan.y.roche@gmail.com
#
# 1st version 20150405
# 20150419 add vid/aud icons
# 20160102 txt 1 page !
# 20160103 html thumb
# 20160123 fetch config from php
############################################
#############################################
# inotify seems not to initialize ENV fine
# so be sure ENV is here
SHELL=/bin/bash
LANG=fr_FR.UTF-8
HOME=/home/login/apache
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/opt/miscbin:/opt/java/bin:.
export PATH SHELL LANG HOME
# do we need those ? hope not
#USER=apache
#LOGNAME=apache
#export USER LOGNAME
##########################################################
# fetch config
##########################################################
# fetch global application config (php !)
#
MYSELF=$0
MYDIR=$(dirname ${MYSELF})
APPCONF=${MYDIR}/../app/Config.php
if [ -s ${APPCONF} ]
then
# get the config from php conf
TMP1=$(cat ${APPCONF} | grep '^ *$this->TopAppDir')
CDIR1=$(expr "${TMP1}" : ' *$this->TopAppDir *= *\"\(.*\)\"')
else
echo "Can't find application config file - aborting !"
exit 3
fi
CSXDIR=${CDIR1}
# verify
if [ ! -d ${CSXDIR} ]
then
echo "application dir ${CSXDIR} not found - aborting !"
exit 4
fi
TSIZE=x60
TSUF=png
ICODIR=${CSXDIR}/default_icons
ICO_GEN=${ICODIR}/file.png
ICO_VID=${ICODIR}/video.png
ICO_AUD=${ICODIR}/audio.png
############################################
# args
THEDIR=$1
if [ ! -d ${THEDIR} ]
then
exit 2
fi
if [ ! -d ${THEDIR}/.thumbs ]
then
mkdir ${THEDIR}/.thumbs
fi
######################
# function
GenerateThumb() {
FIL=$1
# get extension
EXT0=$( expr "${FIL}" : '.*\.\([^\.]*\)')
EXT=$(echo -n ${EXT0} | tr "[A-Z]" "[a-z]")
case ${EXT} in
gif | jpg | jpeg | png | bmp )
convert -resize ${TSIZE} "${THEDIR}/${FIL}" "${THEDIR}/.thumbs/${FIL}.${TSUF}"
;;
pdf )
pdftk "${THEDIR}/${FIL}" cat 1-1 output /tmp/thnz_$$.pdf
convert -resize ${TSIZE} /tmp/thnz_$$.pdf "${THEDIR}/.thumbs/${FIL}.${TSUF}"
rm -f /tmp/thnz_$$.pdf
;;
txt )
head -n 58 "${THEDIR}/${FIL}" > /tmp/thnz_$$.txt
convert -resize ${TSIZE} /tmp/thnz_$$.txt "${THEDIR}/.thumbs/${FIL}.${TSUF}"
rm -f /tmp/thnz_$$.txt
;;
html )
convert -resize ${TSIZE} "${THEDIR}/${FIL}" /tmp/thnz_h2i_$$.${TSUF}
if [ -s /tmp/thnz_h2i_$$.${TSUF} ]
then
mv /tmp/thnz_h2i_$$.${TSUF} "${THEDIR}/.thumbs/${FIL}.${TSUF}"
elif [ -s /tmp/thnz_h2i_$$-0.${TSUF} ]
then
mv /tmp/thnz_h2i_$$-0.${TSUF} "${THEDIR}/.thumbs/${FIL}.${TSUF}"
fi
rm -f /tmp/thnz_h2i_$$*
;;
doc | xls | ppt | docx | xlsx | pptx | odt | odg | odp | ods )
/usr/bin/unoconv --stdout -f pdf "${THEDIR}/${FIL}" | pdftk - cat 1-1 output /tmp/thnz_$$.pdf
convert -resize ${TSIZE} /tmp/thnz_$$.pdf "${THEDIR}/.thumbs/${FIL}.${TSUF}"
rm -f /tmp/thnz_$$.pdf
;;
mts | avi | mkv | mp4 | mpg | flv | wmv | mov )
cp ${ICO_VID} "${THEDIR}/.thumbs/${FIL}.${TSUF}"
;;
mp3 | ogg | wav | mp4 | wma | flac | mid | midi )
cp ${ICO_AUD} "${THEDIR}/.thumbs/${FIL}.${TSUF}"
;;
* )
cp ${ICO_GEN} "${THEDIR}/.thumbs/${FIL}.${TSUF}"
esac
}
######################
# loop on file
for ITEM in ${THEDIR}/*
do
if [ ! -s "${ITEM}" ]
then
continue
fi
BNI=$(basename "${ITEM}")
if [ "${BNI}" = "index.html" ]
then
continue
fi
if [ ! -s "${THEDIR}/.thumbs/${BNI}.${TSUF}" ]
then
GenerateThumb "${BNI}"
continue
fi
M1=$(stat --printf "%Y" "${ITEM}")
M2=$(stat --printf "%Y" "${THEDIR}/.thumbs/${BNI}.${TSUF}")
if [ ${M1} -gt ${M2} ]
then
GenerateThumb "${BNI}"
continue
fi
done