1#!/bin/sh
2# postinst script for eternallands-data
3#
4# see: dh_installdeb(1)
5
6set -e
7
8# summary of how this script can be called:
9#        * <postinst> `configure' <most-recently-configured-version>
10#        * <old-postinst> `abort-upgrade' <new version>
11#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12#          <new-version>
13#        * <postinst> `abort-remove'
14#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
15#          <failed-install-package> <version> `removing'
16#          <conflicting-package> <version>
17# for details, see http://www.debian.org/doc/debian-policy/ or
18# the debian-policy package
19
20
21case "$1" in
22	configure)
23
24	TARGETDIR="/usr/share/games/EternalLands"
25	CACHEDIR="/var/cache/eternallands"
26	DOWNLOADURL="http://twinmoons.org.uk/el/rel/195"
27	DOWNLOADMAIN="eternallands-data_1.9.5.9-1.zip"
28	MD5SUMMAIN="82c0b5601faed923fb30d01906e25ca3"
29	# post release updates
30	#DOWNLOADUPDATE1=""
31	#MD5SUMUPDATE1=""
32
33	[ -f ~paul/el/installpkg/localdownload ] && DOWNLOADURL="https://harry/~paul/el"
34
35	mkdir -p $CACHEDIR
36	cd $CACHEDIR
37
38	# remove old downloads
39	rm -f el_195_data_files.zip el_195_1_data_files.zip el_195_p7_data_files.zip \
40		el_195_latest_data.zip el_data_20201214.zip eternallands-data_1.9.5.9.zip
41
42	# if we already have an archive check the md5sum is ok and remove if not
43	[ ! -f "$DOWNLOADMAIN" ] || echo "$MD5SUMMAIN  $DOWNLOADMAIN" | md5sum -c - || rm -fv $DOWNLOADMAIN
44	# post release updates
45	#[ ! -f "$DOWNLOADUPDATE1" ] || echo "$MD5SUMUPDATE1  $DOWNLOADUPDATE1" | md5sum -c - || rm -fv $DOWNLOADUPDATE1
46
47	# Use existing file or download it
48	if [ ! -f "$DOWNLOADMAIN" ]
49	then
50		wget -P "." -v --progress="dot:mega" --no-check-certificate $DOWNLOADURL/$DOWNLOADMAIN
51		echo "$MD5SUMMAIN  $DOWNLOADMAIN" | md5sum -c -
52	fi
53	# post release updates
54	#if [ ! -f "$DOWNLOADUPDATE1" ]
55	#then
56	#	wget -P "." -v --progress="dot:mega" --no-check-certificate $DOWNLOADURL/$DOWNLOADUPDATE1
57	#	echo "$MD5SUMUPDATE1  $DOWNLOADUPDATE1" | md5sum -c -
58	#fi
59
60	# unnpack the archive
61	UNPACKDIR="`mktemp -d /tmp/eternallands-data.XXXXXXXXXX`"
62	cd $UNPACKDIR
63	unzip -q $CACHEDIR/$DOWNLOADMAIN
64	# post release updates
65	#cd el_data
66	#unzip -q -o $CACHEDIR/$DOWNLOADUPDATE1
67
68	# fix el.ini and server.lst, remove unneeded files and set the permissions
69	cd $UNPACKDIR/el_data
70	rm -f *.dll *.exe el.*.bin
71	sed -i 's/^#data_dir.*$/#data_dir = \/usr\/share\/games\/EternalLands/g' el.ini
72	sed -i 's/^#browser.*$/#browser = x-www-browser/g' el.ini
73	sed -i 's/^#use_new_selection.*$/#use_new_selection = 1/g' el.ini
74	grep -v ^official servers.lst > sl
75	mv sl servers.lst
76	chown -R root:root .
77	chmod -R a=rX .
78
79	# make the file lists
80	FILELIST="eternallands-data.filelist"
81	DIRLIST="eternallands-data.dirlist"
82	find . -type f -exec echo \"{}\" \; > $TARGETDIR/$FILELIST
83	find . -type d ! -name "." -exec echo \"{}\" \; | sort -r > $TARGETDIR/$DIRLIST
84
85	# remove any existing files in the lists then move the new files into the target directory
86	cd $TARGETDIR/
87	[ ! -s $FILELIST ] || cat $FILELIST | xargs rm -f || true
88	[ ! -s $DIRLIST ] || cat $DIRLIST | xargs rmdir --ignore-fail-on-non-empty > /dev/null 2>&1 || true
89	chmod -R +w .
90	cp --remove-destination -rpf $UNPACKDIR/el_data/* .
91
92	rm -rf $UNPACKDIR
93
94	;;
95
96	abort-upgrade|abort-remove|abort-deconfigure)
97	;;
98
99	*)
100		echo "postinst called with unknown argument \`$1'" >&2
101		exit 1
102	;;
103esac
104
105# dh_installdeb will replace this with shell code automatically
106# generated by other debhelper scripts.
107
108#DEBHELPER#
109
110exit 0
111