Skip to content

Commit

Permalink
Update json/netbox.json
Browse files Browse the repository at this point in the history
Co-Authored-By: Håvard Gjøby Thom <[email protected]>
  • Loading branch information
bvdberg01 and havardthom committed Nov 18, 2024
1 parent 515eb30 commit 60da4ee
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 85 deletions.
76 changes: 45 additions & 31 deletions ct/netbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
101 changes: 54 additions & 47 deletions install/netbox-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
14 changes: 7 additions & 7 deletions json/netbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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"
}
]
}

0 comments on commit 60da4ee

Please sign in to comment.