New naming convention, and reorder functions as bash would prefer them to be.

This commit is contained in:
Dan Schaper 2016-11-01 22:19:40 -07:00
parent bdd240ecb6
commit 7a22471787
2 changed files with 35 additions and 35 deletions

View file

@ -14,22 +14,10 @@
# Variables # Variables
readonly WEBINTERFACEGITURL="https://github.com/pi-hole/AdminLTE.git" readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git"
readonly WEBINTERFACEDIR="/var/www/html/admin" readonly ADMIN_INTERFACE_DIR="/var/www/html/admin"
readonly PIHOLEGITURL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git"
readonly PIHOLEFILESDIR="/etc/.pihole" readonly PI_HOLE_FILES_DIR="/etc/.pihole"
getGitFiles() {
# Setup git repos for directory and repository passed
# as arguments 1 and 2
echo ":::"
echo "::: Checking for existing repository..."
if is_repo "${1}"; then
update_repo "${1}"
else
make_repo "${1}" "${2}"
fi
}
is_repo() { is_repo() {
# Use git to check if directory is currently under VCS # Use git to check if directory is currently under VCS
@ -61,6 +49,18 @@ update_repo() {
echo " done!" echo " done!"
} }
getGitFiles() {
# Setup git repos for directory and repository passed
# as arguments 1 and 2
echo ":::"
echo "::: Checking for existing repository..."
if is_repo "${1}"; then
update_repo "${1}"
else
make_repo "${1}" "${2}"
fi
}
if [ ! -d "/etc/.pihole" ]; then #This is unlikely if [ ! -d "/etc/.pihole" ]; then #This is unlikely
echo "::: Critical Error: Pi-Hole repo missing from system!" echo "::: Critical Error: Pi-Hole repo missing from system!"
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
@ -109,7 +109,7 @@ if [[ "${piholeVersion}" == "${piholeVersionLatest}" ]] && [[ "${webVersion}" ==
elif [[ "${piholeVersion}" == "${piholeVersionLatest}" ]] && [[ "${webVersion}" != "${webVersionLatest}" ]]; then elif [[ "${piholeVersion}" == "${piholeVersionLatest}" ]] && [[ "${webVersion}" != "${webVersionLatest}" ]]; then
echo "::: Pi-hole Web Admin files out of date" echo "::: Pi-hole Web Admin files out of date"
getGitFiles "${WEBINTERFACEDIR}" "${WEBINTERFACEGITURL}" getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
echo ":::" echo ":::"
webVersion=$(/usr/local/bin/pihole -v -a -c) webVersion=$(/usr/local/bin/pihole -v -a -c)
echo "::: Web Admin version is now at ${webVersion}" echo "::: Web Admin version is now at ${webVersion}"
@ -117,7 +117,7 @@ elif [[ "${piholeVersion}" == "${piholeVersionLatest}" ]] && [[ "${webVersion}"
echo "" echo ""
elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}" == "${webVersionLatest}" ]]; then elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}" == "${webVersionLatest}" ]]; then
echo "::: Pi-hole core files out of date" echo "::: Pi-hole core files out of date"
getGitFiles "${PIHOLEFILESDIR}" "${PIHOLEGITURL}" 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 /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
@ -128,7 +128,7 @@ elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}"
echo "" echo ""
elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}" != "${webVersionLatest}" ]]; then elif [[ "${piholeVersion}" != "${piholeVersionLatest}" ]] && [[ "${webVersion}" != "${webVersionLatest}" ]]; then
echo "::: Updating Everything" echo "::: Updating Everything"
getGitFiles "${PIHOLEFILESDIR}" "${PIHOLEGITURL}" 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 /etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1

View file

@ -712,6 +712,22 @@ install_dependent_packages() {
done done
} }
make_repo() {
# Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..."
rm -rf "${1}"
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
echo " done!"
}
update_repo() {
# Pull the latest commits
echo -n "::: Updating repo in $1..."
cd "${1}" || exit 1
git stash -q > /dev/null & spinner $!
git pull -q > /dev/null & spinner $!
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
@ -731,22 +747,6 @@ is_repo() {
git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1
} }
make_repo() {
# Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..."
rm -rf "${1}"
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
echo " done!"
}
update_repo() {
# Pull the latest commits
echo -n "::: Updating repo in $1..."
cd "${1}" || exit 1
git stash -q > /dev/null & spinner $!
git pull -q > /dev/null & spinner $!
echo " done!"
}
CreateLogFile() { CreateLogFile() {
# Create logfiles if necessary # Create logfiles if necessary