174 lines
6.5 KiB
Bash
174 lines
6.5 KiB
Bash
# Copyright 1999-2022 Gentoo Authors
|
|
# Distributed under the terms of the GNU General Public License v2
|
|
|
|
EAPI=8
|
|
|
|
PYTHON_COMPAT=( python3_{10,11,12} )
|
|
|
|
POSTGRES_COMPAT=( {12..17} )
|
|
POSTGRES_USEDEP="server"
|
|
inherit python-r1 systemd
|
|
|
|
DESCRIPTION="IP address and data center infrastructure management tool"
|
|
HOMEPAGE="https://github.com/netbox-community/netbox"
|
|
SRC_URI="https://github.com/netbox-community/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
|
|
|
|
LICENSE="Apache-2.0"
|
|
SLOT="0"
|
|
KEYWORDS="amd64"
|
|
IUSE="branching ldap"
|
|
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
|
|
|
|
RDEPEND="acct-user/netbox
|
|
${PYTHON_DEPS}
|
|
dev-python/django[${PYTHON_USEDEP}]
|
|
dev-python/django-cors-headers[${PYTHON_USEDEP}]
|
|
dev-python/django-debug-toolbar[${PYTHON_USEDEP}]
|
|
dev-python/django-filter[${PYTHON_USEDEP}]
|
|
dev-python/django-graphiql-debug-toolbar[${PYTHON_USEDEP}]
|
|
dev-python/django-htmx[${PYTHON_USEDEP}]
|
|
dev-python/django-mptt[${PYTHON_USEDEP}]
|
|
dev-python/django-pglocks[${PYTHON_USEDEP}]
|
|
dev-python/django-prometheus[${PYTHON_USEDEP}]
|
|
dev-python/django-redis[${PYTHON_USEDEP}]
|
|
dev-python/django-rich[${PYTHON_USEDEP}]
|
|
dev-python/django-rq[${PYTHON_USEDEP}]
|
|
dev-python/django-tables2[${PYTHON_USEDEP}]
|
|
dev-python/django-taggit[${PYTHON_USEDEP}]
|
|
dev-python/django-timezone-field[${PYTHON_USEDEP}]
|
|
dev-python/djangorestframework[${PYTHON_USEDEP}]
|
|
dev-python/drf-spectacular[${PYTHON_USEDEP}]
|
|
dev-python/drf-spectacular-sidecar[${PYTHON_USEDEP}]
|
|
dev-python/feedparser[${PYTHON_USEDEP}]
|
|
dev-python/jinja2[${PYTHON_USEDEP}]
|
|
dev-python/markdown[${PYTHON_USEDEP}]
|
|
dev-python/markdown-include[${PYTHON_USEDEP}]
|
|
dev-python/mkdocs-material[${PYTHON_USEDEP}]
|
|
dev-python/mkdocstrings[${PYTHON_USEDEP}]
|
|
dev-python/mkdocstrings-python[${PYTHON_USEDEP}]
|
|
dev-python/netaddr[${PYTHON_USEDEP}]
|
|
dev-python/nh3[${PYTHON_USEDEP}]
|
|
dev-python/pillow[${PYTHON_USEDEP}]
|
|
>=dev-python/psycopg-3[${PYTHON_USEDEP}]
|
|
dev-python/pyyaml[${PYTHON_USEDEP}]
|
|
dev-python/requests[${PYTHON_USEDEP}]
|
|
dev-python/social-auth-core[${PYTHON_USEDEP}]
|
|
dev-python/social-auth-app-django[${PYTHON_USEDEP}]
|
|
dev-python/strawberry-graphql[${PYTHON_USEDEP}]
|
|
dev-python/strawberry-graphql-django[${PYTHON_USEDEP}]
|
|
dev-python/svgwrite[${PYTHON_USEDEP}]
|
|
dev-python/tablib[${PYTHON_USEDEP}]
|
|
dev-python/tzdata[${PYTHON_USEDEP}]
|
|
branching? ( www-plugins/netboxlabs-netbox-branching[${PYTHON_USEDEP}] )
|
|
ldap? ( dev-python/django-auth-ldap[${PYTHON_USEDEP}] )"
|
|
DEPEND="${RDEPEND}"
|
|
|
|
DOCS=( {CHANGELOG,CONTRIBUTING,README}.md )
|
|
|
|
src_prepare() {
|
|
default
|
|
|
|
sed -i -e "s:PLUGINS = \[\]:PLUGINS = \[\n\]:g" \
|
|
netbox/netbox/configuration_example.py || die
|
|
|
|
if use branching; then
|
|
cat "${FILESDIR}"/local_settings_branching.py >> netbox/netbox/local_settings.py
|
|
sed -i -e "s:PLUGINS = \[:PLUGINS = \[\n 'netbox_branching\',:g" \
|
|
netbox/netbox/configuration_example.py || die
|
|
fi
|
|
}
|
|
|
|
src_install() {
|
|
insinto /etc/netbox
|
|
doins "${FILESDIR}/nginx.conf"
|
|
doins "${FILESDIR}/uwsgi.ini"
|
|
doins netbox/netbox/configuration_example.py
|
|
|
|
rm -rf netbox/media netbox/reports netbox/scripts
|
|
insinto "/usr/lib/netbox"
|
|
doins -r netbox/.
|
|
dosym /etc/netbox/configuration.py /usr/lib/netbox/netbox/configuration.py
|
|
keepdir /var/lib/netbox/media
|
|
keepdir /var/lib/netbox/reports
|
|
keepdir /var/lib/netbox/scripts
|
|
fowners -R netbox:netbox /var/lib/netbox
|
|
dosym /var/lib/netbox/media /usr/lib/netbox/media
|
|
dosym /var/lib/netbox/reports /usr/lib/netbox/reports
|
|
dosym /var/lib/netbox/scripts /usr/lib/netbox/scripts
|
|
|
|
exeinto "/usr/lib/netbox"
|
|
doexe netbox/generate_secret_key.py
|
|
doexe netbox/manage.py
|
|
|
|
newinitd "${FILESDIR}"/netbox-rqworker.initd netbox-rqworker
|
|
newconfd "${FILESDIR}"/netbox-rqworker.confd netbox-rqworker
|
|
systemd_dounit "${FILESDIR}/netbox.service"
|
|
systemd_dounit "${FILESDIR}/netbox-rq.service"
|
|
systemd_dounit "${FILESDIR}/netbox-housekeeping.service"
|
|
systemd_dounit "${FILESDIR}/netbox-housekeeping.timer"
|
|
diropts -o netbox -g netbox -m 0700
|
|
keepdir /var/log/netbox
|
|
}
|
|
|
|
pkg_postinst() {
|
|
elog "After new installation or update, execute the following command:"
|
|
elog " emerge --config =${CATEGORY}/${PF}"
|
|
}
|
|
|
|
pkg_config() {
|
|
if ! "${EROOT}"/usr/bin/psql -U postgres -Aqtc 'SELECT version()' 2> /dev/null; then
|
|
eerror "Is the postgresql server running?"
|
|
die "Couldn't connect to server."
|
|
fi
|
|
|
|
if [ -f "${EROOT}/etc/netbox/configuration.py" ]; then
|
|
einfo "Netbox configuration exists,"
|
|
einfo "linking \"${EROOT}/etc/netbox/configuration.py\""
|
|
einfo "to \"${EROOT}/usr/lib/netbox/netbox/configuration.py\""
|
|
DATABASE_PASS=$(grep "# PostgreSQL password" "${EROOT}/etc/netbox/configuration.py" | sed "s/.*'PASSWORD': '\(.*\)',.*/\1/")
|
|
else
|
|
einfo "No netbox configuration exists,"
|
|
einfo "create \"${EROOT}/etc/netbox/configuration.py\""
|
|
einfo "from \"${EROOT}/usr/lib/netbox/netbox/configuration_example.py\""
|
|
DATABASE_PASS=$(head -c 300 /dev/urandom | tr -cd 'a-zA-Z0-9' | head -c 16)
|
|
SECRET_KEY=$(/usr/lib/netbox/generate_secret_key.py)
|
|
cp "${EROOT}/usr/lib/netbox/netbox/configuration_example.py" "${EROOT}/etc/netbox/configuration.py"
|
|
sed -i -e "s/^ALLOWED_HOSTS.*/ALLOWED_HOSTS = ['*']/g" \
|
|
-e "s/'USER'.*,/'USER': 'netbox',/g" \
|
|
-e "s/.*# PostgreSQL password/ 'PASSWORD': '${DATABASE_PASS}', # PostgreSQL password/g" \
|
|
-e "s/^SECRET_KEY.*/SECRET_KEY = '${SECRET_KEY}'/g" \
|
|
-e "s/'SERVER'.*,/'SERVER': '$(hostname -f)',/g" \
|
|
-e "s/'USE_TLS'.*,/'USE_TLS': True,/g" \
|
|
-e "s/'FROM_EMAIL'.*,/'FROM_EMAIL': 'netbox@example.com',/g" \
|
|
"${EROOT}/etc/netbox/configuration.py"
|
|
fi
|
|
ln -sf "${EROOT}/etc/netbox/configuration.py" "${EROOT}/usr/lib/netbox/netbox/configuration.py"
|
|
|
|
einfo "Initializing the database \"netbox\" for user \"netbox\"..."
|
|
if "${EROOT}"/usr/bin/psql -lqt -U postgres | cut -d \| -f 1 | grep -qw "netbox"; then
|
|
einfo " Database \"netbox found, skipping\""
|
|
else
|
|
"${EROOT}"/usr/bin/psql -U postgres -d postgres -c "CREATE USER netbox WITH PASSWORD '$DATABASE_PASS';"
|
|
"${EROOT}"/usr/bin/psql -U postgres -d postgres -c "CREATE DATABASE netbox WITH OWNER netbox;"
|
|
"${EROOT}"/usr/bin/psql -U postgres -d postgres -c "GRANT CREATE ON SCHEMA public TO netbox;"
|
|
fi
|
|
|
|
einfo "Netbox database migration..."
|
|
"${EROOT}"/usr/lib/netbox/manage.py migrate
|
|
|
|
einfo "Netbox trace paths..."
|
|
"${EROOT}"/usr/lib/netbox/manage.py trace_paths --no-input
|
|
|
|
einfo "Netbox collect static web content..."
|
|
"${EROOT}"/usr/lib/netbox/manage.py collectstatic --no-input
|
|
|
|
einfo "Netbox remove stale contenttypes..."
|
|
"${EROOT}"/usr/lib/netbox/manage.py remove_stale_contenttypes --no-input
|
|
|
|
einfo "Netbox reindex database..."
|
|
"${EROOT}"/usr/lib/netbox/manage.py reindex --lazy
|
|
|
|
einfo "Netbox clear sessions..."
|
|
"${EROOT}"/usr/lib/netbox/manage.py clearsessions
|
|
}
|