2020-07-20 15:20:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
os=$(cat "$__global/explorer/os")
|
|
|
|
|
|
|
|
case "$os" in
|
|
|
|
debian|ubuntu)
|
|
|
|
# Install netbox dependencies.
|
|
|
|
for pkg in python3-pip python3-venv python3-dev build-essential libxml2-dev \
|
|
|
|
libxslt1-dev libffi-dev libpq-dev libssl-dev zlib1g-dev curl virtualenv; do
|
|
|
|
__package $pkg
|
|
|
|
done
|
|
|
|
|
2020-07-21 05:46:45 +00:00
|
|
|
if [ -f "$__object/parameter/ldap-server" ]; then
|
|
|
|
for pkg in libldap2-dev libsasl2-dev libssl-dev; do
|
|
|
|
__package $pkg
|
|
|
|
done
|
|
|
|
fi
|
2020-07-20 15:20:33 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "$os" "${__type##*/}" >&2
|
|
|
|
printf "Please contribute an implementation for it if you can.\n" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-08-12 07:01:05 +00:00
|
|
|
DATABASE_NAME=$(cat "$__object/parameter/database")
|
|
|
|
export DATABASE_NAME
|
|
|
|
DATABASE_PASSWORD=$(cat "$__object/parameter/database-password")
|
|
|
|
export DATABASE_PASSWORD
|
|
|
|
ALLOWED_HOST=$(cat "$__object/parameter/host")
|
|
|
|
export ALLOWED_HOST
|
|
|
|
SECRET_KEY=$(cat "$__object/parameter/secret-key")
|
|
|
|
export SECRET_KEY
|
2020-07-20 15:20:33 +00:00
|
|
|
|
2020-07-21 05:46:45 +00:00
|
|
|
if [ -f "$__object/parameter/ldap-server" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_SERVER=$(cat "$__object/parameter/ldap-server")
|
|
|
|
export LDAP_SERVER
|
2020-07-21 05:46:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/ldap-bind-dn" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_BIND_DN=$(cat "$__object/parameter/ldap-bind-dn")
|
|
|
|
export LDAP_BIND_DN
|
2020-07-21 05:46:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/ldap-bind-password" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_BIND_PASSWORD=$(cat "$__object/parameter/ldap-bind-password")
|
|
|
|
export LDAP_BIND_PASSWORD
|
2020-07-21 05:46:45 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-21 06:30:09 +00:00
|
|
|
if [ -f "$__object/parameter/ldap-user-base" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_USER_BASE=$(cat "$__object/parameter/ldap-user-base")
|
|
|
|
export LDAP_USER_BASE
|
2020-07-21 06:30:09 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/ldap-group-base" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_GROUP_BASE=$(cat "$__object/parameter/ldap-group-base")
|
|
|
|
export LDAP_GROUP_BASE
|
2020-07-21 06:30:09 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/ldap-require-group" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_REQUIRE_GROUP=$(cat "$__object/parameter/ldap-require-group")
|
|
|
|
export LDAP_REQUIRE_GROUP
|
2020-07-21 06:30:09 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$__object/parameter/ldap-superuser-group" ]; then
|
2020-08-12 07:01:05 +00:00
|
|
|
LDAP_SUPERUSER_GROUP=$(cat "$__object/parameter/ldap-superuser-group")
|
|
|
|
export LDAP_SUPERUSER_GROUP
|
2020-07-21 05:46:45 +00:00
|
|
|
fi
|
|
|
|
|
2020-07-20 15:20:33 +00:00
|
|
|
# Create system user used to run netbox.
|
|
|
|
__user netbox --system --home /opt/netbox --create-home
|
|
|
|
|
|
|
|
# Generate and upload netbox configuration.
|
|
|
|
mkdir -p "$__object/files"
|
|
|
|
"$__type/files/configuration.py.sh" > "$__object/files/configuration.py"
|
2020-07-21 05:46:45 +00:00
|
|
|
"$__type/files/ldap_config.py.sh" > "$__object/files/ldap_config.py"
|
2020-07-20 15:20:33 +00:00
|
|
|
|
|
|
|
require="__user/netbox" __directory /opt/netbox/netbox/cdist --parents
|
|
|
|
require="__directory/opt/netbox/netbox/cdist " __file \
|
|
|
|
/opt/netbox/netbox/cdist/configuration.py --mode 640 --owner netbox \
|
|
|
|
--source "$__object/files/configuration.py"
|
|
|
|
|
2020-07-21 05:46:45 +00:00
|
|
|
if [ -f "$__object/parameter/ldap-server" ]; then
|
|
|
|
require="__directory/opt/netbox/netbox/cdist " __file \
|
|
|
|
/opt/netbox/netbox/cdist/ldap_config.py --mode 640 --owner netbox \
|
|
|
|
--source "$__object/files/ldap_config.py"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2020-07-20 15:20:33 +00:00
|
|
|
# Upload systemd units and gunicorn configuration.
|
|
|
|
for unit in netbox netbox-rq; do
|
2020-08-12 06:58:29 +00:00
|
|
|
__systemd_unit $unit.service \
|
|
|
|
--source "$__type/files/$unit.service" \
|
|
|
|
--enablement-state enabled
|
2020-07-20 15:20:33 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Python worker configuration.
|
|
|
|
require="__user/netbox" __file /opt/netbox/gunicorn.py \
|
|
|
|
--mode 644 --source "$__type/files/gunicorn.py"
|