Improvements For Storage Space Management (#26)

* Add cleaning commands to DNF.

* Clean flatpak as best we can.

* Taking advice from TechRepublic about clean commands.

* Add prompt for removing freebsd-update folder.

* Add trash checking function with cleanup option.

* Enhance check-trash to include "trash" such as mail.

* Separate the call to mounted filesystems.

* Add clean function to clear local trash.

* Change underscore version to alias not function.

* Fix `clean`.

* Reduce journalctl log size to 100M. Also modified names.
This commit is contained in:
Hyperling 2022-04-25 07:06:14 -05:00 committed by GitHub
parent 3c670b5961
commit b644ba9479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 14 deletions

View File

@ -64,7 +64,7 @@
update_package_manager: |
echo "*** Apt ***" &&
sudo apt update &&
sudo apt autoclean {{ update_accept_var }} &&
sudo apt clean {{ update_accept_var }} &&
sudo apt autoremove {{ update_accept_var }} &&
sudo dpkg --configure -a &&
sudo apt --fix-broken --fix-missing install &&
@ -81,9 +81,16 @@
- name: General | Facts | Package | Update Commands | pkg
set_fact:
update_package_manager: |
echo "*** FreeBSD-Update ***" &&
sudo sh -c "rm -rfv /var/db/freebsd-update; mkdir -v /var/db/freebsd-update" &&
sudo freebsd-update fetch install &&
echo "*** FreeBSD-Update ***"
clean=""
[[ "{{ update_accept_var }}" == "-y" ]] || echo "Are you sure you'd like to clean /var/db/freebsd-update? [y/N] "
[[ "{{ update_accept_var }}" == "-y" ]] || read -N 1 clean
typeset -l clean
if [[ "{{ update_accept_var }}" == "-y" || "$clean" == "y" ]]; then
echo "Cleaning directory..."
sudo sh -c "rm -rfv /var/db/freebsd-update; mkdir -v /var/db/freebsd-update"
fi
sudo freebsd-update fetch install
echo "*** Pkg ***" &&
sudo pkg update &&
@ -113,6 +120,8 @@
set_fact:
update_package_manager: |
echo "*** DNF ***" &&
sudo dnf clean all {{ update_accept_var }} &&
sudo dnf autoremove {{ update_accept_var }} &&
sudo dnf upgrade {{ update_accept_var }} &&
when: ansible_pkg_mgr in ("dnf")
@ -126,6 +135,7 @@
set_fact:
update_flatpak: |
echo "*** Flatpak ***" &&
sudo flatpak uninstall --unused {{ update_accept_var }} &&
sudo flatpak update {{ update_accept_var }} &&
when: flatpak_exec is defined and flatpak_exec.failed is defined and not flatpak_exec.failed

View File

@ -115,7 +115,7 @@
alias_cp: alias cp='cp -v'
alias_mv: alias mv='mv -v'
alias_rm: alias rm='echo "Use mv ~/TRASH/ instead!"'
alias_clean: alias clean='mv * ~/TRASH/'
alias_clean_dir: alias clean-dir='mv * ~/TRASH/'
alias_clean_trash: alias clean-trash='sh -c "rm -rfv ~/TRASH/*"'
path_additions: export PATH="~/bin:$PATH"
function_wttr: |
@ -191,6 +191,71 @@
alias edit-config-wrk="sudo $EDITOR {{ wrk_file }}"
alias edit-config-mnr="sudo $EDITOR {{ mnr_file }}"
alias edit-config-srv="sudo $EDITOR {{ srv_file }}"
function_check_trash: |
function check-trash() {
unset OPTIND
while (( $# > 0 )); do
case $1 in
-c | -y | --clean ) clean="Y" ;;
-n | -net | --network ) network="Y" ;;
* ) echo "
ERROR: Option '$1' with value '$2' not recognized.
$PROG [-c|-clean|--clean|-y] [-n|-net|--network]
"
return 1
esac
shift
done
echo "clean=$clean"
echo "network=$network"
echo "Grabbing sudo permissions..."
sudo echo "Success! Starting search..."
function dirs_to_check {
echo "/root"
echo "/home"
}
dirs_to_check | while read dir; do
echo "Checking $dir..."
sudo find $dir -name TRASH | while read trash; do
if [[ "$trash" != "" && `sudo ls $trash` ]]; then
echo "Found $trash with contents:"
sudo ls -lh $trash
if [[ "$clean" == "Y" ]]; then
echo "Cleaning trash..."
sudo sh -c "rm -rfv $trash/*"
fi
fi
done
done
if [[ "$network" == "Y" ]]; then
function network_to_check {
find /mnt -maxdepth 1 -mindepth 1
}
network_to_check | while read dir; do
echo "Checking $dir..."
sudo find $dir -name TRASH | while read trash; do
if [[ "$trash" != "" && `sudo ls $trash` ]]; then
echo "Found $trash with contents:"
sudo ls -lh $trash
if [[ "$clean" == "Y" ]]; then
echo "Cleaning trash..."
sudo sh -c "rm -rfv $trash/*"
fi
fi
done
done
fi
echo "Checking but not cleaning /var/mail..."
du -ha /var/mail | sort -h
return 0
}
alias check_trash="check-trash"
function_clean: |
function clean() {
sudo df -h
check-trash --clean
sudo df -h
}
- name: General | Account Management | Users | Files | Common Variable
set_fact:
@ -199,7 +264,7 @@
{{ alias_cp }}
{{ alias_mv }}
{{ alias_rm }}
{{ alias_clean }}
{{ alias_clean_dir }}
{{ alias_clean_trash }}
{{ function_wttr }}
{{ PS1 }}
@ -212,6 +277,8 @@
{{ metasploit }}
{{ show_config }}
{{ edit_config }}
{{ function_check_trash }}
{{ function_clean }}
- name: General | Account Management | Users | Files | .bashrc
blockinfile:

