Merge branch 'development' into new/UninstallCleanup

Signed-off-by: Adam Warner <adamw@rner.email>

# Conflicts:
#	automated install/uninstall.sh
This commit is contained in:
Adam Warner 2017-09-09 18:56:17 +01:00
commit 774c6e8ac0
No known key found for this signature in database
GPG key ID: 03843F6C65554B22
5 changed files with 82 additions and 46 deletions

View file

@ -1,28 +1,49 @@
# Determine if terminal is capable of showing colours
if [[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]; then if [[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]; then
# Bold and underline may not show up on all clients
# If something MUST be emphasised, use both
COL_BOLD=''
COL_ULINE=''
COL_NC='' COL_NC=''
COL_WHITE='' COL_GRAY=''
COL_BLACK='' COL_RED=''
COL_BLUE='' COL_GREEN=''
COL_LIGHT_BLUE='' COL_YELLOW=''
COL_GREEN='' COL_BLUE=''
COL_LIGHT_GREEN='' COL_PURPLE=''
COL_CYAN='' COL_CYAN=''
COL_LIGHT_CYAN='' else
COL_RED='' # Provide empty variables for `set -u`
COL_LIGHT_RED='' COL_BOLD=""
COL_URG_RED='' COL_ULINE=""
COL_PURPLE=''
COL_LIGHT_PURPLE='' COL_NC=""
COL_BROWN='' COL_GRAY=""
COL_YELLOW='' COL_RED=""
COL_GRAY='' COL_GREEN=""
COL_LIGHT_GRAY='' COL_YELLOW=""
COL_DARK_GRAY='' COL_BLUE=""
COL_PURPLE=""
COL_CYAN=""
fi fi
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]" # Deprecated variables
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]" COL_WHITE="${COL_BOLD}"
COL_BLACK="${COL_NC}"
COL_LIGHT_BLUE="${COL_BLUE}"
COL_LIGHT_GREEN="${COL_GREEN}"
COL_LIGHT_CYAN="${COL_CYAN}"
COL_LIGHT_RED="${COL_RED}"
COL_URG_RED="${COL_RED}${COL_BOLD}${COL_ULINE}"
COL_LIGHT_PURPLE="${COL_PURPLE}"
COL_BROWN="${COL_YELLOW}"
COL_LIGHT_GRAY="${COL_GRAY}"
COL_DARK_GRAY="${COL_GRAY}"
TICK="[${COL_GREEN}✓${COL_NC}]"
CROSS="[${COL_RED}✗${COL_NC}]"
INFO="[i]" INFO="[i]"
QST="[?]" QST="[?]"
DONE="${COL_LIGHT_GREEN} done!${COL_NC}" DONE="${COL_GREEN} done!${COL_NC}"
OVER="\r\033[K" OVER="\\r"

View file

@ -217,6 +217,10 @@ SetExcludeClients() {
change_setting "API_EXCLUDE_CLIENTS" "${args[2]}" change_setting "API_EXCLUDE_CLIENTS" "${args[2]}"
} }
Poweroff(){
nohup bash -c "sleep 5; poweroff" &> /dev/null </dev/null &
}
Reboot() { Reboot() {
nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null & nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null &
} }
@ -230,7 +234,7 @@ RestartDNS() {
output=$( { service dnsmasq restart; } 2>&1 ) output=$( { service dnsmasq restart; } 2>&1 )
fi fi
if [[ -z "${output}" ]]; then if [[ -z "${output}" ]]; then
[[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}" [[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}"
else else
[[ ! -t 1 ]] && OVER="" [[ ! -t 1 ]] && OVER=""
@ -480,6 +484,7 @@ main() {
"setdns" ) SetDNSServers;; "setdns" ) SetDNSServers;;
"setexcludedomains" ) SetExcludeDomains;; "setexcludedomains" ) SetExcludeDomains;;
"setexcludeclients" ) SetExcludeClients;; "setexcludeclients" ) SetExcludeClients;;
"poweroff" ) Poweroff;;
"reboot" ) Reboot;; "reboot" ) Reboot;;
"restartdns" ) RestartDNS;; "restartdns" ) RestartDNS;;
"setquerylog" ) SetQueryLogOptions;; "setquerylog" ) SetQueryLogOptions;;

View file

