aboutsummaryrefslogtreecommitdiff
blob: 588c79dce6ecf31f8d5e055aede1825d9fbc3c14 (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
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{10..12} )

inherit python-single-r1 readme.gentoo-r1 systemd tmpfiles

DESCRIPTION="‎Modern, responsive, cross-platform, self-hosted web IRC client"
HOMEPAGE="https://thelounge.chat/"

SRC_URI="
	https://github.com/thelounge/thelounge/archive/refs/tags/v${PV/_rc/-rc.}.tar.gz -> ${P}.tar.gz
	https://github.com/rahilarious/gentoo-distfiles/releases/download/${P}/deps.tar.xz -> ${P}-deps.tar.xz
	sqlite? ( https://github.com/rahilarious/gentoo-distfiles/releases/download/${P}/sqlite.tar.xz -> ${P}-sqlite.tar.xz )
"

S="${WORKDIR}/${PN}-${PV/_rc/-rc.}"
LICENSE="BSD MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE="+sqlite"
REQUIRED_USE="sqlite? ( ${PYTHON_REQUIRED_USE} )"

RDEPEND="
	acct-user/${PN}
	acct-group/${PN}
	>=net-libs/nodejs-18
	sqlite? ( dev-db/sqlite:3= )
"
DEPEND="${RDEPEND}"
BDEPEND="
	sqlite? ( ${PYTHON_DEPS} )
	>=net-libs/nodejs-18[npm]
	sys-apps/yarn
"

DOC_CONTENTS="\n
##### Defaults #####\n
Data directory: /var/lib/${PN}\n
Listens on: 0.0.0.0:9000\n
Log file (openrc): /var/log/${PN}.log\n
Config file: /var/lib/${PN}/config.js\n
\n
##### Initialization #####\n
Run \`THELOUNGE_HOME=/var/lib/${PN} ${PN} add <user>\`
"

mooyarn() {
	use !sqlite && local YARN_OPTS="--ignore-optional"
	yarn --verbose  --non-interactive --frozen-lockfile --cache-folder "${WORKDIR}"/yarn-cache --offline \
		 --ignore-scripts ${YARN_OPTS} "${@}" || die
}

src_prepare() {
	default
	use !sqlite && { sed -i -e 's|\["sqlite", |\[|g;' defaults/config.js  || die ; }

}
src_compile() {
	# thelounge build
	mooyarn install
	NODE_ENV=production mooyarn build
	local BUILT_TAR=$(realpath $(npm pack || die))
	# thelounge install
	mkdir -v moobuild && cp -v {package.json,yarn.lock} moobuild/ || die
	pushd moobuild || die
	NODE_ENV=production mooyarn add file:${BUILT_TAR:?}

	if use sqlite; then
		# sqlite3 build
		pushd node_modules/sqlite3 || die
		export \
			npm_config_cache="${WORKDIR}"/npm-cache \
			npm_config_nodedir="${EPREFIX}"/usr \
			NODE_GYP_FORCE_PYTHON="$(command -v ${PYTHON_SINGLE_TARGET/_/.})" \
			|| die
		npm --verbose --offline install --build-from-source --sqlite="${EPREFIX}"/usr || die
		# sqlite3 cleanup
		rm -rf node_modules || die
		find build* -type f -not -path build/Release/node_sqlite3.node -delete || die
		popd || die
	fi
	popd || die

}

src_install() {
	insinto /usr/$(get_libdir)/node_modules/"${PN}"
	doins -r moobuild/node_modules

	fperms 755 /usr/$(get_libdir)/node_modules/"${PN}"/node_modules/"${PN}"/index.js
	dosym -r /usr/$(get_libdir)/node_modules/"${PN}"/node_modules/"${PN}"/index.js /usr/bin/"${PN}"

	systemd_newunit "${FILESDIR}"/"${PN}"-4.4.1.service "${PN}".service
	systemd_newuserunit "${FILESDIR}"/"${PN}"-4.4.1-user.service "${PN}".service
	newinitd "${FILESDIR}"/"${PN}"-4.4.1.initd "${PN}"
	newconfd "${FILESDIR}"/"${PN}"-4.4.1.confd "${PN}"
	newtmpfiles "${FILESDIR}"/"${PN}"-4.4.1-tmpfiles.conf "${PN}".conf
	insinto /etc/logrotate.d
	newins "${FILESDIR}"/"${PN}"-4.4.1.logrotate "${PN}"

	readme.gentoo_create_doc
}

pkg_postinst() {
	tmpfiles_process "${PN}".conf
	readme.gentoo_print_elog
}