2023-01-16 17:51:54 +01:00
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI = 8
inherit optfeature savedconfig
# NOTE: check for updates on each bump
MY_COMMIT_ASSETS = "0179793ec891856d6f37a3be16ba4c22f67a81b5"
MY_COMMIT_EMOJIS = "cae981eb4c5189ea9ea3230e83b876a5068df7d1"
DESCRIPTION = "An interplanetary microblogging platform"
HOMEPAGE = "https://misskey-hub.net/"
SRC_URI = "
https://github.com/misskey-dev/misskey/archive/refs/tags/${ PV } .tar.gz -> ${ P } .tar.gz
https://github.com/misskey-dev/assets/archive/${ MY_COMMIT_ASSETS } .tar.gz -> ${ PN } -assets-${ MY_COMMIT_ASSETS } .tar.gz
2023-01-16 18:08:05 +01:00
https://github.com/misskey-dev/emojis/archive/${ MY_COMMIT_EMOJIS } .tar.gz -> ${ PN } -emojis-${ MY_COMMIT_EMOJIS } .tar.gz
2023-01-16 17:51:54 +01:00
https://tastytea.de/files/gentoo/${ P } -deps.tar.xz
"
# NOTE: to generate the deps archive:
# export CYPRESS_CACHE_FOLDER="$(realpath ./packages-cache)"
# export npm_config_cache="$(realpath ./packages-cache)"
2023-01-16 18:35:32 +01:00
# pnpm config set store-dir "$(realpath ./packages-cache)"
2023-01-17 01:02:19 +01:00
# pnpm install --frozen-lockfile
2023-01-16 17:51:54 +01:00
# tar -caf ${P}-deps.tar.xz packages-cache
2023-01-16 18:35:32 +01:00
# unset CYPRESS_CACHE_FOLDER npm_config_cache
2023-01-16 17:51:54 +01:00
LICENSE = "GPL-3"
SLOT = "0"
2023-01-17 01:57:22 +01:00
# KEYWORDS="~amd64"
2023-01-16 17:51:54 +01:00
IUSE = "nginx +savedconfig source"
REQUIRED_USE = "savedconfig"
RESTRICT = "strip network-sandbox"
COMMON_DEPEND = "
>= net-libs/nodejs-18:= [ npm]
"
BDEPEND = "
${ COMMON_DEPEND }
dev-lang/nasm
virtual/pkgconfig
"
RDEPEND = "
${ COMMON_DEPEND }
acct-user/misskey
>= dev-db/postgresql-15
dev-db/redis
nginx? ( www-servers/nginx )
"
QA_PREBUILT = "
/opt/misskey/misskey/packages/backend/node_modules/msgpackr-extract/prebuilds/*
/opt/misskey/misskey/packages/client/node_modules/microtime/prebuilds/*
"
2023-01-17 01:02:19 +01:00
setup_pnpm( ) {
2023-01-17 16:56:17 +01:00
ewarn "This ebuild is getting more and more hacky… 🥴"
2023-01-17 01:02:19 +01:00
# use the pnpm from nodejs if it isn't installed
if ! type pnpm > /dev/null 2>& 1; then
mkdir " ${ T } " /bin || die "could not create dir in temporary directory"
ln -s /usr/$( get_libdir) /node_modules/corepack/dist/pnpm.js \
" ${ T } " /bin/pnpm || die "could not create pnpm symlink"
2023-01-17 16:02:10 +01:00
export PATH = " ${ T } /bin: ${ PATH } "
2023-01-16 19:20:11 +01:00
fi
}
2023-01-17 01:02:19 +01:00
pkg_setup( ) {
setup_pnpm
}
2023-01-16 17:51:54 +01:00
src_unpack( ) {
default
mv --no-target-directory assets-${ MY_COMMIT_ASSETS } ${ P } /${ PN } -assets \
|| die "Could not move assets"
2023-01-16 18:05:00 +01:00
mv --no-target-directory emojis-${ MY_COMMIT_EMOJIS } ${ P } /fluent-emojis \
2023-01-16 17:51:54 +01:00
|| die "Could not move emojis"
mv packages-cache " ${ T } " / || die "Could not move packages cache"
}
src_prepare( ) {
export CYPRESS_CACHE_FOLDER = " ${ T } " /packages-cache
export npm_config_cache = " ${ T } " /packages-cache
export PNPMFLAGS = "--verbose"
2023-01-16 19:32:34 +01:00
pnpm config set cache " ${ T } " /packages-cache
pnpm config set store-dir " ${ T } " /packages-cache
2023-01-16 18:19:18 +01:00
2023-01-16 17:51:54 +01:00
# use system node-gyp
PATH += ":/usr/lib64/node_modules/npm/bin/node-gyp-bin"
export npm_config_nodedir = /usr/include/node/
restore_config .config/default.yml
if [ [ ! -f .config/default.yml ] ] ; then
eerror "Edit .config/example.yml and save it to the location mentioned above"
die "No config file found"
fi
default
}
src_compile( ) {
2023-01-17 00:16:56 +01:00
pnpm ${ PNPMFLAGS } install --frozen-lockfile || die "dependency installation failed"
2023-01-16 17:51:54 +01:00
NODE_ENV = production pnpm ${ PNPMFLAGS } run build || die "build failed"
}
src_install( ) {
insinto opt/misskey/misskey
insopts -o misskey -g misskey
if use source; then
doins -r .
else
2023-01-16 19:45:30 +01:00
doins -r package.json .node-version .config built node_modules packages
2023-01-16 17:51:54 +01:00
fi
# insopts doesn't affect directories
chown --recursive misskey:misskey " ${ ED } " /opt/misskey/misskey
chmod o = " ${ ED } " /opt/misskey/misskey
newinitd " ${ FILESDIR } " /${ PN } .initd ${ PN }
if use nginx; then
sed -i 's/use logger$/use logger nginx/' " ${ ED } " /etc/init.d/${ PN } \
|| die "Could not modify OpenRC init script"
fi
einstalldocs
}
pkg_preinst( ) {
# Apparently Misskey creates files at runtime that can interfere
# after an upgrade. Normally you would run 'yarn cleanall'.
einfo "Cleaning up Misskey directory …"
2023-01-17 16:56:17 +01:00
su --shell /bin/bash --login --command \
2023-01-16 17:51:54 +01:00
"rm -rf misskey/{built,node_modules} && rm -rf misskey/packages/{backend,client,sw}/{built,node_modules}" \
misskey || die "cleanup failed"
}
pkg_postinst( ) {
# Only run migrations if database exists
2023-01-17 16:02:10 +01:00
if su --command "psql misskey -c ''" postgres; then
2023-01-16 17:51:54 +01:00
einfo "Running migration…"
2023-01-17 16:02:10 +01:00
su --shell /bin/bash --command \
2023-01-20 22:55:23 +01:00
" cd \" ${ EPREFIX } \"/opt/misskey/misskey && pnpm run migrate " \
2023-01-16 17:51:54 +01:00
misskey || die "migration failed"
else
elog " Run emerge --config ${ CATEGORY } / ${ PN } to initialise the PostgreSQL database "
fi
if use nginx; then
einfo "An nginx example config can be found at <https://misskey-hub.net/en/docs/admin/nginx.html>"
fi
optfeature "thumbnail generation support" media-video/ffmpeg
}
pkg_config( ) {
einfo "Initialising PostgreSQL database"
echo -n "password for misskey user: "
read -r MY_PASSWORD || die "Reading password failed"
2023-01-17 00:16:56 +01:00
echo " create database misskey with encoding = 'UTF8'; create user misskey with encrypted password ' ${ MY_PASSWORD } '; grant all privileges on database misskey to misskey; \q " \
2023-01-17 16:02:10 +01:00
| su --command psql postgres || die "database creation failed"
2023-01-16 17:51:54 +01:00
2023-01-17 16:02:10 +01:00
su --shell /bin/bash --command \
2023-01-20 22:55:23 +01:00
" cd \" ${ EPREFIX } \"/opt/misskey/misskey && pnpm run init " \
2023-01-16 17:51:54 +01:00
misskey || die "database initialisation failed"
ewarn "When you first start Misskey you will be asked to add an admin account via the web interface, and registrations are enabled."
ewarn "Do not expose the web interface to the public until after you configured your instance\!"
}