Compare commits
41 Commits
0e1d2fc993
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ad26474a6 | |||
| 9d5303fdc6 | |||
| 707ebe3a62 | |||
| ba29fe637f | |||
| 73132456f3 | |||
| 1121ef6db8 | |||
| 80e47ee92d | |||
| 1e3b7b9e94 | |||
| c6e7e05eef | |||
| 74ded3ddbe | |||
| 36bf3c9ba5 | |||
| 153f1b0dcd | |||
| 3ccf6c1758 | |||
| aed2e11a47 | |||
| 9c2a255e1c | |||
| 77016eefaa | |||
| 4478fc74c8 | |||
| db4006a820 | |||
| 69aa1b6903 | |||
| f03af21605 | |||
| fe910e5f79 | |||
| 6b1790171d | |||
| 2d9f26a558 | |||
| 97fb7da9b3 | |||
| f03573d275 | |||
| 8719bfbe27 | |||
| ed6614c4b1 | |||
| f08ba95750 | |||
| d81683b431 | |||
| 3bd1c3f9bd | |||
| 42782597cd | |||
| 4fedc39d1a | |||
| f4e42a53be | |||
| f978c47939 | |||
| ea3d2b76b5 | |||
| 0f2a754e17 | |||
| 2c3e27fa37 | |||
| a32adb2080 | |||
| bd0452a3ea | |||
| d29ff254db | |||
| f03603a1f5 |
32
.gitea/workflows/pingflow.yaml
Normal file
32
.gitea/workflows/pingflow.yaml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
name: Ansible Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Python
|
||||||
|
#uses: actions/setup-python@v4
|
||||||
|
run: |
|
||||||
|
apt -y update
|
||||||
|
apt -y install python3 python3-pip
|
||||||
|
|
||||||
|
- name: Install Ansible
|
||||||
|
run: |
|
||||||
|
python3 -m pip install --upgrade pip
|
||||||
|
pip install ansible
|
||||||
|
|
||||||
|
- name: Set up SSH
|
||||||
|
uses: webfactory/ssh-agent@v0.5.0
|
||||||
|
with:
|
||||||
|
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
|
||||||
|
- name: Run Ansible Playbook
|
||||||
|
run: |
|
||||||
|
ansible-playbook -i inventory.yml ping.yaml -vv
|
||||||
107
Donnagurai
Executable file
107
Donnagurai
Executable file
@@ -0,0 +1,107 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
##Alias to show how long a process has been running.
|
||||||
|
#+Thank Ron for this absolute banger.
|
||||||
|
#source /root/.bash_profile > /dev/null 2>&1 #SLOW
|
||||||
|
source "$SCRIPTS/Okiru"
|
||||||
|
arg0=$(basename "$0")
|
||||||
|
#Show help if arguments are misused
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
exec 1>2 # Send standard output to standard error
|
||||||
|
help
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
flag_error()
|
||||||
|
{
|
||||||
|
echo -e "$arg0: $*." >&2
|
||||||
|
help
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
help()
|
||||||
|
{
|
||||||
|
echo "$arg0 - show how long a process has been running"
|
||||||
|
echo " {-p|--process-id} # -- Process ID to check"
|
||||||
|
echo " {-h|--help} -- Print this help message and exit"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
#Pass arguments to the script
|
||||||
|
declare -a PIDS=()
|
||||||
|
flags()
|
||||||
|
{
|
||||||
|
if [[ $# == "0" ]]; then
|
||||||
|
help
|
||||||
|
exit 1
|
||||||
|
elif [[ $# == "1" ]]; then
|
||||||
|
if [[ $1 =~ ^[0-9].*$ ]]; then
|
||||||
|
PIDS+=("$1")
|
||||||
|
export PIDS
|
||||||
|
elif [[ $1 =~ ^[a-z].*$ ]]; then
|
||||||
|
procs=$(ps aux | grep $1 | grep -v grep | grep -v "$(pwdx $$ | awk '{print $NF}')")
|
||||||
|
# exclude the path of the current script PID ^
|
||||||
|
if [[ -n "$procs" ]]; then
|
||||||
|
for proc in "$procs"; do
|
||||||
|
proc_pid=$(echo "$proc" | awk '{print $2}' | grep -v "$(pwdx $$)")
|
||||||
|
if [[ -n $(ps aux | grep "$proc_pid") ]]; then
|
||||||
|
PIDS+=("$proc_pid")
|
||||||
|
export PIDS
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
elif [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
flag_error "Invalid process ID: $1"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
while test $# -gt 0
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
(-p|--process-id)
|
||||||
|
shift
|
||||||
|
[ $# = 0 ] && flag_error "No process ID specified!"
|
||||||
|
if [[ $1 =~ ^[0-9].*$ ]]; then
|
||||||
|
PIDS+=("$1")
|
||||||
|
export PIDS
|
||||||
|
else
|
||||||
|
flag_error "Invalid process ID: $1"
|
||||||
|
fi
|
||||||
|
shift;;
|
||||||
|
(-h|--help)
|
||||||
|
help;;
|
||||||
|
(*) help;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
flags "$@"
|
||||||
|
for pid in ${PIDS[@]}; do
|
||||||
|
elapsed=$(ps -p $pid -o etime | grep -v "ELAPSED")
|
||||||
|
cmd=$(ps -o command $pid | tail -1)
|
||||||
|
if [[ -z $elapsed ]]; then
|
||||||
|
printf "No data for PID ${RED}$pid${STOP}.\n"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ -n $(echo $elapsed | grep "-") ]]; then
|
||||||
|
days=$(echo $elapsed | awk -F- '{print $1}')
|
||||||
|
hours=$(echo $elapsed | sed -e "s/$days-//g" | awk -F: '{print $1}')
|
||||||
|
minutes=$(echo $elapsed | sed -e "s/$days-//g" | awk -F: '{print $2}')
|
||||||
|
seconds=$(echo $elapsed | sed -e "s/$days-//g" | awk -F: '{print $2}')
|
||||||
|
printf "Process ${PURPLE}$pid${STOP} (${YELLOW}$cmd${STOP}) has been up for ${BLUE}$days${STOP} days, ${LIGHT_BLUE}$hours${STOP} hours, ${CYAN}$minutes${STOP} minutes and ${LIGHT_CYAN}$seconds${STOP} seconds.\n"
|
||||||
|
elif [[ -z $(echo $elapsed | grep "-") ]]; then
|
||||||
|
#If a process has been running for an hour or longer, output is 3 fields
|
||||||
|
if [[ $(echo "$elapsed" | awk -F: '{print NF+1}') == 4 ]]; then
|
||||||
|
hours=$(echo $elapsed | awk -F: '{print $1}')
|
||||||
|
minutes=$(echo $elapsed | awk -F: '{print $2}')
|
||||||
|
seconds=$(echo $elapsed | awk -F: '{print $2}')
|
||||||
|
printf "Process ${PURPLE}$pid${STOP} (${YELLOW}$cmd${STOP}) has been up for ${BLUE}$hours${STOP} hours, ${LIGHT_BLUE}$minutes${STOP} minutes and ${CYAN}$seconds${STOP} seconds.\n"
|
||||||
|
#If running for less than an hour - only 2 fields
|
||||||
|
elif [[ $(echo "$elapsed" | awk -F: '{print NF+1}') == 3 ]]; then
|
||||||
|
minutes=$(echo $elapsed | awk -F: '{print $1}')
|
||||||
|
seconds=$(echo $elapsed | awk -F: '{print $2}')
|
||||||
|
printf "Process ${PURPLE}$pid${STOP} (${YELLOW}$cmd${STOP}) has been up for ${BLUE}$minutes${STOP} minutes and ${LIGHT_BLUE}$seconds${STOP} seconds.\n"
|
||||||
|
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
174
Kumonoboru
174
Kumonoboru
@@ -1,174 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
##Simple script to run Restic backups
|
|
||||||
source $SCRIPTS/Okiru
|
|
||||||
source /etc/environment
|
|
||||||
arg0=$(basename "$0")
|
|
||||||
#Show help if arguments are misused
|
|
||||||
usage()
|
|
||||||
{
|
|
||||||
exec 1>2 # Send standard output to standard error
|
|
||||||
help
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
flag_error()
|
|
||||||
{
|
|
||||||
echo -e "$arg0: $*." >&2
|
|
||||||
help
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
help()
|
|
||||||
{
|
|
||||||
echo "$arg0 - Back up important location to the B2 cloud using Restic."
|
|
||||||
echo " {-c|--clean} -- Force prune of the remote repositories"
|
|
||||||
echo " {-r|--repository} repository -- Only backup the specified repository."
|
|
||||||
echo " {-l|--limit} #[Kbps] -- Limit upload & download speed"
|
|
||||||
echo " {-h|--help} -- Print this help message and exit"
|
|
||||||
echo "Available repositories:"
|
|
||||||
echo "Gerbil-TK Photos (path: /Red-Vol/Media/Pictures)"
|
|
||||||
echo "Pukeko-XYZ-Containers Containers (path: /Red-Vol/Media/Containers)"
|
|
||||||
echo "Pukeko-XYZ-Cloud Data from all devices (path: /Red-Vol/Media/Cloud/Syncthing)"
|
|
||||||
exit 0
|
|
||||||
}
|
|
||||||
#Pass arguments to the script
|
|
||||||
flags()
|
|
||||||
{
|
|
||||||
#This is utterly useless
|
|
||||||
if [[ $# == "0" ]]; then
|
|
||||||
:
|
|
||||||
fi
|
|
||||||
while test $# -gt 0
|
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
(-c|--clean)
|
|
||||||
debug "Cleaning will take place per request."
|
|
||||||
export CLEAN="1"
|
|
||||||
shift;;
|
|
||||||
(-r|--repository)
|
|
||||||
shift
|
|
||||||
export REPOSITORY="$1"
|
|
||||||
debug "Only repository $1 will be processed per request."
|
|
||||||
shift;;
|
|
||||||
(-l|--limit)
|
|
||||||
shift
|
|
||||||
export BWLIMIT="$1"
|
|
||||||
debug "Bandwidth will be limited to $BWLIMIT Kbps per request."
|
|
||||||
shift;;
|
|
||||||
(-h|--help)
|
|
||||||
help;;
|
|
||||||
(*) help;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
}
|
|
||||||
flags "$@"
|
|
||||||
logging Kumonoboru
|
|
||||||
#Defaults
|
|
||||||
if [[ -z $BWLIMIT ]]; then
|
|
||||||
export BWLIMIT="0"
|
|
||||||
fi
|
|
||||||
#Safety function; accepts repository to check
|
|
||||||
safety(){
|
|
||||||
REPOSITORY="$1"
|
|
||||||
info "Checking if repository $REPOSITORY is in use..."
|
|
||||||
#Check no other Restic process is using this repository; Free unnecessary locks, if present
|
|
||||||
if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
|
|
||||||
warn "Repository $REPOSITORY is in use - ignoring"
|
|
||||||
return 1
|
|
||||||
# ^ If there's a restic process holding the repository, leave it alone.
|
|
||||||
else
|
|
||||||
info "Repository $REPOSITORY is not in use - unlocking"
|
|
||||||
restic -r b2:$REPOSITORY unlock
|
|
||||||
# ^ If a lock exists but no process, the repository is safe and should be unlocked.
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
#Backup function; accepts repository and path to backup
|
|
||||||
backup(){
|
|
||||||
REPOSITORY="$1"
|
|
||||||
REPOSITORY_PATH="$2"
|
|
||||||
if safety "$REPOSITORY"; then
|
|
||||||
#Run the backup
|
|
||||||
info "Backing up repository $REPOSITORY"
|
|
||||||
if restic -r b2:"$REPOSITORY" backup "$REPOSITORY_PATH" --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT" | tee -a $LOG; then
|
|
||||||
ok "Path $REPOSITORY_PATH completed upload to $REPOSITORY."
|
|
||||||
check "$REPOSITORY"
|
|
||||||
else
|
|
||||||
error "Repository $REPOSTIORY failed to upload path $REPOSITORY_PATH!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
check(){
|
|
||||||
REPOSITORY="$1"
|
|
||||||
PRUNE="$2"
|
|
||||||
debug "Working on Repostory $1 with prune option $2"
|
|
||||||
## ^ This variable will have value if repo is already clean, indicating
|
|
||||||
#+ This is a post backup check.
|
|
||||||
if [[ -n $PRUNE ]]; then
|
|
||||||
warn "This repository has been cleaned already; will not clean again."
|
|
||||||
fi
|
|
||||||
if safety "$REPOSITORY"; then
|
|
||||||
info "Checking repository $REPOSITORY"
|
|
||||||
if restic -r b2:"$REPOSITORY" check --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT" | tee -a $LOG; then
|
|
||||||
ok "Repository $REPOSITORY passed integrity check!"
|
|
||||||
info "Current snapshots:"
|
|
||||||
restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG
|
|
||||||
else
|
|
||||||
error "Repository $REPOSITORY failed integrity check!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
clean(){
|
|
||||||
REPOSITORY="$1"
|
|
||||||
if safety "$REPOSITORY"; then
|
|
||||||
info "Cleaning repository $REPOSITORY"
|
|
||||||
if restic -r b2:$REPOSITORY forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT" | tee -a $LOG; then
|
|
||||||
ok "Repository $REPOSITORY is trim!"
|
|
||||||
debug "Running post clean check..."
|
|
||||||
check "$REPOSITORY" "1"
|
|
||||||
# Marks repository as cleaned already ^ so it won't passed to this function again.
|
|
||||||
else
|
|
||||||
error "Repository $REPOSITORY failed to prune!"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
#If a specific repository was requested, back it up; otherwise, back them all up.
|
|
||||||
if [[ -n $REPOSITORY ]] && [[ -z $CLEAN ]]; then
|
|
||||||
case "$REPOSITORY" in
|
|
||||||
(Gerbil-TK)
|
|
||||||
backup Gerbil-TK /Red-Vol/Media/Pictures/
|
|
||||||
;;
|
|
||||||
(Pukeko-XYZ-Containers)
|
|
||||||
backup Pukeko-XYZ-Containers /Red-Vol/Media/Containers
|
|
||||||
;;
|
|
||||||
(Pukeko-XYZ-Cloud)
|
|
||||||
backup Pukeko-XYZ-Cloud /Red-Vol/Media/Cloud/Syncthing
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
help;;
|
|
||||||
esac
|
|
||||||
#If cleaning was not forced, backup the repositories
|
|
||||||
elif [[ -z $CLEAN ]]; then
|
|
||||||
backup Gerbil-TK /Red-Vol/Media/Pictures/
|
|
||||||
backup Pukeko-XYZ-Containers /Red-Vol/Media/Containers
|
|
||||||
backup Pukeko-XYZ-Cloud /Red-Vol/Media/Cloud/Syncthing
|
|
||||||
#If a specific repository was requested to be cleaned, clean it
|
|
||||||
elif [[ -n $REPOSITORY ]] && [[ -n $CLEAN ]]; then
|
|
||||||
case "$REPOSITORY" in
|
|
||||||
(Gerbil-TK)
|
|
||||||
clean Gerbil-TK
|
|
||||||
;;
|
|
||||||
(Pukeko-XYZ-Containers)
|
|
||||||
clean Pukeko-XYZ-Containers
|
|
||||||
;;
|
|
||||||
(Pukeko-XYZ-Cloud)
|
|
||||||
clean Pukeko-XYZ-Cloud
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
help;;
|
|
||||||
esac
|
|
||||||
#If cleaning was forced and no repository specified, clean all repositories
|
|
||||||
elif [[ -n $CLEAN ]] || [[ $(date +%a) == "Friday" ]]; then
|
|
||||||
clean Gerbil-TK
|
|
||||||
clean Pukeko-XYZ-Containers
|
|
||||||
clean Pukeko-XYZ-Cloud
|
|
||||||
fi
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#Script to backup all important environment files
|
#Script to backup all important environment files
|
||||||
source /etc/environment
|
source /home/shmick/Scripts/Okiru
|
||||||
source $SCRIPTS/Okiru
|
|
||||||
logging "ConfigBackup"
|
logging "ConfigBackup"
|
||||||
export CONF_DIR="/home/shmick/Config"
|
export CONF_DIR="/home/shmick/Config"
|
||||||
if [[ ! -d $CONF_DIR ]]; then
|
if [[ ! -d $CONF_DIR ]]; then
|
||||||
@@ -39,14 +38,20 @@ elif [[ ! -f "$1" ]]; then
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Configuration files to sync
|
#Configuration files to sync
|
||||||
conf_sync /etc/ddclient.conf $CONF_DIR
|
conf_sync /etc/docker/daemon.json
|
||||||
for tab in $(ls /var/spool/cron/tabs/*); do
|
|
||||||
conf_sync $tab
|
|
||||||
done
|
|
||||||
conf_sync /etc/environment
|
conf_sync /etc/environment
|
||||||
|
conf_sync /etc/fstab
|
||||||
conf_sync /etc/hosts
|
conf_sync /etc/hosts
|
||||||
conf_sync /etc/postfix/main.cf
|
conf_sync /etc/postfix/main.cf
|
||||||
conf_sync /etc/anacrontab
|
conf_sync /etc/profile
|
||||||
|
for conf in $(ls /etc/snapper/configs/* 2> /dev/null); do
|
||||||
|
conf_sync $conf
|
||||||
|
done
|
||||||
|
for conf in $(ls /etc/systemd/system/Murchison*); do
|
||||||
|
conf_sync $conf
|
||||||
|
done
|
||||||
|
for conf in $(ls /etc/systemd/system/Kumonoboru*); do
|
||||||
|
conf_sync $conf
|
||||||
|
done
|
||||||
#Fix permissions
|
#Fix permissions
|
||||||
chown -R shmick $CONF_DIR
|
chown -R shmick $CONF_DIR
|
||||||
96
Okiru
96
Okiru
@@ -24,13 +24,16 @@ YELLOW='\033[1;33m'
|
|||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
LIGHT_BLUE='\033[1;34m'
|
LIGHT_BLUE='\033[1;34m'
|
||||||
PURPLE='\033[0;35m'
|
PURPLE='\033[0;35m'
|
||||||
PURPLE='\033[1;35m'
|
LIGHT_PURPLE='\033[1;35m'
|
||||||
CYAN='\033[0;36m'
|
CYAN='\033[0;36m'
|
||||||
LIGHT_CYAN='\033[1;36m'
|
LIGHT_CYAN='\033[1;36m'
|
||||||
WHITE='\033[0;37m'
|
WHITE='\033[0;37m'
|
||||||
GRAY='\033[1;37m'
|
GRAY='\033[1;37m'
|
||||||
STOP="\e[0m"
|
STOP="\e[0m"
|
||||||
|
|
||||||
|
#If passed from calling script, run in verbose mode (enables debug logging level)
|
||||||
|
VERBOSE="$VERBOSE"
|
||||||
|
|
||||||
|
|
||||||
#If a function calls 'logging' for a log, it will create a log file; otherwise, keep the
|
#If a function calls 'logging' for a log, it will create a log file; otherwise, keep the
|
||||||
#+variable empty thus printing only to terminal
|
#+variable empty thus printing only to terminal
|
||||||
@@ -57,6 +60,12 @@ logging () {
|
|||||||
zstd -11 --rm -f "$(dirname $LOG)/$(basename $LOG)_"$OLD_LOG_DATE"_"$OLD_LOG_TIME"" > /dev/null 2>&1
|
zstd -11 --rm -f "$(dirname $LOG)/$(basename $LOG)_"$OLD_LOG_DATE"_"$OLD_LOG_TIME"" > /dev/null 2>&1
|
||||||
# ^ Append timestamp (YYYYMMDD_HHMMSS - ex 20210301_093543) to log if it exists
|
# ^ Append timestamp (YYYYMMDD_HHMMSS - ex 20210301_093543) to log if it exists
|
||||||
fi
|
fi
|
||||||
|
if [[ -f "$REPORT" ]]; then
|
||||||
|
OLD_REPORT_DATE=$(stat $REPORT | grep Modify | awk '{print $2}' | sed -e 's/-//g')
|
||||||
|
OLD_REPORT_TIME=$(stat $REPORT | grep Modify | awk '{print $3}' | sed -e 's/://g' | awk -F. '{print $1}')
|
||||||
|
mv "$REPORT" "$(dirname $REPORT)/$(basename $REPORT)_"$OLD_REPORT_DATE"_"$OLD_REPORT_TIME"" 2> /dev/null 2>&1
|
||||||
|
zstd -11 --rm -f "$(dirname $REPORT)/$(basename $REPORT)_"$OLD_REPORT_DATE"_"$OLD_REPORT_TIME"" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
touch $LOG
|
touch $LOG
|
||||||
touch $REPORT
|
touch $REPORT
|
||||||
#Greeter
|
#Greeter
|
||||||
@@ -70,37 +79,69 @@ logging () {
|
|||||||
printf "Logging is ${RED}disabled${STOP}; No log file will be generated.\n"
|
printf "Logging is ${RED}disabled${STOP}; No log file will be generated.\n"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Debugging level logging; can be toggled via a switch
|
#If VERBOSE mode is enabled, print debug messages
|
||||||
debug () {
|
if [[ -n $VERBOSE ]]; then
|
||||||
printf "${BLUE}[DEBUG]: $1${STOP}\n" > /dev/stdout
|
#Debugging level logging; can be toggled via a switch
|
||||||
|
debug () {
|
||||||
|
if [[ -z $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${BLUE}[DEBUG]: %s${STOP}\n" "$1"
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [DEBUG]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG
|
||||||
fi
|
fi
|
||||||
}
|
elif [[ -n $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${BLUE}[DEBUG]: %s${STOP} ${LIGHT_BLUE}%s${STOP}\n" "$1" "$2"
|
||||||
|
if [[ -f $LOG ]]; then
|
||||||
|
echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
#Otherwise, ignore debug calls;
|
||||||
|
else
|
||||||
|
debug () {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
fi
|
||||||
#Information level logging;
|
#Information level logging;
|
||||||
info () {
|
info () {
|
||||||
printf "${CYAN}[INFO]:${STOP} $1\n" > /dev/stdout
|
if [[ -z $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${CYAN}[INFO]:${STOP} %s\n" "$1"
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [INFO]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [INFO]: $1" >> $LOG
|
||||||
|
fi
|
||||||
|
elif [[ -n $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${CYAN}[INFO]:${STOP} %s ${LIGHT_CYAN}%s${STOP}\n" "$1" "$2"
|
||||||
|
if [[ -f $LOG ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${CYAN}[INFO]:${STOP} %s ${LIGHT_CYAN}%s${STOP}\n" "$1" "$2" >> $LOG
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Warning level logging;
|
#Warning level logging;
|
||||||
warn () {
|
warn () {
|
||||||
printf "${YELLOW}[WARNING]:${STOP} $1\n" > /dev/stdout
|
if [[ -z $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${ORANGE}[WARNING]:${STOP} %s\n" "$1"
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [WARN]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [WARN]: $1" >> $LOG
|
||||||
|
fi
|
||||||
|
elif [[ -n $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${ORANGE}[WARNING]:${STOP} %s ${YELLOW}%s${STOP}\n" "$1" "$2"
|
||||||
|
if [[ -f $LOG ]]; then
|
||||||
|
echo -e "$(date +"%T:%N") [WARN]: $1" >> $LOG
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#Error logging function; Errors are added to an array and a report file.
|
#Error logging function; Errors are added to an array and a report file.
|
||||||
error () {
|
error () {
|
||||||
echo $1 1>&2
|
if [[ -z $2 ]]; then
|
||||||
# ` ^ Output error message to stderr
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${RED}[ERROR]: %s${STOP}\n" "$1"
|
||||||
printf "${RED}[ERROR]: $1${STOP}\n" > /dev/stdout
|
|
||||||
# ^ Print it to the screen
|
# ^ Print it to the screen
|
||||||
|
elif [[ -n $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${RED}[ERROR]: %s${STOP}${LIGHT_RED} %s${STOP}\n" "$1"
|
||||||
|
fi
|
||||||
errors+=("$1")
|
errors+=("$1")
|
||||||
# ^ And add to errors array
|
# ^ And add to errors array
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [ERROR]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [ERROR]: $1" >> $LOG
|
||||||
# ^ Log it with its' time and date
|
# ^ Log it with its' time and date
|
||||||
fi
|
fi
|
||||||
if [[ -f $REPORT ]]; then
|
if [[ -f $REPORT ]]; then
|
||||||
@@ -110,9 +151,16 @@ error () {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
ok () {
|
ok () {
|
||||||
printf "${GREEN}[SUCCESS]: $1${STOP}\n" > /dev/stdout
|
if [[ -z $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${GREEN}[SUCCESS]: %s${STOP}\n" "$1"
|
||||||
if [[ -f $LOG ]]; then
|
if [[ -f $LOG ]]; then
|
||||||
echo -e "$(date | awk '{print $4}') [SUCCESS]: $1" >> $LOG
|
echo -e "$(date +"%T:%N") [SUCCESS]: $1" >> $LOG
|
||||||
|
fi
|
||||||
|
elif [[ -n $2 ]]; then
|
||||||
|
printf "${PURPLE}$(date +"%T:%N")${STOP} ${GREEN}[SUCCESS]:${LIGHT_GREEN} %s${STOP}${GREEN} %s${STOP}\n" "$1" "$2"
|
||||||
|
if [[ -f $LOG ]]; then
|
||||||
|
echo -e "$(date +"%T:%N") [SUCCESS]: $1" >> $LOG
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,3 +176,19 @@ lock () {
|
|||||||
rm -rf $1
|
rm -rf $1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
#Same as logging function opener, for scripts that need to wrap things up nicely
|
||||||
|
end_logging () {
|
||||||
|
if [[ -f "$LOG" ]]; then
|
||||||
|
OLD_LOG_DATE=$(stat $LOG | grep Modify | awk '{print $2}' | sed -e 's/-//g')
|
||||||
|
OLD_LOG_TIME=$(stat $LOG | grep Modify | awk '{print $3}' | sed -e 's/://g' | awk -F. '{print $1}')
|
||||||
|
mv "$LOG" "$(dirname $LOG)/$(basename $LOG)_"$OLD_LOG_DATE"_"$OLD_LOG_TIME"" 2> /dev/null 2>&1
|
||||||
|
zstd -11 --rm -f "$(dirname $LOG)/$(basename $LOG)_"$OLD_LOG_DATE"_"$OLD_LOG_TIME"" > /dev/null 2>&1
|
||||||
|
# ^ Append timestamp (YYYYMMDD_HHMMSS - ex 20210301_093543) to log if it exists
|
||||||
|
fi
|
||||||
|
if [[ -f "$REPORT" ]]; then
|
||||||
|
OLD_REPORT_DATE=$(stat $REPORT | grep Modify | awk '{print $2}' | sed -e 's/-//g')
|
||||||
|
OLD_REPORT_TIME=$(stat $REPORT | grep Modify | awk '{print $3}' | sed -e 's/://g' | awk -F. '{print $1}')
|
||||||
|
mv "$REPORT" "$(dirname $REPORT)/$(basename $REPORT)_"$OLD_REPORT_DATE"_"$OLD_REPORT_TIME"" 2> /dev/null 2>&1
|
||||||
|
zstd -11 --rm -f "$(dirname $REPORT)/$(basename $REPORT)_"$OLD_REPORT_DATE"_"$OLD_REPORT_TIME"" > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|||||||
20
UnboundUnbound
Executable file
20
UnboundUnbound
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#Simple script to use standard DNS if Unbound (behind Adguard) is unavailable for some reason
|
||||||
|
if [[ -z $1 ]]; then
|
||||||
|
SECONDS=0
|
||||||
|
# ^ If nothing is specified, do not wait
|
||||||
|
else
|
||||||
|
SECONDS=$1
|
||||||
|
# ^ If specified, wait however many seconds user specifies
|
||||||
|
fi
|
||||||
|
sleep $SECONDS
|
||||||
|
if ! nc -vz localhost 53 >/dev/null 2>&1; then
|
||||||
|
# ^ If you cannot connect to DNS port on local host
|
||||||
|
sed -i -e 's/192.168.0.66/1.1.1.1/g' /etc/resolv.conf
|
||||||
|
# ^ replace local address with 1.1.1.1 (Cloudflare DNS)
|
||||||
|
else
|
||||||
|
sed -i -e 's/1.1.1.1/192.168.0.66/g' /etc/resolv.conf
|
||||||
|
# ^ If connection is established, use local DNS
|
||||||
|
fi
|
||||||
|
#Force update of DNS resolution
|
||||||
|
/sbin/netconfig update -f
|
||||||
5
inventory.yml
Normal file
5
inventory.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
all:
|
||||||
|
hosts:
|
||||||
|
takahe:
|
||||||
|
ansible_host: 192.168.0.66
|
||||||
|
ansible_user: shmick
|
||||||
Reference in New Issue
Block a user