Refactor and move some bits.

This commit is contained in:
Dan Schaper 2016-11-02 06:41:51 -07:00
parent 93d91353a1
commit ece1667fb0

View file

@ -20,10 +20,9 @@ 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, do not exit if failed # 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
} }
@ -31,6 +30,7 @@ prep_dirs() {
# Prepare directory for local repository building # Prepare directory for local repository building
local dir_to_clean="${1}" local dir_to_clean="${1}"
rm -rf "${dir_to_clean}" &> /dev/null rm -rf "${dir_to_clean}" &> /dev/null
return
} }
make_repo() { make_repo() {
@ -39,18 +39,18 @@ make_repo() {
local dest_dir="${1}" local dest_dir="${1}"
echo -n "::: Cloning ${source_repo} into ${dest_dir}..." echo -n "::: Cloning ${source_repo} into ${dest_dir}..."
prep_dirs "${dest_dir}" if (prep_dirs "${dest_dir}" && git clone -q --depth 1 "${source_repo}" "${dest_dir}" > /dev/null); then \
git clone -q --depth 1 "${source_repo}" "${dest_dir}" > /dev/null \ echo " done!" || (echo "Unable to clone repository, please contact support"; exit false)
|| (echo "Unable to clone directory, please contact support"; exit false) fi
echo " done!"
} }
update_repo() { update_repo() {
local dest_dir="${1}"
# Pull the latest commits # Pull the latest commits
echo -n "::: Updating repo in $1..." echo -n "::: Updating repository in ${dest_dir}..."
cd "${1}" || exit 1 cd "${1}" || exit 1
git stash -q > /dev/null || exit 1 git stash -q > /dev/null || exit $?
git pull -q > /dev/null || exit 1 git pull -q > /dev/null || exit $?
echo " done!" echo " done!"
} }
@ -98,49 +98,39 @@ main() {
# pull pihole repo run install --unattended # pull pihole repo run install --unattended
if [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then if [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
echo "::: Pi-hole version is $pihole_version_current"
echo "::: Web Admin version is $web_version_current"
echo "::: Everything is up to date!" echo "::: Everything is up to date!"
echo ""
exit 0
elif [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then elif [[ "${pihole_version_current}" == "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then
echo "::: Pi-hole Web Admin files out of date" echo "::: Pi-hole Web Admin files out of date"
getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}" getGitFiles "${ADMIN_INTERFACE_DIR}" "${ADMIN_INTERFACE_GIT_URL}"
echo ":::" echo ":::"
web_version_current="$(/usr/local/bin/pihole -v -a -c)" web_version_current="$(/usr/local/bin/pihole -v -a -c)"
echo "::: Web Admin version is now at ${web_version_current}"
echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'"
echo ""
elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" == "${web_version_latest}" ]]; then
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 /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
echo ":::" echo ":::"
pihole_version_current="$(/usr/local/bin/pihole -v -p -c)" pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo ""
elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then elif [[ "${pihole_version_current}" != "${pihole_version_latest}" ]] && [[ "${web_version_current}" != "${web_version_latest}" ]]; then
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 /etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X # Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
web_version_current="$(/usr/local/bin/pihole -v -a -c)" web_version_current="$(/usr/local/bin/pihole -v -a -c)"
# Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X # Checks Pi-hole version > admin only > current local git repo version : returns string in format vX.X.X
pihole_version_current="$(/usr/local/bin/pihole -v -p -c)" pihole_version_current="$(/usr/local/bin/pihole -v -p -c)"
echo ":::"
echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo ":::"
echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo ""
fi fi
echo ":::"
echo "::: Pi-hole version is now at ${pihole_version_current}"
echo "::: If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'"
echo ":::"
echo "::: Web Admin version is now at ${web_version_current}"
echo "::: If you had made any changes in '/var/www/html/admin/', they have been stashed using 'git stash'"
echo ""
exit 0
} }
main main