Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions bin/backup
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
##########
_version() {
cat <<VERSION
Backup v2.4.0
Written by Sandor Semsey, Copyright(C) 2020, License MIT
backup v2.4.0
Written by Sandor Semsey, Copyright (C) 2020, License MIT
VERSION
}

Expand All @@ -38,30 +38,30 @@ This is basically a wrapper for rsync
OPTIONS

REQUIRED
-s, --source [DIR] source DIRECTORY to backup
-d, --destination [DIR] destination DIRECTORY to put backup on
target filesystem (relative to mounting point)
-f, --filesystem [FS] target FILESYSTEM to backup to (eg. /dev/sda3)
-m, --mount [DIR] mounting point for given filesystem
-s, --source [DIR] Source DIRECTORY to backup
-d, --destination [DIR] Destination DIRECTORY to put backup on
target filesystem (relative to mounting point)
-f, --filesystem [FS] Target FILESYSTEM to backup to (eg. /dev/sda3)
-m, --mount [DIR] Mounting point for given filesystem

OPTIONAL
-a, --archive [DIR] put archives in DIR, defaults to 'archive'
--expire [NUM] deletes archives older than NUM days (NUM*24 hours)
--format [FORMAT] appends current date to archive filename
supported FORMATS:
24H (HH:MM:SS eg. 17:26:14)
YMD (YYYY-mm-dd eg. 2020-02-19) <--default
FULL (YYYY-mm-dd_HH:MM:SS)
--mode [MODE] select MODE:
ARCHIVE: backup and create archives <--default
SNAPSHOT: snapshot backup
QUICK: backup only
--exclude [PATTERN] exclude files matching PATTERN
--prefix [STRING] optional prefix on archive files
-q, --quiet suppress non-error messages
--debug print commands as executed
-h, --help display this help
-v, --version print version info
-a, --archive [DIR] Put archives in DIR, defaults to 'archive'
--expire [NUM] Deletes archives older than NUM days (NUM*24 hours)
--format [FORMAT] Appends current date to archive filename
Supported FORMATS:
24H (HH:MM:SS eg. 17:26:14)
YMD (YYYY-mm-dd eg. 2020-02-19) <--default
FULL (YYYY-mm-dd_HH:MM:SS)
--mode [MODE] Select MODE:
ARCHIVE: backup and create archives <--default
SNAPSHOT: snapshot backup
QUICK: backup only
--exclude [PATTERN] Exclude files matching PATTERN
--prefix [STRING] Optional prefix on archive files
-q, --quiet Suppress non-error messages
--debug Print commands as executed
-h, --help Display this help
-v, --version Print version info
HELP
}

Expand Down
34 changes: 17 additions & 17 deletions bin/benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ runs_download_deep+=("Vultr;Sydney;https://syd-au-ping.vultr.com/vultr.com.1000M
##########
_version() {
cat <<EOF
Benchmark v${version}
Written by Sandor Semsey, Copyright(C) 2020, License MIT
benchmark v${version}
Written by Sandor Semsey, Copyright (C) 2020, License MIT
EOF
}

Expand All @@ -115,21 +115,21 @@ Usage: benchmark [OPTIONS]...

OPTIONS:

-c, --cpu
-m, --memory
-d, --disk
--download
Run appropriate test. If no test specified, all will run.
Ignored if '-s' given.
-s, --system Run only a system check
-r, --report Save test report to file
--report-prefix Report file prefix, implies '-r'
-q, --quick Do a quick benchmark. Ignored if '-s' given.
--deep Deep benchmarking. Ignored if '-s' given.
-p, --params Config file to override test parameters

-h, --help Display this help
-v, --version Print version
-c, --cpu
-m, --memory
-d, --disk
--download
Run appropriate test. If no test specified, all will run.
Ignored if '-s' given.
-s, --system Run only a system check
-r, --report Save test report to file
--report-prefix Report file prefix, implies '-r'
-q, --quick Do a quick benchmark. Ignored if '-s' given.
--deep Deep benchmarking. Ignored if '-s' given.
-p, --params Config file to override test parameters

-h, --help Display this help
-v, --version Print version
EOF
}

Expand Down
119 changes: 105 additions & 14 deletions bin/clean
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,125 @@
## Delete caches ##
##############################

# Config
journal_retention=2w
###############
## FUNCTIONS ##
###############

## Version
##########
_version() {
cat <<VERSION
clean v1.0.0
Written by Sandor Semsey, Copyright (C) 2023, License MIT
VERSION
}

## Usage
########
_usage() {
cat <<HELP

Usage: clean [OPTIONS]...

Clean-up temporary and other unused files to free up disk space

OPTIONS

-j, --journal [TIME] Remove journal older than this time (specified with the usual "s", "m", "h", etc. suffixes).
Defaults to 2 weeks (2w).
-u, --user [USER] Clear temp files in user's HOME also.
Can be specified multiple times to clean more user HOME.
-q, --quiet Suppress non-error messages
-h, --help Display this help
-v, --version Print version info
HELP
}

