Consistency and standards basic-install start.

This commit is contained in:
Dan Schaper 2016-11-02 05:17:28 -07:00
parent 035e4bf727
commit 7740e4268c

View file

@ -33,7 +33,7 @@ IPv4_address=""
IPv6_address="" IPv6_address=""
# Find the rows and columns will default to 80x24 is it can not be detected # Find the rows and columns will default to 80x24 is it can not be detected
screen_size=$(stty size 2>/dev/null || echo 24 80) screen_size=$(stty size 2>/dev/null || echo 24 80)
rows=$(echo $screen_size | awk '{print $1}') rows=$(echo $screen_size | awk '{print $1}')
columns=$(echo $screen_size | awk '{print $2}') columns=$(echo $screen_size | awk '{print $2}')
@ -53,119 +53,123 @@ runUnattended=false
# Must be root to install # Must be root to install
echo ":::" echo ":::"
if [[ ${EUID} -eq 0 ]]; then if [[ ${EUID} -eq 0 ]]; then
echo "::: You are root." echo "::: You are root."
else else
echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures" echo "::: 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 "::: 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 "::: any concerns with this requirement. Please be sure to download this script from a trusted source."
echo ":::" echo ":::"
echo "::: Detecting the presence of the sudo utility for continuation of this install..." echo "::: Detecting the presence of the sudo utility for continuation of this install..."
if [ -x "$(command -v sudo)" ]; then if [ -x "$(command -v sudo)" ]; then
echo "::: Utility sudo located." echo "::: Utility sudo located."
exec curl -sSL https://install.pi-hole.net | sudo bash "$@" exec curl -sSL https://install.pi-hole.net | sudo bash "$@"
exit $? exit $?
else else
echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed." echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed."
exit 1 exit 1
fi fi
fi fi
# Compatibility # Compatibility
if [[ $(command -v apt-get) ]]; then if [[ $(command -v apt-get) ]]; then
#Debian Family #Debian Family
############################################# #############################################
PKG_MANAGER="apt-get" PKG_MANAGER="apt-get"
PKG_CACHE="/var/lib/apt/lists/" PKG_CACHE="/var/lib/apt/lists/"
UPDATE_PKG_CACHE="${PKG_MANAGER} update" UPDATE_PKG_CACHE="${PKG_MANAGER} update"
PKG_UPDATE="${PKG_MANAGER} upgrade" PKG_UPDATE="${PKG_MANAGER} upgrade"
PKG_INSTALL="${PKG_MANAGER} --yes --fix-missing install" 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 TRUE # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE
PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
# ######################################### # #########################################
# fixes for dependancy differences # fixes for dependancy differences
# Debian 7 doesn't have iproute2 use iproute # Debian 7 doesn't have iproute2 use iproute
${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1 && IPROUTE_PKG="iproute2" || IPROUTE_PKG="iproute" ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1 && IPROUTE_PKG="iproute2" || IPROUTE_PKG="iproute"
# Ubuntu 16.04 LTS php / php5 fix # Ubuntu 16.04 LTS php / php5 fix
${PKG_MANAGER} install --dry-run php5 > /dev/null 2>&1 && phpVer="php5" || phpVer="php" ${PKG_MANAGER} install --dry-run php5 > /dev/null 2>&1 && phpVer="php5" || phpVer="php"
# ######################################### # #########################################
INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5) INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5)
PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron ${IPROUTE_PKG} ) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron ${IPROUTE_PKG} )
LIGHTTPD_USER="www-data" LIGHTTPD_USER="www-data"
LIGHTTPD_GROUP="www-data" LIGHTTPD_GROUP="www-data"
LIGHTTPD_CFG="lighttpd.conf.debian" LIGHTTPD_CFG="lighttpd.conf.debian"
DNSMASQ_USER="dnsmasq" DNSMASQ_USER="dnsmasq"
package_check_install() {
dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" package_check_install() {
} dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}"
}
elif [ $(command -v rpm) ]; then elif [ $(command -v rpm) ]; then
# Fedora Family # Fedora Family
if [ $(command -v dnf) ]; then if [ $(command -v dnf) ]; then
PKG_MANAGER="dnf" PKG_MANAGER="dnf"
else else
PKG_MANAGER="yum" PKG_MANAGER="yum"
fi fi
PKG_CACHE="/var/cache/${PKG_MANAGER}" PKG_CACHE="/var/cache/${PKG_MANAGER}"
UPDATE_PKG_CACHE="${PKG_MANAGER} check-update" UPDATE_PKG_CACHE="${PKG_MANAGER} check-update"
PKG_UPDATE="${PKG_MANAGER} update -y" PKG_UPDATE="${PKG_MANAGER} update -y"
PKG_INSTALL="${PKG_MANAGER} install -y" PKG_INSTALL="${PKG_MANAGER} install -y"
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=( iproute net-tools procps-ng newt git ) INSTALLER_DEPS=( iproute net-tools procps-ng newt git )
PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat ) PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat )
if grep -q 'Fedora' /etc/redhat-release; then
remove_deps=(epel-release); if grep -q 'Fedora' /etc/redhat-release; then
PIHOLE_DEPS=( ${PIHOLE_DEPS[@]/$remove_deps} ); remove_deps=(epel-release);
fi PIHOLE_DEPS=( ${PIHOLE_DEPS[@]/$remove_deps} );
LIGHTTPD_USER="lighttpd" fi
LIGHTTPD_GROUP="lighttpd" LIGHTTPD_USER="lighttpd"
LIGHTTPD_CFG="lighttpd.conf.fedora" LIGHTTPD_GROUP="lighttpd"
DNSMASQ_USER="nobody" LIGHTTPD_CFG="lighttpd.conf.fedora"
package_check_install() { DNSMASQ_USER="nobody"
rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}"
} package_check_install() {
rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}"
}
else else
echo "OS distribution not supported" echo "OS distribution not supported"
exit exit
fi fi
####### FUNCTIONS ########## ####### FUNCTIONS ##########
spinner() { spinner() {
local pid=$1 local pid=$1
local delay=0.50 local delay=0.50
local spinstr='/-\|' local spinstr='/-\|'
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
local temp=${spinstr#?} while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
printf " [%c] " "${spinstr}" local temp=${spinstr#?}
local spinstr=${temp}${spinstr%"$temp"} printf " [%c] " "${spinstr}"
sleep ${delay} local spinstr=${temp}${spinstr%"$temp"}
printf "\b\b\b\b\b\b" sleep ${delay}
done printf "\b\b\b\b\b\b"
printf " \b\b\b\b" done
printf " \b\b\b\b"
} }
is_repo() { is_repo() {
# Use git to check if directory is currently under VCS # Use git to check if directory is currently under VCS
echo -n "::: Checking $1 is a repo..." echo -n "::: Checking $1 is a repo..."
cd "${1}" &> /dev/null || return 1 cd "${1}" &> /dev/null || return 1
git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 git status &> /dev/null && (echo " OK!"; true) || (echo " not found!"; false)
} }
make_repo() { make_repo() {
# Remove the non-repod interface and clone the interface # Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..." echo -n "::: Cloning $2 into $1..."
rm -rf "${1}" rm -rf "${1}"
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
echo " done!" echo " done!"
} }
update_repo() { update_repo() {
# Pull the latest commits # Pull the latest commits
echo -n "::: Updating repo in $1..." echo -n "::: Updating repo in $1..."
cd "${1}" || exit 1 cd "${1}" || exit 1
git stash -q > /dev/null & spinner $! git stash -q > /dev/null & spinner $!
git pull -q > /dev/null & spinner $! git pull -q > /dev/null & spinner $!
echo " done!" echo " done!"
} }
getGitFiles() { getGitFiles() {
@ -1035,7 +1039,7 @@ main() {
# Decide what upstream DNS Servers to use # Decide what upstream DNS Servers to use
setDNS setDNS
# Install and log everything to a file # Install and log everything to a file
installPihole | tee ${tmpLog} installPihole | tee ${tmpLog}
else else
updatePihole | tee ${tmpLog} updatePihole | tee ${tmpLog}
fi fi