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
47 changes: 27 additions & 20 deletions bin/backup
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##########
_version() {
cat <<VERSION
backup v2.4.0
backup v2.5.0
Written by Sandor Semsey, Copyright (C) 2020, License MIT
VERSION
}
Expand Down Expand Up @@ -128,7 +128,7 @@ while :; do
SNAPSHOT) backup_mode=snapshot ;;
ARCHIVE) backup_mode=archive ;;
*)
echo "Not supported mode: ${1}"
echo Not supported mode: "${1}" >&2
_usage
exit 1
;;
Expand All @@ -141,7 +141,7 @@ while :; do
24H) date_format=%T ;;
FULL) date_format=%F_%T ;;
*)
echo "Not supported format: ${1}"
echo Not supported format: "${1}" >&2
_usage
exit 1
;;
Expand All @@ -163,7 +163,7 @@ while :; do
;;
"") break ;;
*)
echo "Not supported option: ${1}"
echo Not supported option: "${1}" >&2
_usage
exit 1
;;
Expand All @@ -174,28 +174,32 @@ done
check-root

# Check required options
: "${file_system:?"Filesystem missing"}"
: "${mount_point:?"Mounting point missing"}"
: "${source_dir:?"Source missing"}"
: "${dest_dir:?"Destination missing"}"
: "${file_system:?Filesystem missing}"
: "${mount_point:?Mounting point missing}"
: "${source_dir:?Source missing}"
: "${dest_dir:?Destination missing}"

print-status Mount "${file_system}" to "${mount_point}"...
if ! findmnt "${mount_point}" >/dev/null; then
print-status "Mount backup filesystem..."
mount "${file_system}" "${mount_point}"
print-finish
else
print-finish Already mounted, skip.
fi

now=$(date "+${date_format}")
destination="${mount_point}/${dest_dir}"

print-status Create destination dir "${destination}..."
if [[ ! -e "${destination}" ]]; then
print-status "Create destination dir..."
mkdir -p "${destination}"
print-finish
else
print-finish Already created, skip.
fi

# Set rsync targets, options
if [[ "${backup_mode}" == "archive" || "${backup_mode}" == "quick" ]]; then
if [[ "${backup_mode}" == archive || "${backup_mode}" == quick ]]; then
target="${destination}/actual"
opt=(--delete --inplace)
else
Expand All @@ -204,52 +208,55 @@ else
opt=("--link-dest=${last}")
fi

print-header "Backup files..."
print-header Backup files...
rsync -aAXHEh --info=stats1 --info=progress2 "${opt[@]}" "${exclusion[@]}" "${quiet[@]}" "${source_dir}" "${target}"

# Post backup steps
case "${backup_mode}" in
snapshot)
print-status "Manage links for snapshots..."
print-status Manage links for snapshots...
# Remove symlink to previous snapshot
rm -f "${last}"
# Create new symlink to latest snapshot for the next backup to hardlink
ln -s "${target}" "${last}"
print-finish

if [[ -n "${expire_date}" ]]; then
print-status "Delete expired snapshots..."
print-status Delete expired snapshots...
find "${destination}" -mindepth 1 -maxdepth 1 -mtime "+${expire_date}" -exec rm -rf {} \;
print-finish
fi
;;
archive)
print-status Create archive dir "${destination}/${archive_dir}..."
if [[ ! -e "${destination}/${archive_dir}" ]]; then
print-status "Create archive dir..."
mkdir -p "${destination}/${archive_dir}"
print-finish
else
print-finish Already created, skip.
fi

print-status "Compress files..."
print-status Compress files...
tar -C "${destination}" -I "pigz --fast" --sort=name -cf "${destination}/${archive_dir}/${archive_prefix}${now}.tar.gz" actual/
print-finish

if [[ -n "${expire_date}" ]]; then
print-status "Delete expired archives..."
print-status Delete expired archives...
find "${destination}/${archive_dir}" -mindepth 1 -maxdepth 1 -mtime "+${expire_date}" -exec rm -rf {} \;
print-finish
fi
;;
*) ;;
esac

# Unmount filesystem
print-status Unmounting "${mount_point}..."
if findmnt "${mount_point}" >/dev/null; then
print-status "Unmounting backup filesystem..."
umount "${mount_point}" || true
print-finish
else
print-finish Already unmounted, skip.
fi

print-finish "Backup finished"
print-finish Backup finished

