Compare commits
63 Commits
4ab64cc1f1
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
e7f6697038 | ||
|
3be7c31aa5 | ||
|
77eb648a9a | ||
|
1e53f004f7 | ||
|
696a71bd8b | ||
|
713ea521c8 | ||
b6226ad3cb | |||
72549ac3bf | |||
eb875363e1 | |||
7b61dd700a | |||
01a838c7f2 | |||
89cbb8a4d4 | |||
4b409db718 | |||
ef2bb4f28a | |||
2e9d4712fa | |||
50c4834032 | |||
617326fd52 | |||
5501e3fa57 | |||
6cf389acdd | |||
b22dcd6831 | |||
4873410cd2 | |||
|
2a7519024c | ||
|
254e7834b7 | ||
|
8ff7e47140 | ||
|
6806beb733 | ||
|
dd157e834c | ||
|
f504eb3c63 | ||
|
05a05dfca6 | ||
|
22669044db | ||
|
2b6efc9a5d | ||
|
fc82020be3 | ||
|
47fbc1cb8a | ||
2291793f6d | |||
d61b97bc49 | |||
6bb33bad72 | |||
7e1c698858 | |||
97b5db543d | |||
4059d7cfc2 | |||
1991b72b7b | |||
620666220f | |||
60ab5840ba | |||
de8c7de945 | |||
a734bbf83b | |||
02dbe5e0eb | |||
4e5967e3bc | |||
0911f7b134 | |||
f334b8d66e | |||
431918e013 | |||
d15bbd57fa | |||
88d8054d53 | |||
0a53b9674d | |||
9074cf529d | |||
6b20dba53e | |||
6c660b941a | |||
de14c072f7 | |||
|
7d1a292111 | ||
2437e4a869 | |||
3102d34556 | |||
708d599cce | |||
c6c5af8c36 | |||
b160492424 | |||
8d986d7a77 | |||
9dc28a1cf6 |
5
.gitmodules
vendored
5
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
|||||||
[submodule "DnD-Tools"]
|
[submodule "DnD-Tools"]
|
||||||
path = DnD-Tools
|
path = DnD-Tools
|
||||||
url = GS:tristan/dnd-tools
|
url = gitea@git.arcanium.tech:tristan/dnd-tools
|
||||||
|
[submodule "DHCPInfo"]
|
||||||
|
path = DHCPInfo
|
||||||
|
url = gitea@git.arcanium.tech:tristan/DHCPInfo
|
||||||
|
1
DHCPInfo
Submodule
1
DHCPInfo
Submodule
Submodule DHCPInfo added at 9320c9d340
Submodule DnD-Tools updated: 824d0e2487...3c163cec07
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# MyScripts
|
||||||
|
|
||||||
|
## This repo
|
||||||
|
This repo is just meant to house my general-use scripts. I've made MANY scripts over the years working with linux, but it never occured to me to archive them.
|
||||||
|
|
||||||
|
Although I'm trying to get into the habit of it going forward (and you never know, someone might find one of my scripts useful).
|
@@ -1,33 +1,163 @@
|
|||||||
#!/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"
|
||||||
|
local -n OUTPUT_VAR="$2"
|
||||||
|
shift 2
|
||||||
|
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 () {
|
||||||
|
local PROMPT="$1"
|
||||||
|
local -n OUTPUT_VAR="$2"
|
||||||
|
shift 2
|
||||||
|
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="${2:?"Disk was not provided"}"
|
DISK=""
|
||||||
[[ ! -b $DISK ]] && {
|
declare -a DISKS
|
||||||
echo "Your disk ($DISK) does not exist. Please provide a valid one"
|
get_disks DISKS
|
||||||
exit
|
get_choice "Which disk are you wanting to use? : " DISK "${DISKS[@]}"
|
||||||
}
|
|
||||||
EFI_PARTITION=${DISK}1
|
|
||||||
SWAP_PARTITION=${DISK}2
|
|
||||||
ROOT_PARTITION=${DISK}3
|
|
||||||
|
|
||||||
|
# If the disk is a nvme drive
|
||||||
|
if [[ "$DISK" =~ ^/dev/nvmen[0-9]$ ]]; then
|
||||||
|
DISK_BASE=${DISK}p
|
||||||
|
else
|
||||||
|
DISK_BASE="${DISK}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $BOOT_METHOD in
|
||||||
|
EFI)
|
||||||
|
EFI_PARTITION=${DISK_BASE}1
|
||||||
|
SWAP_PARTITION=${DISK_BASE}2
|
||||||
|
ROOT_PARTITION=${DISK_BASE}3
|
||||||
|
;;
|
||||||
|
|
||||||
|
BIOS)
|
||||||
|
SWAP_PARTITION=${DISK_BASE}1
|
||||||
|
ROOT_PARTITION=${DISK_BASE}2
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
## 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
|
||||||
@@ -35,17 +165,6 @@ FORMAT_DISK_COMMANDS_BIOS="
|
|||||||
# Create MBR partition table
|
# Create MBR partition table
|
||||||
o
|
o
|
||||||
|
|
||||||
# Create bios header (area where boot information is stored at the beginning of the disk)
|
|
||||||
n
|
|
||||||
# Create Primary partition (which is technically the default anyway)
|
|
||||||
p
|
|
||||||
# Press Enter to select default partition number
|
|
||||||
|
|
||||||
# Press Enter to select default starting sector
|
|
||||||
|
|
||||||
# Allocate 10 MB at beginning of disk for BIOS table (you will do nothing with it)
|
|
||||||
+10MiB
|
|
||||||
|
|
||||||
# Create Swap Partition
|
# Create Swap Partition
|
||||||
n
|
n
|
||||||
# Create Primary partition (which is technically the default anyway)
|
# Create Primary partition (which is technically the default anyway)
|
||||||
@@ -181,6 +300,9 @@ A program needed for privelege escalation. Basically to provide a user of an adm
|
|||||||
|
|
||||||
Installing it here because it is not installed by default. An alternative is doas, a utility to perform the same funciton.
|
Installing it here because it is not installed by default. An alternative is doas, a utility to perform the same funciton.
|
||||||
"
|
"
|
||||||
|
pacman -Sy archlinux-keyring
|
||||||
|
pacman-key --init
|
||||||
|
pacman-key --populate archlinux
|
||||||
pacstrap /mnt base linux linux-headers linux-firmware sudo
|
pacstrap /mnt base linux linux-headers linux-firmware sudo
|
||||||
|
|
||||||
## Setting up fstab
|
## Setting up fstab
|
||||||
@@ -256,10 +378,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
build-synergy-fedora-39.sh
Normal file
106
build-synergy-fedora-39.sh
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
####################################################################################
|
||||||
|
# build-synergy-fedora-39.sh #
|
||||||
|
####################################################################################
|
||||||
|
# This script is just meant to show how to compile synergy-core manually, in the #
|
||||||
|
# case someone doesn't want to pay for the license to download an installer. #
|
||||||
|
# #
|
||||||
|
# Understand that even if you do compile it here you will need a license to access #
|
||||||
|
# many of the advanced features (however it will still let you use the software). #
|
||||||
|
# #
|
||||||
|
# Note as well, this is the older version of the software (synergy 1). To get #
|
||||||
|
# Synergy 3.x you will need to purchase the license to use it. Otherwise, I #
|
||||||
|
# haven't been able to find that repo (unless I'm overlooking something) #
|
||||||
|
# #
|
||||||
|
# If you find an error in this let me know via my contact info in the README of my #
|
||||||
|
# journal repo (https://git.arcanium.tech/tristan/journal). If I've overlooked a #
|
||||||
|
# step I'll update this script. #
|
||||||
|
# #
|
||||||
|
# NOTE: #
|
||||||
|
# This script will likely work on fedora 36 -> 39, as I don't believe dependencies #
|
||||||
|
# have changed from then. #
|
||||||
|
# #
|
||||||
|
####################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Variables
|
||||||
|
|
||||||
|
declare -a NEEDED_PACKAGES=(
|
||||||
|
# Cmake Deps
|
||||||
|
cmake
|
||||||
|
|
||||||
|
## Well...for git and stuff
|
||||||
|
git
|
||||||
|
|
||||||
|
# Compiler dependencies
|
||||||
|
libX11-devel
|
||||||
|
libXtst-devel
|
||||||
|
glib2-devel
|
||||||
|
gdk-pixbuf2-devel
|
||||||
|
libnotify-devel
|
||||||
|
libXinerama-devel
|
||||||
|
|
||||||
|
## For qt5_add_translation macro
|
||||||
|
qt5-qttools-devel
|
||||||
|
|
||||||
|
## For X11/extensions/XKBrules.h
|
||||||
|
libxkbfile-devel
|
||||||
|
)
|
||||||
|
|
||||||
|
## URL to git repo
|
||||||
|
REPO_URL='https://github.com/symless/synergy-core'
|
||||||
|
|
||||||
|
## Getting REPO name for later use
|
||||||
|
REPO_NAME="${REPO_URL##*\/}"
|
||||||
|
|
||||||
|
# END: Variables
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Pre-Work Check
|
||||||
|
|
||||||
|
## Clean cache
|
||||||
|
sudo dnf clean all
|
||||||
|
|
||||||
|
## Make package manager cache any new changes to repo (to ensure that all packages are accurate)
|
||||||
|
sudo dnf makecache
|
||||||
|
|
||||||
|
## I could do an elegant check for each individual package, but this is much easier
|
||||||
|
sudo dnf install -y ${NEEDED_PACKAGES[@]}
|
||||||
|
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "Package install exited uncleanly, please address and run again"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# END: Pre-Work Check
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Work
|
||||||
|
|
||||||
|
## Move to downloads dir, to clone the repo and do work
|
||||||
|
cd ~/Downloads
|
||||||
|
|
||||||
|
## Clone repo
|
||||||
|
git clone $REPO_URL
|
||||||
|
|
||||||
|
## Moving to git repo
|
||||||
|
cd $REPO_NAME
|
||||||
|
|
||||||
|
## INIT-ing and updating submodules (needed to build)
|
||||||
|
git submodule init && git submodule update
|
||||||
|
|
||||||
|
## Make and cd into the directory that you're building the project in
|
||||||
|
mkdir build && cd build
|
||||||
|
|
||||||
|
## Making the buildfile and preparing for the build
|
||||||
|
cmake ..
|
||||||
|
|
||||||
|
## Build & install the project
|
||||||
|
make && make install
|
||||||
|
|
||||||
|
# END: Work
|
134
check-postfix.sh
Executable file
134
check-postfix.sh
Executable file
@@ -0,0 +1,134 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
#############################################################################################################
|
||||||
|
# check-postfix.sh #
|
||||||
|
#############################################################################################################
|
||||||
|
# #
|
||||||
|
# This script is just something I cooked up for work. I setup a server with posftix configured as an` #
|
||||||
|
# email/smtp relay so that some of our old equipment can still function without having to try and #
|
||||||
|
# configure our commercial Email Server to accept unauthed requests to send email. #
|
||||||
|
# #
|
||||||
|
# This requres a few packages to be installed: #
|
||||||
|
# - postfix (of course) #
|
||||||
|
# - telnet #
|
||||||
|
# - sendmail #
|
||||||
|
# #
|
||||||
|
# The issue is if the postfix service dies and fails to come back up after a restart via this script, #
|
||||||
|
# you will be unable to send any emails via a smtp client (as they will try to contact the service #
|
||||||
|
# on the server itself). So the only workaround I was able to find is to manually send the email via #
|
||||||
|
# telnet using a coproc. You could use a smtp library with python or perl, but I like to keep these #
|
||||||
|
# scripts using a single language wherever possible. #
|
||||||
|
# #
|
||||||
|
# Since telnet is just a basic tcp client we are able to interact with the smpt port on a mailserver #
|
||||||
|
# (port 25). So setting it up as coproc allows us to run a concurrent process and pipe commands into #
|
||||||
|
# the file-descriptor to send the commands to the mailserver. Which allows us to manually send an email #
|
||||||
|
# to an authoritative email server (provided they don't have your IP blocklisted or are filtering #
|
||||||
|
# traffic on port 25). #
|
||||||
|
# #
|
||||||
|
#############################################################################################################
|
||||||
|
|
||||||
|
# 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
|
||||||
|
FROM_DOMAIN=` echo $FROM_EMAIL | cut -d @ -f 2 `
|
||||||
|
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 as an email relay, 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 `hostname` (`hostname -i`) 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; }
|
||||||
|
coproc TELNET { telnet $MAILSERVER 25; }
|
||||||
|
|
||||||
|
## Commands to send email manually
|
||||||
|
local -a commands=(
|
||||||
|
"ehlo $FROM_DOMAIN\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
|
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# do-daily-backup.sh #
|
# do-daily-btrfs-snapshot.sh #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# This script is my attempt at replicating the same function that timeshift #
|
# This script is my attempt at replicating the same function that timeshift #
|
||||||
# performs. This is a very simplified script to handle automated btrfs #
|
# performs. This is a very simplified script to handle automated btrfs #
|
||||||
@@ -26,9 +26,9 @@
|
|||||||
# BEGIN: Variables
|
# BEGIN: Variables
|
||||||
|
|
||||||
## Reusable vars
|
## Reusable vars
|
||||||
DATE=`date +%Y-%m-%d`
|
DATE=$(date +%Y-%m-%d)
|
||||||
### Getting the name of the script (as it will be the first thing passed to bash when executing)
|
### Getting the name of the script (as it will be the first thing passed to bash when executing)
|
||||||
SCRIPT=`basename $0`
|
SCRIPT=$(basename $0)
|
||||||
BACKUP_DIR=/.backups
|
BACKUP_DIR=/.backups
|
||||||
### Setting dir to house log files
|
### Setting dir to house log files
|
||||||
LOG_DIR=/var/log/$SCRIPT
|
LOG_DIR=/var/log/$SCRIPT
|
||||||
@@ -38,9 +38,6 @@ LOG_FILE=$LOG_DIR/$DATE.log
|
|||||||
## The amount of backups that are allowed of each configured subvols
|
## The amount of backups that are allowed of each configured subvols
|
||||||
LIMIT=5
|
LIMIT=5
|
||||||
|
|
||||||
## Because cron fucks our env, and loading /etc/bashrc doesn't always fix it
|
|
||||||
alias btrfs='/usr/bin/btrfs'
|
|
||||||
|
|
||||||
## The subvols that we want to backup
|
## The subvols that we want to backup
|
||||||
### <actual-directory>:<name-of-backup-dir>
|
### <actual-directory>:<name-of-backup-dir>
|
||||||
declare -a SUBVOLS=(
|
declare -a SUBVOLS=(
|
||||||
@@ -53,18 +50,71 @@ DATE_REGEX='[0-9]{4}-[0-9]{2}-[0-9]{2}'
|
|||||||
# END: Variables
|
# END: Variables
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Helper Functions
|
||||||
|
|
||||||
|
function handle_logs() {
|
||||||
|
cd $LOG_DIR
|
||||||
|
echo "Began Handling logs at: $(date)"
|
||||||
|
local ARCHIVE_FILE=archive.tar.gz
|
||||||
|
local ARCHIVE_FILE_UNZIPPED=${ARCHIVE_FILE%.gz}
|
||||||
|
|
||||||
|
if [[ -f $ARCHIVE_FILE ]]; then
|
||||||
|
## Decompressing archive in case it exists
|
||||||
|
gunzip $ARCHIVE_FILE 2>/dev/null
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Getting all files
|
||||||
|
local FILES=( $( ls -1tr *.log ) )
|
||||||
|
if [[ ${#FILES[@]} -le $LIMIT ]]; then
|
||||||
|
echo "Only had ${#FILES[@]} logs, and did not exceed $LIMIT. Not handling logs"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Getting files we are keeping
|
||||||
|
local FILES_TO_KEEP=${FILES[@]: -$LIMIT}
|
||||||
|
|
||||||
|
## Creating REGEX filter
|
||||||
|
FILES_TO_KEEP=${FILES_TO_KEEP//[[:space:]]/|}
|
||||||
|
|
||||||
|
## Filtering out logs to keep
|
||||||
|
local FILES_TO_ARCHIVE=( $( ls -1 *.log | grep -Ev "(${FILES_TO_KEEP})" ) )
|
||||||
|
|
||||||
|
echo "Adding archived logs to archive"
|
||||||
|
## Updating archive
|
||||||
|
tar uvf $ARCHIVE_FILE_UNZIPPED ${FILES_TO_ARCHIVE[@]}
|
||||||
|
|
||||||
|
## Compressing Archive
|
||||||
|
echo "Compressing Archive"
|
||||||
|
gzip $ARCHIVE_FILE_UNZIPPED
|
||||||
|
|
||||||
|
## Removing archived logs
|
||||||
|
echo "Removing archived files"
|
||||||
|
rm -vf ${FILES_TO_ARCHIVE[@]}
|
||||||
|
echo "Finished Handling logs at: $(date)"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# END: Helper Functions
|
||||||
|
|
||||||
# BEGIN: Pre-Work Checks
|
# BEGIN: Pre-Work Checks
|
||||||
|
|
||||||
## This will check to make sure that the log directory has been created, if not it will create it
|
|
||||||
[[ ! -d $LOG_DIR ]] && mkdir -p $LOG_DIR
|
|
||||||
## Setting up the script to direct all output to the log file for this snapshot session
|
## Setting up the script to direct all output to the log file for this snapshot session
|
||||||
exec > $LOG_FILE
|
exec > $LOG_FILE
|
||||||
|
|
||||||
|
## This will check to make sure that the log directory has been created, if not it will create it
|
||||||
|
[[ ! -d $LOG_DIR ]] && {
|
||||||
|
mkdir -p $LOG_DIR
|
||||||
|
echo "$LOG_DIR did not exist. Creating"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# END: Pre-Work Checks
|
# END: Pre-Work Checks
|
||||||
|
|
||||||
|
|
||||||
# BEGIN: Work
|
# BEGIN: Work
|
||||||
|
echo "Beginning backup at `date`"
|
||||||
for SUBVOL_INFO in ${SUBVOLS[@]}; do
|
for SUBVOL_INFO in ${SUBVOLS[@]}; do
|
||||||
|
|
||||||
## Stripping the delemited info out of the subvol entry
|
## Stripping the delemited info out of the subvol entry
|
||||||
@@ -90,7 +140,7 @@ for SUBVOL_INFO in ${SUBVOLS[@]}; do
|
|||||||
if [[ ${#backups[@]} -ge $LIMIT ]]; then
|
if [[ ${#backups[@]} -ge $LIMIT ]]; then
|
||||||
SNAPSHOT_PATH="$SUBVOL_BACKUP_DIR/${backups[0]}"
|
SNAPSHOT_PATH="$SUBVOL_BACKUP_DIR/${backups[0]}"
|
||||||
echo "${#backups[@]} was found to be equal to or greater than $LIMIT. Deleting $SNAPSHOT_PATH."
|
echo "${#backups[@]} was found to be equal to or greater than $LIMIT. Deleting $SNAPSHOT_PATH."
|
||||||
btrfs subvol del "$SUBVOL_BACKUP_DIR/${backups[0]}"
|
/usr/sbin/btrfs subvol del "$SUBVOL_BACKUP_DIR/${backups[0]}"
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@@ -101,7 +151,15 @@ for SUBVOL_INFO in ${SUBVOLS[@]}; do
|
|||||||
|
|
||||||
SNAPSHOT=$SUBVOL_BACKUP_DIR/$DATE
|
SNAPSHOT=$SUBVOL_BACKUP_DIR/$DATE
|
||||||
## If the snapshot doesn't already exist, then create a new read-only snapshot
|
## If the snapshot doesn't already exist, then create a new read-only snapshot
|
||||||
[[ ! -d $SNAPSHOT ]] && btrfs subvol snapshot -r $DIR $SNAPSHOT
|
if [[ ! -d $SNAPSHOT ]]; then
|
||||||
|
/usr/sbin/btrfs subvol snapshot -r $DIR $SNAPSHOT
|
||||||
|
else
|
||||||
|
echo "$SNAPSHOT already existed. Not doing a snapshot"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
handle_logs
|
||||||
|
|
||||||
|
echo "Finishing backup at `date`"
|
||||||
|
|
||||||
# END: Work
|
# END: Work
|
||||||
|
345
install-discord-linux.rb
Executable file
345
install-discord-linux.rb
Executable file
@@ -0,0 +1,345 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
# BEGIN: Includes & Requires
|
||||||
|
|
||||||
|
require 'erb'
|
||||||
|
require 'time'
|
||||||
|
require 'json'
|
||||||
|
require 'zlib'
|
||||||
|
require 'find'
|
||||||
|
require 'English'
|
||||||
|
require 'net/http'
|
||||||
|
require 'optparse'
|
||||||
|
require 'fileutils'
|
||||||
|
require 'rubygems/package'
|
||||||
|
|
||||||
|
# END: Includes & Requires
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Overrides
|
||||||
|
|
||||||
|
class Dir
|
||||||
|
def / (path)
|
||||||
|
output_path = File.join(self.path + '/' + path)
|
||||||
|
if File.directory? output_path
|
||||||
|
Dir.new(output_path)
|
||||||
|
else
|
||||||
|
output_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
alias to_s path
|
||||||
|
|
||||||
|
## For backwards compat
|
||||||
|
def chdir(dir = nil, &block)
|
||||||
|
if dir.nil?
|
||||||
|
Dir.chdir(self, &block)
|
||||||
|
else
|
||||||
|
Dir.chdir(dir, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class String
|
||||||
|
def / (other)
|
||||||
|
File.join(self, other)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# END: Overrides
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Variables
|
||||||
|
URL_DOWNLOAD_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
|
||||||
|
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||||
|
|
||||||
|
$CONFIG = Hash.new
|
||||||
|
$CONFIG[:icon_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'icons'
|
||||||
|
File.mkdir($CONFIG[:icon_dir]) if not File.exist?($CONFIG[:icon_dir])
|
||||||
|
$CONFIG[:discord_config_path] = Dir.new(Dir.home) / '.config' / 'discord'
|
||||||
|
$CONFIG[:local_application_install_dir] = Dir.new(Dir.home) / '.local' / 'share' / 'applications'
|
||||||
|
File.mkdir($CONFIG[:local_application_install_dir]) if not File.exist?($CONFIG[:local_application_install_dir])
|
||||||
|
$CONFIG[:install_dir] = Dir.new(Dir.home) / '.opt'
|
||||||
|
$CONFIG[:desktop_path] = $CONFIG[:install_dir] / 'Discord' / 'discord.desktop'
|
||||||
|
File.mkdir($CONFIG[:install_dir]) if not File.exist?($CONFIG[:install_dir])
|
||||||
|
$CONFIG[:discord_path] = $CONFIG[:install_dir] / 'Discord'
|
||||||
|
$CONFIG[:desktop_file_path] = $CONFIG[:local_application_install_dir] / 'discord.desktop'
|
||||||
|
$CONFIG[:discord_version_file] = $CONFIG[:discord_path] / 'resources' / 'build_info.json'
|
||||||
|
$CONFIG[:action] = 'install'
|
||||||
|
$CONFIG[:keep_installer] = false
|
||||||
|
$CONFIG[:debug] = false
|
||||||
|
DISCORD_DESKTOP_TEMPLATE = ERB.new(<<ERB, trim_mode:'-')
|
||||||
|
[Desktop Entry]
|
||||||
|
Name=Discord
|
||||||
|
StartupWMClass=discord
|
||||||
|
Comment=All-in-one voice and text chat for gamers that's free, secure, and works on both your desktop and phone.
|
||||||
|
GenericName=Internet Messenger
|
||||||
|
Exec=<%= $CONFIG[:discord_path] %>/Discord
|
||||||
|
Icon=discord
|
||||||
|
Type=Application
|
||||||
|
Categories=Network;InstantMessaging;
|
||||||
|
Path=<%= $CONFIG[:discord_path] %>
|
||||||
|
ERB
|
||||||
|
# END: Variables
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Handle CLI ARgs
|
||||||
|
|
||||||
|
OptionParser.new do |parser|
|
||||||
|
parser.banner = "#{ File.basename($0) } [action]"
|
||||||
|
parser.separator ""
|
||||||
|
parser.separator " Actions"
|
||||||
|
parser.separator "------------------------------------------------------------------------"
|
||||||
|
|
||||||
|
parser.on('-c', '--check', "Check and report installed & remote versions") do
|
||||||
|
$CONFIG[:action] = 'check'
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-i', '--install', "Check for & Install new version of discord (default)") do
|
||||||
|
$CONFIG[:action] = 'install'
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-u', '--uninstall', "Uninstall Discord (not-implemented)") do
|
||||||
|
$CONFIG[:action] = 'uninstall'
|
||||||
|
$CONFIG[:backup_filename] = Dir.home / 'discord-backup-' + Time.now.strftime('%Y-%m-%d') + '.tar.gz'
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-b', '--backup [FILENAME]', "Backup Discord Installation") do |backup_filename|
|
||||||
|
$CONFIG[:action] = 'backup'
|
||||||
|
if backup_filename.nil?
|
||||||
|
$CONFIG[:backup_filename] = Dir.home / 'discord-backup-' + Time.now.strftime('%Y-%m-%d') + '.tar.gz'
|
||||||
|
else
|
||||||
|
$CONFIG[:backup_filename] = backup_filename + ".tar.gz"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('--update-desktop', "Update desktop file"){
|
||||||
|
$CONFIG[:action] = 'update-desktop'
|
||||||
|
}
|
||||||
|
|
||||||
|
parser.separator ""
|
||||||
|
parser.separator " General Flags"
|
||||||
|
parser.separator "------------------------------------------------------------------------"
|
||||||
|
parser.on('-h', '--help', "Show this help output") do
|
||||||
|
puts parser
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('-d', '--debug', "Turn on debug logging") do
|
||||||
|
$CONFIG[:debug] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on('--keep', "Keep discord tar.gz file (default: #{$CONFIG[:keep_installer].to_s})") do
|
||||||
|
$CONFIG[:keep_installer] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
end.parse!
|
||||||
|
|
||||||
|
# BEGIN: Handle CLI ARgs
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Helper Classes
|
||||||
|
class DesktopFile
|
||||||
|
@@file = File.open($CONFIG[:desktop_path])
|
||||||
|
@@installed_file = File.open($CONFIG[:desktop_file_path])
|
||||||
|
|
||||||
|
def needs_update?
|
||||||
|
@@installed_file.read() != contents
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if needs_update?
|
||||||
|
File.open(@@file, 'w') do |file|
|
||||||
|
puts "Updating Desktop File, changes are needed"
|
||||||
|
file.write(contents)
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "update_desktop_file: Triggering desktop to install new desktop entry and refresh entries"
|
||||||
|
%x[ desktop-file-install --dir=#{$CONFIG[:local_application_install_dir]} #{$CONFIG[:desktop_path]} ]
|
||||||
|
else
|
||||||
|
puts "Not updating file. Changes not needed"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
DISCORD_DESKTOP_TEMPLATE.def_method(DesktopFile, 'contents')
|
||||||
|
|
||||||
|
class Installer
|
||||||
|
URL_DOWNLOAD_BASE='https://dl.discordapp.net/apps/linux/{VERSION}/discord-{VERSION}.tar.gz'
|
||||||
|
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||||
|
@@desktop_file = DesktopFile.new
|
||||||
|
|
||||||
|
def needs_update?
|
||||||
|
local_version < remote_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def remote_version
|
||||||
|
if @remote_version.nil?
|
||||||
|
uri = URI(DOWNLOAD_URL)
|
||||||
|
response = Net::HTTP.get(uri)
|
||||||
|
if response =~ /discord-(?<version>\d+\.\d+\.\d+).tar.gz/
|
||||||
|
@remote_version = Gem::Version.new($LAST_MATCH_INFO['version'])
|
||||||
|
else
|
||||||
|
raise "Failed to retrieve remote version"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@remote_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def local_version
|
||||||
|
if @local_version.nil?
|
||||||
|
@local_version = if File.exist? $CONFIG[:discord_version_file]
|
||||||
|
data = JSON.load_file($CONFIG[:discord_version_file])
|
||||||
|
Gem::Version.new(data['version'])
|
||||||
|
else
|
||||||
|
Gem::Version.new('0.0.0')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@local_version
|
||||||
|
end
|
||||||
|
|
||||||
|
def download
|
||||||
|
version = self.remote_version.to_s
|
||||||
|
uri = URI(URL_DOWNLOAD_BASE.gsub('{VERSION}',version))
|
||||||
|
puts "download_installer: Downloading The discord #{version} tar.gz"
|
||||||
|
file_contents = Net::HTTP.get(uri)
|
||||||
|
output_file = "discord-#{version}.tar.gz"
|
||||||
|
puts "download_installer: Output file will #{output_file}"
|
||||||
|
$CONFIG[:install_dir].chdir do
|
||||||
|
File.open(output_file, 'wb') do |file|
|
||||||
|
file.write(file_contents)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "download_installer: tar.gz was downloaded"
|
||||||
|
end
|
||||||
|
|
||||||
|
def install
|
||||||
|
installer_file = "discord-#{self.remote_version}.tar.gz"
|
||||||
|
puts "do_install: Extracting new installer"
|
||||||
|
$CONFIG[:install_dir].chdir do
|
||||||
|
File.open(installer_file, 'rb') do |file|
|
||||||
|
Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir])
|
||||||
|
end
|
||||||
|
|
||||||
|
if not $CONFIG[:keep_installer]
|
||||||
|
puts "do_install: Removing new installer (#{installer_file})"
|
||||||
|
File.unlink(installer_file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@@desktop_file.update
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# END: Helper Classes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Helper Functions
|
||||||
|
|
||||||
|
def make_backup
|
||||||
|
files = {
|
||||||
|
files: Array.new,
|
||||||
|
dirs: Array.new,
|
||||||
|
symlinks: Array.new
|
||||||
|
}
|
||||||
|
|
||||||
|
[ $CONFIG[:discord_config_path].path, $CONFIG[:discord_path].path ].each do |backup_dir|
|
||||||
|
puts "make_backup: Getting Files from #{backup_dir})"
|
||||||
|
Find.find("#{backup_dir}").each{ |item|
|
||||||
|
puts("#{item} was retrieved from #{backup_dir}") if $CONFIG[:debug]
|
||||||
|
if File.file?(item)
|
||||||
|
puts("#{item} was found to be a file") if $CONFIG[:debug]
|
||||||
|
files[:files] << item
|
||||||
|
elsif File.symlink?(item)
|
||||||
|
puts("#{item} was found to be a symlink") if $CONFIG[:debug]
|
||||||
|
files[:symlinks] << item
|
||||||
|
elsif File.directory?(item)
|
||||||
|
puts("#{item} was found to be a directory") if $CONFIG[:debug]
|
||||||
|
files[:dirs] << item
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.chdir(Dir.home) do
|
||||||
|
puts "make_backup: Beginning backup process (OUTPUT_FILE = #{$CONFIG[:backup_filename]})"
|
||||||
|
File.open($CONFIG[:backup_filename], "wb") do |backup_file|
|
||||||
|
Zlib::GzipWriter.wrap(backup_file) do |gzip|
|
||||||
|
Gem::Package::TarWriter.new(gzip) do |tar|
|
||||||
|
|
||||||
|
puts "\nmake_backup : files : Beginning backup process for files (Count: #{files[:files].count})"
|
||||||
|
file_count = files[:files].count
|
||||||
|
files[:files].each_with_index { |file, i|
|
||||||
|
puts "make_backup : files : Backing up #{file} (#{i+1}/#{file_count})" if $CONFIG[:debug]
|
||||||
|
File.open(file, 'rb') { |file_to_archive|
|
||||||
|
contents = file_to_archive.read()
|
||||||
|
tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) { |io|
|
||||||
|
io.write(contents)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts "\nmake_backup : directories : Beginning backup process for directories (Count: #{files[:dirs].count})"
|
||||||
|
dir_count = files[:dirs].count
|
||||||
|
files[:dirs].each_with_index {|dir,i|
|
||||||
|
puts "make_backup : directories : Backing up #{dir} (#{i+1}/#{dir_count})" if $CONFIG[:debug]
|
||||||
|
tar.mkdir(dir.sub("#{Dir.home}/",""), File.stat(dir).mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
puts "\nmake_backup : symlinks : Beginning backup process for symlinks (Count: #{files[:symlinks].count})"
|
||||||
|
symlink_count = files[:symlinks].count
|
||||||
|
files[:symlinks].each_with_index {|symlink,i|
|
||||||
|
puts "make_backup : symlinks : Backing up #{symlink} (#{i+1}/#{symlink_count})" if $CONFIG[:debug]
|
||||||
|
tar.add_symlink(symlink.sub("#{Dir.home}/",""), File.readlink(symlink), File.lstat(symlink).mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# END: Helper Functions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: Work
|
||||||
|
|
||||||
|
installer = Installer.new
|
||||||
|
case $CONFIG[:action]
|
||||||
|
|
||||||
|
when 'install'
|
||||||
|
if installer.needs_update?
|
||||||
|
puts "main: Installed Version will be updated"
|
||||||
|
installer.download
|
||||||
|
installer.install
|
||||||
|
elsif installer.local_version == installer.remote_version
|
||||||
|
puts "main: Installed Version is up-to-date"
|
||||||
|
else
|
||||||
|
puts "main: What?"
|
||||||
|
end
|
||||||
|
|
||||||
|
when 'check'
|
||||||
|
puts
|
||||||
|
puts " Report"
|
||||||
|
puts "-------------------------------------"
|
||||||
|
puts " Remote Version: #{installer.remote_version.to_s}"
|
||||||
|
puts " Local Version: #{installer.local_version.to_s}"
|
||||||
|
puts " Needs Updating: #{installer.needs_update? ? "Yes" : "No"}"
|
||||||
|
|
||||||
|
when 'backup'
|
||||||
|
make_backup
|
||||||
|
|
||||||
|
when 'update-desktop'
|
||||||
|
DesktopFile.new.update
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# END: Work
|
@@ -1,29 +1,88 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
|
||||||
|
######################################################################################
|
||||||
|
# install-discord-linux.sh #
|
||||||
|
######################################################################################
|
||||||
|
# Description # #
|
||||||
|
############### #
|
||||||
|
# #
|
||||||
|
# This script was created to automate the install of discord on your system. #
|
||||||
|
# It installs it separately from a package manager (snap, apt, dnf, etc), so this #
|
||||||
|
# can be used to install it on any linux system regardless of distro #
|
||||||
|
# as long as the OS & processor supports it. #
|
||||||
|
# #
|
||||||
|
# This script was originally just setup to handle installing or updating the #
|
||||||
|
# existing installation. It can be setup in crontab to handle it automatically so #
|
||||||
|
# you never have to manually do it again. All you have to do is add it to your #
|
||||||
|
# crontab to run daily or hourly (assuming you have a cron service installed) #
|
||||||
|
# #
|
||||||
|
# EX: #
|
||||||
|
# """ #
|
||||||
|
# CRONTAB="$(crontab -l)" #
|
||||||
|
# if [[ $? -eq 0 ]]; then #
|
||||||
|
# CRONTAB+="\n0 0 * * * /path/to/script.sh" #
|
||||||
|
# echo -e "$CRONTAB" | crontab - #
|
||||||
|
# else #
|
||||||
|
# echo "0 0 * * * /path/to/script.sh" | crontab - #
|
||||||
|
# fi #
|
||||||
|
# """ #
|
||||||
|
# #
|
||||||
|
# Eventually I am wanting this script to also provide additional functionalities: #
|
||||||
|
# - Install BetterDiscord #
|
||||||
|
# - Handle multiple installations of discord (makes named config directories #
|
||||||
|
# and will symlink them based on what "profile" you want to use). This will also #
|
||||||
|
# allow you to have a installation that contains mods and others without. #
|
||||||
|
# - Handle manual configurations of discord (where applicable) #
|
||||||
|
# #
|
||||||
|
######################################################################################
|
||||||
|
# Dependencies # #
|
||||||
|
################ #
|
||||||
|
# #
|
||||||
|
# 1) curl #
|
||||||
|
# 2) bash (of course) #
|
||||||
|
# #
|
||||||
|
######################################################################################
|
||||||
|
|
||||||
# BEGIN: Variables
|
# BEGIN: Variables
|
||||||
|
|
||||||
|
DEBUG=1
|
||||||
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
|
||||||
|
[[ ! -d $INSTALL_DIR ]] && mkdir -p $INSTALL_DIR
|
||||||
|
LOCAL_APPLICATION_DIR=~/.local/share/applications
|
||||||
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
|
||||||
|
INSTALLED_DESKTOP_FILE=$LOCAL_APPLICATION_DIR/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=~/.local/share/icons
|
||||||
|
DESKTOP_FILE_NEEDS_UPDATE=0
|
||||||
|
REMOVE_AFTER_INSTALL=1
|
||||||
|
|
||||||
# END: Variables
|
# END: Variables
|
||||||
|
|
||||||
|
|
||||||
# BEGIN: Helper Functions
|
# BEGIN: Helper Functions
|
||||||
|
|
||||||
|
function log () {
|
||||||
|
if [[ $DEBUG -eq 1 ]]; then
|
||||||
|
local DATE=`date`
|
||||||
|
local MESSAGE="${1:?"log: Message not provided"}"
|
||||||
|
echo "$DATE : $MESSAGE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function get_remote_version(){
|
function get_remote_version(){
|
||||||
local REMOTE_VERSION=`curl $DOWNLOAD_URL | grep -Eo $VERSION_REGEX | head -n 1`
|
local REMOTE_VERSION=`curl -s $DOWNLOAD_URL | grep -Eo $VERSION_REGEX | head -n 1`
|
||||||
|
|
||||||
if [[ "$REMOTE_VERSION" ]]; then
|
if [[ "$REMOTE_VERSION" ]]; then
|
||||||
echo "$REMOTE_VERSION"
|
echo "$REMOTE_VERSION"
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
echo "error: remote version not found"
|
log "error: remote version not found"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -33,24 +92,28 @@ function do_download(){
|
|||||||
|
|
||||||
## If the provided version doesn't match the format #.#.#
|
## If the provided version doesn't match the format #.#.#
|
||||||
if [[ ! "$VERSION" =~ ^$VERSION_REGEX$ ]]; then
|
if [[ ! "$VERSION" =~ ^$VERSION_REGEX$ ]]; then
|
||||||
echo "do_download : the version ($VERSION) provided, does not match format $VERSION_REGEX."
|
log "do_download : the version ($VERSION) provided, does not match format $VERSION_REGEX."
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Making the URL to download the package
|
## Making the URL to download the package
|
||||||
### replacing all {VERSION} in PACKAGE_DOWNLOAD_URL_BASE with $REMOTE_VERSION using string substitution
|
### replacing all {VERSION} in PACKAGE_DOWNLOAD_URL_BASE with $REMOTE_VERSION using string substitution
|
||||||
PACKAGE_DOWNLOAD_URL="${PACKAGE_DOWNLOAD_URL_BASE//\{VERSION\}/$REMOTE_VERSION}"
|
PACKAGE_DOWNLOAD_URL="${PACKAGE_DOWNLOAD_URL_BASE//\{VERSION\}/$REMOTE_VERSION}"
|
||||||
|
log "Download url created ($PACKAGE_DOWNLOAD_URL)"
|
||||||
|
|
||||||
## Getting filename from url
|
## Getting filename from url
|
||||||
### Removing all characters from the last / back to leave only the filename
|
### Removing all characters from the last / back to leave only the filename
|
||||||
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"
|
||||||
|
log "File was downloaded as $FILENAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_desktop_file() {
|
function update_desktop_file() {
|
||||||
|
|
||||||
|
log "Updating desktop file"
|
||||||
|
|
||||||
## Desktop file in the current/new install
|
## Desktop file in the current/new install
|
||||||
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
|
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
|
||||||
|
|
||||||
@@ -72,9 +135,16 @@ function update_desktop_file() {
|
|||||||
|
|
||||||
## Pushing replacement values to desktop file
|
## Pushing replacement values to desktop file
|
||||||
echo -e "$DESKTOP_FILE_CONTENTS" > $DESKTOP_FILE
|
echo -e "$DESKTOP_FILE_CONTENTS" > $DESKTOP_FILE
|
||||||
|
log "Desktop file has been updated"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function remove_installer () {
|
||||||
|
if [[ $REMOVE_AFTER_INSTALL -eq 1 ]]; then
|
||||||
|
rm -f $FILENAME
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function do_install() {
|
function do_install() {
|
||||||
|
|
||||||
cd "$INSTALL_DIR"
|
cd "$INSTALL_DIR"
|
||||||
@@ -86,26 +156,16 @@ function do_install() {
|
|||||||
if [[ -f $FILENAME ]]; then
|
if [[ -f $FILENAME ]]; then
|
||||||
tar xf "$FILENAME"
|
tar xf "$FILENAME"
|
||||||
else
|
else
|
||||||
echo "$FILENAME failed to download. Exiting now"
|
log "$FILENAME failed to download. Exiting now"
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
update_desktop_file
|
update_desktop_file
|
||||||
|
|
||||||
## If your icon dir (configured above) exists in the env variable
|
|
||||||
if [[ "$XDG_DATA_DIRS" != *$ICON_DIR* ]]; then
|
|
||||||
export XDG_DATA_DIRS=$XDG_DATA_DIRS:$ICON_DIR
|
|
||||||
if [[ $SHELL == *bash ]]; then
|
|
||||||
echo 'export XDG_DATA_DIRS=$XDG_DATA_DIRS':$ICON_DIR > ~/.bashrc
|
|
||||||
else
|
|
||||||
echo 'export XDG_DATA_DIRS=$XDG_DATA_DIRS':$ICON_DIR > ~/.profile
|
|
||||||
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
[[ ! -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
|
|
||||||
|
remove_installer
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_upgrade(){
|
function do_upgrade(){
|
||||||
@@ -120,6 +180,8 @@ function do_upgrade(){
|
|||||||
tar xf "$FILENAME"
|
tar xf "$FILENAME"
|
||||||
|
|
||||||
update_desktop_file
|
update_desktop_file
|
||||||
|
|
||||||
|
remove_installer
|
||||||
}
|
}
|
||||||
|
|
||||||
# END: Helper Functions
|
# END: Helper Functions
|
||||||
@@ -130,11 +192,13 @@ function do_upgrade(){
|
|||||||
|
|
||||||
if [[ -d $EXISTING_INSTALL ]] && [[ -f $BUILD_FILE ]]; then
|
if [[ -d $EXISTING_INSTALL ]] && [[ -f $BUILD_FILE ]]; then
|
||||||
LOCAL_VERSION=`grep -Eo $VERSION_REGEX $BUILD_FILE`
|
LOCAL_VERSION=`grep -Eo $VERSION_REGEX $BUILD_FILE`
|
||||||
|
log "Local version was found to be ($LOCAL_VERSION)"
|
||||||
else
|
else
|
||||||
ACTION=INSTALL
|
ACTION=INSTALL
|
||||||
fi
|
fi
|
||||||
|
|
||||||
REMOTE_VERSION=`curl $DOWNLOAD_URL | grep -Eo $VERSION_REGEX | head -n 1`
|
REMOTE_VERSION=`get_remote_version`
|
||||||
|
log "Retrieved remote version ($REMOTE_VERSION)"
|
||||||
|
|
||||||
# END: Pre-Work Check
|
# END: Pre-Work Check
|
||||||
|
|
||||||
@@ -176,3 +240,32 @@ esac
|
|||||||
|
|
||||||
|
|
||||||
# END: Work
|
# END: Work
|
||||||
|
|
||||||
|
|
||||||
|
# BEGIN: End Work Check
|
||||||
|
|
||||||
|
## If discord isn't already setup, go ahead and mark it for install/update
|
||||||
|
if [[ ! -f $INSTALLED_DESKTOP_FILE ]]; then
|
||||||
|
log "Desktop file not found in the local applications dir ($LOCAL_APPLICATION_DIR) installing now"
|
||||||
|
DESKTOP_FILE_NEEDS_UPDATE=1
|
||||||
|
|
||||||
|
else
|
||||||
|
# If there is a change for any reason update it
|
||||||
|
if [[ "$(<$DESKTOP_FILE)" != "$(<$INSTALLED_DESKTOP_FILE)" ]]; then
|
||||||
|
log "Desktop file for new version of discord has changed. Updating the existing installation"
|
||||||
|
DESKTOP_FILE_NEEDS_UPDATE=1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $DESKTOP_FILE_NEEDS_UPDATE -eq 1 ]]; then
|
||||||
|
log "Updating/Installing desktop file"
|
||||||
|
desktop-file-install --dir=$LOCAL_APPLICATION_DIR $DESKTOP_FILE
|
||||||
|
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
log "There was an issue with installtion"
|
||||||
|
else
|
||||||
|
log "Desktop file was successfully installed"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# END: End Work Check
|
||||||
|
209
install-librenms.sh
Executable file
209
install-librenms.sh
Executable file
@@ -0,0 +1,209 @@
|
|||||||
|
#!/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
|
Reference in New Issue
Block a user