2023-03-05 08:15:16 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
declare -a pkgs
|
|
|
|
while read pkg; do
|
|
|
|
pkgs+=("${pkg}")
|
|
|
|
done
|
|
|
|
|
2023-03-06 00:14:09 +01:00
|
|
|
declare operation
|
|
|
|
operation="${1}"
|
|
|
|
|
2023-03-05 08:15:16 +01:00
|
|
|
declare conf_file
|
|
|
|
conf_file='/etc/pacman-zfs-snapshot.conf'
|
|
|
|
|
|
|
|
declare important_names snaps_trivial_keep snaps_important_keep snaps_trivial_suffix snaps_important_suffix
|
|
|
|
if [[ -r "${conf_file}" ]]; then
|
|
|
|
source "${conf_file}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! "${important_names}" ]]; then important_names='linux'; fi
|
|
|
|
if [[ ! "${snaps_trivial_keep}" ]]; then snaps_trivial_keep='5'; fi
|
|
|
|
if [[ ! "${snaps_important_keep}" ]]; then snaps_important_keep='5'; fi
|
|
|
|
if [[ ! "${snaps_trivial_suffix}" ]]; then snaps_trivial_suffix='trv'; fi
|
|
|
|
if [[ ! "${snaps_important_suffix}" ]]; then snaps_important_suffix='imp'; fi
|
2023-03-06 00:13:33 +01:00
|
|
|
if [[ ! "${pkgs_list_max_length}" ]]; then pkgs_list_max_length='24'; fi
|
2023-03-05 08:15:16 +01:00
|
|
|
|
|
|
|
function split_pkgs_by_importance () {
|
|
|
|
local pkgs_in_transaction
|
|
|
|
pkgs_in_transaction=("${@}")
|
|
|
|
for pkg in "${pkgs_in_transaction[@]}"; do
|
|
|
|
if grep -Piq -- '^'"${important_names}"'$' <<<"${pkg}"; then
|
|
|
|
important_pkgs_in_transaction+=("${pkg}")
|
|
|
|
else
|
2023-03-05 22:17:21 +01:00
|
|
|
trivial_pkgs_in_transaction+=("${pkg}")
|
2023-03-05 08:15:16 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-03-06 00:14:47 +01:00
|
|
|
function set_severity () {
|
|
|
|
if [[ "${#important_pkgs_in_transaction[@]}" -ge '1' ]]; then
|
|
|
|
severity='imp'
|
|
|
|
else
|
|
|
|
severity='trv'
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-03-06 00:32:58 +01:00
|
|
|
function get_globally_snappable_datasets () {
|
|
|
|
local datasets_list
|
|
|
|
# For all datasets show their 'space.quico:auto-snapshot' property; only
|
|
|
|
# print dataset name in column 1 and property value in column 2. In awk
|
|
|
|
# limit this list to datasets where tab-delimited column 2 has exact
|
|
|
|
# string '^true$' then further limit output by eliminating snapshots
|
|
|
|
# from list, i.e. dataset names that contain an '@' character.
|
|
|
|
datasets_list="$(zfs get -H -o 'name,value' 'space.quico:auto-snapshot' | \
|
|
|
|
awk -F'\t' '{if($2 ~ /^true$/ && $1 !~ /@/) print $1}')"
|
|
|
|
while IFS= read -r dataset; do
|
|
|
|
globally_snappable_datasets+=("${dataset}")
|
|
|
|
done <<<"${datasets_list}"
|
|
|
|
}
|
|
|
|
|
2023-03-06 00:15:23 +01:00
|
|
|
function write_pkg_list_oneline () {
|
|
|
|
local unabridged_pkg_list_oneline
|
|
|
|
if [[ "${severity}" == 'imp' ]]; then
|
|
|
|
for pkg in "${important_pkgs_in_transaction[@]}"; do
|
|
|
|
if [[ "${unabridged_pkg_list_oneline}" ]]; then
|
|
|
|
unabridged_pkg_list_oneline="${unabridged_pkg_list_oneline}"','"${pkg}"
|
|
|
|
else
|
|
|
|
unabridged_pkg_list_oneline="${pkg}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [[ "${#trivial_pkgs_in_transaction[@]}" -ge '1' ]]; then
|
|
|
|
for pkg in "${trivial_pkgs_in_transaction[@]}"; do
|
|
|
|
if [[ "${unabridged_pkg_list_oneline}" ]]; then
|
|
|
|
unabridged_pkg_list_oneline="${unabridged_pkg_list_oneline}"','"${pkg}"
|
|
|
|
else
|
|
|
|
unabridged_pkg_list_oneline="${pkg}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-03-05 08:15:16 +01:00
|
|
|
function main () {
|
|
|
|
local pkgs_in_transaction
|
|
|
|
pkgs_in_transaction=("${@}")
|
|
|
|
|
2023-03-06 00:16:00 +01:00
|
|
|
local -a important_pkgs_in_transaction trivial_pkgs_in_transaction
|
2023-03-05 08:15:16 +01:00
|
|
|
split_pkgs_by_importance "${pkgs_in_transaction[@]}"
|
|
|
|
|
2023-03-06 00:14:47 +01:00
|
|
|
local severity
|
|
|
|
set_severity
|
|
|
|
|
2023-03-06 00:32:58 +01:00
|
|
|
local -a globally_snappable_datasets
|
|
|
|
get_globally_snappable_datasets
|
|
|
|
|
2023-03-06 00:15:23 +01:00
|
|
|
local pkg_list_oneline
|
|
|
|
write_pkg_list_oneline
|
|
|
|
|
2023-03-05 08:15:16 +01:00
|
|
|
#for pkg in "${!important_pkgs_in_transaction[@]}"; do
|
|
|
|
# printf -- 'Array item '"'"'%s'"'"' equals '"'"'%s'"'"'\n' "${pkg}" "${important_pkgs_in_transaction[${pkg}]}"
|
|
|
|
#done
|
|
|
|
}
|
|
|
|
|
|
|
|
main "${pkgs[@]}"
|