View File

@ -3,7 +3,7 @@
## Cron ##
- name: General | Software | Services | Enable CROND
- name: General | Software | Services | CROND | Enable
service:
name: "{{ crond }}"
pattern: "{{ crond_pattern }}"
@ -13,7 +13,7 @@
## SSHFS ##
- name: General | Software | Services | Enable FuseFS (FreeBSD rc.conf)
- name: General | Software | Services | SSHFS | Enable FuseFS (FreeBSD rc.conf)
lineinfile:
path: "{{ rc_conf }}"
regexp: 'fusefs_enable='
@ -23,7 +23,7 @@
backup: yes
when: ansible_system == "FreeBSD"
- name: General | Software | Services | Enable SSHFS (FreeBSD service)
- name: General | Software | Services | SSHFS | Enable SSHFS (FreeBSD service)
service:
name: fusefs
pattern: fusefs
@ -34,14 +34,14 @@
## CUPS ##
- name: General | Software | Services | Disable CUPS Daemon
- name: General | Software | Services | CUPS | Disable
service:
name: "{{ cups }}"
pattern: "{{ cups_pattern }}"
state: stopped
enabled: no
- name: General | Software | Services | Disable CUPS-Browse Daemon
- name: General | Software | Services | CUPS-Browse | Disable
service:
name: "{{ cups_browse }}"
pattern: "{{ cups_browse_pattern }}"
@ -51,7 +51,7 @@
## SSHD ##
- name: General | Software | Services | Configure SSHD
- name: General | Software | Services | SSHD | Configure
lineinfile:
path: "{{ sshd_config }}"
regexp: '{{ item.key }}'
@ -75,7 +75,7 @@
- { "key": '^[\#]?AllowAgentForwarding', "value": 'AllowAgentForwarding no'}
- { "key": '^[\#]?PermitEmptyPasswords', "value": 'PermitEmptyPasswords no'}
- name: General | Software | Services | Configure SSHD
- name: General | Software | Services | SSHD | Configure (PVE)
lineinfile:
path: "{{ sshd_config }}"
regexp: '{{ item.key }}'
@ -89,9 +89,17 @@
- { "key": '^[\#]?MaxSessions', "value": 'MaxSessions 5'}
when: "'pve' in ansible_kernel"
- name: General | Software | Services | Enable SSHD
- name: General | Software | Services | SSHD | Enable
service:
name: "{{ sshd }}"
pattern: "{{ sshd_pattern }}"
state: reloaded
enabled: yes
## JournalCTL ##
- name: General | Software | Services | JournalCTL | Reduce Log Size
shell: journalctl --vacuum-size=100M
when: ansible_system == "Linux"
ignore_errors: yes