mirror of
https://github.com/m8tin/cis.git
synced 2025-12-06 07:48:26 +01:00
Ask for repository URL until it is correct.
This commit is contained in:
@@ -21,30 +21,9 @@ function checkPermissions(){
|
|||||||
&& git -C "${_FOLDER}" push --dry-run &> /dev/null \
|
&& git -C "${_FOLDER}" push --dry-run &> /dev/null \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
echo "FAIL: The rights of the repository are incorrect: ("$(readlink -f ${0})")"
|
echo "FAIL: The rights of the repository are incorrect: ("$(readlink -f ${0})")" >&2
|
||||||
echo " - '${_FOLDER}' is not '${_RIGHTS}'"
|
echo " - '${_FOLDER}' is not '${_RIGHTS}'" >&2
|
||||||
echo " - check the settings of gitea."
|
echo " - check the settings of gitea." >&2
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkRemoteRepository() {
|
|
||||||
local _FOLDER _REPOSITORY
|
|
||||||
_FOLDER="${1:?"Missing first parameter FOLDER"}"
|
|
||||||
_REPOSITORY="${2:?"Missing second parameter REPOSITORY"}"
|
|
||||||
readonly _FOLDER _REPOSITORY
|
|
||||||
|
|
||||||
#Should exist after successful clone only, therefore the remote repository exists and was accessible.
|
|
||||||
[ -d "${_FOLDER}/.git" ] \
|
|
||||||
&& return 0
|
|
||||||
|
|
||||||
#Checks if repository exists and is accessible.
|
|
||||||
! [ -d "${_FOLDER}/.git" ] \
|
|
||||||
&& git ls-remote "${_REPOSITORY}" \
|
|
||||||
&& return 0
|
|
||||||
|
|
||||||
echo "FAIL: The remote repository is not accessible: ("$(readlink -f ${0})")"
|
|
||||||
echo " - '${_REPOSITORY}'"
|
|
||||||
echo " - check the settings of gitea."
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,17 +33,17 @@ function cloneOrPull {
|
|||||||
_REPOSITORY="${2:?"Missing second parameter REPOSITORY"}"
|
_REPOSITORY="${2:?"Missing second parameter REPOSITORY"}"
|
||||||
readonly _FOLDER _REPOSITORY
|
readonly _FOLDER _REPOSITORY
|
||||||
|
|
||||||
! [ -d "${_FOLDER}/.git" ] \
|
|
||||||
&& git clone "${_REPOSITORY}" "${_FOLDER}" &> /dev/null \
|
|
||||||
&& return 0
|
|
||||||
|
|
||||||
[ -d "${_FOLDER}/.git" ] \
|
[ -d "${_FOLDER}/.git" ] \
|
||||||
&& git -C "${_FOLDER}" pull &> /dev/null \
|
&& git -C "${_FOLDER}" pull &> /dev/null \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
echo "FAIL: The local repository is not updatable: ("$(readlink -f ${0})")"
|
! [ -d "${_FOLDER}/.git" ] \
|
||||||
echo " - '${_FOLDER}'"
|
&& git clone "${_REPOSITORY}" "${_FOLDER}" &> /dev/null \
|
||||||
echo " - check your network and the permissions in gitea."
|
&& return 0
|
||||||
|
|
||||||
|
echo "FAIL: The local repository is not updatable: ("$(readlink -f ${0})")" >&2
|
||||||
|
echo " - '${_FOLDER}'" >&2
|
||||||
|
echo " - check your network and the permissions in gitea." >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,10 +58,17 @@ function printRepository(){
|
|||||||
&& echo "${_CONFIGURED_REPOSITORY}" \
|
&& echo "${_CONFIGURED_REPOSITORY}" \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
read -e -p "Enter URL to clone Repository: " -i "${_SUGGESTED_REPOSITORY}" _REPOSITORY
|
while true; do
|
||||||
echo "${_REPOSITORY:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \
|
read -e -p "Enter ssh URL to clone Repository: " -i "${_SUGGESTED_REPOSITORY}" _REPOSITORY
|
||||||
&& return 0
|
echo "${_REPOSITORY}" | grep -F 'git@' &> /dev/null \
|
||||||
|
&& git ls-remote "${_REPOSITORY}" &> /dev/null \
|
||||||
|
&& echo "${_REPOSITORY:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \
|
||||||
|
&& return 0
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "FAIL: The remote repository is not accessible: ("$(readlink -f ${0})")" >&2
|
||||||
|
echo " - '${_REPOSITORY}'" >&2
|
||||||
|
echo " - check the settings of gitea." >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,19 +81,19 @@ function addAndCheckGitRepository() {
|
|||||||
_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:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \
|
echo \
|
||||||
&& cloneOrPull "${_FOLDER}" "${_REPOSITORY}" \
|
&& cloneOrPull "${_FOLDER}" "${_REPOSITORY:?"Missing REPOSITORY: e.g. ssh://git@your.domain.com/cis.git"}" \
|
||||||
&& 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})")" \
|
||||||
&& echo " - remote repository: '${_REPOSITORY}'" \
|
&& echo " - remote repository: '${_REPOSITORY}'" \
|
||||||
&& echo " - local repository: '${_FOLDER}' (${_RIGHTS})" \
|
&& echo " - local repository: '${_FOLDER}' (${_RIGHTS})" \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
echo "FAIL: The repository is not functional: ("$(readlink -f ${0})")"
|
echo "FAIL: The repository is not functional: ("$(readlink -f ${0})")" >&2
|
||||||
echo " - remote repository: '${_REPOSITORY}'"
|
echo " - remote repository: '${_REPOSITORY}'" >&2
|
||||||
echo " - local repository: '${_FOLDER}'"
|
echo " - local repository: '${_FOLDER}'" >&2
|
||||||
echo " - due to an error or insufficient rights or"
|
echo " - due to an error or insufficient rights or" >&2
|
||||||
echo " - one check failed."
|
echo " - one check failed." >&2
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,10 +109,10 @@ function getOrSetDomain() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getRemoteRepositoryPath() {
|
function getRemoteRepositoryPath() {
|
||||||
_RESULT="$(git -C "${_CIS_ROOT:?"Missing CIS_ROOT"}" remote show origin | grep -i 'fetch' | xargs -n 1 | grep -i 'ssh://')"
|
_REPOSITORY="$(git -C "${_CIS_ROOT:?"Missing CIS_ROOT"}" config --get remote.origin.url 2> /dev/null | grep -i 'git@')"
|
||||||
_RESULT="${_RESULT%/*}" #Removes shortest matching pattern '/*' from the end
|
_PATH="${_REPOSITORY%/*}" #Removes shortest matching pattern '/*' from the end
|
||||||
! [ -z "${_RESULT}" ] \
|
! [ -z "${_PATH}" ] \
|
||||||
&& echo "${_RESULT}/" \
|
&& echo "${_PATH}/" \
|
||||||
&& return 0
|
&& return 0
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
@@ -126,14 +126,12 @@ function addDefinition(){
|
|||||||
|
|
||||||
[ "$(id -u)" == "0" ] \
|
[ "$(id -u)" == "0" ] \
|
||||||
&& echo "Running setup as 'root' trying to add definition repository:" \
|
&& 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 "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
|
||||||
|
|||||||
Reference in New Issue
Block a user