Compare commits

...

14 Commits

Author SHA1 Message Date
88d8054d53 Added a section that will install the desktop file if it isn't detected as installed 2023-11-18 18:40:49 -06:00
0a53b9674d Re-enabled the desktop portion of the installer, was testing out other features 2023-11-18 15:15:22 -06:00
9074cf529d Added a few menues for user to choose timezone and locale 2023-11-18 14:27:06 -06:00
6b20dba53e Began implementing timezone logic 2023-11-18 12:59:17 -06:00
6c660b941a Merge remote branch “origin/master” 2023-11-18 12:43:41 -06:00
de14c072f7 Added new helper functions to make script more interactive, and implemented them. 2023-11-18 12:41:35 -06:00
Tristan Ancelet
7d1a292111 Made a new script to handle sending an alert email if postfix is found to have crashed 2023-11-17 13:37:45 -06:00
2437e4a869 Had to change INSTALL_DIR to my actual install dir ($HOME/.opt) 2023-11-13 21:36:33 -06:00
3102d34556 Had to fix typo with getenforce (was genenforce), and fix some comments 2023-11-13 20:14:13 -06:00
708d599cce Had to delete and re-add repo to this repo 2023-11-13 20:08:04 -06:00
c6c5af8c36 Yes 2023-11-12 18:20:41 -06:00
b160492424 added new project 2023-11-12 18:12:49 -06:00
8d986d7a77 Had to fix a few spelling errors and update the path of one of the variables 2023-11-11 15:18:30 -06:00
9dc28a1cf6 Just mocked up a script to install LibreNMS, my coworker want's us to use this for network monitoring instead of zabbix. So I thought I might give it a try 2023-11-11 15:03:41 -06:00
7 changed files with 469 additions and 23 deletions

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "DnD-Tools"] [submodule "DnD-Tools"]
path = DnD-Tools path = DnD-Tools
url = GS:tristan/dnd-tools url = GS:tristan/dnd-tools
[submodule "DHCPInfo"]
path = DHCPInfo
url = gitea@git.arcanium.tech:tristan/DHCPInfo

1
DHCPInfo Submodule

Submodule DHCPInfo added at 9320c9d340

View File