exit 0
42 changes: 21 additions & 21 deletions bin/benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
############

# Version
version=1.2.3
version=1.2.4
# Individual benchmark time limit (seconds)
# Quick benchmark
test_run_time_quick=6
Expand Down Expand Up @@ -155,9 +155,9 @@ _cpu-app-test() {
# shellcheck disable=SC2312
time_aes=$({ TIME="%e seconds" time openssl enc -e -aes-256-cbc -pass pass:12345678 -pbkdf2 >/dev/null <test_file.cpu; } 2>&1)

printf "%-20s %s\n" "SHA256-hashing:" "${time_sha}"
printf "%-20s %s\n" "bzip2-compressing:" "${time_bzip}"
printf "%-20s %s\n" "AES-encrypting:" "${time_aes}"
printf "%-20s %s\n" SHA256-hashing: "${time_sha}"
printf "%-20s %s\n" bzip2-compressing: "${time_bzip}"
printf "%-20s %s\n" AES-encrypting: "${time_aes}"

rm -f test_file.cpu
}
Expand All @@ -168,7 +168,7 @@ _cpu-app-test() {
## @param $@ Params for benchmark
#####################################
_run-benchmark() {
local type="${1?:"Benchmark type missing"}"
local type="${1?:Benchmark type missing}"
local params=("--time=${test_run_time}")

# Compile params
Expand All @@ -181,15 +181,15 @@ _run-benchmark() {
return 0
;;
*)
echo "Not supported type" >&2
echo Not supported type >&2
return 1
;;
esac

# Run benchmark
[[ "${type}" == "disk" ]] && sysbench "${params[@]}" prepare
[[ "${type}" == disk ]] && sysbench "${params[@]}" prepare
sysbench "${params[@]}" run
[[ "${type}" == "disk" ]] && sysbench "${params[@]}" cleanup
[[ "${type}" == disk ]] && sysbench "${params[@]}" cleanup

return 0
}
Expand All @@ -200,8 +200,8 @@ _run-benchmark() {
## @param $2 Raw results
#######################################
_filter-results() {
local type="${1?:"Benchmark type missing"}"
local raw="${2?:"Raw results missing"}"
local type="${1?:Benchmark type missing}"
local raw="${2?:Raw results missing}"
local filter

case "${type}" in
Expand All @@ -214,7 +214,7 @@ _filter-results() {
return 0
;;
*)
echo "Not supported type" >&2
echo Not supported type >&2
return 1
;;
esac
Expand Down Expand Up @@ -327,7 +327,7 @@ _print-summary() {
printf "%-15s [%-10s] : " "${params[1]}" "${params[0]}"
;;
*)
echo "Not supported testname: ${testname}" >&2
echo Not supported testname: "${testname}" >&2
exit 1
;;
esac
Expand All @@ -338,7 +338,7 @@ _print-summary() {
done

# Print CPU application test results
if [[ "${testname}" == "cpu" ]]; then
if [[ "${testname}" == cpu ]]; then
printf "\nApplication test\n----------------\n\n%s\n" "${summary[cpu_app]}"
fi
}
Expand Down Expand Up @@ -392,7 +392,7 @@ while :; do
;;
"") break ;;
*)
echo "Not supported option: ${1}" >&2
echo Not supported option: "${1}" >&2
_usage
exit 1
;;
Expand Down Expand Up @@ -429,7 +429,7 @@ case "${benchmark_depth}" in
;;
*)
if [[ -z "${sys_check}" ]]; then
echo "Not supported depth: ${benchmark_depth}" >&2
echo Not supported depth: "${benchmark_depth}" >&2
_usage
exit 1
fi
Expand All @@ -444,7 +444,7 @@ if [[ -z "${sys_check}" ]]; then
required_commands=(dd sha256sum bzip2 openssl lsblk sysbench curl)
for cmd in "${required_commands[@]}"; do
if ! command -v "${cmd}" >/dev/null 2>&1; then
echo "Missing dependency: ${cmd}" >&2
echo Missing dependency: "${cmd}" >&2
exit 1
fi
done
Expand Down Expand Up @@ -492,10 +492,10 @@ _print-sysinfo | tee "${output_file}"
trap _clean-up EXIT INT TERM

