File: comDOWNLOAD

package info (click to toggle)
samhain 4.1.4-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,720 kB
  • sloc: ansic: 84,043; sh: 15,325; asm: 5,756; makefile: 1,614; perl: 1,231
file content (280 lines) | stat: -rw-r--r-- 7,672 bytes parent folder | download | duplicates (8)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#########################################################################
#
# Subroutine for the 'download' command
#
#########################################################################
#
# Copyright Rainer Wichmann (2005)
#
# License Information:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

commandDOWNLOAD() {
    printINFO "About to run \"$action\" for samhain version \"$src_version\""

    needEXE du gunzip tar gpg


    if test x"$simulate" = x0
    then
	cd "${basedir}/tmp" || printFATAL "could not cd to ${basedir}/tmp"
	rm -f "samhain-${src_version}.tar.gz"
    else
	# 
	# -- Simulate only: print what would be done
	#
	printINFO "cd ${basedir}/tmp"
	printINFO "rm -f samhain-${src_version}.tar.gz"
    fi

    command=""

    if test -z "$command"
    then
        findEXE wget
        if test -n "$EXECUTABLE"
        then
	    command="$EXECUTABLE"
	    opt1="--quiet"
	    opt2="-O"
	    opt3="-"
        fi
    fi

    if test -z "$command"
    then
        findEXE curl
        if test -n "$EXECUTABLE"
        then
	    command="$EXECUTABLE"
	    opt1="--silent"
	    opt2="--show-error"
	    opt3="--fail"
        fi
    fi

    if test -z "$command"
    then
	findEXE lynx
	if test -n "$EXECUTABLE"
	then
	    command="$EXECUTABLE"
	    opt1="-source"
	    opt2=""
	    opt3=""
	fi
    fi

    if test -z "$command"
    then
	findEXE links
	if test -n "$EXECUTABLE"
	then
	    command="$EXECUTABLE"
	    opt1="-source"
	    opt2=""
	    opt3=""
	fi
    fi

    if test -z "$command"
    then
	findEXE lwp-request
	if test -n "$EXECUTABLE"
	then
	    command="$EXECUTABLE"
	    opt1=""
	    opt2=""
	    opt3=""
	fi
    fi

    if test -z "$command"
    then
	findEXE fetch
	if test -n "$EXECUTABLE"
	then
	    command="$EXECUTABLE"
	    opt1="-q"
	    opt2="-o"
	    opt3="-"
	fi
    fi

    if test -z "$command"
    then
	findEXE fget
	if test -n "$EXECUTABLE"
	then
	    command="$EXECUTABLE"
	    opt1=""
	    opt2=""
	    opt3=""
	fi
    fi

    if test -z "$command"
    then
	printFATAL "No wget, curl, lynx, links, lwp-request, fetch, fget in your \$PATH, cannot download"
    fi

    if test x"${src_version}" = xcurrent
    then
	location="http://la-samhna.de/samhain/samhain-current.tar.gz"
	if test -f /usr/bin/md5sum && test -f /bin/hostname
	then
	    #
	    # for testing
	    #
	    dl_tmp_hna=`/bin/hostname -f 2>/dev/null`
	    dl_tmp_md5=`echo "x${dl_tmp_hna}" | md5sum`
	    if test x"$dl_tmp_md5" = "xc5f41bf28a7baf12c763f1be27a9b863"
	    then
		location="http://localhost/samhain-current.tar.gz"
	    fi
	fi
    else
	location="http://la-samhna.de/archive/samhain_signed-${src_version}.tar.gz"
	if test -f /usr/bin/md5sum && test -f /bin/hostname
	then
	    #
	    # for testing
	    #
	    dl_tmp_hna=`/bin/hostname -f 2>/dev/null`
	    dl_tmp_md5=`echo "x${dl_tmp_hna}" | /usr/bin/md5sum 2>/dev/null`
	    if test x"$dl_tmp_md5" = "xc5f41bf28a7baf12c763f1be27a9b863"
	    then
	    	location="http://localhost/samhain_signed-${src_version}.tar.gz"
	    fi
	fi
    fi


    printINFO "Executing $command $opt1 $opt2 $opt3 $location"

    if test x"$simulate" = x0
    then
	eval "$command" "$opt1" "$opt2" "$opt3" "$location" 1>"samhain-${src_version}.tar.gz" 2>/dev/null
    else
	printINFO "$command" "$opt1" "$opt2" "$opt3" "$location" 1>"samhain-${src_version}.tar.gz"
	printINFO "du -s -k samhain-${src_version}.tar.gz | awk '{ print $1 }'"
	printLOG  "Downloaded to samhain-${src_version}.tar.gz (XXX kB)"
	printINFO "gunzip -c samhain-${src_version}.tar.gz | tar -tvf - "
	printINFO "Source in tarball is version X.X.X"
	printINFO "Unpacking to ${tmpD}"
	printINFO "cd ${tmpD}"
	printINFO "gunzip -c ${basedir}/tmp/samhain-${src_version}.tar.gz | tar -xf -"
	printINFO "rm -f ${basedir}/tmp/samhain-${src_version}.tar.gz"
	printINFO "Checking PGP signature" 
	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')"
	printINFO "cp samhain-X.X.X.tar.gz.asc samhain-X.X.X.tar.gz ${basedir}/source"
	printLOG "Installed samhain (X.X.X) source"
	return 0
    fi

    if test -f "samhain-${src_version}.tar.gz"
    then
	:
    else
	printFATAL "failed: $command $location"
    fi

    size=`du -s -k "samhain-${src_version}.tar.gz" | awk '{ print $1 }'`

    if test $size -lt 100
    then
	rm -f "samhain-${src_version}.tar.gz"
	printFATAL "failed: $command $location"
    else
	printLOG   "Downloaded to samhain-${src_version}.tar.gz (${size} kB)"
    fi

    files=`gunzip -c "samhain-${src_version}.tar.gz" | tar -tvf - 2>/dev/null`
    sig=`echo $files | egrep ' samhain.*tar\.gz\.asc$' 2>/dev/null`
    sig_version=`echo $files | egrep ' samhain.*tar\.gz\.asc$' 2>/dev/null | sed 's/.*samhain\-//g' | sed 's/\.tar\.gz\.asc//g'`
    if test x"$sig" = x
    then
	rm -f "samhain-${src_version}.tar.gz"
	printFATAL "downloaded file does not contain a PGP signature"
    fi

    if test x"${sig_version}" = x
    then
	rm -f "samhain-${src_version}.tar.gz"
	printFATAL "cannot determine samhain version from downloaded file"
    fi

    if test x"${src_version}" != xcurrent
    then
	if test x"${src_version}" != x"${sig_version}"
	then
	    rm -f "samhain-${src_version}.tar.gz"
	    printFATAL "downloaded version (${sig_version}) != requested version (${src_version})"
	fi
    fi

    printINFO "Source in tarball is version ${sig_version}"
    printINFO "Unpacking to ${basedir}/source"

    cd "${tmpD}" || { 
	rm -f "${basedir}/tmp/samhain-${src_version}.tar.gz"
	printFATAL "could not cd to ${tmpD}"
	}

    gunzip -c "${basedir}/tmp/samhain-${src_version}.tar.gz" | tar -xf - 

    rm -f "${basedir}/tmp/samhain-${src_version}.tar.gz"

    if test -f "samhain-${sig_version}.tar.gz"
    then
	if test -f "samhain-${sig_version}.tar.gz.asc"
	then
	    :
	else
	    printFATAL "not found in source: PGP signature samhain-${sig_version}.tar.gz.asc"
	fi
    else
	printFATAL "not found in source: samhain-${sig_version}.tar.gz"
    fi


    printINFO "Checking PGP signature" 
    sig_lines=`(LANG="C"; gpg --status-fd 1 --verify "samhain-${sig_version}.tar.gz.asc" "samhain-${sig_version}.tar.gz" 2>/dev/null)`
    sig_ok=`echo ${sig_lines} | grep 'GOODSIG'`

    sig_nokey=`echo ${sig_lines} | grep 'NO_PUBKEY'`

    if test x"${sig_nokey}" != x
    then
	printWARNING "Public key (ID 0F571F6C) not found, trying to import it."
	gpg --import ${basedir}/private/0F571F6C.asc 2>&5
	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')`
    fi

    if test x"${sig_ok}" = x
    then
	(LANG="C"; gpg --verify "samhain-${sig_version}.tar.gz.asc" "samhain-${sig_version}.tar.gz")
	printFATAL "no good signature"
    fi

    cp  "samhain-${sig_version}.tar.gz"  "samhain-${sig_version}.tar.gz.asc" \
	${basedir}/source/ || \
	printFATAL "failed: cp samhain-${sig_version}.tar.gz samhain-${sig_version}.tar.gz.asc ${basedir}/source/"
	      
    printLOG "Installed samhain source (version=${sig_version})"

    return 0
}