__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:
parent
dfd9f108b1
commit
efab6ac23e
4 changed files with 50 additions and 7 deletions
5
type/__netbox/explorer/version
Executable file
5
type/__netbox/explorer/version
Executable 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
|
|
@ -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
|
||||||
|
|
||||||
cat << EOF
|
if [ "$VERSION" != "$old_version" ]; then
|
||||||
set -e
|
cat << EOF
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -41,11 +43,11 @@ virtualenv /opt/netbox/venv
|
||||||
/opt/netbox/venv/bin/pip3 install -r "\$tmpdir/$src/requirements.txt"
|
/opt/netbox/venv/bin/pip3 install -r "\$tmpdir/$src/requirements.txt"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -f "$__object/parameter/ldap-server" ]; then
|
if [ -f "$__object/parameter/ldap-server" ]; then
|
||||||
echo "/opt/netbox/venv/bin/pip3 install django-auth-ldap"
|
echo "/opt/netbox/venv/bin/pip3 install django-auth-ldap"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
# Set final permissions.
|
# Set final permissions.
|
||||||
chown -R netbox /opt/netbox
|
chown -R netbox /opt/netbox
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
|
|
@ -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
0
type/__netbox/manifest
Normal file → Executable file
Loading…
Reference in a new issue