# Run Benchmarks
echo "Start Benchmarking..."
echo Start Benchmarking...
for type in "${tests[@]}"; do
if [[ "${type}" == "cpu" ]]; then
echo "Running CPU application test..."
if [[ "${type}" == cpu ]]; then
echo Running CPU application test...
results=$(_cpu-app-test)
summary[cpu_app]=$(_filter-results cpu_app "${results}")
fi
Expand All @@ -506,15 +506,15 @@ for type in "${tests[@]}"; do
selector="${type}_${i}"
IFS=";" read -r -a params <<<"${run_param}"

echo "Running ${type^^} benchmark #$((i + 1))..."
echo Running "${type^^}" benchmark "#$((i + 1))..."
results=$(_run-benchmark "${type}" "${params[@]}")
summary[${selector}]=$(_filter-results "${type}" "${results}")

i=$((i + 1))
done
done

echo "Benchmarking finished."
echo Benchmarking finished.
echo

## Summary
Expand Down
10 changes: 5 additions & 5 deletions bin/clean
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
##########
_version() {
cat <<VERSION
clean v1.2.0
clean v1.2.1
Written by Sandor Semsey, Copyright (C) 2023, License MIT
VERSION
}
Expand Down Expand Up @@ -92,7 +92,7 @@ while :; do
;;
"") break ;;
*)
echo "Not supported option: ${1}"
echo Not supported option: "${1}" >&2
_usage
exit 1
;;
Expand Down Expand Up @@ -125,11 +125,11 @@ print Done.
# User caches
for user in "${users[@]}"; do
if ! homedir=$(getent passwd "${user}" | cut -d: -f6); then
echo "User not exits: ${user}" 1>&2
echo User not exits: "${user}" >&2
exit 1
fi

print "Clean-up for ${user}..."
print Clean-up for "${user}..."

print -n Empty trash bin...
sudo test -d "${homedir}/.local/share/Trash" && sudo find "${homedir}/.local/share/Trash" -mindepth 1 -delete
Expand All @@ -151,7 +151,7 @@ for user in "${users[@]}"; do
sudo test -d "${homedir}/snap/spotify/common/.cache" && sudo find "${homedir}/snap/spotify/common/.cache" -mindepth 1 -delete
print Done.

print "Cleanup finished for ${user}."
print Cleanup finished for "${user}."
done

exit 0
10 changes: 5 additions & 5 deletions bin/generate-moduli
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
## @param $2 Output file path
#########################################
_generate-DH-primes() {
local bit="${1?:"Bit missing"}"
local output_file="${2?:"Output file name missing"}"
local bit="${1?:Bit missing}"
local output_file="${2?:Output file name missing}"
local candidates
candidates=$(mktemp --tmpdir DH_candidates.XXXXXXXX)

Expand All @@ -37,13 +37,13 @@ IFS=$'\n\t'
source "${ES_SHELL_LOADER}"

# Parse options
IFS=$',' read -r -a bits <<<"${1:-4096,6144,7680,8192}"
IFS=, read -r -a bits <<<"${1:-4096,6144,7680,8192}"
results_file="${2:-DH_moduli}"

# Validate bits
for bit in "${bits[@]}"; do
if [[ ! "${bit}" =~ ^[0-9]+$ ]]; then
echo "Only integers as BIT_SIZE."
echo Only integers as BIT_SIZE.
exit 1
fi
done
Expand All @@ -66,7 +66,7 @@ done
print-finish

found=$(wc -l < "${results_file}")
echo "Primes found: $((found - 1))"
echo Primes found: $((found - 1))

print-run-time

Expand Down
10 changes: 5 additions & 5 deletions bin/pass-man
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ timer=6h
_usage() {
cat <<HELP

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

Usage: pass-man ACTION [TARGET] [EXTRA]...
Expand Down Expand Up @@ -79,7 +79,7 @@ _vault-generate() {
## @param $@ Extra arguments to 'pass'
##########################################
_vault-retrieve() {
local path="${1?:"Path to password missing"}"
local path="${1?:Path to password missing}"
shift
_vault-open
pass "${@}" "${path}"
Expand Down Expand Up @@ -110,13 +110,13 @@ case "${action}" in
if [[ -n "${pass_path}" ]]; then
shift
else
print-error "Path to password missing"
print-error Path to password missing
_usage
fi
_vault-retrieve "${pass_path}" "${@}"
;;
"") print-error "Action missing" && _usage ;;
*) print-error "Invalid action" && _usage ;;
"") print-error Action missing && _usage ;;
*) print-error Invalid action && _usage ;;
esac

exit 0
Loading