summaryrefslogtreecommitdiff
blob: 7d8dcc0bde07076a64bc636f054d4ccea543e128 (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
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
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

JAVA_PKG_IUSE="doc source test"
JAVA_TESTING_FRAMEWORKS="junit-4"

inherit java-pkg-2 java-pkg-simple systemd verify-sig

DESCRIPTION="An encrypted network without censorship"
HOMEPAGE="https://freenetproject.org/"
# Currently we bundle a binary version of pebble, see bug #905005
PEV="3.1.6"
SRC_URI="https://github.com/hyphanet/fred/releases/download/build0${PV#*p}/freenet-build0${PV#*p}-source.tar.bz2
	https://github.com/hyphanet/seedrefs/archive/build01480.tar.gz -> seednodes-0.7.5_p1480.tar.gz
	https://repo1.maven.org/maven2/io/pebbletemplates/pebble/${PEV}/pebble-${PEV}.jar
	mirror://gentoo/freenet-ant-1.7.1.jar
	verify-sig? (
		https://github.com/hyphanet/fred/releases/download/build0${PV#*p}/freenet-build0${PV#*p}-source.tar.bz2.sig
	)"
S="${WORKDIR}/freenet-build0${PV#*p}"

# 'SPDX-License-Identifier: BSD-3-Clause'
# needed for pebble is 'BSD' in Gentoo.
LICENSE="GPL-2+ GPL-2 MIT BSD-2 BSD Apache-2.0"
SLOT="0"
KEYWORDS="amd64 ~arm ~arm64 ~x86"
IUSE="+nss"

CP_DEPEND="
	dev-java/bcprov:0
	dev-java/commons-compress:0
	dev-java/fec:0
	dev-java/freenet-ext:29
	dev-java/jbitcollider-core:0
	dev-java/jna:4
	dev-java/lzma:0
	dev-java/lzmajio:0
	dev-java/mersennetwister:0
	dev-java/java-service-wrapper:0
	dev-java/unbescape:0
"

DEPEND="
	>=virtual/jdk-1.8:*
	${CP_DEPEND}
	test? (
		dev-java/hamcrest:0
		dev-java/mockito:0
		dev-java/objenesis:0
		net-libs/NativeThread:0
	)
"
RDEPEND="
	acct-user/freenet
	acct-group/freenet
	>=virtual/jre-1.8:*
	${CP_DEPEND}
	nss? ( dev-libs/nss )
"
BDEPEND="
	app-arch/unzip
	verify-sig? ( sec-keys/openpgp-keys-freenet )
"
PDEPEND="net-libs/NativeThread:0"

DOCS=(
	AUTHORS
	CONTRIBUTING.md
	NEWS.md
	README.md
	SECURITY.md
)

PATCHES=(
	"${FILESDIR}/freenet-0.7.5_p1497-ignore-failing-tests.patch"
)

JAVA_CLASSPATH_EXTRA="java-service-wrapper"
# pebble packaging resistant
JAVA_GENTOO_CLASSPATH_EXTRA="${DISTDIR}/pebble-${PEV}.jar"
JAVA_RESOURCE_DIRS="res"
JAVA_SRC_DIR="src"
JAVA_TEST_GENTOO_CLASSPATH="
	hamcrest
	junit-4
	mockito
	objenesis
"
# Yes, both variables point to the same directory
# https://github.com/hyphanet/fred/blob/build01497/build.gradle#L169-L173
JAVA_TEST_RESOURCE_DIRS="test"
JAVA_TEST_SRC_DIR="test"

VERIFY_SIG_OPENPGP_KEY_PATH="${BROOT}/usr/share/openpgp-keys/freenetproject.org.asc"
src_unpack() {
	if use verify-sig; then
		verify-sig_verify_detached \
			"${DISTDIR}"/freenet-build0${PV#*p}-source.tar.bz2 \
			"${DISTDIR}"/freenet-build0${PV#*p}-source.tar.bz2.sig
	fi
	unpack freenet-build0${PV#*p}-source.tar.bz2
	unpack seednodes-0.7.5_p1480.tar.gz
}

src_prepare() {
	default
	java-pkg-2_src_prepare

	# Could not get resource : freenet/l10n/freenet.l10n.pt-PT.properties
	# https://github.com/hyphanet/fred/pull/500
	mv src/freenet/l10n/freenet.l10n.pt{_,-}PT.properties || die

	# java-pkg-simple wants resources in JAVA_RESOURCE_DIRS
	mkdir res || die
	pushd src  > /dev/null || die
		find -type f \
			! -name '*.java' \
			! -name 'package.html' \
			! -path '*/simulator/readme.txt' \
			| xargs cp --parent -t ../res || die
	popd > /dev/null || die

	mkdir "${JAVA_RESOURCE_DIRS}/META-INF" || die
	cat > "${JAVA_RESOURCE_DIRS}/META-INF/MANIFEST.MF" <<- EOF || die
		Add-opens: java.base/java.lang java.base/java.util java.base/java.io
	EOF

	cat "${WORKDIR}"/seedrefs-build01480/* > "${S}"/seednodes.fref
	cp "${FILESDIR}"/freenet-0.7.5_p1491-wrapper.conf freenet-wrapper.conf || die
	cp "${FILESDIR}"/run.sh-20090501 run.sh || die

	sed -i -e "s:=/usr/lib:=/usr/$(get_libdir):g" \
		freenet-wrapper.conf || die "sed failed"

	echo "wrapper.java.classpath.1=/usr/share/freenet/lib/freenet.jar" >> freenet-wrapper.conf || die
	if use nss; then
		echo "wrapper.java.additional.11=-Dfreenet.jce.use.NSS=true" >> freenet-wrapper.conf || die
	fi
}

src_compile() {
	java-pkg-simple_src_compile

	# Moved here because of using JAVA_GENTOO_CLASSPATH which is populated by java-pkg_gen-cp.
	local i=2 pkg jars jar
	local ifs_original=${IFS}
	IFS=","
	for pkg in ${JAVA_GENTOO_CLASSPATH} ; do
		jars="$(java-pkg_getjars ${pkg})"
		for jar in ${jars} ; do
			echo "wrapper.java.classpath.$((i++))=${jar}" >> freenet-wrapper.conf || die
		done
	done
	IFS=${ifs_original}
	echo "wrapper.java.classpath.$((i++))=/usr/share/freenet/lib/ant.jar" >> freenet-wrapper.conf || die
	echo "wrapper.java.library.path.2=/usr/$(get_libdir)/java-service-wrapper" >> freenet-wrapper.conf || die
	echo "wrapper.java.library.path.3=/usr/$(get_libdir)/jna-4" >> freenet-wrapper.conf || die

	cp "${DISTDIR}"/freenet-ant-1.7.1.jar lib/ant.jar || die
}

src_test() {
	JAVA_TEST_EXTRA_ARGS=(
		-Djava.library.path="${EPREFIX}/usr/$(get_libdir)/jna-4/"
		-Djna.nosys=false
		-Dnetworkaddress.cache.negative.ttl=0
		-Dnetworkaddress.cache.ttl=0
		# https://github.com/hyphanet/fred/blob/build01497/build.gradle#L194-L196
		# "test.l10npath_main" reads from the JAR file.
		-Dtest.l10npath_test="freenet/l10n/"
		-Dtest.l10npath_main="freenet/l10n/"
	)
	local vm_version="$(java-config -g PROVIDES_VERSION)"
	if ver_test "${vm_version}" -ge 17; then
		JAVA_TEST_EXTRA_ARGS+=(
			--add-opens=java.base/java.io=ALL-UNNAMED
			--add-opens=java.base/java.lang=ALL-UNNAMED
			--add-opens=java.base/java.util=ALL-UNNAMED
		)
	fi

	pushd test > /dev/null || die
		local JAVA_TEST_RUN_ONLY=$(find * \
			-type f  -name "*Test.java" \
			)
		JAVA_TEST_RUN_ONLY="${JAVA_TEST_RUN_ONLY//.java}"
		JAVA_TEST_RUN_ONLY="${JAVA_TEST_RUN_ONLY//\//.}"
	popd > /dev/null || die
	java-pkg-simple_src_test
}

src_install() {
	java-pkg-simple_src_install

	java-pkg_newjar "${DISTDIR}"/freenet-ant-1.7.1.jar ant.jar

	doinitd "${FILESDIR}"/freenet

	systemd_dounit "${FILESDIR}"/freenet.service

	insinto /etc
	doins freenet-wrapper.conf
	insinto /var/freenet
	doins run.sh seednodes.fref
	fperms +x /var/freenet/run.sh
}

pkg_postinst() {
	elog " "
	elog "1. Start freenet with rc-service freenet start."
	elog "2. Open localhost:8888 in your browser for the web interface."
	#workaround for previously existing freenet user
	[[ $(stat --format="%U" /var/freenet) == "freenet" ]] || chown \
		freenet:freenet /var/freenet
}

pkg_postrm() {
	if ! [[ -e /usr/share/freenet/lib/freenet.jar ]] ; then
		elog " "
		elog "If you dont want to use freenet any more"
		elog "and dont want to keep your identity/other stuff"
		elog "remember to do 'rm -rf /var/freenet' to remove everything"
	fi
}