@@ -1,33 +1,150 @@
#!/usr/bin/bash #!/usr/bin/bash
# BEGIN: Helper Functions
get_disks () {
local -a FOUND_DISKS
local -n OUTPUT_VAR="${1:?"get_disks: No variable was passed through"}"
if ls /dev/?d? >/dev/null 2>&1; then
FOUND_DISKS+=( /dev/?d? )
fi
if ls /dev/nvmen? >/dev/null 2>&1 ; then
FOUND_DISKS+=( /dev/nvmen? )
fi
OUTPUT_VAR=( ${FOUND_DISKS[@]} )
}
get_choices () {
local PROMPT="$1"
shift
local -n OUTPUT_VAR="$2"
shift
local -a OPTIONS=( $@ )
select item in ${OPTIONS[@]} quit; do
case $item in
quit)
return 0
;;
?)
continue
;;
*)
if [[ "$item" ]]; then
OUTPUT_VAR+=( "$item" )
fi
;;
esac
done
}
get_choice () {
echo "1: $1"
local PROMPT="$1"
local -n OUTPUT_VAR="$2"
shift
shift
local -a OPTIONS=( $@ )
select item in ${OPTIONS[@]} quit; do
case $item in
quit)
return 0
;;
?)
continue
;;
*)
if [[ "$item" ]]; then
OUTPUT_VAR="$item"
return 0
fi
;;
esac
done
}
get_yes_no () {
local PROMPT="${1:?"get_yes_no: Prompt was not provided"} "
local CHOICE_REGEX='(y|n|yes|no)'
local ANSWER
while true; do
read -p "$PROMPT" ANSWER
ANSWER="${ANSWER,,}"
if [[ "$ANSWER" =~ ^$CHOICE_REGEX$ ]]; then
case $ANSWER in
y | yes)
return 0
;;
n | no)
return 1
;;
esac
else
echo "$ANSWER is not acceptible, please try again"
fi
done
}
get_answer () {
local PROMPT="${1:?"get_answer: Prompt was not provided"}"
local -n OUTER_VAR="${2:?"get_answer: Return variable not provided"}"
local ANSWER
while true; do
read -p "$PROMPT" ANSWER
if get_yes_no "Are you sure $ANSWER is what you want? (y/n): "; then
OUTER_VAR="$ANSWER"
return
fi
done
}
# END: Helper Functions
# BEGIN: Variables # BEGIN: Variables
HOSTNAME="ExampleHostname" HOSTNAME=""
BOOT_METHOD="${1:?"Boot method was not provided. (BIOS, EFI)"}" get_answer "What is the hostname of this machine?: " HOSTNAME
BOOT_METHOD="${BOOT_METHOD^^}"
[[ ! "$BOOT_METHOD" =~ ^(EFI|BIOS)$ ]] && { BOOT_METHOD=""
echo "Your boot method $BOOT_METHOD, is not acceptible. Please provide a vaild one" get_choice "What is your boot method?: " BOOT_METHOD BIOS EFI
exit
} DISK=""
declare -a DISKS
get_disks DISKS
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
DISK="${2:?"Disk was not provided"}"
[[ ! -b $DISK ]] && {
echo "Your disk ($DISK) does not exist. Please provide a valid one"
exit
}
EFI_PARTITION=${DISK}1 EFI_PARTITION=${DISK}1
SWAP_PARTITION=${DISK}2 SWAP_PARTITION=${DISK}2
ROOT_PARTITION=${DISK}3 ROOT_PARTITION=${DISK}3
## New Login creds for your new user and the root user ## New Login creds for your new user and the root user
ROOT_PASSWORD="root" ROOT_PASSWORD=""
NEW_USER="username" get_answer "What do you want the root password to be? : " ROOT_PASSWORD
NEW_PASSWORD="password"
TIMEZONE_INFO=America/Chicago NEW_USER=""
LOCALE=en_US.UTF-8 get_answer "What other user do you want to configure on the system? : " NEW_USER
NEW_PASSWORD=""
get_answer "What do you want the password for $NEW_USER to be? : " NEW_PASSWORD
declare -a TIMEZONES=( $( timedatectl list-timezones ) )
TIMEZONE_INFO=""
get_choice "What is your timezone? : " TIMEZONE_INFO ${TIMEZONES[@]}
declare -a LOCALES=( $( localectl list-locales ) )
LOCALE=""
get_choice "What is your locale? : " LOCALE ${LOCALES[@]}
## Commands to create disks un-interactively with fdisk ## Commands to create disks un-interactively with fdisk
## will clean up comments later with grep command ## will clean up comments later with grep command
@@ -256,10 +373,10 @@ grub-mkconfig -o /boot/grub/grub.cfg
# This is the default desktop manager (login screen) for gnome. This just handles the login screen and starting up your desktop session & windowing system based off of your choices. # This is the default desktop manager (login screen) for gnome. This just handles the login screen and starting up your desktop session & windowing system based off of your choices.
## Install desktop env ## Install desktop env
#pacman -S --noconfirm gnome pacman -S --noconfirm gnome
## Enable desktop manager/login-screen ## Enable desktop manager/login-screen
#systemctl enable gdm systemctl enable gdm
## Setting root password ## Setting root password
echo -e '$ROOT_PASSWORD\n$ROOT_PASSWORD\n' | passwd echo -e '$ROOT_PASSWORD\n$ROOT_PASSWORD\n' | passwd

106
check-postfix.sh Executable file
View File

