From dac2b8942e8924ac58bb1db1ccb0d2742f015905 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 9 Oct 2016 22:38:00 -0700 Subject: [PATCH 1/9] Typo fix to generate commit. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 32da07d2..859e54c1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -721,7 +721,7 @@ installCron() { } runGravity() { - # Rub gravity.sh to build blacklists + # Run gravity.sh to build blacklists echo ":::" echo "::: Preparing to run gravity.sh to refresh hosts..." if ls /etc/pihole/list* 1> /dev/null 2>&1; then From 8a15fd44d5dfeb2c63478fe8fc7d7bd3ea8dcdd1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 9 Oct 2016 23:53:18 -0700 Subject: [PATCH 2/9] Update `is_repo()` to use `git status` for validity checks. --- automated install/basic-install.sh | 34 ++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 859e54c1..887e695e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -632,36 +632,31 @@ getGitFiles() { echo ":::" echo "::: Checking for existing base files..." if is_repo ${piholeFilesDir}; then - make_repo ${piholeFilesDir} ${piholeGitUrl} + update_repo ${piholeFilesDir} else - update_repo ${piholeFilesDir} - fi + make_repo ${piholeFilesDir} ${piholeGitUrl} + fi - echo ":::" - echo "::: Checking for existing web interface..." - if is_repo ${webInterfaceDir}; then - make_repo ${webInterfaceDir} ${webInterfaceGitUrl} - else - update_repo ${webInterfaceDir} - fi + #echo ":::" + #echo "::: Checking for existing web interface..." + #if is_repo ${webInterfaceDir}; then +# make_repo ${webInterfaceDir} ${webInterfaceGitUrl} + #else +# update_repo ${webInterfaceDir} +# fi } is_repo() { - # If the directory does not have a .git folder it is not a repo echo -n "::: Checking $1 is a repo..." - if [ -d "$1/.git" ]; then - echo " OK!" - return 1 - fi - echo " not found!!" - return 0 + cd $1 || return 1 + git status && 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 "$2" "$1" > /dev/null & spinner $! + git clone -q --depth 1 "$2" "$1" > /dev/null & spinner $! echo " done!" } @@ -788,11 +783,10 @@ installPihole() { chmod 775 /var/www/html usermod -a -G ${LIGHTTPD_GROUP} pihole if [ -x "$(command -v lighty-enable-mod)" ]; then - lighty-enable-mod fastcgi fastcgi-php > /dev/null + lighty-enable-mod fastcgi fastcgi-php > /dev/null || true else printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" fi - getGitFiles installScripts installConfigs From ca59b808d8127eef2002b55f5c553aa3db01e410 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 00:02:50 -0700 Subject: [PATCH 3/9] Git clone/update now occurs right after installer dependency checks. Allows for inclusion of installer source files in the repo. Passes `set -e` --- automated install/basic-install.sh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 887e695e..6cc2d431 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -628,22 +628,15 @@ install_dependent_packages(){ } getGitFiles() { - # Setup git repos for base files and web admin + # Setup git repos for directory and repository passed + # as arguments 1 and 2 echo ":::" echo "::: Checking for existing base files..." - if is_repo ${piholeFilesDir}; then - update_repo ${piholeFilesDir} + if is_repo ${1}; then + update_repo ${1} else - make_repo ${piholeFilesDir} ${piholeGitUrl} + make_repo ${1} ${2} fi - - #echo ":::" - #echo "::: Checking for existing web interface..." - #if is_repo ${webInterfaceDir}; then -# make_repo ${webInterfaceDir} ${webInterfaceGitUrl} - #else -# update_repo ${webInterfaceDir} -# fi } is_repo() { @@ -787,7 +780,6 @@ installPihole() { else printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" fi - getGitFiles installScripts installConfigs CreateLogFile @@ -802,7 +794,6 @@ installPihole() { updatePihole() { # Install base files and web interface stopServices - getGitFiles installScripts installConfigs CreateLogFile @@ -907,9 +898,13 @@ notify_package_updates_available install_dependent_packages INSTALLER_DEPS[@] if [[ ${useUpdateVars} == false ]]; then + # Display welcome dialogs welcomeDialogs + # Create directory for Pi-hole storage mkdir -p /etc/pihole/ - # + # Get Git files for Core and Admin + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} # Find IP used to route to outside world findIPRoute # Find interfaces and let the user choose one From e60eb662836a36792d531cc24a93bfd95f4a34d0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 01:04:03 -0700 Subject: [PATCH 4/9] UpdateDialogs are now a Whiptail Menu, self-explanatory. --- automated install/basic-install.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6cc2d431..b8250836 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -631,32 +631,33 @@ getGitFiles() { # Setup git repos for directory and repository passed # as arguments 1 and 2 echo ":::" - echo "::: Checking for existing base files..." - if is_repo ${1}; then - update_repo ${1} + echo "::: Checking for existing repository..." + if is_repo "${1}"; then + update_repo "${1}" else - make_repo ${1} ${2} + make_repo "${1}" "${2}" fi } is_repo() { + # Use git to check if directory is currently under VCS echo -n "::: Checking $1 is a repo..." - cd $1 || return 1 - git status && echo " OK!"; return 0 || echo " not found!"; return 1 + cd "${1}" || 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 $! + 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 + cd "${1}" || exit 1 git pull -q > /dev/null & spinner $! echo " done!" } @@ -844,13 +845,12 @@ View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" $ updateDialogs(){ - UpdateCmd=(whiptail --separate-output --radiolist "We have detected an existing install.\n\n Selecting Update will retain settings from the existing install.\n\n Selecting Install will allow you to enter new settings.\n\n(Highlight desired option, and press space to select!)" ${r} ${c} 2) - UpdateChoices=(Update "" on - Install "" off) - UpdateChoice=$("${UpdateCmd[@]}" "${UpdateChoices[@]}" 2>&1 >/dev/tty) + UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "We have detected an existing install.\n\n Please chose from the following options:" ${r} ${c} 2 \ + "Update" "Update install will retain existing settings." \ + "Install" "Install will allow you to enter new settings." 3>&2 2>&1 1>&3) if [[ $? = 0 ]];then - case ${UpdateChoice} in + case ${UpdateCmd} in Update) echo "::: Updating existing install" useUpdateVars=true From 43e2aaebf012272ea79cedde01eab8609023ab43 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 01:04:59 -0700 Subject: [PATCH 5/9] rename `updateDialogs` to `update_dialogs` --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b8250836..225c04c3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -843,7 +843,7 @@ The install log is in /etc/pihole. View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" ${r} ${c} } -updateDialogs(){ +update_dialogs(){ UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "We have detected an existing install.\n\n Please chose from the following options:" ${r} ${c} 2 \ "Update" "Update install will retain existing settings." \ @@ -874,7 +874,7 @@ if [[ -f ${setupVars} ]];then if [ "$1" == "pihole" ]; then useUpdateVars=true else - updateDialogs + update_dialogs fi fi From 5287ea85377bf150cad0fe5afd600073d2729d8b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 01:25:11 -0700 Subject: [PATCH 6/9] Refactor `stopServices` into `stop_service` and accept arguments for service to stop. Quiet output from a few other functions. --- automated install/basic-install.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 225c04c3..05073d00 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -567,15 +567,15 @@ installConfigs() { chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress } -stopServices() { - # Stop dnsmasq and lighttpd +stop_service() { + # Stop service passed in as argument. + # Can softfail, as process may not be installed when this is called echo ":::" - echo -n "::: Stopping services..." - #$SUDO service dnsmasq stop & spinner $! || true + echo -n "::: Stopping ${1} service..." if [ -x "$(command -v systemctl)" ]; then - systemctl stop lighttpd & spinner $! || true + systemctl stop "${1}" &> /dev/null & spinner $! || true else - service lighttpd stop & spinner $! || true + service "${1}" &> /dev/null stop & spinner $! || true fi echo " done." } @@ -642,7 +642,7 @@ getGitFiles() { is_repo() { # Use git to check if directory is currently under VCS echo -n "::: Checking $1 is a repo..." - cd "${1}" || return 1 + cd "${1}" &> /dev/null || return 1 git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 } @@ -768,7 +768,6 @@ finalExports() { installPihole() { # Install base files and web interface - stopServices setUser if [ ! -d "/var/www/html" ]; then mkdir -p /var/www/html @@ -794,7 +793,6 @@ installPihole() { updatePihole() { # Install base files and web interface - stopServices installScripts installConfigs CreateLogFile @@ -905,6 +903,9 @@ if [[ ${useUpdateVars} == false ]]; then # Get Git files for Core and Admin getGitFiles ${piholeFilesDir} ${piholeGitUrl} getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} + # Stop resolver and webserver while installing proceses + stop_service dnsmasq + stop_service lighttpd # Find IP used to route to outside world findIPRoute # Find interfaces and let the user choose one From 7f179f9a584f3e212ef0a6a93c4fa98f329248d8 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 01:40:56 -0700 Subject: [PATCH 7/9] Remove sourcing bash completion, would fall off as soon as the subshell terminated. --- automated install/basic-install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 05073d00..f3e51a63 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -537,7 +537,6 @@ installScripts() { install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole - . /etc/bash_completion.d/pihole #Tidy up /usr/local/bin directory if installing over previous install. oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) From 25cbf4cb35d5f977ca00f942567da4c8b4f59bde Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 01:43:10 -0700 Subject: [PATCH 8/9] Factor out legacy location script removal. --- automated install/basic-install.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f3e51a63..d8ec764c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -524,6 +524,16 @@ versionCheckDNSmasq(){ sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1} } +remove_legacy_scripts(){ + #Tidy up /usr/local/bin directory if installing over previous install. + oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) + for i in "${oldFiles[@]}"; do + if [ -f "/usr/local/bin/$i.sh" ]; then + rm /usr/local/bin/"$i".sh + fi + done +} + installScripts() { # Install the scripts from /etc/.pihole to their various locations echo ":::" @@ -537,15 +547,6 @@ installScripts() { install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole - - #Tidy up /usr/local/bin directory if installing over previous install. - oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) - for i in "${oldFiles[@]}"; do - if [ -f "/usr/local/bin/$i.sh" ]; then - rm /usr/local/bin/"$i".sh - fi - done - echo " done." } @@ -899,6 +900,8 @@ if [[ ${useUpdateVars} == false ]]; then welcomeDialogs # Create directory for Pi-hole storage mkdir -p /etc/pihole/ + # Remove legacy scripts from previous storage location + remove_legacy_scripts # Get Git files for Core and Admin getGitFiles ${piholeFilesDir} ${piholeGitUrl} getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} From bad7a088042079845b3dbd707a64dd6c878b6638 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 10 Oct 2016 01:51:19 -0700 Subject: [PATCH 9/9] Refactor and rename `create_pihole_user`. Now to actually use the user created... --- automated install/basic-install.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d8ec764c..dc34810e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -721,15 +721,10 @@ runGravity() { /opt/pihole/gravity.sh } -setUser(){ +create_pihole_user(){ # Check if user pihole exists and create if not echo "::: Checking if user 'pihole' exists..." - if id -u pihole > /dev/null 2>&1; then - echo "::: User 'pihole' already exists" - else - echo "::: User 'pihole' doesn't exist. Creating..." - useradd -r -s /usr/sbin/nologin pihole - fi + id -u pihole &> /dev/null && echo "::: User 'pihole' already exists" || echo "::: User 'pihole' doesn't exist. Creating..."; useradd -r -s /usr/sbin/nologin pihole } configureFirewall() { @@ -768,7 +763,7 @@ finalExports() { installPihole() { # Install base files and web interface - setUser + create_pihole_user if [ ! -d "/var/www/html" ]; then mkdir -p /var/www/html fi