mirror of
https://github.com/m8tin/cis.git
synced 2025-12-06 15:58:26 +01:00
URL of repository can be entered now
This commit is contained in:
@@ -68,16 +68,34 @@ function cloneOrPull {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function printRepository(){
|
||||||
|
local _FOLDER _CONFIGURED_REPOSITORY _SUGGESTED_REPOSITORY
|
||||||
|
_FOLDER="${1:?"Missing first parameter FOLDER"}"
|
||||||
|
_CONFIGURED_REPOSITORY="$(git -C "${_FOLDER:?"Missing FOLDER"}" config --get remote.origin.url 2> /dev/null)"
|
||||||
|
_SUGGESTED_REPOSITORY="${2}"
|
||||||
|
readonly _FOLDER _CONFIGURED_REPOSITORY _SUGGESTED_REPOSITORY
|
||||||
|
|
||||||
|
! [ -z "${_CONFIGURED_REPOSITORY}" ] \
|
||||||
|
&& echo "${_CONFIGURED_REPOSITORY}" \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
read -e -p "Enter URL to clone Repository: " -i "${_SUGGESTED_REPOSITORY}" _REPOSITORY
|
||||||
|
echo "${_REPOSITORY:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
# Note that an unprivileged user can use this script successfully,
|
# Note that an unprivileged user can use this script successfully,
|
||||||
# if no user has to be added to the host because it already exists.
|
# if no user has to be added to the host because it already exists.
|
||||||
function addAndCheckGitRepository() {
|
function addAndCheckGitRepository() {
|
||||||
local _FOLDER _REPOSITORY
|
local _FOLDER _REPOSITORY
|
||||||
_FOLDER="${1:?"Missing first parameter FOLDER"}"
|
_FOLDER="${1:?"Missing first parameter FOLDER"}"
|
||||||
_REPOSITORY="${2:?"Missing second parameter REPOSITORY: e.g. ssh://git@your.domain.com/cis.git "}"
|
_REPOSITORY="$(printRepository "${_FOLDER}" "${2}")"
|
||||||
_RIGHTS="${3:?"Missing third parameter RIGHTS: (readonly, writable) "}"
|
_RIGHTS="${3:?"Missing third parameter RIGHTS: (readonly, writable) "}"
|
||||||
readonly _FOLDER _REPOSITORY
|
readonly _FOLDER _REPOSITORY
|
||||||
|
|
||||||
checkRemoteRepository "${_FOLDER}" "${_REPOSITORY}" \
|
checkRemoteRepository "${_FOLDER}" "${_REPOSITORY:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \
|
||||||
&& cloneOrPull "${_FOLDER}" "${_REPOSITORY}" \
|
&& cloneOrPull "${_FOLDER}" "${_REPOSITORY}" \
|
||||||
&& checkPermissions "${_FOLDER}" "${_RIGHTS}" \
|
&& checkPermissions "${_FOLDER}" "${_RIGHTS}" \
|
||||||
&& echo "SUCCESS: The git repository is usable. ("$(readlink -f ${0})")" \
|
&& echo "SUCCESS: The git repository is usable. ("$(readlink -f ${0})")" \
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ function getRemoteRepositoryPath() {
|
|||||||
_RESULT="$(git -C "${_CIS_ROOT:?"Missing CIS_ROOT"}" remote show origin | grep -i 'fetch' | xargs -n 1 | grep -i 'ssh://')"
|
_RESULT="$(git -C "${_CIS_ROOT:?"Missing CIS_ROOT"}" remote show origin | grep -i 'fetch' | xargs -n 1 | grep -i 'ssh://')"
|
||||||
_RESULT="${_RESULT%/*}" #Removes shortest matching pattern '/*' from the end
|
_RESULT="${_RESULT%/*}" #Removes shortest matching pattern '/*' from the end
|
||||||
! [ -z "${_RESULT}" ] \
|
! [ -z "${_RESULT}" ] \
|
||||||
&& echo "${_RESULT}" \
|
&& echo "${_RESULT}/" \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
@@ -120,15 +120,20 @@ function getRemoteRepositoryPath() {
|
|||||||
|
|
||||||
function addDefinition(){
|
function addDefinition(){
|
||||||
local _DEFINITIONS _REPOSITORY
|
local _DEFINITIONS _REPOSITORY
|
||||||
_DEFINITIONS="${1:?"Missing parameter DEFINITIONS"}"
|
_DEFINITIONS="${1:?"Missing first parameter DEFINITIONS"}"
|
||||||
_REPOSITORY="${2:?"Missing parameter REPOSITORY"}"
|
_REPOSITORY="$(getRemoteRepositoryPath)cis-definition-${2:?"Missing second parameter DOMAIN"}.git"
|
||||||
readonly _DEFINITIONS _REPOSITORY
|
readonly _DEFINITIONS _REPOSITORY
|
||||||
|
|
||||||
[ "$(id -u)" == "0" ] \
|
[ "$(id -u)" == "0" ] \
|
||||||
|
&& echo "Running setup as 'root' trying to add definition repository:" \
|
||||||
|
&& echo \
|
||||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" "${_REPOSITORY}" readonly \
|
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" "${_REPOSITORY}" readonly \
|
||||||
&& echo " - definitions are usable for this host." \
|
&& echo " - definitions are usable for this host." \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
[ "$(id -u)" != "0" ] \
|
[ "$(id -u)" != "0" ] \
|
||||||
|
&& echo "Running setup as 'user' trying to add definition repository:" \
|
||||||
|
&& echo \
|
||||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" "${_REPOSITORY}" writable \
|
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_DEFINITIONS}" "${_REPOSITORY}" writable \
|
||||||
&& echo " - definitions are usable, as working copy." \
|
&& echo " - definitions are usable, as working copy." \
|
||||||
&& return 0
|
&& return 0
|
||||||
@@ -138,16 +143,20 @@ function addDefinition(){
|
|||||||
|
|
||||||
function addState() {
|
function addState() {
|
||||||
local _STATES _REPOSITORY
|
local _STATES _REPOSITORY
|
||||||
_STATES="${1:?"Missing parameter STATES"}"
|
_STATES="${1:?"Missing first parameter STATES"}"
|
||||||
_REPOSITORY="${2:?"Missing parameter REPOSITORY"}"
|
_REPOSITORY="$(getRemoteRepositoryPath)cis-state-${2:?"Missing second parameter DOMAIN"}.git"
|
||||||
readonly _STATES _REPOSITORY
|
readonly _STATES _REPOSITORY
|
||||||
|
|
||||||
[ "$(id -u)" == "0" ] \
|
[ "$(id -u)" == "0" ] \
|
||||||
|
&& echo "Running setup as 'root' trying to add state repository:" \
|
||||||
|
&& echo \
|
||||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" "${_REPOSITORY}" writable \
|
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" "${_REPOSITORY}" writable \
|
||||||
&& echo " - states are usable for this host." \
|
&& echo " - states are usable for this host." \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
[ "$(id -u)" != "0" ] \
|
[ "$(id -u)" != "0" ] \
|
||||||
|
&& echo "Running setup as 'user' trying to add state repository:" \
|
||||||
|
&& echo \
|
||||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" "${_REPOSITORY}" writable \
|
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addAndCheckGitRepository.sh" "${_STATES}" "${_REPOSITORY}" writable \
|
||||||
&& echo " - states are usable, as working copy." \
|
&& echo " - states are usable, as working copy." \
|
||||||
&& return 0
|
&& return 0
|
||||||
@@ -182,25 +191,20 @@ function setupCoreFunctionality() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
local _DEFINITIONS _DEFINITIONS_REPOSITORY _DOMAIN _REPOSITORY_PATH _STATES _STATES_REPOSITORY
|
local _DEFINITIONS _DOMAIN _STATES
|
||||||
_DOMAIN="$(getOrSetDomain "${1}")"
|
_DOMAIN="$(getOrSetDomain "${1}")"
|
||||||
_REPOSITORY_PATH="$(getRemoteRepositoryPath)"
|
|
||||||
|
|
||||||
! checkPreconditions "${_DOMAIN}" \
|
! checkPreconditions "${_DOMAIN}" \
|
||||||
&& return 1
|
&& return 1
|
||||||
|
|
||||||
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}"
|
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}"
|
||||||
_DEFINITIONS_REPOSITORY="${_REPOSITORY_PATH:?"Missing REPOSITORY_PATH"}/cis-definition-${_DOMAIN:?"Missing DOMAIN"}.git"
|
|
||||||
_STATES="${_CIS_ROOT:?"Missing CIS_ROOT"}states/${_DOMAIN:?"Missing DOMAIN"}"
|
_STATES="${_CIS_ROOT:?"Missing CIS_ROOT"}states/${_DOMAIN:?"Missing DOMAIN"}"
|
||||||
_STATES_REPOSITORY="${_REPOSITORY_PATH:?"Missing REPOSITORY_PATH"}/cis-state-${_DOMAIN:?"Missing DOMAIN"}.git"
|
readonly _DEFINITIONS _DOMAIN _STATES
|
||||||
readonly _DEFINITIONS _DEFINITIONS_REPOSITORY _DOMAIN _REPOSITORY_PATH _STATES _STATES_REPOSITORY
|
|
||||||
|
|
||||||
echo \
|
echo \
|
||||||
&& echo "Running setup using repositories of: '${_REPOSITORY_PATH:?"Missing REPOSITORY_PATH"}' ..." \
|
&& addDefinition "${_DEFINITIONS:?"Missing DEFINITIONS"}" "${_DOMAIN:?"Missing DOMAIN"}" \
|
||||||
&& echo \
|
&& echo \
|
||||||
&& addDefinition "${_DEFINITIONS:?"Missing DEFINITIONS"}" "${_DEFINITIONS_REPOSITORY:?"Missing DEFINITIONS_REPOSITORY"}" \
|
&& addState "${_STATES:?"Missing STATES"}" "${_DOMAIN:?"Missing DOMAIN"}" \
|
||||||
&& echo \
|
|
||||||
&& addState "${_STATES:?"Missing STATES"}" "${_STATES_REPOSITORY:?"Missing STATES_REPOSITORY"}" \
|
|
||||||
&& echo \
|
&& echo \
|
||||||
&& echo "Using definitions: '${_DEFINITIONS:?"Missing DEFINITIONS"}' ..." \
|
&& echo "Using definitions: '${_DEFINITIONS:?"Missing DEFINITIONS"}' ..." \
|
||||||
&& setupCoreFunctionality "${_DEFINITIONS:?"Missing DEFINITIONS"}" \
|
&& setupCoreFunctionality "${_DEFINITIONS:?"Missing DEFINITIONS"}" \
|
||||||
|
|||||||
Reference in New Issue
Block a user