@@ -0,0 +1,106 @@
#!/usr/bin/bash
# BEGIN: Variables
## Duration to wait to see if service has come back up
DURATION=10
## Wait duration to send next part of message
WAIT=1
## Test flag
TEST=0
## Email addresses
NOTIFY_EMAIL=recipient@domain.com
MAIL_FROM=username@domain.net
DAMAIN=` echo $NOTIFY_EMAIL | cut -d @ -f 2 `
# END: Variables
# BEGIN: Helper Functions
send_email () {
local MESSAGE="${1:?"send_email: No message was passed through"}"
sendmail $NOTIFY_EMAIL <<< "$MESSAGE"
}
: "
The only option is to manually telnet to the smtp port on the authoritative mailserver for the target domain. As otherwise unless a mail-host is configured for email proxy, you will be unable to send an email to a user outside of the mailservers domain (without authentication).
"
do_emergency_email () {
local MESSAGE="${1:-"The Postfix service has failed to come up on tartarus (192.168.3.2) after a service restart. Please ssh into server to troubleshoot the issues."}"
## Getting a mailserver IP for manual message
MAILSERVER=`dig $DOMAIN mx | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -n 1`
## Setting up coprocess to send commands to telnet session
coproc TELNET { telnet $MAILSERVER 25; }
## Commands to send email manually
local -a commands=(
"ehlo camtel.net\n"
"mail from: <$MAIL_FROM>\n"
"rcpt to: <$NOTIFY_EMAIL>\n"
"data\n"
"Subject: Postfix Service Failure\nFrom: $MAIL_FROM\nTo: $NOTIFY_EMAIL\n"
"$MESSAGE\n\n.\n"
"quit\n"
)
## Iterate through commands and send them to coprocesses
### We need to wait before each command as the remote mailserver will not catch everything otherwise.
for i in ${!commands[@]}; do
COMMAND="${commands[$i]}"
echo -e "$COMMAND" >&${TELNET[1]}
sleep $WAIT
done
}
# END: Helper Functions
# BEGIN: Test Check
if [[ $TEST -eq 1 ]]; then
MESSAGE_1="
This is a test message to verify that postfix can send an email
"
send_email "$MESSAGE_1"
MESSAGE_2="This is a test email to make sure the postfix crash workaround email works"
do_emergency_email "$MESSAGE_2"
exit
fi
# END: Test Check
# BEGIN: Work
if [[ `systemctl is-active postfix` != 'active' ]]; then
systemctl restart postfix
sleep $DURATION
SERVICE_STATUS=` systemctl is-active postfix `
if [[ "$SERVICE_STATUS" == 'active' ]]; then
MESSAGE="
SUBJECT: Postfix Service Failure
FROM: root
TO: $NOTIFY_EMAIL
The postfix service on `hostname` (`hostname -i`) was found to be not running.
The service has been restarted, and after waiting $DURATION seconds it was found to be $SERVICE_STATUS.
"
send_email "$MESSAGE"
else
do_emergency_email
fi
fi
# END: Work

View File

