Compare commits
10 Commits
d15bbd57fa
...
1991b72b7b
Author | SHA1 | Date | |
---|---|---|---|
1991b72b7b | |||
620666220f | |||
60ab5840ba | |||
de8c7de945 | |||
a734bbf83b | |||
02dbe5e0eb | |||
4e5967e3bc | |||
0911f7b134 | |||
f334b8d66e | |||
431918e013 |
@@ -1,6 +1,6 @@
|
||||
# MyScripts
|
||||
|
||||
## This repo
|
||||
This repo is just meant to house my general-use scripts. Historically I've made over 50-60 large scale scripts (of varying quality), but I've never actually made a habit of archiving them in a repo.
|
||||
This repo is just meant to house my general-use scripts. I've made MANY 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).
|
||||
|
@@ -123,10 +123,27 @@ declare -a DISKS
|
||||
get_disks DISKS
|
||||
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]$ ]]
|
||||
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
|
||||
ROOT_PASSWORD=""
|
||||
get_answer "What do you want the root password to be? : " ROOT_PASSWORD
|
||||
@@ -152,17 +169,6 @@ FORMAT_DISK_COMMANDS_BIOS="
|
||||
# Create MBR partition table
|
||||
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
|
||||
n
|
||||
# Create Primary partition (which is technically the default anyway)
|
||||
|
@@ -1,5 +1,33 @@
|
||||
#!/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
|
||||
@@ -12,6 +40,7 @@ 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
|
||||
@@ -27,20 +56,18 @@ send_email () {
|
||||
|
||||
|
||||
: "
|
||||
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).
|
||||
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 tartarus (192.168.3.2) after a service restart. Please ssh into server to troubleshoot the issues."}"
|
||||
|
||||
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; }
|
||||
## 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"
|
||||
"ehlo $FROM_DOMAIN\n"
|
||||
"mail from: <$MAIL_FROM>\n"
|
||||
"rcpt to: <$NOTIFY_EMAIL>\n"
|
||||
"data\n"
|
||||
|
@@ -39,7 +39,7 @@ LOG_FILE=$LOG_DIR/$DATE.log
|
||||
LIMIT=5
|
||||
|
||||
## Because cron fucks our env, and loading /etc/bashrc doesn't always fix it
|
||||
alias btrfs='/usr/bin/btrfs'
|
||||
alias btrfs='/usr/sbin/btrfs'
|
||||
|
||||
## The subvols that we want to backup
|
||||
### <actual-directory>:<name-of-backup-dir>
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
# BEGIN: Variables
|
||||
|
||||
DEBUG=1
|
||||
ACTION=""
|
||||
DOWNLOAD_URL='https://discord.com/api/download/stable?platform=linux&format=tar.gz'
|
||||
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+'
|
||||
@@ -19,14 +20,20 @@ DESKTOP_FILE_INSTALLED=0
|
||||
|
||||
# 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(){
|
||||
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
|
||||
echo "$REMOTE_VERSION"
|
||||
return 0
|
||||
else
|
||||
echo "error: remote version not found"
|
||||
log "error: remote version not found"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
@@ -36,17 +43,19 @@ function do_download(){
|
||||
|
||||
## If the provided version doesn't match the format #.#.#
|
||||
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
|
||||
fi
|
||||
|
||||
## Making the URL to download the package
|
||||
### replacing all {VERSION} in PACKAGE_DOWNLOAD_URL_BASE with $REMOTE_VERSION using string substitution
|
||||
PACKAGE_DOWNLOAD_URL="${PACKAGE_DOWNLOAD_URL_BASE//\{VERSION\}/$REMOTE_VERSION}"
|
||||
log "Download url created ($PACKAGE_DOWNLOAD_URL)"
|
||||
|
||||
## Getting filename from url
|
||||
### Removing all characters from the last / back to leave only the filename
|
||||
FILENAME="${PACKAGE_DOWNLOAD_URL/*\/}"
|
||||
log "File was downloaded as $FILENAME"
|
||||
|
||||
## Downloading the discord package (tar.gz)
|
||||
curl "$PACKAGE_DOWNLOAD_URL" -o "$FILENAME" >/dev/null 2>&1
|
||||
@@ -54,6 +63,8 @@ function do_download(){
|
||||
|
||||
function update_desktop_file() {
|
||||
|
||||
log "Updating desktop file"
|
||||
|
||||
## Desktop file in the current/new install
|
||||
DESKTOP_FILE=$EXISTING_INSTALL/discord.desktop
|
||||
|
||||
@@ -75,6 +86,7 @@ function update_desktop_file() {
|
||||
|
||||
## Pushing replacement values to desktop file
|
||||
echo -e "$DESKTOP_FILE_CONTENTS" > $DESKTOP_FILE
|
||||
log "Desktop file has been updated"
|
||||
|
||||
}
|
||||
|
||||
@@ -89,8 +101,8 @@ function do_install() {
|
||||
if [[ -f $FILENAME ]]; then
|
||||
tar xf "$FILENAME"
|
||||
else
|
||||
echo "$FILENAME failed to download. Exiting now"
|
||||
exit 1
|
||||
log "$FILENAME failed to download. Exiting now"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
update_desktop_file
|
||||
@@ -137,11 +149,13 @@ function do_upgrade(){
|
||||
|
||||
if [[ -d $EXISTING_INSTALL ]] && [[ -f $BUILD_FILE ]]; then
|
||||
LOCAL_VERSION=`grep -Eo $VERSION_REGEX $BUILD_FILE`
|
||||
log "Local version was found to be ($LOCAL_VERSION)"
|
||||
else
|
||||
ACTION=INSTALL
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user