mirror of
https://github.com/m8tin/cis.git
synced 2026-08-01 11:47:31 +02:00
module function explained
This commit is contained in:
@@ -3,6 +3,11 @@ source /cis/core/base.module.sh
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# composition.isRunningOnThisHost COMPOSITION
|
||||||
|
# - COMPOSITION mandatory: "uptime-kuma-prod"
|
||||||
|
#
|
||||||
|
# This function checks if the given composition runs or should run on this host.
|
||||||
|
# Therefore a file 'current-host' defines the the current host where the composition runs.
|
||||||
function composition.isRunningOnThisHost() {
|
function composition.isRunningOnThisHost() {
|
||||||
local _COMPOSITION _CURRENTHOST_FILE
|
local _COMPOSITION _CURRENTHOST_FILE
|
||||||
_COMPOSITION="${1:?"Missing first parameter COMPOSITION"}"
|
_COMPOSITION="${1:?"Missing first parameter COMPOSITION"}"
|
||||||
@@ -20,6 +25,12 @@ function composition.isRunningOnThisHost() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# composition.isSyncedByThisHost COMPOSITION
|
||||||
|
# - COMPOSITION mandatory: "uptime-kuma-prod"
|
||||||
|
#
|
||||||
|
# This function checks if the given composition is or should be synced to this host.
|
||||||
|
# Therefore a file 'composition-sync-hosts' defines a list of host, one per line, where the composition should be synced to.
|
||||||
|
# This host either runs the composition or syncs it.
|
||||||
function composition.isSyncedByThisHost() {
|
function composition.isSyncedByThisHost() {
|
||||||
local _COMPOSITION _COMPOSITION_PATH _CURRENTHOST_FILE _SYNCHOSTS_FILE
|
local _COMPOSITION _COMPOSITION_PATH _CURRENTHOST_FILE _SYNCHOSTS_FILE
|
||||||
_COMPOSITION="${1:?"Missing first parameter COMPOSITION"}"
|
_COMPOSITION="${1:?"Missing first parameter COMPOSITION"}"
|
||||||
@@ -39,6 +50,9 @@ function composition.isSyncedByThisHost() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# composition.printAll
|
||||||
|
#
|
||||||
|
# This function prints a list of all compositions, one per line.
|
||||||
function composition.printAll() {
|
function composition.printAll() {
|
||||||
local _COMPOSITIONS
|
local _COMPOSITIONS
|
||||||
_COMPOSITIONS="${CIS[COMPOSITIONS]:?"Missing CIS_COMPOSITIONS"}"
|
_COMPOSITIONS="${CIS[COMPOSITIONS]:?"Missing CIS_COMPOSITIONS"}"
|
||||||
@@ -53,6 +67,10 @@ function composition.printAll() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# composition.printAllRunningOnThisHost
|
||||||
|
#
|
||||||
|
# This function prints a list of all compositions which run or should run on this host, one per line.
|
||||||
|
# see also: composition.isRunningOnThisHost
|
||||||
function composition.printAllRunningOnThisHost() {
|
function composition.printAllRunningOnThisHost() {
|
||||||
|
|
||||||
composition.printAll | while read -r _COMPOSITION; do
|
composition.printAll | while read -r _COMPOSITION; do
|
||||||
@@ -61,6 +79,10 @@ function composition.printAllRunningOnThisHost() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# composition.printAllSyncedByThisHost
|
||||||
|
#
|
||||||
|
# This function prints a list of all compositions which should be synced to this host, one per line.
|
||||||
|
# see also: composition.isSyncedByThisHost
|
||||||
function composition.printAllSyncedByThisHost() {
|
function composition.printAllSyncedByThisHost() {
|
||||||
|
|
||||||
composition.printAll | while read -r _COMPOSITION; do
|
composition.printAll | while read -r _COMPOSITION; do
|
||||||
@@ -69,6 +91,10 @@ function composition.printAllSyncedByThisHost() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# composition.start COMPOSITION
|
||||||
|
# - COMPOSITION mandatory: "uptime-kuma-prod"
|
||||||
|
#
|
||||||
|
# This function starts the given composition on this host, provided that this is the defined result.
|
||||||
function composition.start() {
|
function composition.start() {
|
||||||
local _COMPOSITION _COMPOSITION_FILE_BACKUP _COMPOSITION_HOME _COMPOSITION_HOME_FILE
|
local _COMPOSITION _COMPOSITION_FILE_BACKUP _COMPOSITION_HOME _COMPOSITION_HOME_FILE
|
||||||
_COMPOSITION="${1:?"composition.start(): Missing first parameter COMPOSITION"}"
|
_COMPOSITION="${1:?"composition.start(): Missing first parameter COMPOSITION"}"
|
||||||
@@ -129,8 +155,7 @@ if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
|
|||||||
echo ' #Loads this module'
|
echo ' #Loads this module'
|
||||||
echo ' base.loadModule composition'
|
echo ' base.loadModule composition'
|
||||||
echo
|
echo
|
||||||
echo "Now you can use the functions provided by this module inside your script:"
|
base.explain 'composition' "${1}" "${2}"
|
||||||
echo "-------------------------------------------------------------------------"
|
echo
|
||||||
declare -F | grep "composition." | cut -d" " -f3
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -208,8 +208,7 @@ if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
|
|||||||
echo ' #Loads this module'
|
echo ' #Loads this module'
|
||||||
echo ' base.loadModule log'
|
echo ' base.loadModule log'
|
||||||
echo
|
echo
|
||||||
echo "Now you can use the functions provided by this module inside your script:"
|
base.explain 'log' "${1}" "${2}"
|
||||||
echo "-------------------------------------------------------------------------"
|
echo
|
||||||
declare -F | grep "log." | cut -d" " -f3
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -3,6 +3,12 @@ source /cis/core/base.module.sh
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ssh.onHostRun remotehost command
|
||||||
|
# - remotehost mandatory: "[user@]host.example.net[:port]"
|
||||||
|
# - command mandatory: "lsb_release -a | grep Description:"
|
||||||
|
#
|
||||||
|
# Runs the given command on the remote host via ssh. User and port are optional and the defaults are as expected.
|
||||||
|
# There are limitations of characters which are allowed to build the command. So try to express the task in a simple way.
|
||||||
function ssh.onHostRun() {
|
function ssh.onHostRun() {
|
||||||
local _REMOTE_HOST _COMMAND
|
local _REMOTE_HOST _COMMAND
|
||||||
base.set _REMOTE_HOST "${1:?"FQDN of server missing: e.g. host.example.net[:port]"}" '^([a-zA-Z0-9][a-zA-Z0-9@.-]*)+(:[0-9]+)?$'
|
base.set _REMOTE_HOST "${1:?"FQDN of server missing: e.g. host.example.net[:port]"}" '^([a-zA-Z0-9][a-zA-Z0-9@.-]*)+(:[0-9]+)?$'
|
||||||
@@ -61,8 +67,7 @@ if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
|
|||||||
echo ' #Loads this module'
|
echo ' #Loads this module'
|
||||||
echo ' base.loadModule ssh'
|
echo ' base.loadModule ssh'
|
||||||
echo
|
echo
|
||||||
echo "Now you can use the functions provided by this module inside your script:"
|
base.explain 'ssh' "${1}" "${2}"
|
||||||
echo "-------------------------------------------------------------------------"
|
echo
|
||||||
declare -F | grep "ssh." | cut -d" " -f3
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user