Matthias Stecher
584e0bbda8
The cdist directory needs to be created to write there. This is done directly after the new tarball is installed.
99 lines
2.6 KiB
Bash
Executable file
99 lines
2.6 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
echo "set -e"
|
|
|
|
old_version="$(cat "$__object/explorer/version")"
|
|
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
|
|
|
|
if [ "$VERSION" != "$old_version" ]; then
|
|
cat << EOF
|
|
# 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.
|
|
curl -sS -L '$url' > '$archive'
|
|
tar xf '$archive'
|
|
|
|
# Save cdist-upload configuration file.
|
|
cp '$install_dir/cdist/configuration.py' "\$tmpdir/configuration.py"
|
|
cp '$install_dir/cdist/ldap_config.py' "\$tmpdir/ldap_config.py"
|
|
|
|
# Deploy sources and restore configuration.
|
|
rm -r '$install_dir'
|
|
cp -r '$src/netbox' '$install_dir'
|
|
mkdir '$install_dir/cdist'
|
|
|
|
cp \$tmpdir/configuration.py '$install_dir/netbox/configuration.py'
|
|
cp \$tmpdir/ldap_config.py '$install_dir/netbox/ldap_config.py'
|
|
|
|
# Setup & enter python virtualenv.
|
|
# forcing python3 to be sure (till python4 gets released ..)
|
|
virtualenv -p python3 /opt/netbox/venv
|
|
|
|
# Install python dependencies.
|
|
/opt/netbox/venv/bin/pip3 install -r "\$tmpdir/$src/requirements.txt"
|
|
EOF
|
|
|
|
if [ -f "$__object/parameter/ldap-server" ]; then
|
|
echo "/opt/netbox/venv/bin/pip3 install django-auth-ldap"
|
|
fi
|
|
|
|
cat << EOF
|
|
# 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"
|
|
|
|
# Save version after successful installation
|
|
printf "%s\\n" "$VERSION" > '$install_dir/cdist/version'
|
|
EOF
|
|
|
|
# meta
|
|
printf "installed %s\n" "$VERSION" >> "$__messages_out"
|
|
changes=yes
|
|
|
|
# check if configuration changed
|
|
elif grep -q "^__file/opt/netbox/" "$__messages_in"; then
|
|
# check if coping is required
|
|
if grep -q "^__file/opt/netbox/netbox/cdist/" "$__messages_in"; then
|
|
cat << EOF
|
|
# 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
|
|
fi
|
|
|
|
# meta
|
|
printf "configuration\n" >> "$__messages_out"
|
|
changes=yes
|
|
fi
|
|
|
|
|
|
# check for changes
|
|
if [ "$changes" = "yes" ]; then
|
|
cat << EOF
|
|
# Restart services.
|
|
service netbox restart
|
|
service netbox-rq restart
|
|
EOF
|
|
fi
|