Compare commits

..

41 Commits

Author SHA1 Message Date
3ad26474a6 Remove split HatarashiHako and Kumonoboru
All checks were successful
Ansible Deploy / deploy (push) Successful in 53s
2023-11-18 13:20:28 +02:00
9d5303fdc6 Trying Ansible actions
All checks were successful
Ansible Deploy / deploy (push) Successful in 54s
2023-11-17 23:40:24 +02:00
707ebe3a62 Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 53s
2023-11-17 23:36:37 +02:00
ba29fe637f Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 54s
2023-11-17 23:33:16 +02:00
73132456f3 Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 53s
2023-11-17 23:26:26 +02:00
1121ef6db8 Trying Ansible actions
All checks were successful
Ansible Deploy / deploy (push) Successful in 54s
2023-11-17 23:25:05 +02:00
80e47ee92d Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 54s
2023-11-17 23:23:48 +02:00
1e3b7b9e94 Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 4s
2023-11-17 23:23:09 +02:00
c6e7e05eef Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 5s
2023-11-17 23:21:31 +02:00
74ded3ddbe Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 18s
2023-11-17 23:20:36 +02:00
36bf3c9ba5 Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 28s
2023-11-17 23:17:08 +02:00
153f1b0dcd Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 7s
2023-11-17 23:15:32 +02:00
3ccf6c1758 Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 6s
2023-11-17 23:13:32 +02:00
aed2e11a47 Trying Ansible actions
Some checks failed
Ansible Deploy / deploy (push) Failing after 19s
2023-11-17 23:12:34 +02:00
9c2a255e1c Trying Ansible actions 2023-11-17 23:11:08 +02:00
77016eefaa Trying Ansible actions 2023-11-17 23:10:48 +02:00
4478fc74c8 Update .gitea/workflows/pingflow.yaml
Some checks failed
Ansible Deploy / deploy (push) Failing after 4s
2023-11-17 23:08:08 +02:00
db4006a820 Trying Ansible actions 2023-11-17 23:07:27 +02:00
69aa1b6903 Trying Ansible actions 2023-11-17 23:05:52 +02:00
f03af21605 Trying Ansible actions 2023-11-17 23:05:24 +02:00
fe910e5f79 Trying Gitea actions
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 14s
2023-11-17 22:20:24 +02:00
6b1790171d Hatarashi Hako now provides Prometheus metrics; old updates 2023-11-17 16:50:20 +02:00
2d9f26a558 Updates and enhancements 2023-03-17 13:32:30 +02:00
97fb7da9b3 Check absolutely slaughter download bandwidth; run them once mothly. Relegated logging to systemd 2023-02-24 11:45:32 +02:00
f03573d275 Update Cloud repository location 2022-11-18 15:16:41 +02:00
8719bfbe27 Small service names fix 2022-11-18 15:16:30 +02:00
ed6614c4b1 Clean on the first of each month instead of every friday 2022-11-18 13:23:13 +02:00
f08ba95750 Detect service names nicely 2022-11-18 13:23:01 +02:00
d81683b431 Now relying on global VERBOSE variable 2022-10-28 11:21:26 +03:00
3bd1c3f9bd Extra accuracy fixes 2022-10-28 11:21:14 +03:00
42782597cd Logging format updates - hurray! 2022-10-16 22:11:19 +03:00
4fedc39d1a Script to check if containers are up to date, update if necessary and yell 2022-10-16 19:05:10 +03:00
f4e42a53be Split debug to optional verbose mode (inital); do not yell twice to STDERR 2022-10-16 19:02:16 +03:00
f978c47939 Explicitly mention cache dir; have a nice day 2022-10-16 18:51:59 +03:00
ea3d2b76b5 Bunch of changes; renaming the ConfigBackup; you kinda suck 2022-09-12 20:46:56 +03:00
0f2a754e17 Add DNS resolution reset 2022-04-25 08:46:00 +03:00
2c3e27fa37 No wait by default 2022-04-10 11:38:25 +03:00
a32adb2080 Add ability to use process name 2022-04-10 09:52:35 +03:00
bd0452a3ea Add Donnagurai; Light Purple fix for OKiru 2022-04-07 16:44:53 +03:00
d29ff254db Unbound DNS switcher script 2022-04-07 10:29:31 +03:00
f03603a1f5 Compressing right after script runs 2022-02-05 16:17:44 +02:00
8 changed files with 271 additions and 204 deletions

View 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
View 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

View File

@@ -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

View File

@@ -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

108
Okiru
View File

@@ -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
if [[ -f $LOG ]]; then debug () {
echo -e "$(date | awk '{print $4}') [DEBUG]: $1" >> $LOG if [[ -z $2 ]]; then
fi printf "${PURPLE}$(date +"%T:%N")${STOP} ${BLUE}[DEBUG]: %s${STOP}\n" "$1"
} if [[ -f $LOG ]]; then
echo -e "$(date +"%T:%N") [DEBUG]: $1" >> $LOG
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
if [[ -f $LOG ]]; then printf "${PURPLE}$(date +"%T:%N")${STOP} ${CYAN}[INFO]:${STOP} %s\n" "$1"
echo -e "$(date | awk '{print $4}') [INFO]: $1" >> $LOG if [[ -f $LOG ]]; then
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
if [[ -f $LOG ]]; then printf "${PURPLE}$(date +"%T:%N")${STOP} ${ORANGE}[WARNING]:${STOP} %s\n" "$1"
echo -e "$(date | awk '{print $4}') [WARN]: $1" >> $LOG if [[ -f $LOG ]]; then
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
if [[ -f $LOG ]]; then printf "${PURPLE}$(date +"%T:%N")${STOP} ${GREEN}[SUCCESS]: %s${STOP}\n" "$1"
echo -e "$(date | awk '{print $4}') [SUCCESS]: $1" >> $LOG if [[ -f $LOG ]]; then
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
View 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
View File

@@ -0,0 +1,5 @@
all:
hosts:
takahe:
ansible_host: 192.168.0.66
ansible_user: shmick

8
ping.yaml Normal file
View File

@@ -0,0 +1,8 @@
- hosts: takahe
gather_facts: no
vars:
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
tasks:
- name: ping
ansible.builtin.ping: