Skip to content

Commit

Permalink
Merge pull request #1 from deku-m/deku-m-patch-1
Browse files Browse the repository at this point in the history
Deku m patch 1
  • Loading branch information
deku-m authored Jan 27, 2023
2 parents ab2fb30 + 63482bc commit 3e06660
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ After that you can also restore the sql-files.
## Menu
Providing a menu with the following:
1. Install
2. Update
3. Configure
2. Update
3. Plugins
1. Install
2. Remove
4. Configure
1. LDAP
2. SSO
4. Backup
5. Backup
1. Full
2. Schema-Only
3. Schedule Job
5. Restore
6. Restore

## Screenshots:
![afbeelding](https://user-images.githubusercontent.com/37069737/213706323-b79ae76d-ba37-4190-aa6d-9f6f14472ef9.png)
Expand Down
69 changes: 67 additions & 2 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ echo -e "=======================================================================
exit 0
}

update() {
update_netbox() {
os_check
netbox_old_version
netbox_new_version
Expand Down Expand Up @@ -626,7 +626,72 @@ echo "Cron job created. Remove $(color_red '/etc/cron.d/'$cron_file'') to stop i
fi
}
install() {
install_plugin() {
echo -e "----------------------------------------------------"
echo -e "$(color_yellow 'Install plugin...')"
echo -e "----------------------------------------------------"
echo -e "Enter the plugin-name for requirements file and press Enter:"
read -r plugin_req
sudo sh -c "echo $plugin_req >> /opt/netbox/netbox/netbox/local_requirements.txt"
echo -e "Enter the plugin_name for config file and press Enter:"
read -r plugin_config
echo -e "Enter the plugin additional configuration for config file and press Enter:"
read -r plugin_additional
if grep '#PLUGINS_CONFIG' /opt/netbox/netbox/netbox/configuration.py ;
then
sed -i "s/#PLUGINS_CONFIG = {/PLUGINS_CONFIG = { \n}/" /opt/netbox/netbox/netbox/configuration.py
else
sed -i "s/\PLUGINS = \[]/PLUGINS = [ \n]/" /opt/netbox/netbox/netbox/configuration.py
sed -i "/\PLUGINS = \[/a\ \t ${plugin_config}," /opt/netbox/netbox/netbox/configuration.py
sed -i "/\PLUGINS_CONFIG = {/a\ \t ${plugin_config} ${plugin_additional}," /opt/netbox/netbox/netbox/configuration.py
fi
source /opt/netbox/venv/bin/activate
pip install $plugin_req
cd /opt/netbox/netbox/ || return
python3 manage.py migrate
python3 manage.py collectstatic --no-input
sudo systemctl restart netbox
echo -e "----------------------------------------------------"
echo -e "$(color_green 'Plugin installation completed')"
echo -e "----------------------------------------------------"
if [ "$?" -gt "0" ];
then
echo -e "----------------------------------------------------------"
echo -e "$(color_red 'Plugin not installed successful.')"
echo -e "----------------------------------------------------------"
exit 1
fi
}
remove_plugin() {
echo -e "----------------------------------------------------"
echo -e "$(color_yellow 'Remove plugin...')"
echo -e "----------------------------------------------------"
echo -e "Enter the plugin-name for requirements file to remove and press Enter:"
read -r plugin_req
sed -i "/${plugin_req}/d" /opt/netbox/netbox/netbox/local_requirements.txt
echo -e "Enter the plugin_name for config file to remove and press Enter:"
read -r plugin_config
sed -i "/${plugin_config}/d" /opt/netbox/netbox/netbox/configuration.py
source /opt/netbox/venv/bin/activate
pip uninstall $plugin_req
cd /opt/netbox/netbox/ || return
python3 manage.py migrate
python3 manage.py collectstatic --no-input
sudo systemctl restart netbox
echo -e "----------------------------------------------------"
echo -e "$(color_green 'Plugin removal completed')"
echo -e "----------------------------------------------------"
if [ "$?" -gt "0" ];
then
echo -e "----------------------------------------------------------"
echo -e "$(color_red 'Plugin not removed successful.')"
echo -e "----------------------------------------------------------"
exit 1
fi
}
install_netbox() {
netbox_new_version
os_check
netbox_check
Expand Down
35 changes: 27 additions & 8 deletions menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ if [[ $EUID -ne 0 ]]; then
exit 1
fi

submenu_p() {
echo -ne "
$(color_red 'Plugins')
$(color_green '1)') Install
$(color_green '2)') Remove
$(color_green '0)') Exit
$(color_blue 'Choose an option:')"
read -r ans
case $ans in
1) install_plugin_ ; submenu_p ;;
2) remove_plugin ; submenu_p ;;
3) mainmenu ;;
0) bye ;;
*) fail ;;
esac
}

submenu_c() {
echo -ne "
$(color_red 'Configure')
Expand Down Expand Up @@ -55,18 +72,20 @@ mainmenu() {
$(color_red 'MAIN MENU')
$(color_green '1)') Install
$(color_green '2)') Update
$(color_green '3)') Configure
$(color_green '4)') Backup
$(color_green '5)') Restore
$(color_green '3)') Plugins
$(color_green '4)') Configure
$(color_green '5)') Backup
$(color_green '6)') Restore
$(color_green '0)') Exit
$(color_blue 'Choose an option:')"
read -r ans
case $ans in
1) install ; mainmenu ;;
2) update ; mainmenu ;;
3) submenu_c ; mainmenu ;;
4) submenu_b ; mainmenu ;;
5) restore ; mainmenu ;;
1) install_netbox ; mainmenu ;;
2) update_netbox ; mainmenu ;;
3) submenu_p ; mainmenu ;;
4) submenu_c ; mainmenu ;;
5) submenu_b ; mainmenu ;;
6) restore ; mainmenu ;;
0) bye ;;
*) fail ;;
esac
Expand Down
2 changes: 2 additions & 0 deletions vars
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

# PASSWORDs
CURDIR=`pwd`
POSTGRESPW=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w25 | head -n1)
SECRET_KEY=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w55 | head -n1)
HOSTNAME=$hostname

# BACKUP FILES FORMAT
full_bck_file='netbox-full-$(date +"%m-%d-%y").sql'
sm_bck_file='netbox-schema-$(date +"%m-%d-%y").sql'

0 comments on commit 3e06660

Please sign in to comment.