@ -154,7 +154,12 @@ if command -v apt-get &> /dev/null; then
# fall back on the php5 packages # fall back on the php5 packages
phpVer="php5" phpVer="php5"
fi fi
# We also need the correct version for `php-sqlite` (which differs across distros)
if ${PKG_MANAGER} install --dry-run ${phpVer}-sqlite3 > /dev/null 2>&1; then
phpSqlite="sqlite3"
else
phpSqlite="sqlite"
fi
# Since our install script is so large, we need several other programs to successfuly get a machine provisioned # Since our install script is so large, we need several other programs to successfuly get a machine provisioned
# These programs are stored in an array so they can be looped through later # These programs are stored in an array so they can be looped through later
INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail) INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail)
@ -162,7 +167,7 @@ if command -v apt-get &> /dev/null; then
PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget)
# The Web dashboard has some that also need to be installed # The Web dashboard has some that also need to be installed
# It's useful to separate the two since our repos are also setup as "Core" code and "Web" code # It's useful to separate the two since our repos are also setup as "Core" code and "Web" code
PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi) PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-${phpSqlite})
# The Web server user, # The Web server user,
LIGHTTPD_USER="www-data" LIGHTTPD_USER="www-data"
# group, # group,
@ -172,22 +177,22 @@ if command -v apt-get &> /dev/null; then
# The DNS server user # The DNS server user
DNSMASQ_USER="dnsmasq" DNSMASQ_USER="dnsmasq"
# A function to check... # A function to check...
test_dpkg_lock() { test_dpkg_lock() {
# An iterator used for counting loop iterations # An iterator used for counting loop iterations
i=0 i=0
# fuser is a program to show which processes use the named files, sockets, or filesystems # fuser is a program to show which processes use the named files, sockets, or filesystems
# So while the command is true # So while the command is true
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
# Wait half a second # Wait half a second
sleep 0.5 sleep 0.5
# and increase the iterator # and increase the iterator
((i=i+1)) ((i=i+1))
done done
# Always return success, since we only return if there is no # Always return success, since we only return if there is no
# lock (anymore) # lock (anymore)
return 0 return 0
} }
# If apt-get is not found, check for rpm to see if it's a Red Hat family OS # If apt-get is not found, check for rpm to see if it's a Red Hat family OS
elif command -v rpm &> /dev/null; then elif command -v rpm &> /dev/null; then
@ -204,7 +209,7 @@ elif command -v rpm &> /dev/null; then
PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
INSTALLER_DEPS=(dialog git iproute net-tools newt procps-ng) INSTALLER_DEPS=(dialog git iproute net-tools newt procps-ng)
PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget) PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget)
PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli php-pdo)
if ! grep -q 'Fedora' /etc/redhat-release; then if ! grep -q 'Fedora' /etc/redhat-release; then
INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release"); INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release");
fi fi

View file

@ -180,7 +180,6 @@ removeNoPurge() {
${SUDO} rm -f /etc/init.d/pihole-FTL ${SUDO} rm -f /etc/init.d/pihole-FTL
${SUDO} rm -f /usr/bin/pihole-FTL ${SUDO} rm -f /usr/bin/pihole-FTL
echo -e "${OVER} ${TICK} Removed pihole-FTL" echo -e "${OVER} ${TICK} Removed pihole-FTL"
fi fi

View file

@ -53,6 +53,7 @@ piholeDir=/etc/${basename}
adList=${piholeDir}/gravity.list adList=${piholeDir}/gravity.list
blackList=${piholeDir}/black.list blackList=${piholeDir}/black.list
localList=${piholeDir}/local.list localList=${piholeDir}/local.list
VPNList=/etc/openvpn/ipp.txt
justDomainsExtension=domains justDomainsExtension=domains
matterAndLight=${basename}.0.matterandlight.txt matterAndLight=${basename}.0.matterandlight.txt
supernova=${basename}.1.supernova.txt supernova=${basename}.1.supernova.txt
@ -296,7 +297,7 @@ gravity_unique() {
local str="Removing duplicate domains" local str="Removing duplicate domains"
echo -ne " ${INFO} ${str}..." echo -ne " ${INFO} ${str}..."
sort -u ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon} sort -u -f ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon}
echo -e "${OVER} ${TICK} ${str}" echo -e "${OVER} ${TICK} ${str}"
numberOf=$(wc -l < ${piholeDir}/${preEventHorizon}) numberOf=$(wc -l < ${piholeDir}/${preEventHorizon})
@ -337,6 +338,11 @@ gravity_hostFormatLocal() {
rm "${localList}" rm "${localList}"
gravity_doHostFormat "${localList}.tmp" "${localList}" gravity_doHostFormat "${localList}.tmp" "${localList}"
rm "${localList}.tmp" rm "${localList}.tmp"
# Generate local HOSTS list with information obtained from OpenVPN (if available)
if [[ -f ${VPNList} ]]; then
awk -F, '{printf $2"\t"$1"\n"}' "${VPNList}" >> "${localList}"
fi
} }
gravity_hostFormatGravity() { gravity_hostFormatGravity() {