Using base.module.sh, replaced basename and dirname

This commit is contained in:
m8in
2026-05-15 23:47:44 +02:00
parent 272ebbaf9d
commit 30279d1056
6 changed files with 84 additions and 11 deletions
+2 -1
View File
@@ -51,7 +51,8 @@ function addSessions() {
local _COMPOSITION
grep -lrE "^${_RECEIVERHOST}" ${_DEFINITIONS}compositions/*/${_SYNCHOSTS_FILE} | while read -r _CURRENT_SYNCHOSTS_FILE; do
_SSH_PORT=$(grep -E "^${_RECEIVERHOST} usePort [0-9]*.*$" "${_CURRENT_SYNCHOSTS_FILE}" | cut -d' ' -f3 | xargs)
_COMPOSITION=$(basename $(dirname "${_CURRENT_SYNCHOSTS_FILE}"))
_COMPOSITION="${_CURRENT_SYNCHOSTS_FILE%/*}"
_COMPOSITION="${_COMPOSITION##*/}"
startMissingScreenSession "${_COMPOSITION}" "${_SSH_PORT}"
done
}
+49
View File
@@ -0,0 +1,49 @@
#!/bin/bash
source /cis/core/base.module.sh
function listSnapshotsToDestroy() {
local _FILESYSTEM _SNAPSHOT
_SNAPSHOT="${1:?"Missing first parameter SNAPSHOT"}"
_FILESYSTEM="$(echo ${_SNAPSHOT} | cut -d@ -f1)"
readonly _FILESYSTEM _SNAPSHOT
for _CURRENT in $(zfs list -Ho name -s creation -t snapshot "${_FILESYSTEM:?"Missing first parameter FILESYSTEM"}")
do
[ -z "${_CURRENT}" ] \
&& return 1
[ "${_SNAPSHOT}" == "${_CURRENT}" ] \
&& break
echo "${_CURRENT}"
done
return 0
}
function main() {
local _SNAPSHOT
_SNAPSHOT="${1:?"Missing first parameter SNAPSHOT"}"
readonly _SNAPSHOT
! echo "${_SNAPSHOT}" | grep -q "@" \
&& echo "This is not a snapshot: ${_SNAPSHOT}" \
&& return 1
! zfs list "${_SNAPSHOT}" &> /dev/null \
&& echo "The snapshot does not exist: ${_SNAPSHOT}" \
&& return 1
listSnapshotsToDestroy "${_SNAPSHOT}" | xargs -r -p -n1 zfs destroy \
&& return 0
return 1
}
base.set SNAPSHOT "${1}" '^[-0-9a-zA-Z_/]@[-0-9a-zA-Z_:.]'
main "${SNAPSHOT:?"Missing first parameter SNAPSHOT"}" && exit 0
echo "Something went wrong."
exit 1
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
# trim all mounted or at least root file systems which support it
# call this file with cron
function run(){
local _FSTRIM _MAJOR_VERSION _START
_MAJOR_VERSION="$(lsb_release -r | cut -f2 | cut -d'.' -f1)"
[ "${_MAJOR_VERSION:?"Missing MAJOR_VERSION"}" -ge "16" ] \
&& _FSTRIM="fstrim -v --all" \
|| _FSTRIM="fstrim -v /"
_START="${SECONDS}"
readonly _FSTRIM _MAJOR_VERSION _START
echo -e "$(date) - fstrim started: '$($_FSTRIM)' (duration: $(date -u -d @"$((${SECONDS} - $_START))" +'%-Hh %Mm %Ss'))"
}
run > /var/log/fstrim.log