1 | #########################################################################
|
---|
2 | #
|
---|
3 | # Subroutine for the 'download' command
|
---|
4 | #
|
---|
5 | #########################################################################
|
---|
6 |
|
---|
7 | commandDOWNLOAD() {
|
---|
8 | printINFO "About to run \"$action\" for samhain version \"$src_version\""
|
---|
9 |
|
---|
10 | needEXE du gunzip tar gpg
|
---|
11 |
|
---|
12 |
|
---|
13 | if test x"$simulate" = x0
|
---|
14 | then
|
---|
15 | cd "${basedir}/tmp" || printFATAL "could not cd to ${basedir}/tmp"
|
---|
16 | rm -f "samhain-${src_version}.tar.gz"
|
---|
17 | else
|
---|
18 | #
|
---|
19 | # -- Simulate only: print what would be done
|
---|
20 | #
|
---|
21 | printINFO "cd ${basedir}/tmp"
|
---|
22 | printINFO "rm -f samhain-${src_version}.tar.gz"
|
---|
23 | fi
|
---|
24 |
|
---|
25 | command=""
|
---|
26 |
|
---|
27 | if test -z "$command"
|
---|
28 | then
|
---|
29 | findEXE wget
|
---|
30 | if test -n "$EXECUTABLE"
|
---|
31 | then
|
---|
32 | command="$EXECUTABLE"
|
---|
33 | opt1="--quiet"
|
---|
34 | opt2="-O"
|
---|
35 | opt3="-"
|
---|
36 | fi
|
---|
37 | fi
|
---|
38 |
|
---|
39 | if test -z "$command"
|
---|
40 | then
|
---|
41 | findEXE curl
|
---|
42 | if test -n "$EXECUTABLE"
|
---|
43 | then
|
---|
44 | command="$EXECUTABLE"
|
---|
45 | opt1="--silent"
|
---|
46 | opt2="--show-error"
|
---|
47 | opt3="--fail"
|
---|
48 | fi
|
---|
49 | fi
|
---|
50 |
|
---|
51 | if test -z "$command"
|
---|
52 | then
|
---|
53 | findEXE lynx
|
---|
54 | if test -n "$EXECUTABLE"
|
---|
55 | then
|
---|
56 | command="$EXECUTABLE"
|
---|
57 | opt1="-source"
|
---|
58 | opt2=""
|
---|
59 | opt3=""
|
---|
60 | fi
|
---|
61 | fi
|
---|
62 |
|
---|
63 | if test -z "$command"
|
---|
64 | then
|
---|
65 | findEXE links
|
---|
66 | if test -n "$EXECUTABLE"
|
---|
67 | then
|
---|
68 | command="$EXECUTABLE"
|
---|
69 | opt1="-source"
|
---|
70 | opt2=""
|
---|
71 | opt3=""
|
---|
72 | fi
|
---|
73 | fi
|
---|
74 |
|
---|
75 | if test -z "$command"
|
---|
76 | then
|
---|
77 | findEXE lwp-request
|
---|
78 | if test -n "$EXECUTABLE"
|
---|
79 | then
|
---|
80 | command="$EXECUTABLE"
|
---|
81 | opt1=""
|
---|
82 | opt2=""
|
---|
83 | opt3=""
|
---|
84 | fi
|
---|
85 | fi
|
---|
86 |
|
---|
87 | if test -z "$command"
|
---|
88 | then
|
---|
89 | findEXE fetch
|
---|
90 | if test -n "$EXECUTABLE"
|
---|
91 | then
|
---|
92 | command="$EXECUTABLE"
|
---|
93 | opt1="-q"
|
---|
94 | opt2="-o"
|
---|
95 | opt3="-"
|
---|
96 | fi
|
---|
97 | fi
|
---|
98 |
|
---|
99 | if test -z "$command"
|
---|
100 | then
|
---|
101 | findEXE fget
|
---|
102 | if test -n "$EXECUTABLE"
|
---|
103 | then
|
---|
104 | command="$EXECUTABLE"
|
---|
105 | opt1=""
|
---|
106 | opt2=""
|
---|
107 | opt3=""
|
---|
108 | fi
|
---|
109 | fi
|
---|
110 |
|
---|
111 | if test -z "$command"
|
---|
112 | then
|
---|
113 | printFATAL "No wget, curl, lynx, links, lwp-request, fetch in your \$PATH, cannot download"
|
---|
114 | fi
|
---|
115 |
|
---|
116 | if test x"${src_version}" = xcurrent
|
---|
117 | then
|
---|
118 | location="http://la-samhna.de/samhain/samhain-current.tar.gz"
|
---|
119 | if test -f /usr/bin/md5sum && test -f /bin/hostname
|
---|
120 | then
|
---|
121 | #
|
---|
122 | # for testing
|
---|
123 | #
|
---|
124 | dl_tmp_hna=`/bin/hostname -f 2>/dev/null`
|
---|
125 | dl_tmp_md5=`echo "x${dl_tmp_hna}" | md5sum`
|
---|
126 | if test x"$dl_tmp_md5" = "xc5f41bf28a7baf12c763f1be27a9b863"
|
---|
127 | then
|
---|
128 | location="http://localhost/samhain-current.tar.gz"
|
---|
129 | fi
|
---|
130 | fi
|
---|
131 | else
|
---|
132 | location="http://la-samhna.de/archive/samhain_signed-${src_version}.tar.gz"
|
---|
133 | if test -f /usr/bin/md5sum && test -f /bin/hostname
|
---|
134 | then
|
---|
135 | #
|
---|
136 | # for testing
|
---|
137 | #
|
---|
138 | dl_tmp_hna=`/bin/hostname -f 2>/dev/null`
|
---|
139 | dl_tmp_md5=`echo "x${dl_tmp_hna}" | /usr/bin/md5sum 2>/dev/null`
|
---|
140 | if test x"$dl_tmp_md5" = "xc5f41bf28a7baf12c763f1be27a9b863"
|
---|
141 | then
|
---|
142 | location="http://localhost/samhain_signed-${src_version}.tar.gz"
|
---|
143 | fi
|
---|
144 | fi
|
---|
145 | fi
|
---|
146 |
|
---|
147 |
|
---|
148 | printINFO "Executing $command $opt1 $opt2 $opt3 $location"
|
---|
149 |
|
---|
150 | if test x"$simulate" = x0
|
---|
151 | then
|
---|
152 | eval "$command" "$opt1" "$opt2" "$opt3" "$location" 1>"samhain-${src_version}.tar.gz" 2>/dev/null
|
---|
153 | else
|
---|
154 | printINFO "$command" "$opt1" "$opt2" "$opt3" "$location" 1>"samhain-${src_version}.tar.gz"
|
---|
155 | printINFO "du -s -k samhain-${src_version}.tar.gz | awk '{ print $1 }'"
|
---|
156 | printLOG "Downloaded to samhain-${src_version}.tar.gz (XXX kB)"
|
---|
157 | printINFO "gunzip -c samhain-${src_version}.tar.gz | tar -tvf - "
|
---|
158 | printINFO "Source in tarball is version X.X.X"
|
---|
159 | printINFO "Unpacking to ${tmpD}"
|
---|
160 | printINFO "cd ${tmpD}"
|
---|
161 | printINFO "gunzip -c ${basedir}/tmp/samhain-${src_version}.tar.gz | tar -xf -"
|
---|
162 | printINFO "rm -f ${basedir}/tmp/samhain-${src_version}.tar.gz"
|
---|
163 | printINFO "Checking PGP signature"
|
---|
164 | printINFO "(LANG=C; gpg --status-fd 1 --verify samhain-X.X.X.tar.gz.asc samhain-X.X.X.tar.gz 2>&1 | grep 'GOODSIG')"
|
---|
165 | printINFO "cp samhain-X.X.X.tar.gz.asc samhain-X.X.X.tar.gz ${basedir}/source"
|
---|
166 | printLOG "Installed samhain (X.X.X) source"
|
---|
167 | return 0
|
---|
168 | fi
|
---|
169 |
|
---|
170 | if test -f "samhain-${src_version}.tar.gz"
|
---|
171 | then
|
---|
172 | :
|
---|
173 | else
|
---|
174 | printFATAL "failed: $command $location"
|
---|
175 | fi
|
---|
176 |
|
---|
177 | size=`du -s -k "samhain-${src_version}.tar.gz" | awk '{ print $1 }'`
|
---|
178 |
|
---|
179 | if test $size -lt 100
|
---|
180 | then
|
---|
181 | rm -f "samhain-${src_version}.tar.gz"
|
---|
182 | printFATAL "failed: $command $location"
|
---|
183 | else
|
---|
184 | printLOG "Downloaded to samhain-${src_version}.tar.gz (${size} kB)"
|
---|
185 | fi
|
---|
186 |
|
---|
187 | files=`gunzip -c "samhain-${src_version}.tar.gz" | tar -tvf - 2>/dev/null`
|
---|
188 | sig=`echo $files | egrep ' samhain.*tar\.gz\.asc$' 2>/dev/null`
|
---|
189 | sig_version=`echo $files | egrep ' samhain.*tar\.gz\.asc$' 2>/dev/null | sed 's/.*samhain\-//g' | sed 's/\.tar\.gz\.asc//g'`
|
---|
190 | if test x"$sig" = x
|
---|
191 | then
|
---|
192 | rm -f "samhain-${src_version}.tar.gz"
|
---|
193 | printFATAL "downloaded file does not contain a PGP signature"
|
---|
194 | fi
|
---|
195 |
|
---|
196 | if test x"${sig_version}" = x
|
---|
197 | then
|
---|
198 | rm -f "samhain-${src_version}.tar.gz"
|
---|
199 | printFATAL "cannot determine samhain version from downloaded file"
|
---|
200 | fi
|
---|
201 |
|
---|
202 | if test x"${src_version}" != xcurrent
|
---|
203 | then
|
---|
204 | if test x"${src_version}" != x"${sig_version}"
|
---|
205 | then
|
---|
206 | rm -f "samhain-${src_version}.tar.gz"
|
---|
207 | printFATAL "downloaded version (${sig_version}) != requested version (${src_version})"
|
---|
208 | fi
|
---|
209 | fi
|
---|
210 |
|
---|
211 | printINFO "Source in tarball is version ${sig_version}"
|
---|
212 | printINFO "Unpacking to ${basedir}/source"
|
---|
213 |
|
---|
214 | cd "${tmpD}" || {
|
---|
215 | rm -f "${basedir}/tmp/samhain-${src_version}.tar.gz"
|
---|
216 | printFATAL "could not cd to ${tmpD}"
|
---|
217 | }
|
---|
218 |
|
---|
219 | gunzip -c "${basedir}/tmp/samhain-${src_version}.tar.gz" | tar -xf -
|
---|
220 |
|
---|
221 | rm -f "${basedir}/tmp/samhain-${src_version}.tar.gz"
|
---|
222 |
|
---|
223 | if test -f "samhain-${sig_version}.tar.gz"
|
---|
224 | then
|
---|
225 | if test -f "samhain-${sig_version}.tar.gz.asc"
|
---|
226 | then
|
---|
227 | :
|
---|
228 | else
|
---|
229 | printFATAL "not found in source: PGP signature samhain-${sig_version}.tar.gz.asc"
|
---|
230 | fi
|
---|
231 | else
|
---|
232 | printFATAL "not found in source: samhain-${sig_version}.tar.gz"
|
---|
233 | fi
|
---|
234 |
|
---|
235 |
|
---|
236 | printINFO "Checking PGP signature"
|
---|
237 | sig_lines=`(LANG="C"; gpg --status-fd 1 --verify "samhain-${sig_version}.tar.gz.asc" "samhain-${sig_version}.tar.gz" 2>/dev/null)`
|
---|
238 | sig_ok=`echo ${sig_lines} | grep 'GOODSIG'`
|
---|
239 |
|
---|
240 | sig_nokey=`echo ${sig_lines} | grep 'NO_PUBKEY'`
|
---|
241 |
|
---|
242 | if test x"${sig_nokey}" != x
|
---|
243 | then
|
---|
244 | printWARNING "Public key (ID 0F571F6C) not found, trying to import it."
|
---|
245 | gpg --import ${basedir}/private/0F571F6C.asc 2>&5
|
---|
246 | sig_ok=`(LANG="C"; gpg --status-fd 1 --verify "samhain-${sig_version}.tar.gz.asc" "samhain-${sig_version}.tar.gz" 2>/dev/null | grep 'GOODSIG')`
|
---|
247 | fi
|
---|
248 |
|
---|
249 | if test x"${sig_ok}" = x
|
---|
250 | then
|
---|
251 | (LANG="C"; gpg --verify "samhain-${sig_version}.tar.gz.asc" "samhain-${sig_version}.tar.gz")
|
---|
252 | printFATAL "no good signature"
|
---|
253 | fi
|
---|
254 |
|
---|
255 | cp "samhain-${sig_version}.tar.gz" "samhain-${sig_version}.tar.gz.asc" \
|
---|
256 | ${basedir}/source/ || \
|
---|
257 | printFATAL "failed: cp samhain-${sig_version}.tar.gz samhain-${sig_version}.tar.gz.asc ${basedir}/source/"
|
---|
258 |
|
---|
259 | printLOG "Installed samhain source (version=${sig_version})"
|
---|
260 |
|
---|
261 | return 0
|
---|
262 | }
|
---|