Skip to content

Commit 515eb30

Browse files
authored
new scripts for NetBox
1 parent 60ae3f1 commit 515eb30

File tree

3 files changed

+254
-0
lines changed

3 files changed

+254
-0
lines changed

ct/netbox.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/usr/bin/env bash
2+
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)
3+
# Copyright (c) 2021-2024 community-scripts ORG
4+
# Author: bvdberg01
5+
# License: MIT
6+
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
7+
8+
function header_info {
9+
clear
10+
cat <<"EOF"
11+
__ __
12+
____ ___ / /_/ /_ ____ _ __
13+
/ __ \/ _ \/ __/ __ \/ __ \| |/_/
14+
/ / / / __/ /_/ /_/ / /_/ /> <
15+
/_/ /_/\___/\__/_.___/\____/_/|_|
16+
17+
EOF
18+
}
19+
header_info
20+
echo -e "Loading..."
21+
APP="Netbox"
22+
var_disk="4"
23+
var_cpu="2"
24+
var_ram="2048"
25+
var_os="debian"
26+
var_version="12"
27+
variables
28+
color
29+
catch_errors
30+
31+
function default_settings() {
32+
CT_TYPE="1"
33+
PW=""
34+
CT_ID=$NEXTID
35+
HN=$NSAPP
36+
DISK_SIZE="$var_disk"
37+
CORE_COUNT="$var_cpu"
38+
RAM_SIZE="$var_ram"
39+
BRG="vmbr0"
40+
NET="dhcp"
41+
GATE=""
42+
APT_CACHER=""
43+
APT_CACHER_IP=""
44+
DISABLEIP6="no"
45+
MTU=""
46+
SD=""
47+
NS=""
48+
MAC=""
49+
VLAN=""
50+
SSH="no"
51+
VERB="no"
52+
echo_default
53+
}
54+
55+
function update_script() {
56+
header_info
57+
if [[ ! -f /opt/netbox/netbox/netbox/configuration.py ]]; then msg_error "No ${APP} Installation Found!"; exit; fi
58+
RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
59+
if [ ! -d "/opt/netbox-${RELEASE}" ]; then
60+
msg_info "Updating $APP LXC"
61+
apt-get update &>/dev/null
62+
apt-get -y upgrade &>/dev/null
63+
64+
OLD_VERSION_PATH=$(ls -d /opt/netbox-*/)
65+
wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.tar.gz"
66+
tar -xzf "v${RELEASE}.tar.gz" -C /opt
67+
ln -sfn "/opt/netbox-${RELEASE}/" /opt/netbox
68+
rm "v${RELEASE}.tar.gz"
69+
70+
cp "${OLD_VERSION_PATH}netbox/netbox/configuration.py" /opt/netbox/netbox/netbox/
71+
cp -pr "${OLD_VERSION_PATH}netbox/media/" /opt/netbox/netbox/
72+
cp -r "${OLD_VERSION_PATH}netbox/scripts" /opt/netbox/netbox/
73+
cp -r "${OLD_VERSION_PATH}netbox/reports" /opt/netbox/netbox/
74+
cp "${OLD_VERSION_PATH}gunicorn.py" /opt/netbox/
75+
76+
if [ -d "${OLD_VERSION_PATH}local_requirements.txt" ]; then
77+
cp "${OLD_VERSION_PATH}local_requirements.txt" /opt/netbox/
78+
fi
79+
80+
if [ -d "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" ]; then
81+
cp "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" /opt/netbox/netbox/netbox/
82+
fi
83+
84+
rm -r "${OLD_VERSION_PATH}"
85+
/opt/netbox/upgrade.sh &>/dev/null
86+
systemctl restart --now netbox netbox-rq
87+
msg_ok "Updated $APP LXC"
88+
else
89+
msg_ok "No update required. ${APP} is already at ${RELEASE}"
90+
fi
91+
exit
92+
}
93+
94+
start
95+
build_container
96+
description
97+
98+
msg_ok "Completed Successfully!\n"
99+
echo -e "${APP} should be reachable by going to the following URL.
100+
${BL}https://${IP}${CL} \n"

