2020-07-20 15:20:33 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-08-16 13:18:47 +00:00
|
|
|
echo "set -e"
|
|
|
|
|
|
|
|
old_version="$(cat "$__object/explorer/version")"
|
2020-07-20 15:20:33 +00:00
|
|
|
VERSION=$(cat "$__object/parameter/version")
|
|
|
|
|
|
|
|
src="netbox-$VERSION"
|
|
|
|
archive="v$VERSION.tar.gz"
|
|
|
|
url="https://github.com/netbox-community/netbox/archive/$archive"
|
|
|
|
install_dir=/opt/netbox/netbox
|
|
|
|
|
2020-08-16 13:18:47 +00:00
|
|
|
if [ "$VERSION" != "$old_version" ]; then
|
|
|
|
cat << EOF
|
2020-07-20 15:20:33 +00:00
|
|
|
# Ensure that coreutils is installed.
|
|
|
|
if [ ! -x \$(which mktemp) ]; then
|
|
|
|
echo "mktemp is not available on the remote host." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create temporary working directory.
|
|
|
|
tmpdir=\$(mktemp -d)
|
|
|
|
cd "\$tmpdir"
|
|
|
|
|
|
|
|
# Download and extract sources.
|
2020-08-22 19:50:54 +00:00
|
|
|
curl -sS -L '$url' > '$archive'
|
2020-07-20 15:20:33 +00:00
|
|
|
tar xf '$archive'
|
|
|
|
|
|
|
|
# Save cdist-upload configuration file.
|
|
|
|
cp '$install_dir/cdist/configuration.py' "\$tmpdir/configuration.py"
|
2020-07-21 05:46:45 +00:00
|
|
|
cp '$install_dir/cdist/ldap_config.py' "\$tmpdir/ldap_config.py"
|
2020-07-20 15:20:33 +00:00
|
|
|
|
|
|
|
# Deploy sources and restore configuration.
|
|
|
|
rm -r '$install_dir'
|
|
|
|
cp -r '$src/netbox' '$install_dir'
|
2020-08-22 20:23:36 +00:00
|
|
|
mkdir '$install_dir/cdist'
|
|
|
|
|
2020-08-26 18:01:23 +00:00
|
|
|
cp '$src/requirements.txt' /opt/netbox/ # backup dependency info
|
2020-07-20 15:20:33 +00:00
|
|
|
cp \$tmpdir/configuration.py '$install_dir/netbox/configuration.py'
|
2020-07-21 05:46:45 +00:00
|
|
|
cp \$tmpdir/ldap_config.py '$install_dir/netbox/ldap_config.py'
|
2020-07-20 15:20:33 +00:00
|
|
|
|
|
|
|
# Setup & enter python virtualenv.
|
2020-08-22 19:29:30 +00:00
|
|
|
# forcing python3 to be sure (till python4 gets released ..)
|
|
|
|
virtualenv -p python3 /opt/netbox/venv
|
2020-07-20 15:20:33 +00:00
|
|
|
|
|
|
|
# Install python dependencies.
|
2020-08-26 18:01:23 +00:00
|
|
|
# avoid gunicorn, because it will be done in an other type
|
|
|
|
grep -v "^gunicorn==" "\$tmpdir/$src/requirements.txt" \
|
|
|
|
| xargs /opt/netbox/venv/bin/pip3 install
|
2020-07-21 05:46:45 +00:00
|
|
|
EOF
|
|
|
|
|
2020-08-16 13:18:47 +00:00
|
|
|
if [ -f "$__object/parameter/ldap-server" ]; then
|
|
|
|
echo "/opt/netbox/venv/bin/pip3 install django-auth-ldap"
|
2020-08-26 15:39:19 +00:00
|
|
|
else
|
|
|
|
echo "/opt/netbox/venv/bin/pip3 uninstall django-auth-ldap"
|
2020-08-16 13:18:47 +00:00
|
|
|
fi
|
2020-07-20 15:20:33 +00:00
|
|
|
|
2020-08-16 13:18:47 +00:00
|
|
|
cat << EOF
|
2020-07-20 15:20:33 +00:00
|
|
|
# Set final permissions.
|
|
|
|
chown -R netbox /opt/netbox
|
|
|
|
|
|
|
|
# Run database migrations.
|
|
|
|
sudo -u netbox /opt/netbox/venv/bin/python3 /opt/netbox/netbox/manage.py migrate
|
|
|
|
|
|
|
|
# Generate static assets.
|
|
|
|
sudo -u netbox /opt/netbox/venv/bin/python3 /opt/netbox/netbox/manage.py collectstatic --no-input
|
|
|
|
|
|
|
|
# Remove temporary working directory.
|
|
|
|
cd /
|
|
|
|
rm -r "\$tmpdir"
|
|
|
|
|
2020-08-16 13:18:47 +00:00
|
|
|
# Save version after successful installation
|
|
|
|
printf "%s\\n" "$VERSION" > '$install_dir/cdist/version'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# meta
|
2020-08-22 07:19:12 +00:00
|
|
|
printf "installed %s\n" "$VERSION" >> "$__messages_out"
|
2020-08-16 13:18:47 +00:00
|
|
|
changes=yes
|
|
|
|
|
|
|
|
# check if configuration changed
|
|
|
|
elif grep -q "^__file/opt/netbox/" "$__messages_in"; then
|
2020-08-22 07:19:12 +00:00
|
|
|
# check if coping is required
|
|
|
|
if grep -q "^__file/opt/netbox/netbox/cdist/" "$__messages_in"; then
|
|
|
|
cat << EOF
|
2020-08-16 13:18:47 +00:00
|
|
|
# Copy configuration
|
|
|
|
cp '$install_dir/cdist/configuration.py' '$install_dir/netbox/configuration.py'
|
|
|
|
cp '$install_dir/cdist/ldap_config.py' '$install_dir/netbox/ldap_config.py'
|
|
|
|
EOF
|
2020-08-22 07:19:12 +00:00
|
|
|
fi
|
2020-08-16 13:18:47 +00:00
|
|
|
|
|
|
|
# meta
|
2020-08-27 17:46:09 +00:00
|
|
|
printf "configured\n" >> "$__messages_out"
|
2020-08-16 13:18:47 +00:00
|
|
|
changes=yes
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# check for changes
|
|
|
|
if [ "$changes" = "yes" ]; then
|
2020-08-22 07:19:12 +00:00
|
|
|
cat << EOF
|
2020-08-26 18:01:23 +00:00
|
|
|
# Restart service.
|
2020-07-20 15:20:33 +00:00
|
|
|
service netbox-rq restart
|
|
|
|
EOF
|
2020-08-16 13:18:47 +00:00
|
|
|
fi
|