mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-24 13:50:17 +00:00
Merge pull request #1185 from pi-hole/cleanup/git_functions
Move git functions to one script
This commit is contained in:
commit
18eb8a2159
2 changed files with 23 additions and 74 deletions
|
@ -19,74 +19,17 @@ readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
|
||||||
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
|
||||||
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
|
||||||
|
|
||||||
is_repo() {
|
PH_TEST=true
|
||||||
# Use git to check if directory is currently under VCS, return the value
|
source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh
|
||||||
local directory="${1}"
|
|
||||||
local curdir
|
|
||||||
local rc
|
|
||||||
|
|
||||||
curdir="${PWD}"
|
# is_repo() sourced from basic-install.sh
|
||||||
cd "${directory}" &> /dev/null || return 1
|
# make_repo() sourced from basic-install.sh
|
||||||
git status --short &> /dev/null
|
# update_repo() source from basic-install.sh
|
||||||
rc=$?
|
# getGitFiles() sourced from basic-install.sh
|
||||||
cd "${curdir}" &> /dev/null || return 1
|
|
||||||
return "${rc}"
|
|
||||||
}
|
|
||||||
|
|
||||||
prep_repo() {
|
|
||||||
# Prepare directory for local repository building
|
|
||||||
local directory="${1}"
|
|
||||||
|
|
||||||
rm -rf "${directory}" &> /dev/null
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
make_repo() {
|
|
||||||
# Remove the non-repod interface and clone the interface
|
|
||||||
local remoteRepo="${2}"
|
|
||||||
local directory="${1}"
|
|
||||||
|
|
||||||
(prep_repo "${directory}" && git clone -q --depth 1 "${remoteRepo}" "${directory}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
update_repo() {
|
|
||||||
local directory="${1}"
|
|
||||||
local curdir
|
|
||||||
|
|
||||||
curdir="${PWD}"
|
|
||||||
cd "${directory}" &> /dev/null || return 1
|
|
||||||
# Pull the latest commits
|
|
||||||
# Stash all files not tracked for later retrieval
|
|
||||||
git stash --all --quiet
|
|
||||||
# Force a clean working directory for cloning
|
|
||||||
git clean --force -d
|
|
||||||
# Fetch latest changes and apply
|
|
||||||
git pull --quiet
|
|
||||||
cd "${curdir}" &> /dev/null || return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
getGitFiles() {
|
|
||||||
# Setup git repos for directory and repository passed
|
|
||||||
# as arguments 1 and 2
|
|
||||||
local directory="${1}"
|
|
||||||
local remoteRepo="${2}"
|
|
||||||
echo ":::"
|
|
||||||
echo "::: Checking for existing repository..."
|
|
||||||
if is_repo "${directory}"; then
|
|
||||||
echo -n "::: Updating repository in ${directory}..."
|
|
||||||
update_repo "${directory}" || (echo "*** Error: Could not update local repository. Contact support."; exit 1)
|
|
||||||
echo " done!"
|
|
||||||
else
|
|
||||||
echo -n "::: Cloning ${remoteRepo} into ${directory}..."
|
|
||||||
make_repo "${directory}" "${remoteRepo}" || (echo "Unable to clone repository, please contact support"; exit 1)
|
|
||||||
echo " done!"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
GitCheckUpdateAvail() {
|
GitCheckUpdateAvail() {
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
curdir=$PWD;
|
curdir=$PWD
|
||||||
cd "${directory}"
|
cd "${directory}"
|
||||||
|
|
||||||
# Fetch latest changes in this repo
|
# Fetch latest changes in this repo
|
||||||
|
@ -185,13 +128,13 @@ main() {
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo "::: Pi-hole core files out of date"
|
echo "::: Pi-hole core files out of date"
|
||||||
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
||||||
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
||||||
|
|
||||||
elif ${core_update} && ${web_update} ; then
|
elif ${core_update} && ${web_update} ; then
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo "::: Updating Everything"
|
echo "::: Updating Everything"
|
||||||
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
|
||||||
/etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
|
||||||
else
|
else
|
||||||
echo "*** Update script has malfunctioned, fallthrough reached. Please contact support"
|
echo "*** Update script has malfunctioned, fallthrough reached. Please contact support"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -149,15 +149,17 @@ make_repo() {
|
||||||
|
|
||||||
update_repo() {
|
update_repo() {
|
||||||
local directory="${1}"
|
local directory="${1}"
|
||||||
|
local curdir
|
||||||
|
|
||||||
|
curdir="${PWD}"
|
||||||
|
cd "${directory}" &> /dev/null || return 1
|
||||||
# Pull the latest commits
|
# Pull the latest commits
|
||||||
echo -n "::: Updating repo in ${1}..."
|
echo -n "::: Updating repo in ${1}..."
|
||||||
if [[ -d "${directory}" ]]; then
|
git stash --all --quiet &> /dev/null || true # Okay for stash failure
|
||||||
cd "${directory}"
|
git clean --force -d || true # Okay for already clean directory
|
||||||
git stash -q &> /dev/null || true # Okay for stash failure
|
git pull --quiet &> /dev/null || return $?
|
||||||
git pull -q &> /dev/null || return $?
|
echo " done!"
|
||||||
echo " done!"
|
cd "${curdir}" &> /dev/null || return 1
|
||||||
fi
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +171,13 @@ 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}" || return 1
|
echo -n "::: Updating repository in ${directory}..."
|
||||||
|
update_repo "${directory}" || { echo "*** Error: Could not update local repository. Contact support."; exit 1; }
|
||||||
|
echo " done!"
|
||||||
else
|
else
|
||||||
make_repo "${directory}" "${remoteRepo}" || return 1
|
echo -n "::: Cloning ${remoteRepo} into ${directory}..."
|
||||||
|
make_repo "${directory}" "${remoteRepo}" || { echo "Unable to clone repository, please contact support"; exit 1; }
|
||||||
|
echo " done!"
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue