Skip to content

Commit 37eeadb

Browse files
author
bvdberg01
committed
Updated based on pull request review
1 parent 515eb30 commit 37eeadb

File tree

3 files changed

+73
-47
lines changed

3 files changed

+73
-47
lines changed

ct/netbox.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,26 @@ function default_settings() {
5454

5555
function update_script() {
5656
header_info
57+
check_container_storage
58+
check_container_resources
5759
if [[ ! -f /opt/netbox/netbox/netbox/configuration.py ]]; then msg_error "No ${APP} Installation Found!"; exit; fi
5860
RELEASE=$(curl -s https://api.github.com/repos/netbox-community/netbox/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
5961
if [ ! -d "/opt/netbox-${RELEASE}" ]; then
62+
63+
msg_info "Stopping ${APP}"
64+
systemctl stop netbox netbox-rq
65+
msg_ok "Stopped ${APP}"
66+
6067
msg_info "Updating $APP LXC"
6168
apt-get update &>/dev/null
6269
apt-get -y upgrade &>/dev/null
6370

6471
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
72+
cd /opt
73+
wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.zip"
74+
unzip -q "v${RELEASE}.zip"
6775
ln -sfn "/opt/netbox-${RELEASE}/" /opt/netbox
68-
rm "v${RELEASE}.tar.gz"
76+
6977

7078
cp "${OLD_VERSION_PATH}netbox/netbox/configuration.py" /opt/netbox/netbox/netbox/
7179
cp -pr "${OLD_VERSION_PATH}netbox/media/" /opt/netbox/netbox/
@@ -81,10 +89,18 @@ if [ ! -d "/opt/netbox-${RELEASE}" ]; then
8189
cp "${OLD_VERSION_PATH}netbox/netbox/ldap_config.py" /opt/netbox/netbox/netbox/
8290
fi
8391

84-
rm -r "${OLD_VERSION_PATH}"
92+
8593
/opt/netbox/upgrade.sh &>/dev/null
86-
systemctl restart --now netbox netbox-rq
87-
msg_ok "Updated $APP LXC"
94+
msg_ok "Updated $APP successfully"
95+
96+
msg_info "Starting ${APP}"
97+
systemctl start netbox netbox-rq
98+
msg_ok "Started ${APP}"
99+
100+
msg_info "Cleaning up"
101+
rm "v${RELEASE}.zip"
102+
rm -rf "${OLD_VERSION_PATH}"
103+
msg_ok "Cleaned"
88104
else
89105
msg_ok "No update required. ${APP} is already at ${RELEASE}"
90106
fi

install/netbox-install.sh

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,24 @@ update_os
1515

1616
msg_info "Installing Dependencies"
1717
$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
18+
$STD apt-get install -y \
19+
curl \
20+
sudo \
21+
mc \
22+
apache2 \
23+
redis-server \
24+
postgresql \
25+
python3 \
26+
python3-pip \
27+
python3-venv \
28+
python3-dev \
29+
build-essential \
30+
libxml2-dev \
31+
libxslt1-dev \
32+
libffi-dev \
33+
libpq-dev \
34+
libssl-dev \
35+
zlib1g-dev
3536
msg_ok "Installed Dependencies"
3637

3738
msg_info "Setting up PostgreSQL"
@@ -42,32 +43,32 @@ $STD sudo -u postgres psql -c "CREATE ROLE $DB_USER WITH LOGIN PASSWORD '$DB_PAS
4243
$STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER TEMPLATE template0;"
4344
msg_ok "Set up PostgreSQL"
4445

45-
msg_info "Installing NetBox"
46+
msg_info "Installing NetBox"
47+
cd /opt
4648
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+
wget -q "https://github.com/netbox-community/netbox/archive/refs/tags/v${RELEASE}.zip"
50+
unzip -q "v${RELEASE}.zip"
4951
ln -s "/opt/netbox-${RELEASE}/" /opt/netbox
50-
rm "v${RELEASE}.tar.gz"
5152

5253
$STD adduser --system --group netbox
5354
chown --recursive netbox /opt/netbox/netbox/media/
5455
chown --recursive netbox /opt/netbox/netbox/reports/
5556
chown --recursive netbox /opt/netbox/netbox/scripts/
5657

57-
cp /opt/netbox/netbox/netbox/configuration_example.py /opt/netbox/netbox/netbox/configuration.py
58+
mv /opt/netbox/netbox/netbox/configuration_example.py /opt/netbox/netbox/netbox/configuration.py
5859

59-
secret=$(python3 /opt/netbox/netbox/generate_secret_key.py)
60-
escaped_secret=$(printf '%s\n' "$secret" | sed 's/[&/\]/\\&/g')
60+
SECRET_KEY=$(python3 /opt/netbox/netbox/generate_secret_key.py)
61+
ESCAPED_SECRET_KEY=$(printf '%s\n' "$SECRET_KEY" | sed 's/[&/\]/\\&/g')
6162

6263
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 "s|SECRET_KEY = ''|SECRET_KEY = '${ESCAPED_SECRET_KEY}'|" /opt/netbox/netbox/netbox/configuration.py
6465
sed -i "/DATABASE = {/,/}/s/'USER': '[^']*'/'USER': '$DB_USER'/" /opt/netbox/netbox/netbox/configuration.py
6566
sed -i "/DATABASE = {/,/}/s/'PASSWORD': '[^']*'/'PASSWORD': '$DB_PASS'/" /opt/netbox/netbox/netbox/configuration.py
6667

6768
$STD /opt/netbox/upgrade.sh &>/dev/null
68-
sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping
69+
ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping
6970

70-
sudo cp /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf
71+
mv /opt/netbox/contrib/apache.conf /etc/apache2/sites-available/netbox.conf
7172
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
7273
$STD a2enmod ssl proxy proxy_http headers rewrite
7374
$STD a2ensite netbox
@@ -81,29 +82,37 @@ systemctl enable -q --now netbox netbox-rq
8182
msg_ok "Installed NetBox"
8283

8384
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)
85+
DJANGO_USER=Admin
86+
DJANGO_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
8687

8788
source /opt/netbox/venv/bin/activate
8889
$STD python3 /opt/netbox/netbox/manage.py shell << EOF
8990
from django.contrib.auth import get_user_model
9091
UserModel = get_user_model()
91-
user = UserModel.objects.create_user('$NetBox_USER', password='$NetBox_PASS')
92+
user = UserModel.objects.create_user('$DJANGO_USER', password='$DJANGO_PASS')
9293
user.is_superuser = True
9394
user.is_staff = True
9495
user.save()
9596
EOF
9697
msg_ok "Setup Django Admin"
9798

9899
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
100+
# PSQL:
101+
{
102+
echo "Netbox-Credentials"
103+
echo -e "Netbox Database User: \e[32m$DB_USER\e[0m"
104+
echo -e "Netbox Database Password: \e[32m$DB_PASS\e[0m"
105+
echo -e "Netbox Database Name: \e[32m$DB_NAME\e[0m"
106+
echo -e "Netbox Secret: \e[32m$SECRET_KEY\e[0m"
107+
} >> ~/netbox.creds
108+
109+
# DJANGO:
110+
{
111+
echo ""
112+
echo "Netbox-Django-Credentials"
113+
echo -e "Django User: \e[32m$DJANGO_USER\e[0m"
114+
echo -e "Django Password: \e[32m$DJANGO_PASS\e[0m"
115+
} >> ~/netbox.creds
107116
msg_ok "Save cred file"
108117

109118
motd_ssh
@@ -112,4 +121,5 @@ customize
112121
msg_info "Cleaning up"
113122
$STD apt-get -y autoremove
114123
$STD apt-get -y autoclean
124+
rm "/opt/v${RELEASE}.zip"
115125
msg_ok "Cleaned"

json/netbox.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"interface_port": "443",
1212
"documentation": "https://netboxlabs.com/docs/netbox/en/stable/",
1313
"website": "https://github.com/netbox-community/netbox",
14-
"logo": "https://netboxlabs.com/wp-content/uploads/2023/10/logo_netboxlabs_bright_teal.svg",
14+
"logo": "https://github.com/netbox-community/netbox/wiki/images/logos/netbox_icon.svg",
1515
"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",
1616
"install_methods": [
1717
{
@@ -28,11 +28,11 @@
2828
],
2929
"default_credentials": {
3030
"username": "Admin",
31-
"password": "See output: cat NetBox.creds"
31+
"password": "See output: cat netbox.creds"
3232
},
3333
"notes": [
3434
{
35-
"text": "Generated database & admin credentials see output: `cat NetBox.creds`",
35+
"text": "Generated database & admin credentials see output: `cat netbox.creds`",
3636
"type": "warning"
3737
}
3838
]

0 commit comments

Comments
 (0)