Defensive git cloning

Signed-off-by: Dan Schaper <dan.schaper@pi-hole.net>
This commit is contained in:
Dan Schaper 2017-01-01 00:07:10 -08:00
parent 7cceb8615a
commit ad07655630
No known key found for this signature in database
GPG key ID: 572E999E385B7BFC

View file

@ -168,12 +168,16 @@ make_repo() {
update_repo() { update_repo() {
local directory="${1}" local directory="${1}"
# Pull the latest commits # Pull the latest commits
echo -n "::: Updating repo in $1..." echo -n "::: Updating repo in ${1}..."
cd "${directory}" || exit 1 if [[ -d "${directory}" ]]; then
git stash -q &> /dev/null cd "${directory}"
git pull -q &> /dev/null git stash -q &> /dev/null || true # Okay for stash failure
git pull -q &> /dev/null || return $?
echo " done!" echo " done!"
fi
return 0
} }
getGitFiles() { getGitFiles() {
@ -184,12 +188,9 @@ getGitFiles() {
echo ":::" echo ":::"
echo "::: Checking for existing repository..." echo "::: Checking for existing repository..."
if is_repo "${directory}"; then if is_repo "${directory}"; then
update_repo "${directory}" update_repo "${directory}" || return 1
else else
make_repo "${directory}" "${remoteRepo}" || \ make_repo "${directory}" "${remoteRepo}" || return 1
{ echo "!!! Unable to clone ${remoteRepo} into ${directory}"; \
return 1; \
}
fi fi
return 0 return 0
} }
@ -1091,8 +1092,14 @@ main() {
echo "::: --reconfigure passed to install script. Not downloading/updating local repos" echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
else else
# Get Git files for Core and Admin # Get Git files for Core and Admin
getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} || { echo "Unable to clone ${piholeGitUrl}"; exit 1; } getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} || \
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || { echo "Unable to clone ${webInterfaceGitUrl}"; exit 1; } { echo "!!! Unable to clone ${piholeGitUrl} into ${PI_HOLE_LOCAL_REPO}, unable to continue."; \
exit 1; \
}
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || \
{ echo "!!! Unable to clone ${webInterfaceGitUrl} into ${webInterfaceDir}, unable to continue."; \
exit 1; \
}
fi fi
if [[ ${useUpdateVars} == false ]]; then if [[ ${useUpdateVars} == false ]]; then