install/netbox-install.sh

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2021-2024 community-scripts ORG
4+
# Author: bvdberg01
5+
# License: MIT
6+
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
7+
8+
source /dev/stdin <<< "$FUNCTIONS_FILE_PATH"
9+
color
10+
verb_ip6
11+
catch_errors
12+
setting_up_container
13+
network_check
14+
update_os
15+
16+
msg_info "Installing Dependencies"
17+
$STD apt-get update
18+
$STD apt-get install -y curl
19+
$STD apt-get install -y sudo
20+
$STD apt-get install -y mc
21+
$STD apt-get install -y apache2
22+
$STD apt-get install -y redis-server
23+
$STD apt-get install -y postgresql
24+
$STD apt-get install -y python3
25+
$STD apt-get install -y python3-pip
26+
$STD apt-get install -y python3-venv
27+
$STD apt-get install -y python3-dev
28+
$STD apt-get install -y build-essential
29+
$STD apt-get install -y libxml2-dev
30+
$STD apt-get install -y libxslt1-dev
31+
$STD apt-get install -y libffi-dev
32+
$STD apt-get install -y libpq-dev
33+
$STD apt-get install -y libssl-dev
34+
$STD apt-get install -y zlib1g-dev
35+
msg_ok "Installed Dependencies"
36+
37+
msg_info "Setting up PostgreSQL"
38+
DB_NAME=netbox
39+
DB_USER=netbox
40+
DB_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
41+
$STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PASS';"
42+
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;"
43+
msg_ok "Set up PostgreSQL"
44+
45+
msg_info "Installing NetBox"
46+
RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
47+
wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.tar.gz"
48+
tar -xzf "v${RELEASE}.tar.gz" -C /opt
49+
ln -s "/opt/netbox-${RELEASE}/" /opt/netbox
50+
rm "v${RELEASE}.tar.gz"
51+
52+
$STD adduser --system --group netbox
53+
chown --recursive netbox /opt/netbox/netbox/media/
54+
chown --recursive netbox /opt/netbox/netbox/reports/
55+
chown --recursive netbox /opt/netbox/netbox/scripts/
56+
57+
cp /opt/netbox/netbox/netbox/configuration_example.py /opt/netbox/netbox/netbox/configuration.py
58+
59+
secret=$(python3 /opt/netbox/netbox/generate_secret_key.py)
60+
escaped_secret=$(printf '%s\n' "$secret" | sed 's/[&/\]/\\&/g')
61+
62+
sed -i 's/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = ["*"]/' /opt/netbox/netbox/netbox/configuration.py
63+
sed -i "s|SECRET_KEY = ''|SECRET_KEY = '${escaped_secret}'|" /opt/netbox/netbox/netbox/configuration.py
64+
sed -i "/DATABASE = {/,/}/s/'USER': '[^']*'/'USER': '$DB_USER'/" /opt/netbox/netbox/netbox/configuration.py
65+
sed -i "/DATABASE = {/,/}/s/'PASSWORD': '[^']*'/'PASSWORD': '$DB_PASS'/" /opt/netbox/netbox/netbox/configuration.py
66+
67+
$STD /opt/netbox/upgrade.sh &>/dev/null
68+
sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping
69+
70+
sudo cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf
71+
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
72+
$STD a2enmod ssl proxy proxy_http headers rewrite
73+
$STD a2ensite netbox
74+
systemctl restart apache2
75+
76+
cp /opt/netbox/contrib/gunicorn.py /opt/netbox/gunicorn.py
77+
cp /opt/netbox/contrib/*.service /etc/systemd/system/
78+
systemctl daemon-reload
79+
systemctl enable -q --now netbox netbox-rq
80+
81+
msg_ok "Installed NetBox"
82+
83+
msg_info "Setting up Django Admin"
84+
NetBox_USER=Admin
85+
NetBox_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
86+
87+
source /opt/netbox/venv/bin/activate
88+
$STD python3 /opt/netbox/netbox/manage.py shell << EOF
89+
from django.contrib.auth import get_user_model
90+
UserModel = get_user_model()
91+
user = UserModel.objects.create_user('$NetBox_USER', password='$NetBox_PASS')
92+
user.is_superuser = True
93+
user.is_staff = True
94+
user.save()
95+
EOF
96+
msg_ok "Setup Django Admin"
97+
98+
msg_info "Save credential file"
99+
echo "" >~/NetBox.creds
100+
echo "NetBox Database Credentials" >>~/NetBox.creds
101+
echo "" >>~/NetBox.creds
102+
echo -e "NetBox Database User: \e[32m$DB_USER\e[0m" >>~/NetBox.creds
103+
echo -e "NetBox Database Password: \e[32m$DB_PASS\e[0m" >>~/NetBox.creds
104+
echo -e "NetBox Database Name: \e[32m$DB_NAME\e[0m" >>~/NetBox.creds
105+
echo -e "NetBox Admin user: \e[32m$NetBox_USER\e[0m" >>~/NetBox.creds
106+
echo -e "NetBox Admin Password: \e[32m$NetBox_PASS\e[0m" >>~/NetBox.creds
107+
msg_ok "Save cred file"
108+
109+
motd_ssh
110+
customize
111+
112+
msg_info "Cleaning up"
113+
$STD apt-get -y autoremove
114+
$STD apt-get -y autoclean
115+
msg_ok "Cleaned"

json/netbox.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "NetBox",
3+
"slug": "netbox",
4+
"categories": [
5+
11
6+
],
7+
"date_created": "2024-11-17",
8+
"type": "ct",
9+
"updateable": false,
10+
"privileged": false,
11+
"interface_port": "443",
12+
"documentation": "https://netboxlabs.com/docs/netbox/en/stable/",
13+
"website": "https://github.com/netbox-community/netbox",
14+
"logo": "https://netboxlabs.com/wp-content/uploads/2023/10/logo_netboxlabs_bright_teal.svg",
15+
"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",
16+
"install_methods": [
17+
{
18+
"type": "default",
19+
"script": "ct/netbox.sh",
20+
"resources": {
21+
"cpu": "2",
22+
"ram": "2048",
23+
"hdd": "4",
24+
"os": "debian",
25+
"version": "12"
26+
}
27+
}
28+
],
29+
"default_credentials": {
30+
"username": "Admin",
31+
"password": "See output: cat NetBox.creds"
32+
},
33+
"notes": [
34+
{
35+
"text": "Generated database & admin credentials see output: `cat NetBox.creds`",
36+
"type": "warning"
37+
}
38+
]
39+
}

0 commit comments

Comments
 (0)