__netbox: add version memorisation

This saves the installed version and checks if a new version must be
installed. If no update required, it updates the configuration files
if required.
This commit is contained in:
matze 2020-08-16 15:18:47 +02:00
parent dfd9f108b1
commit efab6ac23e
4 changed files with 50 additions and 7 deletions

5
type/__netbox/explorer/version Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
# output version if exist
version_path="/opt/netbox/netbox/cdist/version"
if [ -f "$version_path" ]; then cat "$version_path"; fi

View file

@ -1,5 +1,8 @@
#!/bin/sh #!/bin/sh
echo "set -e"
old_version="$(cat "$__object/explorer/version")"
VERSION=$(cat "$__object/parameter/version") VERSION=$(cat "$__object/parameter/version")
src="netbox-$VERSION" src="netbox-$VERSION"
@ -7,9 +10,8 @@ archive="v$VERSION.tar.gz"
url="https://github.com/netbox-community/netbox/archive/$archive" url="https://github.com/netbox-community/netbox/archive/$archive"
install_dir=/opt/netbox/netbox install_dir=/opt/netbox/netbox
if [ "$VERSION" != "$old_version" ]; then
cat << EOF cat << EOF
set -e
# Ensure that coreutils is installed. # Ensure that coreutils is installed.
if [ ! -x \$(which mktemp) ]; then if [ ! -x \$(which mktemp) ]; then
echo "mktemp is not available on the remote host." >&2 echo "mktemp is not available on the remote host." >&2
@ -59,7 +61,33 @@ sudo -u netbox /opt/netbox/venv/bin/python3 /opt/netbox/netbox/manage.py collect
cd / cd /
rm -r "\$tmpdir" rm -r "\$tmpdir"
# Save version after successful installation
printf "%s\\n" "$VERSION" > '$install_dir/cdist/version'
EOF
# meta
printf "%s %s\n" "installed" "$VERSION" >> "$__messages_out"
changes=yes
# check if configuration changed
elif grep -q "^__file/opt/netbox/" "$__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
# meta
printf "%s\n" "configuration" >> "$__messages_out"
changes=yes
fi
# check for changes
if [ "$changes" = "yes" ]; then
cat <<EOF
# Restart services. # Restart services.
service netbox restart service netbox restart
service netbox-rq restart service netbox-rq restart
EOF EOF
fi

View file

@ -58,6 +58,16 @@ BOOLEAN PARAMETERS
------------------ ------------------
None. None.
MESSAGES
--------
installed $VERSION
Netbox was fresh installed or updated. The new version number is appended.
configuration
Some configuration files got updated and therefore the service was
restarted. This message will not be echoed if configuration got updated due
a standard installation.
EXAMPLES EXAMPLES
-------- --------

0
type/__netbox/manifest Normal file → Executable file
View file