#!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements# (c) 2015, 2016 by Jacob Salmela# Network-wide ad blocking via your Raspberry Pi# http://pi-hole.net# Installs Pi-hole## Pi-hole is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 2 of the License, or# (at your option) any later version.# pi-hole.net/donate## Install with this command (from your Pi):## curl -L install.pi-hole.net | bashset -e
######## VARIABLES #########tmpLog=/tmp/pihole-install.log
instalLogLoc=/etc/pihole/install.log
setupVars=/etc/pihole/setupVars.conf
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"webInterfaceDir="/var/www/html/admin"piholeGitUrl="https://github.com/pi-hole/pi-hole.git"PI_HOLE_LOCAL_REPO="/etc/.pihole"PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update version)useUpdateVars=falseIPV4_ADDRESS=""IPV6_ADDRESS=""QUERY_LOGGING=true# Find the rows and columns will default to 80x24 is it can not be detectedscreen_size=$(stty size 2>/dev/null ||echo24 80)rows=$(echo$screen_size| awk '{print $1}')columns=$(echo$screen_size| awk '{print $2}')# Divide by two so the dialogs take up half of the screen, which looks nice.r=$(( rows /2))c=$(( columns /2))# Unless the screen is tinyr=$(( r < 20 ? 20 : r ))c=$(( c < 70 ? 70 : c ))######## Undocumented Flags. Shhh ########skipSpaceCheck=falsereconfigure=falserunUnattended=false######## FIRST CHECK ######### Must be root to installecho":::"if[[${EUID} -eq 0]];thenecho"::: You are root."elseecho"::: Script called with non-root privileges. The Pi-hole installs server packages and configures"echo"::: system networking, it requires elevated rights. Please check the contents of the script for"echo"::: any concerns with this requirement. Please be sure to download this script from a trusted source."echo":::"echo"::: Detecting the presence of the sudo utility for continuation of this install..."if[ -x "$(command -v sudo)"];thenecho"::: Utility sudo located."exec curl -sSL https://install.pi-hole.net | sudo bash "$@"exit$?elseecho"::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed."exit1fifi# Compatibilityif[[$(command -v apt-get)]];then#Debian Family#############################################PKG_MANAGER="apt-get"PKG_CACHE="/var/lib/apt/lists/"UPDATE_PKG_CACHE="${PKG_MANAGER} update"PKG_UPDATE="${PKG_MANAGER} upgrade"PKG_INSTALL="${PKG_MANAGER} --yes --fix-missing install"# grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUEPKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"# ########################################## fixes for dependancy differences# Debian 7 doesn't have iproute2 use iproute${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1&&IPROUTE_PKG="iproute2"||IPROUTE_PKG="iproute"# Prefer the php metapackage if it's there, fall back on the php5 pacakges${PKG_MANAGER} install --dry-run php > /dev/null 2>&1&&phpVer="php"||phpVer="php5"# #########################################INSTALLER_DEPS=(apt-utils debconf dhcpcd5 git whiptail)PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils ${IPROUTE_PKG} iputils-ping lighttpd lsof netcat ${phpVer}-common ${phpVer}-cgi sudo unzip wget)LIGHTTPD_USER="www-data"LIGHTTPD_GROUP="www-data"LIGHTTPD_CFG="lighttpd.conf.debian"DNSMASQ_USER="dnsmasq"
package_check_install(){
dpkg-query -W -f='${Status}'"${1}" 2>/dev/null | grep -c "ok installed"||${PKG_INSTALL}"${1}"}elif[$(command -v rpm)];then# Fedora Familyif[$(command -v dnf)];thenPKG_MANAGER="dnf"elsePKG_MANAGER="yum"fiPKG_CACHE="/var/cache/${PKG_MANAGER}"UPDATE_PKG_CACHE="${PKG_MANAGER} check-update"PKG_UPDATE="${PKG_MANA