Fixes & Enhancements #6

Merged
me merged 35 commits from dev into main 2025-10-14 15:01:21 -07:00
5 changed files with 154 additions and 40 deletions

57
files/scripts/backup_system.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
## Variables ##
if [[ -z "$HOSTNAME" ]]; then
echo "*** Pulling Hostname From Command ***"
export HOSTNAME="`hostname`"
fi
if [[ -z "$HOSTNAME" ]]; then
echo "*** Pulling Hostname From /etc/ File ***"
export HOSTNAME="`cat /etc/hostname`"
fi
EXTRA="$1"
TAG="System"
DATE="`date "+%Y%m%d-%H%M%S"`"
BACKUP_DIR="/srv/backup"
BASENAME="Backup"
BACKUP="$BACKUP_DIR/$BASENAME.$DATE.$HOSTNAME.$TAG.zip"
## Initialization ##
echo "*** Creating Backup Directory ***"
sudo mkdir -pv "$BACKUP_DIR"
sudo mkdir -pv "$BACKUP_DIR/TRASH"
sudo chmod -Rv 775 "$BACKUP_DIR"
sudo chown -Rv root:root "$BACKUP_DIR"
## Cleanup ##
echo "*** Removing Old Backups ***"
cd "$BACKUP_DIR"
sudo mv -v "$BASENAME"*"$TAG"* TRASH/
sudo rm -v TRASH/*
## Main
echo "*** Creating backup at '$BACKUP' ***"
sudo zip -rv "$BACKUP" \
/etc /var/{log,mail,spool} /srv /boot \
/usr/local/etc $EXTRA \
-x "/srv/backup/*"
status="$?"
if [[ "$status" != 0 ]]; then
echo "*** ERROR: Failed to create '$BACKUP', file may be incorrect. ***"
fi
if [[ -e "$BACKUP" ]]; then
ls -alh "$BACKUP"
echo "*** '$BACKUP' created successfully! ***"s
else
echo "*** '$BACKUP' not found! ***"
exit 1
fi
exit 0

View File

@@ -132,7 +132,7 @@
pentesting: "{{ lookup('ini', 'pentesting file={{gen_file}} default=false') | bool }}" pentesting: "{{ lookup('ini', 'pentesting file={{gen_file}} default=false') | bool }}"
no_telem: "{{ lookup('ini', 'no_telem file={{gen_file}} default=false') | bool }}" no_telem: "{{ lookup('ini', 'no_telem file={{gen_file}} default=false') | bool }}"
battery: "{{ lookup('ini', 'battery file={{gen_file}} default=false') | bool }}" battery: "{{ lookup('ini', 'battery file={{gen_file}} default=false') | bool }}"
swap_block: "{{ lookup('ini', 'swap_block file={{gen_file}} default=false') | bool }}" swap_block: "{{ lookup('ini', 'swap_block file={{gen_file}} default=false') }}"
swap_count: "{{ lookup('ini', 'swap_count file={{gen_file}} default=1') }}" swap_count: "{{ lookup('ini', 'swap_count file={{gen_file}} default=1') }}"
swap_file: "{{ lookup('ini', 'swap_file file={{gen_file}} default=/swapfile') }}" swap_file: "{{ lookup('ini', 'swap_file file={{gen_file}} default=/swapfile') }}"
sshd_port: "{{ lookup('ini', 'sshd_port file={{gen_file}} default=22') }}" sshd_port: "{{ lookup('ini', 'sshd_port file={{gen_file}} default=22') }}"
@@ -215,7 +215,7 @@
workstation: "{{ lookup('ini', 'enable file={{wrk_file}} default=false') | bool }}" workstation: "{{ lookup('ini', 'enable file={{wrk_file}} default=false') | bool }}"
coding: "{{ lookup('ini', 'coding file={{wrk_file}} default=false') | bool }}" coding: "{{ lookup('ini', 'coding file={{wrk_file}} default=false') | bool }}"
sdks: "{{ lookup('ini', 'sdks file={{wrk_file}} default=false') | bool }}" sdks: "{{ lookup('ini', 'sdks file={{wrk_file}} default=false') | bool }}"
editing: "{{ lookup('ini', 'editing file={{wrk_file}} default=false') | bool }}" editing: "{{ lookup('ini', 'editing file={{wrk_file}} default=false') }}"
gaming: "{{ lookup('ini', 'gaming file={{wrk_file}} default=false') | bool }}" gaming: "{{ lookup('ini', 'gaming file={{wrk_file}} default=false') | bool }}"
rdp: "{{ lookup('ini', 'rdp file={{wrk_file}} default=false') | bool }}" rdp: "{{ lookup('ini', 'rdp file={{wrk_file}} default=false') | bool }}"
vnc: "{{ lookup('ini', 'vnc file={{wrk_file}} default=false') | bool }}" vnc: "{{ lookup('ini', 'vnc file={{wrk_file}} default=false') | bool }}"

View File

@@ -283,6 +283,19 @@
alias edit-config-wrk="sudo $EDITOR {{ wrk_file }}" alias edit-config-wrk="sudo $EDITOR {{ wrk_file }}"
alias edit-config-mnr="sudo $EDITOR {{ mnr_file }}" alias edit-config-mnr="sudo $EDITOR {{ mnr_file }}"
alias edit-config-srv="sudo $EDITOR {{ srv_file }}" alias edit-config-srv="sudo $EDITOR {{ srv_file }}"
function_clean_trashed: |
function clean-trashed {
dir="$1"
if [[ -z $dir ]]; then
dir="./"
fi
cd $dir
dir="`pwd`"
echo "Removing '.trashed*' files in '$dir'."
find "$dir" -name ".trashed*" -exec du -h {} \; -delete | sort -h
}
alias trashed-cleanup="clean-trashed"
alias trashed-clean="clean-trashed"
function_check_trash: | function_check_trash: |
function check-trash() { function check-trash() {
unset OPTIND unset OPTIND
@@ -378,6 +391,9 @@
fi fi
echo "Checking but not cleaning /var/mail..." echo "Checking but not cleaning /var/mail..."
du -ha /var/mail | sort -h du -ha /var/mail | sort -h
if [[ $clean == "Y" ]]; then
clean-trashed "~/"
fi
return 0 return 0
} }
alias check_trash="check-trash" alias check_trash="check-trash"
@@ -386,18 +402,20 @@
alias_trash_clean: alias trash-clean='trash-check --clean' alias_trash_clean: alias trash-clean='trash-check --clean'
alias_clean_dir: | alias_clean_dir: |
function clean-dir() { function clean-dir() {
sudo du -hs
clean_dir="`date '+%Y%m%d_%H%M%S'`_CLEANED" clean_dir="`date '+%Y%m%d_%H%M%S'`_CLEANED"
trash_dir="$HOME/TRASH/$clean_dir" trash_dir="$HOME/TRASH/$clean_dir"
curr_dir="`pwd`" curr_dir="`pwd`"
mkdir -pv "$trash_dir" mkdir -pv "$trash_dir"
echo "$curr_dir is being cleaned at `date`." | tee "$trash_dir"/INFO.txt echo "$curr_dir is being cleaned at `date`." | tee "$trash_dir"/INFO.txt
mv -v ..?* .[!.]* * "$trash_dir"/ | tee -a "$trash_dir"/INFO.txt mv -v ..?* .[!.]* * "$trash_dir"/ | tee -a "$trash_dir"/INFO.txt
sudo du -hs
} }
function_clean: | function_clean: |
function clean() { function clean() {
sudo du -hs clean-trash
clean-dir clean-code
sudo du -hs clean-backups
} }
function_flatpak_usage: | function_flatpak_usage: |
function flatpak-usage() { function flatpak-usage() {
@@ -577,6 +595,11 @@
env-obtainium-hyperling dev env-obtainium-hyperling dev
nodejs-website dev nodejs-website dev
ebook-health-protocol dev ebook-health-protocol dev
ebook-freedom-flyer dev
ebook-technology-alternatives dev
ebook-narcissism-healing dev
ebook-forest-howto dev
ebook-template main
flutter-expense-tracker dev flutter-expense-tracker dev
flutter-social-traveler-app dev flutter-social-traveler-app dev
nodejs-social-traveler-server dev nodejs-social-traveler-server dev
@@ -682,6 +705,9 @@
done done
cd cd
echo -e "******* PDFs *******"
find ~/Code/ebook-* -name "*.pdf" -exec du -h {} \; -delete | sort -h
echo -e "\n*** Done! ***" echo -e "\n*** Done! ***"
} }
alias code-clean="clean-code" alias code-clean="clean-code"
@@ -742,6 +768,7 @@
alias_ls: | alias_ls: |
alias l='ls' alias l='ls'
alias ll='ls -alh' alias ll='ls -alh'
alias lh='ls -ash'
alias_progs: | alias_progs: |
alias progs='ps -ef' alias progs='ps -ef'
alias_nethogs: | alias_nethogs: |
@@ -750,47 +777,47 @@
alias ansible-facts='ansible localhost -m setup --connection=local' alias ansible-facts='ansible localhost -m setup --connection=local'
function_now: | function_now: |
function now { function now {
date "+%Y%m%d_%H%M%S" date "+%Y%m%d-%H%M%S"
}
function today {
date "+%Y%m%d"
} }
function_backup: | function_backup: |
function backup { function backup {
EXTRA="$1" /usr/local/bin/backup_system.sh
BACKUP_DIR="/tmp" }
BACKUP_FILENAME="Backup-`now`.zip" alias backup-system="backup"
BACKUP="$BACKUP_DIR/$BACKUP_FILENAME" alias system-backup="backup"
echo "*** Creating backup at '$BACKUP' ***" alias check-backups="ll /srv/backup"
sudo zip -rv "$BACKUP" \ function clean-backup {
/etc /var/{log,mail,spool} /srv /boot \ sh -c "rm -rfv /srv/backup/*"
/usr/local/etc $EXTRA }
status="$?" alias clean-backups="clean-backup"
if [[ "$status" != 0 ]]; then function_log: |
echo "*** ERROR: Failed to create '$BACKUP', file may be incorrect. ***" function log {
fi echo -e "$1"
if [[ -e "$BACKUP" ]]; then }
ls -alh "$BACKUP" function blog {
echo "*** '$BACKUP' created successfully! ***" echo -e "\n\n$1\n\n"
else
echo "*** '$BACKUP' not found! ***"
fi
} }
function_debian_upgrade: | function_debian_upgrade: |
function debian-upgrade { function debian-upgrade {
typeset -l OLD NEW typeset -l OLD NEW
OLD="$1" OLD="$1"
NEW="$2" NEW="$2"
echo "*** Upgrading from '$OLD' to '$NEW' ***" blog "*** Upgrading from '$OLD' to '$NEW' ***"
if [[ -z "$OLD" || -z "$NEW" ]]; then if [[ -z "$OLD" || -z "$NEW" ]]; then
echo -n "ERROR: Please pass the OLD and NEW version names" echo -n "ERROR: Please pass the OLD and NEW version names"
echo ", such as 'debian-upgrade bookworm trixie'. " echo ", such as 'debian-upgrade bookworm trixie'. "
return 1 return 1
fi fi
echo "*** Running 'backup' before starting upgrade. ***" blog "*** Running 'backup' before starting upgrade. ***"
sleep 1 sleep 1
backup backup
echo "*** Listing the current apt listing for '$OLD' ***" blog "*** Listing the current apt listing for '$OLD' ***"
sudo grep "$OLD" /etc/apt/sources.list /etc/apt/sources.list.d/* sudo grep "$OLD" /etc/apt/sources.list /etc/apt/sources.list.d/*
echo -en "\nAre these the entries you'd like changed to '$NEW'? (y/N) " echo -en "\nAre these the entries you'd like changed to '$NEW'? (y/N) "
@@ -798,49 +825,62 @@
read confirm_change read confirm_change
if [[ -z "$confirm_change" || "$confirm_change" == "N"* ]]; then if [[ -z "$confirm_change" || "$confirm_change" == "N"* ]]; then
echo "*** Aborting upgrade, change rejected. ***" blog "*** Aborting upgrade, change rejected. ***"
return 1 return 1
fi fi
unset confirm_change unset confirm_change
echo "*** Continuing with upgrade. ***" blog "*** Continuing with upgrade. ***"
sudo sed -i "s/$OLD/$NEW/g" /etc/apt/sources.list sudo sed -i "s/$OLD/$NEW/g" /etc/apt/sources.list
find /etc/apt/sources.list.d -name "*.list" \ find /etc/apt/sources.list.d/ -name "*.list" \
-exec sudo sed -i "s/$OLD/$NEW/g" {} \;
find /etc/apt/sources.list.d/ -name "*.sources" \
-exec sudo sed -i "s/$OLD/$NEW/g" {} \; -exec sudo sed -i "s/$OLD/$NEW/g" {} \;
sudo grep $OLD /etc/apt/sources.list /etc/apt/sources.list.d/* sudo grep $OLD /etc/apt/sources.list /etc/apt/sources.list.d/*.{list,sources}
sudo grep $NEW /etc/apt/sources.list /etc/apt/sources.list.d/* sudo grep $NEW /etc/apt/sources.list /etc/apt/sources.list.d/*.{list,sources}
echo -en "\nDo the source files look correct? (y/N) " echo -en "\nDo the source files look correct? (y/N) "
typeset -u confirm_correct typeset -u confirm_correct
read confirm_correct read confirm_correct
if [[ -z "$confirm_correct" || "$confirm_correct" == "N"* ]]; then if [[ -z "$confirm_correct" || "$confirm_correct" == "N"* ]]; then
echo "*** Aborting upgrade, confirmation rejected. ***" blog "*** Aborting upgrade, confirmation rejected. ***"
return 1 return 1
fi fi
unset confirm_correct unset confirm_correct
echo "*** Starting the upgrade. ***" blog "*** Starting the upgrade. ***"
sleep 1 sleep 1
sudo apt update sudo apt update
sudo apt upgrade --without-new-pkgs sudo apt upgrade --without-new-pkgs
echo "*** Upgrades complete, now add new packages. ***" blog -e "*** Upgrades complete, now add new packages. ***"
sleep 1 sleep 1
sudo apt full-upgrade sudo apt full-upgrade
echo "*** New packages complete, clean apt files. ***" blog "*** New packages complete, clean apt files. ***"
sleep 1 sleep 1
sudo apt autoremove --purge sudo apt autoremove --purge
sudo apt clean sudo apt clean
echo "*** All done! '$OLD' is now '$NEW'. Please reboot. ***" blog "*** All done! '$OLD' is now '$NEW'. Please reboot. ***"
sleep 1 sleep 1
unset OLD NEW unset OLD NEW
} }
alias upgrade-debian="debian-upgrade" alias upgrade-debian="debian-upgrade"
function_ebook_convert: |
# Regenerate all eBook projects at once.
function ebook-convert {
find ~/Code/ebook-* -name "*.pdf" -print -delete
find ~/Code/ebook-* -name convert.sh -print -exec bash "{}" \;
}
alias ebooks="ebook-convert"
alias convert="ebook-convert"
alias_sudo: |
# Allows for alias expansions when using sudo, such as doing "sudo ll".
alias sudo="sudo "
- name: General | Account Management | Users | Files | Common Variable - name: General | Account Management | Users | Files | Common Variable
set_fact: set_fact:
@@ -878,6 +918,7 @@
{{ metasploit_aliases }} {{ metasploit_aliases }}
{{ show_config_aliases }} {{ show_config_aliases }}
{{ edit_config_aliases }} {{ edit_config_aliases }}
{{ function_clean_trashed }}
{{ function_check_trash }} {{ function_check_trash }}
{{ function_clean }} {{ function_clean }}
{{ function_flatpak_usage }} {{ function_flatpak_usage }}
@@ -911,7 +952,10 @@
{{ alias_ansible_facts }} {{ alias_ansible_facts }}
{{ function_now }} {{ function_now }}
{{ function_backup }} {{ function_backup }}
{{ function_log }}
{{ function_debian_upgrade }} {{ function_debian_upgrade }}
{{ function_ebook_convert }}
{{ alias_sudo }}
- name: General | Account Management | Users | Files | .bashrc - name: General | Account Management | Users | Files | .bashrc
blockinfile: blockinfile:

View File

@@ -1,12 +1,18 @@
--- ---
# Jobs relating to the ansible user. # Jobs relating to the ansible user.
# $RANDOM is anywhere from 0 to 32767 in BASH. This would be up to ~9 hours.
# $RANDOM / 10 can be up to about 3200 seconds, or ~55 minutes.
# $RANDOM / 20 can be up to about 1600 seconds, or ~27 minutes.
# $RANDOM / 50 can be up to about 650 seconds, or ~11 minutes.
# $RANDOM / 100 can be up to about 320 seconds, or ~5 minutes.
# This prevents multiple systems from hitting it at the exact same time.
- name: General | Cron | Ansible | Create Subscriber Job - name: General | Cron | Ansible | Create Subscriber Job
cron: cron:
user: ansible user: ansible
name: "Ansible Sync" name: "Ansible Sync"
minute: "*/30" minute: "*/30"
job: "sudo {{ ansible_pull_exec.stdout }} -v -o -U {{ git_repo_http }} --checkout {{ branch }}" job: "sleep $(( $RANDOM / 20 )); sudo {{ ansible_pull_exec.stdout }} -v -o -U {{ git_repo_http }} --checkout {{ branch }}"
state: present state: present
disabled: "{{ 'yes' if no_telem else 'no' }}" disabled: "{{ 'yes' if no_telem else 'no' }}"
@@ -14,7 +20,7 @@
cron: cron:
user: ansible user: ansible
name: "Ansible Weekly Forced Sync" name: "Ansible Weekly Forced Sync"
special_time: weekly special_time: daily
job: "{{ user_root.home }}/bin/scm.sh" job: "sleep $(( $RANDOM / 1 )); sudo {{ ansible_pull_exec.stdout }} -v -U {{ git_repo_http }} --checkout {{ branch }}"
state: present state: present
disabled: "{{ 'yes' if no_telem else 'no' }}" disabled: "{{ 'yes' if no_telem else 'no' }}"

View File

@@ -120,3 +120,10 @@
until: ntp_status.state == "started" until: ntp_status.state == "started"
retries: 3 retries: 3
delay: 3 delay: 3
## Timezone ##
# TBD/TODO:
# Add a field to general.yml config file which gets applied via timedatectl and /etc/localtime.
# Example of what to do to file:
# /etc/localtime -> ../usr/share/zoneinfo/America/Phoenix