summaryrefslogtreecommitdiff
blob: 0c12ee44c03955e93dbb59303bdccaabb8dbc086 (plain)
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
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils games

MY_P="${PN}-patch-${PV}.tar.gz"
DESCRIPTION="Uplink is a commercial hacking strategy game."
HOMEPAGE="http://www.uplink.co.uk/"
SRC_URI="http://www.uplink.co.uk/test/${MY_P}"

LICENSE="uplink"
SLOT="0"
KEYWORDS="-* ~amd64 ~x86"
RESTRICT="strip mirror"
IUSE=""

RDEPEND=""
DEPEND="${RDEPEND}
	app-arch/unzip"

dir=${GAMES_PREFIX_OPT}/${PN}
Ddir=${D}/${dir}

upl_versions=(
	"1.0"
	"1.31"
)
upl_files=(
	"uplink.zip"
	"uplink-complete-1.31.sh"
)

uplink_find_file() {
	local searchdir=${1}
	local i=0

	for f in ${upl_files[*]}
	do
		if [ -e "${searchdir}/${f}" ] ; then
			export upl_file=${f}
			export upl_version=${upl_versions[${i}]}
		else
			i=$((${i}+1))
		fi
	done
}

pkg_setup() {
	export upl_version="0"
	export upl_file=""

	games_pkg_setup

	# If the file still exists from an earlier install, assume its the same
	# Otherwise copy it from the CD
	uplink_find_file "${PORTAGE_ACTUAL_DISTDIR}"

	# No local copy - try the CD drive
	if [[ "${upl_version}" == "0" ]] ; then
		cdrom_get_cds linux
		local searchdir="${CDROM_ROOT}/linux"
		uplink_find_file "${searchdir}"

		if [[ "${upl_version}" != "0" ]] ; then
			einfo "Found the original Uplink CD (${upl_version})"
			einfo "Copying ${upl_file} to ${PORTAGE_ACTUAL_DISTDIR}"
			cp "${searchdir}/${upl_file}" "${PORTAGE_ACTUAL_DISTDIR}/${upl_file}"
		fi

	fi

	if [[ "${upl_version}" == "0" ]] ; then
		eerror "Unable to find a known Uplink CD ROM"
		eerror "If you believe you have a valid Uplink CD ROM, please report this bug attaching"
		eerror " details of the name and location of the linux installer on the CD ROM"
		die
	fi
}

src_install() {
	dodir "${dir}"
	cd "${Ddir}"

	if [[ "${upl_file}" == "uplink.zip" ]] ; then
		# Unzip basic uplink
		unzip -qq "${PORTAGE_ACTUAL_DISTDIR}/${upl_file}"
	else
		# Assume it's a .sh

		# Create a temporary directory to extract the .sh to
		cd "${T}"
		# Extract the .sh using its own routines
		"${PORTAGE_ACTUAL_DISTDIR}/${upl_file}" --noexec --keep --target .
		# Delete unnecessary files and move the executable script to where it expects to be
		rm -rf setup.data setup.sh
		mv bin/Linux/x86/uplink .
		rm -rf bin
		# Copy everything to Ddir
		cp -pPR * "${Ddir}"
		# cd out of T to avoid errors when we delete it.
		cd "${Ddir}"
		# Delete the temporary files
		rm -rf "${T}"
	fi

	if [[ "${upl_version}" != "1.53" ]] ; then
		# Copy over patch files
		cp -pPR "${WORKDIR}"/uplink/* ./
		rm sounds.dat
		mv *.dat lib/
	fi


	# Correct permissions
	chown -R root:games "${Ddir}"
	chmod -R 640 "${Ddir}/*"
	chmod 750 "${Ddir}/uplink"
	if [[ -e "${Ddir}/lib" ]] ; then
		chmod 750 "${Ddir}"/lib
		if [[ -e "${Ddir}"/lib/uplink.bin.x86 ]] ; then
			chmod 750 "${Ddir}"/lib/uplink.bin.x86
		fi
	fi

	games_make_wrapper uplink ./uplink "${dir}" "${dir}"
	make_desktop_entry uplink "Uplink" "" "Game"
}

pkg_postinst() {
	games_pkg_postinst
	if [[ "${upl_version}" != "1.53" ]] ; then
		einfo "The first time you start uplink, it will patch itself and then exit. Restart the game to play."
		einfo "The location of the data files has changed. If you have any custom modifications you will need to move them into the lib/ directory."
	fi
}