From 515eb303f096bcfe575cecca3d2cad233a73286a Mon Sep 17 00:00:00 2001 From: bvdberg01 <74251551+bvdberg01@users.noreply.github.com> Date: Sun, 17 Nov 2024 16:19:17 +0100 Subject: [PATCH 1/3] new scripts for NetBox --- ct/netbox.sh | 100 +++++++++++++++++++++++++++++++++ install/netbox-install.sh | 115 ++++++++++++++++++++++++++++++++++++++ json/netbox.json | 39 +++++++++++++ 3 files changed, 254 insertions(+) create mode 100644 ct/netbox.sh create mode 100644 install/netbox-install.sh create mode 100644 json/netbox.json diff --git a/ct/netbox.sh b/ct/netbox.sh new file mode 100644 index 000000000..182c488d6 --- /dev/null +++ b/ct/netbox.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func) +# Copyright (c) 2021-2024 community-scripts ORG +# Author: bvdberg01 +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +function header_info { +clear +cat <<"EOF" + __ __ + ____ ___ / /_/ /_ ____ _ __ + / __ \/ _ \/ __/ __ \/ __ \| |/_/ + / / / / __/ /_/ /_/ / /_/ /> < +/_/ /_/\___/\__/_.___/\____/_/|_| + +EOF +} +header_info +echo -e "Loading..." +APP="Netbox" +var_disk="4" +var_cpu="2" +var_ram="2048" +var_os="debian" +var_version="12" +variables +color +catch_errors + +function default_settings() { + CT_TYPE="1" + PW="" + CT_ID=$NEXTID + HN=$NSAPP + DISK_SIZE="$var_disk" + CORE_COUNT="$var_cpu" + RAM_SIZE="$var_ram" + BRG="vmbr0" + NET="dhcp" + GATE="" + APT_CACHER="" + APT_CACHER_IP="" + DISABLEIP6="no" + MTU="" + SD="" + NS="" + MAC="" + VLAN="" + SSH="no" + VERB="no" + echo_default +} + +function update_script() { +header_info +if [[ ! -f /opt/netbox/netbox/netbox/configuration.py ]]; then msg_error "No ${APP} Installation Found!"; exit; fi +RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +if [ ! -d "/opt/netbox-${RELEASE}" ]; then + msg_info "Updating $APP LXC" + apt-get update &>/dev/null + apt-get -y upgrade &>/dev/null + + OLD_VERSION_PATH=$(ls -d /opt/netbox-*/) + wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.tar.gz" + tar -xzf "v${RELEASE}.tar.gz" -C /opt + ln -sfn "/opt/netbox-${RELEASE}/" /opt/netbox + rm "v${RELEASE}.tar.gz" + + cp "${OLD_VERSION_PATH}netbox/netbox/configuration.py" /opt/netbox/netbox/netbox/ + cp -pr "${OLD_VERSION_PATH}netbox/media/" /opt/netbox/netbox/ + cp -r "${OLD_VERSION_PATH}netbox/scripts" /opt/netbox/netbox/ + cp -r "${OLD_VERSION_PATH}netbox/reports" /opt/netbox/netbox/ + cp "${OLD_VERSION_PATH}gunicorn.py" /opt/netbox/ + + if [ -d "${OLD_VERSION_PATH}local_requirements.txt" ]; then + cp "${OLD_VERSION_PATH}local_requirements.txt" /opt/netbox/ + fi + + if [ -d "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" ]; then + cp "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" /opt/netbox/netbox/netbox/ + fi + + rm -r "${OLD_VERSION_PATH}" + /opt/netbox/upgrade.sh &>/dev/null + systemctl restart --now netbox netbox-rq + msg_ok "Updated $APP LXC" +else + msg_ok "No update required. ${APP} is already at ${RELEASE}" +fi +exit +} + +start +build_container +description + +msg_ok "Completed Successfully!\n" +echo -e "${APP} should be reachable by going to the following URL. + ${BL}https://${IP}${CL} \n" diff --git a/install/netbox-install.sh b/install/netbox-install.sh new file mode 100644 index 000000000..f1c907282 --- /dev/null +++ b/install/netbox-install.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021-2024 community-scripts ORG +# Author: bvdberg01 +# License: MIT +# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE + +source /dev/stdin <<< "$FUNCTIONS_FILE_PATH" +color +verb_ip6 +catch_errors +setting_up_container +network_check +update_os + +msg_info "Installing Dependencies" +$STD apt-get update +$STD apt-get install -y curl +$STD apt-get install -y sudo +$STD apt-get install -y mc +$STD apt-get install -y apache2 +$STD apt-get install -y redis-server +$STD apt-get install -y postgresql +$STD apt-get install -y python3 +$STD apt-get install -y python3-pip +$STD apt-get install -y python3-venv +$STD apt-get install -y python3-dev +$STD apt-get install -y build-essential +$STD apt-get install -y libxml2-dev +$STD apt-get install -y libxslt1-dev +$STD apt-get install -y libffi-dev +$STD apt-get install -y libpq-dev +$STD apt-get install -y libssl-dev +$STD apt-get install -y zlib1g-dev +msg_ok "Installed Dependencies" + +msg_info "Setting up PostgreSQL" +DB_NAME=netbox +DB_USER=netbox +DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) +$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" +$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;" +msg_ok "Set up PostgreSQL" + +msg_info "Installing NetBox" +RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') +wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.tar.gz" +tar -xzf "v${RELEASE}.tar.gz" -C /opt +ln -s "/opt/netbox-${RELEASE}/" /opt/netbox +rm "v${RELEASE}.tar.gz" + +$STD adduser --system --group netbox +chown --recursive netbox /opt/netbox/netbox/media/ +chown --recursive netbox /opt/netbox/netbox/reports/ +chown --recursive netbox /opt/netbox/netbox/scripts/ + +cp /opt/netbox/netbox/netbox/configuration_example.py /opt/netbox/netbox/netbox/configuration.py + +secret=$(python3 /opt/netbox/netbox/generate_secret_key.py) +escaped_secret=$(printf '%s\n' "$secret" | sed 's/[&/\]/\\&/g') + +sed -i 's/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = ["*"]/' /opt/netbox/netbox/netbox/configuration.py +sed -i "s|SECRET_KEY = ''|SECRET_KEY = '${escaped_secret}'|" /opt/netbox/netbox/netbox/configuration.py +sed -i "/DATABASE = {/,/}/s/'USER': '[^']*'/'USER': '$DB_USER'/" /opt/netbox/netbox/netbox/configuration.py +sed -i "/DATABASE = {/,/}/s/'PASSWORD': '[^']*'/'PASSWORD': '$DB_PASS'/" /opt/netbox/netbox/netbox/configuration.py + +$STD /opt/netbox/upgrade.sh &>/dev/null +sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping + +sudo cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf +openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/netbox.key -out /etc/ssl/certs/netbox.crt -subj "/C=US/O=NetBox/OU=Certificate/CN=localhost" &>/dev/null +$STD a2enmod ssl proxy proxy_http headers rewrite +$STD a2ensite netbox +systemctl restart apache2 + +cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py +cp /opt/netbox/contrib/*.service /etc/systemd/system/ +systemctl daemon-reload +systemctl enable -q --now netbox netbox-rq + +msg_ok "Installed NetBox" + +msg_info "Setting up Django Admin" +NetBox_USER=Admin +NetBox_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) + +source /opt/netbox/venv/bin/activate +$STD python3 /opt/netbox/netbox/manage.py shell << EOF +from django.contrib.auth import get_user_model +UserModel = get_user_model() +user = UserModel.objects.create_user('$NetBox_USER', password='$NetBox_PASS') +user.is_superuser = True +user.is_staff = True +user.save() +EOF +msg_ok "Setup Django Admin" + +msg_info "Save credential file" +echo "" >~/NetBox.creds +echo "NetBox Database Credentials" >>~/NetBox.creds +echo "" >>~/NetBox.creds +echo -e "NetBox Database User: \e[32m$DB_USER\e[0m" >>~/NetBox.creds +echo -e "NetBox Database Password: \e[32m$DB_PASS\e[0m" >>~/NetBox.creds +echo -e "NetBox Database Name: \e[32m$DB_NAME\e[0m" >>~/NetBox.creds +echo -e "NetBox Admin user: \e[32m$NetBox_USER\e[0m" >>~/NetBox.creds +echo -e "NetBox Admin Password: \e[32m$NetBox_PASS\e[0m" >>~/NetBox.creds +msg_ok "Save cred file" + +motd_ssh +customize + +msg_info "Cleaning up" +$STD apt-get -y autoremove +$STD apt-get -y autoclean +msg_ok "Cleaned" diff --git a/json/netbox.json b/json/netbox.json new file mode 100644 index 000000000..52d03796f --- /dev/null +++ b/json/netbox.json @@ -0,0 +1,39 @@ +{ + "name": "NetBox", + "slug": "netbox", + "categories": [ + 11 + ], + "date_created": "2024-11-17", + "type": "ct", + "updateable": false, + "privileged": false, + "interface_port": "443", + "documentation": "https://netboxlabs.com/docs/netbox/en/stable/", + "website": "https://github.com/netbox-community/netbox", + "logo": "https://netboxlabs.com/wp-content/uploads/2023/10/logo_netboxlabs_bright_teal.svg", + "description": "NetBox is the source of truth for everything on your network, from physical components like power systems and cabling to virtual assets like IP addresses and VLANs. Network automation and observability tools depend on NetBox’s authoritative data to roll out configurations, monitor changes, and accelerate operations across the enterprise", + "install_methods": [ + { + "type": "default", + "script": "ct/netbox.sh", + "resources": { + "cpu": "2", + "ram": "2048", + "hdd": "4", + "os": "debian", + "version": "12" + } + } + ], + "default_credentials": { + "username": "Admin", + "password": "See output: cat NetBox.creds" + }, + "notes": [ + { + "text": "Generated database & admin credentials see output: `cat NetBox.creds`", + "type": "warning" + } + ] +} \ No newline at end of file From 60da4eee924884c0459a9757a7ee50a58bf9ff47 Mon Sep 17 00:00:00 2001 From: bvdberg01 Date: Sun, 17 Nov 2024 21:12:16 +0100 Subject: [PATCH 2/3] Update json/netbox.json MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> --- ct/netbox.sh | 76 ++++++++++++++++------------ install/netbox-install.sh | 101 ++++++++++++++++++++------------------ json/netbox.json | 14 +++--- 3 files changed, 106 insertions(+), 85 deletions(-) diff --git a/ct/netbox.sh b/ct/netbox.sh index 182c488d6..2699e7f4f 100644 --- a/ct/netbox.sh +++ b/ct/netbox.sh @@ -8,17 +8,17 @@ source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/m function header_info { clear cat <<"EOF" - __ __ - ____ ___ / /_/ /_ ____ _ __ - / __ \/ _ \/ __/ __ \/ __ \| |/_/ - / / / / __/ /_/ /_/ / /_/ /> < -/_/ /_/\___/\__/_.___/\____/_/|_| + _ __ __ ____ + / | / /__ / /_/ __ )____ _ __ + / |/ / _ \/ __/ __ / __ \| |/_/ + / /| / __/ /_/ /_/ / /_/ /> < +/_/ |_/\___/\__/_____/\____/_/|_| EOF } header_info echo -e "Loading..." -APP="Netbox" +APP="NetBox" var_disk="4" var_cpu="2" var_ram="2048" @@ -54,39 +54,53 @@ function default_settings() { function update_script() { header_info -if [[ ! -f /opt/netbox/netbox/netbox/configuration.py ]]; then msg_error "No ${APP} Installation Found!"; exit; fi +check_container_storage +check_container_resources +if [[ ! -f /etc/systemd/system/netbox.service ]]; then msg_error "No ${APP} Installation Found!"; exit; fi + RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -if [ ! -d "/opt/netbox-${RELEASE}" ]; then - msg_info "Updating $APP LXC" - apt-get update &>/dev/null - apt-get -y upgrade &>/dev/null - - OLD_VERSION_PATH=$(ls -d /opt/netbox-*/) - wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.tar.gz" - tar -xzf "v${RELEASE}.tar.gz" -C /opt - ln -sfn "/opt/netbox-${RELEASE}/" /opt/netbox - rm "v${RELEASE}.tar.gz" +if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then + + msg_info "Stopping ${APP}" + systemctl stop netbox netbox-rq + msg_ok "Stopped ${APP}" + + msg_info "Updating $APP to v${RELEASE}" + mv /opt/netbox/ /opt/netbod-oldversion + cd /opt + wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.zip" + unzip -q "v${RELEASE}.zip" + mv /opt/netbox-${RELEASE}/ /opt/netbox/ - cp "${OLD_VERSION_PATH}netbox/netbox/configuration.py" /opt/netbox/netbox/netbox/ - cp -pr "${OLD_VERSION_PATH}netbox/media/" /opt/netbox/netbox/ - cp -r "${OLD_VERSION_PATH}netbox/scripts" /opt/netbox/netbox/ - cp -r "${OLD_VERSION_PATH}netbox/reports" /opt/netbox/netbox/ - cp "${OLD_VERSION_PATH}gunicorn.py" /opt/netbox/ + cp -r /opt/netbod-oldversion/netbox/netbox/configuration.py /opt/netbox/netbox/netbox/ + cp -r /opt/netbod-oldversion/netbox/media/ /opt/netbox/netbox/ + cp -r /opt/netbod-oldversion/netbox/scripts /opt/netbox/netbox/ + cp -r /opt/netbod-oldversion/netbox/reports /opt/netbox/netbox/ + cp -r /opt/netbod-oldversion/gunicorn.py /opt/netbox/ - if [ -d "${OLD_VERSION_PATH}local_requirements.txt" ]; then - cp "${OLD_VERSION_PATH}local_requirements.txt" /opt/netbox/ + if [ -d /opt/netbod-oldversion/local_requirements.txt ]; then + cp -r /opt/netbod-oldversion/local_requirements.txt /opt/netbox/ fi - if [ -d "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" ]; then - cp "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" /opt/netbox/netbox/netbox/ + if [ -d /opt/netbod-oldversion/netbox/netbox/ldap_config.py ]; then + cp -r /opt/netbod-oldversion/netbox/netbox/ldap_config.py /opt/netbox/netbox/netbox/ fi - - rm -r "${OLD_VERSION_PATH}" + /opt/netbox/upgrade.sh &>/dev/null - systemctl restart --now netbox netbox-rq - msg_ok "Updated $APP LXC" + echo "${RELEASE}" >/opt/${APP}_version.txt + msg_ok "Updated $APP to v${RELEASE}" + + msg_info "Starting ${APP}" + systemctl start netbox netbox-rq + msg_ok "Started ${APP}" + + msg_info "Cleaning up" + rm -r "/opt/v${RELEASE}.zip" + rm -r /opt/netbod-oldversion + msg_ok "Cleaned" + msg_ok "Updated Successfully" else - msg_ok "No update required. ${APP} is already at ${RELEASE}" + msg_ok "No update required. ${APP} is already at v${RELEASE}" fi exit } diff --git a/install/netbox-install.sh b/install/netbox-install.sh index f1c907282..384dd3880 100644 --- a/install/netbox-install.sh +++ b/install/netbox-install.sh @@ -14,24 +14,24 @@ network_check update_os msg_info "Installing Dependencies" -$STD apt-get update -$STD apt-get install -y curl -$STD apt-get install -y sudo -$STD apt-get install -y mc -$STD apt-get install -y apache2 -$STD apt-get install -y redis-server -$STD apt-get install -y postgresql -$STD apt-get install -y python3 -$STD apt-get install -y python3-pip -$STD apt-get install -y python3-venv -$STD apt-get install -y python3-dev -$STD apt-get install -y build-essential -$STD apt-get install -y libxml2-dev -$STD apt-get install -y libxslt1-dev -$STD apt-get install -y libffi-dev -$STD apt-get install -y libpq-dev -$STD apt-get install -y libssl-dev -$STD apt-get install -y zlib1g-dev +$STD apt-get install -y \ + curl \ + sudo \ + mc \ + apache2 \ + redis-server \ + postgresql \ + python3 \ + python3-pip \ + python3-venv \ + python3-dev \ + build-essential \ + libxml2-dev \ + libxslt1-dev \ + libffi-dev \ + libpq-dev \ + libssl-dev \ + zlib1g-dev msg_ok "Installed Dependencies" msg_info "Setting up PostgreSQL" @@ -40,76 +40,83 @@ DB_USER=netbox DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) $STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';" $STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;" +{ +echo "Netbox-Credentials" +echo -e "Netbox Database User: \e[32m$DB_USER\e[0m" +echo -e "Netbox Database Password: \e[32m$DB_PASS\e[0m" +echo -e "Netbox Database Name: \e[32m$DB_NAME\e[0m" +} >> ~/netbox.creds msg_ok "Set up PostgreSQL" -msg_info "Installing NetBox" +msg_info "Installing NetBox" +cd /opt RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') -wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.tar.gz" -tar -xzf "v${RELEASE}.tar.gz" -C /opt -ln -s "/opt/netbox-${RELEASE}/" /opt/netbox -rm "v${RELEASE}.tar.gz" +wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.zip" +unzip -q "v${RELEASE}.zip" +mv /opt/netbox-${RELEASE}/ /opt/netbox $STD adduser --system --group netbox chown --recursive netbox /opt/netbox/netbox/media/ chown --recursive netbox /opt/netbox/netbox/reports/ chown --recursive netbox /opt/netbox/netbox/scripts/ -cp /opt/netbox/netbox/netbox/configuration_example.py /opt/netbox/netbox/netbox/configuration.py +mv /opt/netbox/netbox/netbox/configuration_example.py /opt/netbox/netbox/netbox/configuration.py -secret=$(python3 /opt/netbox/netbox/generate_secret_key.py) -escaped_secret=$(printf '%s\n' "$secret" | sed 's/[&/\]/\\&/g') +SECRET_KEY=$(python3 /opt/netbox/netbox/generate_secret_key.py) +ESCAPED_SECRET_KEY=$(printf '%s\n' "$SECRET_KEY" | sed 's/[&/\]/\\&/g') sed -i 's/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = ["*"]/' /opt/netbox/netbox/netbox/configuration.py -sed -i "s|SECRET_KEY = ''|SECRET_KEY = '${escaped_secret}'|" /opt/netbox/netbox/netbox/configuration.py +sed -i "s|SECRET_KEY = ''|SECRET_KEY = '${ESCAPED_SECRET_KEY}'|" /opt/netbox/netbox/netbox/configuration.py sed -i "/DATABASE = {/,/}/s/'USER': '[^']*'/'USER': '$DB_USER'/" /opt/netbox/netbox/netbox/configuration.py sed -i "/DATABASE = {/,/}/s/'PASSWORD': '[^']*'/'PASSWORD': '$DB_PASS'/" /opt/netbox/netbox/netbox/configuration.py -$STD /opt/netbox/upgrade.sh &>/dev/null -sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping +$STD /opt/netbox/upgrade.sh +ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping -sudo cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf -openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/netbox.key -out /etc/ssl/certs/netbox.crt -subj "/C=US/O=NetBox/OU=Certificate/CN=localhost" &>/dev/null +mv /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf +$STD openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/netbox.key -out /etc/ssl/certs/netbox.crt -subj "/C=US/O=NetBox/OU=Certificate/CN=localhost" $STD a2enmod ssl proxy proxy_http headers rewrite $STD a2ensite netbox systemctl restart apache2 -cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py -cp /opt/netbox/contrib/*.service /etc/systemd/system/ +mv /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py +mv /opt/netbox/contrib/*.service /etc/systemd/system/ systemctl daemon-reload systemctl enable -q --now netbox netbox-rq +echo "${RELEASE}" >/opt/${APPLICATION}_version.txt +{ +echo -e "Netbox Secret: \e[32m$SECRET_KEY\e[0m" +} >> ~/netbox.creds +msg_ok "Set up PostgreSQL" msg_ok "Installed NetBox" msg_info "Setting up Django Admin" -NetBox_USER=Admin -NetBox_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) +DJANGO_USER=Admin +DJANGO_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) source /opt/netbox/venv/bin/activate $STD python3 /opt/netbox/netbox/manage.py shell << EOF from django.contrib.auth import get_user_model UserModel = get_user_model() -user = UserModel.objects.create_user('$NetBox_USER', password='$NetBox_PASS') +user = UserModel.objects.create_user('$DJANGO_USER', password='$DJANGO_PASS') user.is_superuser = True user.is_staff = True user.save() EOF +{ +echo "" +echo "Netbox-Django-Credentials" +echo -e "Django User: \e[32m$DJANGO_USER\e[0m" +echo -e "Django Password: \e[32m$DJANGO_PASS\e[0m" +} >> ~/netbox.creds msg_ok "Setup Django Admin" -msg_info "Save credential file" -echo "" >~/NetBox.creds -echo "NetBox Database Credentials" >>~/NetBox.creds -echo "" >>~/NetBox.creds -echo -e "NetBox Database User: \e[32m$DB_USER\e[0m" >>~/NetBox.creds -echo -e "NetBox Database Password: \e[32m$DB_PASS\e[0m" >>~/NetBox.creds -echo -e "NetBox Database Name: \e[32m$DB_NAME\e[0m" >>~/NetBox.creds -echo -e "NetBox Admin user: \e[32m$NetBox_USER\e[0m" >>~/NetBox.creds -echo -e "NetBox Admin Password: \e[32m$NetBox_PASS\e[0m" >>~/NetBox.creds -msg_ok "Save cred file" - motd_ssh customize msg_info "Cleaning up" +rm "/opt/v${RELEASE}.zip" $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned" diff --git a/json/netbox.json b/json/netbox.json index 52d03796f..adb1c1f90 100644 --- a/json/netbox.json +++ b/json/netbox.json @@ -6,12 +6,12 @@ ], "date_created": "2024-11-17", "type": "ct", - "updateable": false, + "updateable": true, "privileged": false, "interface_port": "443", "documentation": "https://netboxlabs.com/docs/netbox/en/stable/", - "website": "https://github.com/netbox-community/netbox", - "logo": "https://netboxlabs.com/wp-content/uploads/2023/10/logo_netboxlabs_bright_teal.svg", + "website": "https://netboxlabs.com/", + "logo": "https://github.com/netbox-community/netbox/wiki/images/logos/netbox_icon.svg", "description": "NetBox is the source of truth for everything on your network, from physical components like power systems and cabling to virtual assets like IP addresses and VLANs. Network automation and observability tools depend on NetBox’s authoritative data to roll out configurations, monitor changes, and accelerate operations across the enterprise", "install_methods": [ { @@ -27,13 +27,13 @@ } ], "default_credentials": { - "username": "Admin", - "password": "See output: cat NetBox.creds" + "username": null, + "password": null }, "notes": [ { - "text": "Generated database & admin credentials see output: `cat NetBox.creds`", - "type": "warning" + "text": "Show login and database credentials: `cat netbox.creds`", + "type": "info" } ] } \ No newline at end of file From a0590c0be3dec36f4ebc23d28d9113b8508a9037 Mon Sep 17 00:00:00 2001 From: bvdberg01 Date: Mon, 18 Nov 2024 21:18:50 +0100 Subject: [PATCH 3/3] Fixed issues after pr --- ct/netbox.sh | 22 +++++++++++----------- install/netbox-install.sh | 7 ++----- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ct/netbox.sh b/ct/netbox.sh index 2699e7f4f..f2b13b9d1 100644 --- a/ct/netbox.sh +++ b/ct/netbox.sh @@ -66,24 +66,24 @@ if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_v msg_ok "Stopped ${APP}" msg_info "Updating $APP to v${RELEASE}" - mv /opt/netbox/ /opt/netbod-oldversion + mv /opt/netbox/ /opt/netbox-backup cd /opt wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.zip" unzip -q "v${RELEASE}.zip" mv /opt/netbox-${RELEASE}/ /opt/netbox/ - cp -r /opt/netbod-oldversion/netbox/netbox/configuration.py /opt/netbox/netbox/netbox/ - cp -r /opt/netbod-oldversion/netbox/media/ /opt/netbox/netbox/ - cp -r /opt/netbod-oldversion/netbox/scripts /opt/netbox/netbox/ - cp -r /opt/netbod-oldversion/netbox/reports /opt/netbox/netbox/ - cp -r /opt/netbod-oldversion/gunicorn.py /opt/netbox/ + cp -r /opt/netbox-backup/netbox/netbox/configuration.py /opt/netbox/netbox/netbox/ + cp -r /opt/netbox-backup/netbox/media/ /opt/netbox/netbox/ + cp -r /opt/netbox-backup/netbox/scripts /opt/netbox/netbox/ + cp -r /opt/netbox-backup/netbox/reports /opt/netbox/netbox/ + cp -r /opt/netbox-backup/gunicorn.py /opt/netbox/ - if [ -d /opt/netbod-oldversion/local_requirements.txt ]; then - cp -r /opt/netbod-oldversion/local_requirements.txt /opt/netbox/ + if [ -f /opt/netbox-backup/local_requirements.txt ]; then + cp -r /opt/netbox-backup/local_requirements.txt /opt/netbox/ fi - if [ -d /opt/netbod-oldversion/netbox/netbox/ldap_config.py ]; then - cp -r /opt/netbod-oldversion/netbox/netbox/ldap_config.py /opt/netbox/netbox/netbox/ + if [ -f /opt/netbox-backup/netbox/netbox/ldap_config.py ]; then + cp -r /opt/netbox-backup/netbox/netbox/ldap_config.py /opt/netbox/netbox/netbox/ fi /opt/netbox/upgrade.sh &>/dev/null @@ -96,7 +96,7 @@ if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_v msg_info "Cleaning up" rm -r "/opt/v${RELEASE}.zip" - rm -r /opt/netbod-oldversion + rm -r /opt/netbox-backup msg_ok "Cleaned" msg_ok "Updated Successfully" else diff --git a/install/netbox-install.sh b/install/netbox-install.sh index 384dd3880..81a718322 100644 --- a/install/netbox-install.sh +++ b/install/netbox-install.sh @@ -48,7 +48,7 @@ echo -e "Netbox Database Name: \e[32m$DB_NAME\e[0m" } >> ~/netbox.creds msg_ok "Set up PostgreSQL" -msg_info "Installing NetBox" +msg_info "Installing NetBox (Patience)" cd /opt RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }') wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.zip" @@ -85,10 +85,7 @@ systemctl daemon-reload systemctl enable -q --now netbox netbox-rq echo "${RELEASE}" >/opt/${APPLICATION}_version.txt -{ -echo -e "Netbox Secret: \e[32m$SECRET_KEY\e[0m" -} >> ~/netbox.creds -msg_ok "Set up PostgreSQL" +echo -e "Netbox Secret: \e[32m$SECRET_KEY\e[0m" >> ~/netbox.creds msg_ok "Installed NetBox" msg_info "Setting up Django Admin"