mirror of
https://github.com/m8tin/cis.git
synced 2026-08-01 11:47:31 +02:00
Further improvments around compositions
This commit is contained in:
@@ -96,15 +96,14 @@ function sendResume() {
|
||||
}
|
||||
|
||||
function send() {
|
||||
local _ZFS_BRANCH _COMPOSITION _RECEIVERHOST _RECEIVERS_SNAPSHOT _NOW _ZFS _NEW_SNAPSHOT
|
||||
_ZFS_BRANCH="${1:?"send(): Missing first parameter ZFS_BRANCH"}"
|
||||
_COMPOSITION="${2:?"send(): Missing first parameter COMPOSITION"}"
|
||||
_RECEIVERHOST="${3:?"send(): Missing second parameter RECEIVERHOST"}"
|
||||
_RECEIVERS_SNAPSHOT="${4}"
|
||||
local _COMPOSITION _RECEIVERHOST _RECEIVERS_SNAPSHOT _NOW _ZFS _NEW_SNAPSHOT
|
||||
_COMPOSITION="${1:?"send(): Missing first parameter COMPOSITION"}"
|
||||
_RECEIVERHOST="${2:?"send(): Missing second parameter RECEIVERHOST"}"
|
||||
_RECEIVERS_SNAPSHOT="${3}"
|
||||
_NOW=$(date -u "+%Y-%m-%d_%H:%M:%SZ")
|
||||
_ZFS="${_ZFS_BRANCH:?"Missing ZFS_BRANCH"}/${_COMPOSITION:?"Missing COMPOSITION"}"
|
||||
_ZFS=$(composition.printZfsVerified "${_COMPOSITION}")
|
||||
_NEW_SNAPSHOT="${_ZFS:?"Missing ZFS"}@SYNC_${_RECEIVERHOST:?"Missing RECEIVERHOST"}_${_NOW:?"Missing NOW"}"
|
||||
readonly _ZFS_BRANCH _COMPOSITION _RECEIVERHOST _RECEIVERS_SNAPSHOT _NOW _ZFS _NEW_SNAPSHOT
|
||||
readonly _COMPOSITION _RECEIVERHOST _RECEIVERS_SNAPSHOT _NOW _NEW_SNAPSHOT
|
||||
|
||||
# This common snapshot is the starting-point, if available.
|
||||
! _COMMON_SNAPSHOT=$(printFoundCommonSnapshot "${_ZFS}" "${_RECEIVERHOST}" "${_RECEIVERS_SNAPSHOT}") \
|
||||
@@ -127,30 +126,28 @@ function send() {
|
||||
|
||||
|
||||
|
||||
# Parameter 1: Only alphanumeric characters allowed and [._-] if not leading (due to: -oProxyCommand=...).
|
||||
# Parameter 2: Only alphanumeric characters allowed and [/_-] if not leading (due to: -oProxyCommand=...).
|
||||
# Parameter 3: Only alphanumeric characters allowed and [.-] if not leading (due to: -oProxyCommand=...).
|
||||
# Parameter 1: Only alphanumeric characters allowed and [.-] if not leading (due to: -oProxyCommand=...).
|
||||
# Parameter 2: Only alphanumeric characters allowed and [._-] if not leading (due to: -oProxyCommand=...).
|
||||
# Parameter 3: Only alphanumeric characters allowed and [._:-] if not leading (due to: -oProxyCommand=...), but can be empty.
|
||||
# Parameter 4: Only alphanumeric characters allowed and [._:-] if not leading (due to: -oProxyCommand=...), but can be empty.
|
||||
# Parameter 5: Only alphanumeric characters allowed and [._:-] if not leading (due to: -oProxyCommand=...), but can be empty.
|
||||
base.set RECEIVERHOST "${1}" "${REGEX[HOST]}"
|
||||
base.set ZFS_BRANCH "${2}" "${REGEX[ZFS]}"
|
||||
base.set COMPOSITION "${3}" "${REGEX[COMPOSITION]}"
|
||||
base.set RECEIVERS_SNAPSHOT "${4}" "${REGEX[SNAPSHOT]}" optional
|
||||
base.set RESUME_TOKEN "${5}" '^[a-zA-Z0-9][a-zA-Z0-9._:-]*$' optional
|
||||
base.set COMPOSITION "${1}" "${REGEX[COMPOSITION]}"
|
||||
base.set RECEIVERHOST "${2}" "${REGEX[HOST]}"
|
||||
base.set RECEIVERS_SNAPSHOT "${3}" "${REGEX[SNAPSHOT]}" optional
|
||||
base.set RESUME_TOKEN "${4}" '^[a-zA-Z0-9][a-zA-Z0-9._:-]*$' optional
|
||||
|
||||
! composition.shouldBeSyncedByGivenHost "${COMPOSITION}" "${RECEIVERHOST}" \
|
||||
&& base.abort "no sync-host available" \
|
||||
"Host '${RECEIVERHOST}' is no sync-host for composition: '${COMPOSITION}'"
|
||||
|
||||
# Resume mode
|
||||
if [ "${RECEIVERS_SNAPSHOT}" == "@RESUME" ] && [ -n "${RESUME_TOKEN}" ]; then
|
||||
if [ "${RECEIVERS_SNAPSHOT}" == '@RESUME' ] && [ -n "${RESUME_TOKEN}" ]; then
|
||||
sendResume "${RESUME_TOKEN}"
|
||||
|
||||
# Exit preserving the code
|
||||
exit $?
|
||||
fi
|
||||
|
||||
send "${ZFS_BRANCH}" "${COMPOSITION}" "${RECEIVERHOST}" "${RECEIVERS_SNAPSHOT}" \
|
||||
send "${COMPOSITION}" "${RECEIVERHOST}" "${RECEIVERS_SNAPSHOT}" \
|
||||
&& exit 0
|
||||
|
||||
print.failure "Something unexpected happend."
|
||||
|
||||
Reference in New Issue
Block a user