@@ -5,11 +5,14 @@
ACTION="" ACTION=""
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz' DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+' VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+'
INSTALL_DIR=~/Downloads INSTALL_DIR=~/.opt
EXISTING_INSTALL=$INSTALL_DIR/Discord EXISTING_INSTALL=$INSTALL_DIR/Discord
BUILD_FILE=$EXISTING_INSTALL/resources/build_info.json BUILD_FILE=$EXISTING_INSTALL/resources/build_info.json
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
PACKAGE_DOWNLOAD_URL_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz' PACKAGE_DOWNLOAD_URL_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
ICON_DIR=~/.icons ICON_DIR=~/.icons
DESKTOP_FILE_INSTALLED=0
[[ -f /usr/share/applications/discord.desktop ]] && DESKTOP_FILE_INSTALLED=1
# END: Variables # END: Variables
@@ -46,7 +49,7 @@ function do_download(){
FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}" FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}"
## Downloading the discord package (tar.gz) ## Downloading the discord package (tar.gz)
curl "$PACKAGE_DOWNLOAD_URL" -o "$FILENAME" >/dev/null curl "$PACKAGE_DOWNLOAD_URL" -o "$FILENAME" >/dev/null 2>&1
} }
function update_desktop_file() { function update_desktop_file() {
@@ -105,7 +108,7 @@ function do_install() {
[[ ! -d $ICON_DIR ]] && mkdir -p $ICON_DIR [[ ! -d $ICON_DIR ]] && mkdir -p $ICON_DIR
cp $EXISTING_INSTALL/discord.png $ICON_DIR/ cp $EXISTING_INSTALL/discord.png $ICON_DIR/
desktop-file-isntall $DESKTOP_FILE sudo desktop-file-isntall $DESKTOP_FILE
} }
function do_upgrade(){ function do_upgrade(){
@@ -120,6 +123,10 @@ function do_upgrade(){
tar xf "$FILENAME" tar xf "$FILENAME"
update_desktop_file update_desktop_file
if [[ $DESKTOP_FILE_INSTALLED -eq 0 ]]; then
sudo desktop-file-install $DESKTOP_FILE
fi
} }
# END: Helper Functions # END: Helper Functions

212
install-librenms.sh Executable file
View File

@@ -0,0 +1,212 @@
#!/usr/bin/bash
: "
install-librenms.sh
This is just a script I created to handle automating the installation of LibreNMS on a Rocky 8 machine (any distro will do)
I will update it after getting my own instance setup in my lab, as my coworkers are wanting to use this for work. Will design it to actually handle settings already being set (so it will skip the un-necessary steps)
"
# BEGIN: Variables
## These are variables that will be used often throughout the script. So Putting them here to easily change for your deployment.
## Settings or values
TIMEZONE=America/Chicago
SQL_PASSWORD="testpass"
FQDN=librenms.example.com
LIBRENMS_ROOT=/opt/librenms
SNMP_COMMUNITY=lab
## Config Files that need to be interacted with throughout the script
SELINUX_CONFIG=/etc/selinux/config
PHP_ini=/etc/php.ini
MARIADB_CONF=/etc/my.cnf.d/mariadb-server.cnf
PHP_FPM_LIBRENMS=/etc/php-fpm.d/librenms.conf
LIBRENMS_HTTPD_CONF=/etc/httpd/conf.d/librenms.conf
DEFAULT_PHP_FPM_CONF=/etc/php-fpm.d/www.conf
LIBRENMS_SNMP_CONF=$LIBRENMS_ROOT/snmpd.conf.example
SNMP_CONF=/etc/snmp/snmpd.conf
LIBRENMS_CRON=$LIBRENMS_ROOT/dist/librenms.cron
LIBRENMS_CRON_DEST=/etc/cron.d/librenms
LIBRENMS_LOGROTATE_CONF=/opt/librenms/misc/librenms.logrotate
LIBRENMS_LOGROTATE_DEST=/etc/logrotate.d/librenms
## For socket changes in PHP_FPM_LIBRENMS
NEW_SOCKET=/run/php-fpm-librenms.sock
OLD_SOCKET=/run/php-fpm/www.sock
# END: Variables
# BEGIN: Work
## Install Dependencies
dnf -y install epel-release
dnf -y install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module reset php
dnf module enable php:remi-8.1
dnf install bash-completion cronie fping gcc git httpd ImageMagick mariadb-server mtr net-snmp net-snmp-utils nmap php-fpm php-cli php-common php-curl php-gd php-gmp php-json php-mbstring php-process php-snmp php-xml php-zip php-mysqlnd python3 python3-devel python3-PyMySQL python3-redis python3-memcached python3-pip python3-systemd rrdtool unzip
## Add librenms user
useradd librenms -d $LIBRENMS_ROOT -M -r -s "$(which bash)"
## Download LibreNMS
cd `dirname $LIBRENMS_ROOT`
git clone https://github.com/librenms/librenms.git
## Set Permissions
chown -R librenms:librenms $LIBRENMS_ROOT
chmod 771 $LIBRENMS_ROOT
setfacl -d -m g::rwx $LIBRENMS_ROOT/rrd $LIBRENMS_ROOT/logs $LIBRENMS_ROOT/bootstrap/cache/ $LIBRENMS_ROOT/storage/
setfacl -R -m g::rwx $LIBRENMS_ROOT/rrd $LIBRENMS_ROOT/logs $LIBRENMS_ROOT/bootstrap/cache/ $LIBRENMS_ROOT/storage/
## Install php deps
su - librenms <<< "
./scripts/composer_wrapper.php install --no-dev
exit
"
## Set timezones
### Have to change the / in America/Chicago to \/ (America\/Chicago) so that it doesn't cause problems with sed
TIMEZONE_CLEANED="${TIMEZONE/\//\\/}"
### Make backup
cp $PHP_ini{,.bak}
sed -i s"/\;date.timezone=/date.timezone=$TIMEZONE_CLEANED/" $PHP_ini
### Configure timezone with system
timedatectl set-timezone $TIMEZONE
## Configure MariaDB
### Make backup of file
cp $MARIADB_CONF{,.bak}
### Configure options in mariadb-server.cnf
sed -i s'/\[mysqld\]/\[mysqld\]\ninnodb_file_per_table=1\nlower_case_table_names=0/' $MARIADB_CONF
#systemctl enable --now mariadb
systemctl enable mariadb
systemctl restart mariadb
## Create the librenms user in mysql/mariadb-server
mysql -u root <<EOF
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY '$SQL_PASSWORD';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
exit
EOF
# Configure PHP-FPM
cp $DEFAULT_PHP_FPM_CONF $PHP_FPM_LIBRENMS
## Make Backup
cp $PHP_FPM_LIBRENMS{,.bak}
## Replace [www] with [librenms]
sed -i s'/\[www\]/\[librenms\]/' $PHP_FPM_LIBRENMS
## Change user
sed -i s'/user = apache/user = librenms/' $PHP_FPM_LIBRENMS
## Change group
sed -i s'/group = apache/group = librenms/' $PHP_FPM_LIBRENMS
## Change socket
FROM_SOCKET="${OLD_SOCKET//\//\\/}" # Cleaning
TO_SOCKET="${NEW_SOCKET//\//\\/}" # Cleaning
### Doing the change
sed -i s"/listen = $FROM_SOCKET/listen = $TO_SOCKET/" $PHP_FPM_LIBRENMS
## Configure WebServer
### Remove default config
rm -f /etc/httpd/conf.d/welcome.conf
cat > $LIBRENMS_HTTPD_CONF <<EOF
<VirtualHost *:80>
DocumentRoot $LIBRENMS_ROOT/html/
ServerName $FQDN
AllowEncodedSlashes NoDecode
<Directory "$LIBRENMS_ROOT/html/">
Require all granted
AllowOverride All
Options FollowSymLinks MultiViews
</Directory>
# Enable http authorization headers
<IfModule setenvif_module>
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
</IfModule>
<FilesMatch ".+\.php$">
SetHandler "proxy:unix:$NEW_SOCKET|fcgi://localhost"
</FilesMatch>
</VirtualHost>
EOF
## Enable webserver and php-fpm
systemctl enable --now httpd
systemctl enable --now php-fpm
# Disable Selinux
SELINUX_STATE=` grep -Eo 'SELINUX=\S+' $SELINUX_CONFIG | cut -d \= -f 2`
if [[ "${SELINUX_STATE,,}" =~ ^enforcing|permissive$ ]]; then
cp $SELINUX_CONFIG{,.bak}
sed -i s"/SELINUX=$SELINUX_STATE/SELINUX=disabled/" $SELINUX_CONFIG
fi
## If the running selinux is still set to enforcing, set it to permissive (will be diabled next boot)
if [[ `getenforce` == 'Enforcing' ]]; then
setenforce 0
fi
## Allow connections through firewall
### By default Rocky (and most other RedHat family of distros) use firewalld
if [[ `firewall-cmd --state` == 'running' ]]; then
### Using bash expansion
firewall-cmd --zone=public --add-service={http,https}
firewall-cmd --zone=public --add-service={http,https} --perm
fi
## Setup lnms command completion (via bash-completion)
ln -s /opt/librenms/lnms /usr/bin/lnms
cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
## Configure SNMP
cp -f $SNMP_CONF{,.bak}
cat $LIBRENMS_SNMP_CONF > $SNMP_CONF
### Backup
### Replace RANDOMSTRINGGOESHERE with SNMP_COMMUNITY
sed -i s"/RANDOMSTRINGGOESHERE/$SNMP_COMMUNITY/" $SNMP_CONF
### Setup librenms agent
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /usr/bin/distro
### Restart snmpd to load new settings
systemctl enable snmpd
systemctl restart snmpd
### Setup librenms crontab
cp $LIBRENMS_CRON $LIBRENMS_CRON_DEST
## Enable systemd schedulers
cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/
systemctl enable librenms-scheduler.timer
systemctl start librenms-scheduler.timer
## Configure logrotate
cp $LIBRENMS_LOGROTATE_CONF $LIBRENMS_LOGROTATE_DEST
# END: Work