Further tweaks to local repo handling

This commit is contained in:
Adam Warner 2016-11-02 13:34:57 +00:00
parent f36e4ba336
commit 50bd8b4a09
2 changed files with 38 additions and 28 deletions

View file

@ -20,39 +20,44 @@ 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() { is_repo() {
# Use git to check if directory is currently under VCS # Use git to check if directory is currently under VCS, return the value
local directory="${1}" local directory="${1}"
cd "${directory}" &> /dev/null || false git -C "${directory}" status --short &> /dev/null
$(git status --short &> /dev/null)
return return
} }
make_repo() { make_repo() {
local directory="${1}"
local remoteRepo="{$2}"
# Remove the non-repod interface and clone the interface # Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..." echo -n "::: Cloning $remoteRepo into $directory..."
rm -rf "${1}" rm -rf "${directory}"
git clone -q --depth 1 "${2}" "${1}" > /dev/null || exit 1 git clone -q --depth 1 "${remoteRepo}" "${directory}" > /dev/null
echo " done!" echo " done!"
} }
update_repo() { update_repo() {
echo "update" && exit 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 "${1}" || exit 1 cd "${directory}" || exit 1
git stash -q > /dev/null || exit 1 git stash -q > /dev/null
git pull -q > /dev/null || exit 1 git pull -q > /dev/null
echo " done!" echo " done!"
} }
getGitFiles() { getGitFiles() {
# Setup git repos for directory and repository passed # Setup git repos for directory and repository passed
# as arguments 1 and 2 # as arguments 1 and 2
local directory="${1}"
local remoteRepo="{$2}"
echo ":::" echo ":::"
echo "::: Checking for existing repository..." echo "::: Checking for existing repository..."
if is_repo "${1}"; then if is_repo "${directory}"; then
update_repo "${1}" update_repo "${directory}"
else else
make_repo "${1}" "${2}" make_repo "${directory}" "${remoteRepo}"
fi fi
} }

View file

@ -146,24 +146,27 @@ spinner() {
} }
is_repo() { is_repo() {
# Use git to check if directory is currently under VCS # Use git to check if directory is currently under VCS, return the value
echo -n "::: Checking $1 is a repo..." local directory="${1}"
cd "${1}" &> /dev/null || return 1 git -C "${directory}" status --short &> /dev/null
git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 return
} }
make_repo() { make_repo() {
local directory="${1}"
local remoteRepo="${2}"
# Remove the non-repod interface and clone the interface # Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..." echo -n "::: Cloning $remoteRepo into $directory..."
rm -rf "${1}" rm -rf "${directory}"
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! git clone -q --depth 1 "${remoteRepo}" "${directory}" > /dev/null & spinner $!
echo " done!" echo " done!"
} }
update_repo() { update_repo() {
local directory="${1}"
# Pull the latest commits # Pull the latest commits
echo -n "::: Updating repo in $1..." echo -n "::: Updating repo in $1..."
cd "${1}" || exit 1 cd "${directory}" || exit 1
git stash -q > /dev/null & spinner $! git stash -q > /dev/null & spinner $!
git pull -q > /dev/null & spinner $! git pull -q > /dev/null & spinner $!
echo " done!" echo " done!"
@ -172,12 +175,14 @@ update_repo() {
getGitFiles() { getGitFiles() {
# Setup git repos for directory and repository passed # Setup git repos for directory and repository passed
# as arguments 1 and 2 # as arguments 1 and 2
local directory="${1}"
local remoteRepo="${2}"
echo ":::" echo ":::"
echo "::: Checking for existing repository..." echo "::: Checking for existing repository..."
if is_repo "${1}"; then if is_repo "${directory}"; then
update_repo "${1}" update_repo "${directory}"
else else
make_repo "${1}" "${2}" make_repo "${directory}" "${remoteRepo}"
fi fi
} }
@ -671,13 +676,13 @@ installScripts() {
readonly install_dir="/opt/pihole/" readonly install_dir="/opt/pihole/"
echo ":::" echo ":::"
echo -n "::: Installing scripts to ${PI_HOLE_LOCAL_REPO}..." echo -n "::: Installing scripts from ${PI_HOLE_LOCAL_REPO}..."
# Clear out script files from Pi-hole scripts directory. # Clear out script files from Pi-hole scripts directory.
clean_existing "${install_dir}" "${PI_HOLE_FILES}" clean_existing "${install_dir}" "${PI_HOLE_FILES}"
# Install files from local core repository # Install files from local core repository
if [[ $(is_repo "${PI_HOLE_LOCAL_REPO}") ]]; then if is_repo "${PI_HOLE_LOCAL_REPO}"; then
cd "${PI_HOLE_LOCAL_REPO}" cd "${PI_HOLE_LOCAL_REPO}"
install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh
install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh