File: postinst

package info (click to toggle)
quake2-data 9
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 112 kB
  • ctags: 19
  • sloc: sh: 421; exp: 106; makefile: 55
file content (336 lines) | stat: -rwxr-xr-x 8,034 bytes parent folder | download
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/bin/sh
# postinst script for quake2-data
#
# see: dh_installdeb(1)

# die if things go wrong
set -e

# source the debconf library
. /usr/share/debconf/confmodule

sharefile=q2-314-demo-x86.exe
sharemd5="4d1cd4618e80a38db59304132ea0856c"
pointfile=q2-3.20-x86-full-ctf.exe
pointmd5="490557d4a90ff346a175d865a2bade87"

sharepakmd5="27d77240466ec4f3253256832b54db8a"
cdrompakmd5="1ec55a724dc3109fd50dde71ab581d70"
pointpakmd5="42663ea709b7cd3eb9b634b36cfecb1a"

BASE=/usr/lib/games/quake2/baseq2
DOC=/usr/share/doc/quake2-data
CTF=/usr/lib/games/quake2/ctf

inst() {
	_FILE=$1
	_DEST=$2

	# check if the source is on the cdrom
	db_get quake2-data/cdromdir
	_CDROMDIR="$RET"
	_PANTS=`echo $_FILE | sed "s#$_CDROMDIR##"`
	_SRCDIR=`echo $_FILE | sed "s#$_PANTS##"`

	if [ -e "$_FILE" ]; then 
		_DESTFILE="$_DEST/`basename $_FILE`"
		if [ "$NOCOPY" = "false" -a "$_CDROMDIR" = "$_SRCDIR" ]; then
			# check that we havent already installed it
			l=`readlink $_DESTFILE || true`
			if [ "$l" != "$_FILE" ]; then
				ln -sf $_FILE $_DESTFILE
			fi
		else
			# check that we haven't already installed it
			_SRCSUM=`getsum $_FILE`
			_DESTSUM=`getsum $_DESTFILE`
			if [ "$_SRCSUM" != "$_DESTSUM" ]; then
				install -p -m 644 -o root -g games $_FILE $_DESTFILE
			fi
		fi
	fi
}

download() {
	#wget --directory-prefix $STORAGE -c $mirror$name
	_STORAGE=$1
	_FILE=$2
	db_get quake2-data/mirror
	_MIRROR="$RET"
	echo "Downloading $_FILE from $_MIRROR..."
	wget --dot-style=mega --directory-prefix $_STORAGE -c $_MIRROR$_FILE
	echo "done."
}