##################
## SCRIPT START ##
##################

# Strict mode
set -eufo pipefail
IFS=$'\n\t'

user_id=$(id -u)
if [[ "${user_id}" -ne 0 ]]; then
echo "Run as root!"
exit 1
fi
# Parse options
###############
journal_retention=2w
users=()
quiet=()
redirection=/dev/stdout

while :; do
case "${1:-}" in
-j | --journal)
shift
journal_retention="${1}"
;;
-u | --user)
shift
users+=("${1}")
;;
-q | --quiet)
quiet=(--quiet)
redirection=/dev/null
;;
-h | --help)
_version
_usage
exit 0
;;
-v | --version)
_version
exit 0
;;
"") break ;;
*)
echo "Not supported option: ${1}"
_usage
exit 1
;;
esac
shift
done

# apt
apt-get autoremove --purge --yes
apt-get clean --yes
sudo apt-get autoremove --purge --yes "${quiet[@]}" "${quiet[@]}"
sudo apt-get clean --yes "${quiet[@]}" "${quiet[@]}"

# snap
for line in $(snap list --all | awk '/disabled/{print $1, $3}'); do
IFS=$' \t' read -r snapname revision <<< "${line}"
snap remove "${snapname}" --revision="${revision}"
# shellcheck disable=SC2024
sudo snap remove "${snapname}" --purge --revision="${revision}" > "${redirection}"
done

# Rotate journal
journalctl --flush --rotate --vacuum-time="${journal_retention}"
sudo journalctl --flush --rotate --vacuum-time="${journal_retention}" "${quiet[@]}"

# cache
find /var/cache -mindepth 1 -delete
find /var/lib/snapd/cache -mindepth 1 -delete
# System caches
[[ -d /var/cache ]] && sudo find /var/cache -mindepth 1 -delete
[[ -d /var/lib/snapd/cache ]] && sudo find /var/lib/snapd/cache -mindepth 1 -delete

# User caches
for user in "${users[@]}"; do
if ! homedir=$(getent passwd "${user}" | cut -d: -f6); then
echo "User not exits: ${user}" 1>&2
exit 1
fi

# Empty trash bin
sudo test -d "${homedir}/.local/share/Trash" && sudo find "${homedir}/.local/share/Trash" -mindepth 1 -delete
# General cache
sudo test -d "${homedir}/.cache" && sudo find "${homedir}/.cache" -mindepth 1 -delete
# Atom cache
sudo test -d "${homedir}/.atom/.apm/_cacache" && sudo find "${homedir}/.atom/.apm/_cacache" -mindepth 1 -delete
# Chrome cache
sudo test -d "${homedir}/.config/google-chrome" && sudo find "${homedir}/.config/google-chrome" -mindepth 1 -delete
# gdfuse (Google Drive FS) cache
sudo test -d "${homedir}/.gdfuse/${user}/cache" && sudo find "${homedir}/.gdfuse/${user}/cache" -mindepth 1 -delete
# Flush Spotify cache
sudo test -d "${homedir}/snap/spotify/common/.cache" && sudo find "${homedir}/snap/spotify/common/.cache" -mindepth 1 -delete
done

exit 0
8 changes: 4 additions & 4 deletions bin/pass-man
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ _usage() {
cat <<HELP

pass-man v1.3.0
Written by Sandor Semsey, Copyright(C) 2020, License MIT
Written by Sandor Semsey, Copyright (C) 2020, License MIT

Usage: pass-man ACTION [TARGET] [EXTRA]...

Params:
ACTION Action to perform (open, close, generate, retrieve)
TARGET Path to password in password store (mandatory for 'retrieve' action)
EXTRA Extra arguments to 'pass'
ACTION Action to perform (open, close, generate, retrieve)
TARGET Path to password in password store (mandatory for 'retrieve' action)
EXTRA Extra arguments to 'pass'
HELP
exit 1
}
Expand Down
15 changes: 13 additions & 2 deletions docs/bin.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Clean-up temporary and other not needed files to free up disk space:
- Remove unused `apt` packages
- Remove old snaps
- Rotate system journal (keep 2 weeks of logs)
- Delete caches
- Delete caches (various system & user caches)

!!! info

Expand All @@ -131,7 +131,18 @@ Clean-up temporary and other not needed files to free up disk space:
**Usage**

```
Usage: clean
Usage: clean [OPTIONS]...

OPTIONS

-j, --journal [TIME] Remove journal older than this time
specified with the usual "s", "m", "h", etc. suffixes.
Defaults to 2 weeks (2w).
-u, --user [USER] Clear temp files in user's HOME also.
Can be specified multiple times to clean more user HOME.
-q, --quiet Suppress non-error messages
-h, --help Display this help
-v, --version Print version info
```

---
Expand Down