summaryrefslogtreecommitdiff
blob: c6d4fe68eaaa020f200d780df9d86e4ad46b4936 (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
137
138
139
140
141
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-p2p/freenet/freenet-0.5.2.1-r8.ebuild,v 1.5 2004/06/25 00:31:07 agriffis Exp $

inherit eutils

IUSE=""

S=${WORKDIR}/${PN}

DESCRIPTION="large-scale peer-to-peer network that creates a massive virtual information store open to anyone"
SRC_URI="mirror://sourceforge/freenet/${P}.tar.gz"
RESTRICT="nomirror"
HOMEPAGE="http://freenetproject.org/"

SLOT="0"
KEYWORDS="x86 ~ppc ~amd64"
LICENSE="GPL-2"

DEPEND="virtual/jre
	>=sys-apps/sed-4
	app-admin/sudo"

src_install() {
	exeinto /usr/bin
	doexe ${FILESDIR}/start-freenet.sh

	dodoc README

	dodir /var/freenet/stats /var/freenet/store
	keepdir /var/freenet/stats /var/freenet/store

	insinto /usr/lib/freenet
	doins freenet.jar freenet-ext.jar

	insinto /etc/conf.d
	newins ${FILESDIR}/conf.freenet freenet

	exeinto /etc/init.d
	newexe ${FILESDIR}/rc.freenet5 freenet
}

pkg_preinst() {
	enewgroup freenet
	enewuser freenet -1 /bin/bash /var/freenet freenet
}

pkg_postinst() {
	if [ -f /etc/freenet.conf ];then
		chmod 664 /etc/freenet.conf
		chown root:freenet /etc/freenet.conf
	fi
	chown -R freenet:freenet /var/freenet
	einfo "Congratulations on merging freenet, please run"
	einfo "# ebuild ${EBUILD} config"
	einfo "to update freenet to the latest jars and seednodes."
	einfo "This step is also necessary to configure freenet for"
	einfo "first use.  You may also run this step again at any time"
	einfo "to get any updates available to freenet"
	ewarn "Anyone who merged a freenet prior to 0.5.2.1-r3 will"
	ewarn "need to change their logFile setting to /var/freenet/freenet.log"
	ewarn "in order for freenet to continue to function"
}

pkg_postrm() {
	if [ -z has_version ]; then
		einfo "Please remove /var/freenet manually if you are't going to"
		einfo "continue to use Freenet on this machine!"
	fi
}

pkg_config() {
	YN="X"
	while [ "${YN}" != "y" -a "${YN}" != "Y" -a "${YN}" != "n" -a "${YN}" != "N" -a "${YN}" != "" ]; do
		einfo "Would you like to update freenet files now? [Y/n]"
		read YN
	done
	if [ -z "$(echo ${YN}|sed -e s/y//i)" ];then
		einfo "Press U within 2 seconds to try an unstable snapshot"
		read -n 1 -t 2 YN
		if [ "${YN}" == "U" ] || [ "${YN}" == "u" ]; then
			wget http://freenetproject.org/snapshots/freenet-unstable-latest.jar -O /usr/lib/freenet/freenet.jar
			wget http://freenetproject.org/snapshots/unstable.ref -O /var/freenet/seednodes.ref
		else
			wget http://freenetproject.org/snapshots/freenet-latest.jar -O /usr/lib/freenet/freenet.jar
			wget http://freenetproject.org/snapshots/seednodes.ref -O /var/freenet/seednodes.ref
		fi
		touch -d "1/1/1970" /var/freenet/seednodes.ref
		chown freenet:freenet /var/freenet/seednodes.ref
	fi

	if [ -f /etc/freenet.conf ]; then
		einfo "Press C within 2 seconds to force reconfiguration of freenet"
		read -n 1 -t 2 YN
	fi
	if [ ! -f /etc/freenet.conf ] || [ "${YN}" == C ] || [ "${YN}" == "c" ]; then
		einfo "Preparing to configure freenet..."
		if [ -f /etc/freenet.conf ]; then
			cp /etc/freenet.conf .
		else
			# Pre-determine IP address
			IP="$(hostname -i)"
			declare -i DEFLP
			if [ "${RANDOM}" ]; then
				DEFLP=${RANDOM}%30000+2000
			else
				echo "no random in shell, enter a FNP port number + <ENTER>"
				read DEFLP
			fi

			cat << EOF > freenet.conf
ipAddress=${IP}
listenPort=${DEFLP}
seedFile=/var/freenet/seednodes.ref
logFile=/var/freenet/freenet.log
storeFile=/var/freenet/store
diagnosticsPath=/var/freenet/stats
routingDir=/var/freenet
nodeFile=/var/freenet/node
EOF
		fi

		CLASSPATH="/usr/lib/freenet/freenet.jar:/usr/lib/freenet/freenet-ext.jar:${CLASSPATH}"
		$(java-config --java) freenet.node.Main --config
		mv freenet.conf /etc
		sed -i -e "s/^%\(ipAddress\)/\1/" \
		       -e "s/^%\(listenPort\)/\1/" \
		       -e "s/^%\(seedFile\)/\1/" \
		       -e "s/^%\(logFile\)/\1/" \
		       -e "s/^%\(storeFile\)/\1/" \
		       -e "s/^%\(diagnosticsPath\)/\1/" \
		       -e "s/^%\(routingDir\)/\1/" \
		       -e "s/^%\(nodeFile\)/\1/" /etc/freenet.conf
		chmod 664 /etc/freenet.conf
		chown root:freenet /etc/freenet.conf
	fi
	einfo "Congratulations, freenet is configured and up to date"
	einfo "use '/etc/init.d/freenet start' to start it"
	einfo "You can always re-update/reconfigure  your freenet with:"
	einfo "# ebuild ${EBUILD} config"
}