do_install() {
	_NAME=$1
	_SRCBASE=$2
	_SRCDOC=$3
	_SRCCTF=$4
	
	echo "Installing data from $_NAME"

	# base files
	if [ -n "$_SRCBASE" -a -d "$_SRCBASE" ]; then
		for i in $_SRCBASE/*.pak $_SRCBASE/maps.lst ; do
			inst $i $BASE
		done
	fi

	# capture the flag
	if [ -n "$_SRCCTF" -a -d "$_SRCCTF" ]; then
		for i in $_SRCCTF/*.pak ; do
			inst $i $CTF
		done
		install -p -m 644 $_SRCCTF/readme.txt $DOC/README.ctf
	fi

	# full motion videos
	if [ -n "$_SRCBASE/video" ]; then
		for i in $_SRCBASE/video/*.cin ; do
			inst $i $BASE/video
		done
	fi
	
	# documentation
	if [ -n "$_SRCDOC" -a -d "$_SRCDOC" ]; then
		for i in $_SRCDOC/*.txt ; do
			inst $i $DOC
		done
		mv $DOC/readme.txt $DOC/README

		if [ -d "$_SRCDOC/quake2_manual" -a ! -e "$DOC/quake2_manual" ]; then
			# only install the manual once
			inst $_SRCDOC/Manual.html $DOC
			install -d -m 755 $DOC/quake2_manual
			install -d -m 755 $DOC/quake2_manual/images
			for i in $_SRCDOC/quake2_manual/*.html ; do
				inst $i $DOC/quake2_manual
			done
			for i in $_SRCDOC/quake2_manual/images/*.gif ; do
				inst $i $DOC/quake2_manual/images
			done
		fi
	fi

	# player models
	for i in `find $_SRCBASE/players -type d -mindepth 1 | xargs -n 1 basename` ; do
		install -d -m 755 -o root -g games $BASE/players/$i
		for j in `find $_SRCBASE/players/$i -type f | sed 's/^.*players\///'` ; do
			inst $_SRCBASE/players/$j $BASE/players/$i
		done
	done
}

tempdir() {
	_TEMPDIR=`tempfile --directory $1 --prefix quake2-data`
	# kill off fresh tempfile
	rm $_TEMPDIR
	mkdir $_TEMPDIR
	echo $_TEMPDIR
}

validmd5() {
	_FILE=$1
	_SUM=$2

	check=`getsum $_FILE`
	if [ "$check" = "$_SUM" ]; then
		echo true
	else
		echo false
	fi
}

getsum() {
	_FILE=$1

	if [ -e "$_FILE" ]; then
		md5sum $_FILE | cut -f1 -d' '
	fi
}

pushdir() {
	OLDDIR=`pwd`
	cd $1
}

popdir() {
	cd $OLDDIR
}

# versions <= -5 had a bug (#128934) in the player model install
# because it overwrote file data, it's easier just to nuke this lot
# and install again
clean_players() {
	find $BASE/players -name '*.md2' -o -name '*.pcx' -print0 | xargs -0 rm
}

# wrapper around dpkg --compare-versions to get the FUCKING RETURN CODE


# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see /usr/share/doc/packaging-manual/
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

case "$1" in
    configure)
		# if the old version is 5 or lower, then clean up the player models
		if dpkg --compare-versions "$2" lt-nl 6 ; then
			clean_players
		fi

		# first decide if we're going to install the full or shareware version

		# if the first question wasn't answered, then die.
		db_fget quake2-data/instmethod seen
		if [ "$RET" = "false" ]; then
			exit
		fi

		db_get quake2-data/instmethod
		INSTMETHOD="$RET"

		db_get quake2-data/copyfiles
		NOCOPY="$RET"

		DOWNLOAD=0
		
		if [ "$INSTMETHOD" = "download shareware data" ]; then

		    # shareware install

			# check if it's already installed

			VALID=`validmd5 $BASE/pak0.pak $sharepakmd5`
			if dpkg --compare-versions "$2" ge-nl 6 && [ "$VALID" = "true" ]; then
				echo "Shareware data already installed."
			else
			
				db_get quake2-data/storage
				STORAGE="$RET"

				if [ -z "$STORAGE" ]; then
					STORAGE="/root"
				fi

				#get shareware data
				VALID=`validmd5 $STORAGE/$sharefile $sharemd5`
				if [ ! -e "$STORAGE/$sharefile" -o "$VALID" = "false" ]; then
					download $STORAGE $sharefile
					DOWNLOAD=1
				fi
				
				#get a suitable tmpdir
				SRCDIR=`tempdir $STORAGE`
				#unpack the shareware data
				pushdir $SRCDIR
				unzip $STORAGE/$sharefile > /dev/null
				#copy data to dest dir
				do_install $sharefile $SRCDIR/Install/Data/baseq2 $SRCDIR/Install/Data/DOCS ""
				#clean up tmpdir
				popdir
				rm -r $SRCDIR

			fi # already installed
			
		elif [ "$INSTMETHOD" = "install from CD-ROM" ]; then

			# cdrom install
			
			db_get quake2-data/cdromdir
			CDROMDIR="$RET"

#FIXME: check that cdrom is mounted

			# check if it's already installed
			VALID=`validmd5 $BASE/pak0.pak $cdrompakmd5`
			if [ "$VALID" = "true" ]; then
				echo "CD-ROM data already installed."
			else

				#install data -- check for case of directories
				if [ -d "$CDROMDIR/dnstall/data/baseq2" ]; then
					do_install "CD-ROM" $CDROMDIR/install/data/baseq2 $CDROMDIR/install/data/docs ""
				else
					do_install "CD-ROM" $CDROMDIR/Install/Data/baseq2 $CDROMDIR/Install/Data/DOCS ""
				fi
			fi

			#do pointrelease
			db_get quake2-data/pointrelease
			POINTRELEASE="$RET"

			if [ "$POINTRELEASE" = "true" ]; then

				# check if it's alredy installed
				VALID=`validmd5 $BASE/pak1.pak $pointpakmd5`
				if [ "$VALID" = true ]; then
					echo "Point release already installed"
				else

					db_get quake2-data/storage
					STORAGE="$RET"

					if [ -z "$STORAGE" ]; then
						STORAGE="/root"
					fi

					#get pointrelease data
					VALID=`validmd5 $STORAGE/$pointfile $pointmd5`
					if [ ! -e "$STORAGE/$pointfile" -o "$VALID" = "false" ]; then
						download $STORAGE $pointfile
						DOWNLOAD=1
					fi

					#get a suitable tmpdir
					SRCDIR=`tempdir $STORAGE`
					#unpack the shareware data
					pushdir $SRCDIR
					unzip $STORAGE/$pointfile > /dev/null
					#copy data to dest dir
					do_install $pointfile $SRCDIR/baseq2 $SRCDIR/DOCS $SRCDIR/ctf
					#clean up
					popdir
					rm -r $SRCDIR

				fi # already installed
			fi
		fi

		#keep a record of installation
		#echo "OLDDOWNLOAD=$DOWNLOAD" > /etc/quake2-data.conf
		#echo "OLDINSTMETHOD=\"$INSTMETHOD\"" >> /etc/quake2-data.conf
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0