@ -526,6 +526,16 @@ versionCheckDNSmasq(){
sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${ dnsFile1 }
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( ) {
installScripts( ) {
# Install the scripts from /etc/.pihole to their various locations
# Install the scripts from /etc/.pihole to their various locations
echo ":::"
echo ":::"
@ -539,16 +549,6 @@ installScripts() {
install -o " ${ USER } " -Dm755 -t /usr/local/bin/ pihole
install -o " ${ USER } " -Dm755 -t /usr/local/bin/ pihole
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/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)
for i in " ${ oldFiles [@] } " ; do
if [ -f " /usr/local/bin/ $i .sh " ] ; then
rm /usr/local/bin/" $i " .sh
fi
done
echo " done."
echo " done."
}
}
@ -569,15 +569,15 @@ installConfigs() {
chown ${ LIGHTTPD_USER } :${ LIGHTTPD_GROUP } /var/cache/lighttpd/compress
chown ${ LIGHTTPD_USER } :${ LIGHTTPD_GROUP } /var/cache/lighttpd/compress
}
}
stopServices( ) {
stop_service( ) {
# Stop dnsmasq and lighttpd
# Stop service passed in as argument.
# Can softfail, as process may not be installed when this is called
echo ":::"
echo ":::"
echo -n "::: Stopping services..."
echo -n " ::: Stopping ${ 1 } service... "
#$SUDO service dnsmasq stop & spinner $! || true
if [ -x " $( command -v systemctl) " ] ; then
if [ -x " $( command -v systemctl) " ] ; then
systemctl stop lighttpd & spinner $! || true
systemctl stop " ${ 1 } " & > /dev/null & spinner $! || true
else
else
service lighttpd stop & spinner $! || true
service " ${ 1 } " & > /dev/null stop & spinner $! || true
fi
fi
echo " done."
echo " done."
}
}
@ -645,47 +645,36 @@ checkForDependencies() {
}
}
getGitFiles( ) {
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 ":::"
echo "::: Checking for existing base files ..."
echo "::: Checking for existing repository ..."
if is_repo ${ piholeFilesDir } ; then
if is_repo " ${ 1 } " ; then
make_repo ${ piholeFilesDir } ${ piholeGitUrl }
update_repo " ${ 1 } "
else
else
update_repo ${ piholeFilesDir }
make_repo " ${ 1 } " " ${ 2 } "
fi
fi
echo ":::"
echo "::: Checking for existing web interface..."
if is_repo ${ webInterfaceDir } ; then
make_repo ${ webInterfaceDir } ${ webInterfaceGitUrl }
else
update_repo ${ webInterfaceDir }
fi
}
}
is_repo( ) {
is_repo( ) {
# If the directory does not have a .git folder it is not a repo
# Use git to check if directory is currently under VCS
echo -n " ::: Checking $1 is a repo... "
echo -n " ::: Checking $1 is a repo... "
if [ -d " $1 /.git " ] ; then
cd " ${ 1 } " & > /dev/null || return 1
echo " OK!"
git status & > /dev/null && echo " OK!" ; return 0 || echo " not found!" ; return 1
return 1
fi
echo " not found!!"
return 0
}
}
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 " $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
cd " ${ 1} " || exit 1
git pull -q > /dev/null & spinner $!
git pull -q > /dev/null & spinner $!
echo " done!"
echo " done!"
}
}
@ -738,7 +727,7 @@ installCron() {
}
}
runGravity( ) {
runGravity( ) {
# Ru b gravity.sh to build blacklists
# Ru n gravity.sh to build blacklists
echo ":::"
echo ":::"
echo "::: Preparing to run gravity.sh to refresh hosts..."
echo "::: Preparing to run gravity.sh to refresh hosts..."
if ls /etc/pihole/list* 1> /dev/null 2>& 1; then
if ls /etc/pihole/list* 1> /dev/null 2>& 1; then
@ -749,15 +738,10 @@ runGravity() {
/opt/pihole/gravity.sh
/opt/pihole/gravity.sh
}
}
setU ser( ) {
create_pihole_u ser( ) {
# Check if user pihole exists and create if not
# Check if user pihole exists and create if not
echo "::: Checking if user 'pihole' exists..."
echo "::: Checking if user 'pihole' exists..."
if id -u pihole > /dev/null 2>& 1; then
id -u pihole & > /dev/null && echo "::: User 'pihole' already exists" || echo "::: User 'pihole' doesn't exist. Creating..." ; useradd -r -s /usr/sbin/nologin pihole
echo "::: User 'pihole' already exists"
else
echo "::: User 'pihole' doesn't exist. Creating..."
useradd -r -s /usr/sbin/nologin pihole
fi
}
}
configureFirewall( ) {
configureFirewall( ) {
@ -796,9 +780,7 @@ finalExports() {
installPihole( ) {
installPihole( ) {
# Install base files and web interface
# Install base files and web interface
checkForDependencies # done
create_pihole_user
stopServices
setUser
if [ ! -d "/var/www/html" ] ; then
if [ ! -d "/var/www/html" ] ; then
mkdir -p /var/www/html
mkdir -p /var/www/html
fi
fi
@ -806,12 +788,10 @@ installPihole() {
chmod 775 /var/www/html
chmod 775 /var/www/html
usermod -a -G ${ LIGHTTPD_GROUP } pihole
usermod -a -G ${ LIGHTTPD_GROUP } pihole
if [ -x " $( command -v lighty-enable-mod) " ] ; then
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
else
printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
fi
fi
getGitFiles
installScripts
installScripts
installConfigs
installConfigs
CreateLogFile
CreateLogFile
@ -825,9 +805,6 @@ installPihole() {
updatePihole( ) {
updatePihole( ) {
# Install base files and web interface
# Install base files and web interface
checkForDependencies # done
stopServices
getGitFiles
installScripts
installScripts
installConfigs
installConfigs
CreateLogFile
CreateLogFile
@ -882,15 +859,14 @@ The install log is in /etc/pihole.
View the web interface at http://pi.hole/admin or http://${ IPv4addr %/* } /admin" ${ r } ${ c }
View the web interface at http://pi.hole/admin or http://${ IPv4addr %/* } /admin" ${ r } ${ c }
}
}
updateD ialogs( ) {
update_d ialogs( ) {
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)
UpdateCmd = $( whiptail --title "Existing Install Detected!" --menu "We have detected an existing install.\n\n Please chose from the following options:" ${ r } ${ c } 2 \
UpdateChoices = ( Update "" on
"Update" "Update install will retain existing settings." \
Install "" off)
"Install" "Install will allow you to enter new settings." 3>& 2 2>& 1 1>& 3)
UpdateChoice = $( " ${ UpdateCmd [@] } " " ${ UpdateChoices [@] } " 2>& 1 >/dev/tty)
if [ [ $? = 0 ] ] ; then
if [ [ $? = 0 ] ] ; then
case ${ UpdateC hoice } in
case ${ UpdateC md } in
Update)
Update)
echo "::: Updating existing install"
echo "::: Updating existing install"
useUpdateVars = true
useUpdateVars = true
@ -914,7 +890,7 @@ if [[ -f ${setupVars} ]];then
if [ " $1 " = = "pihole" ] ; then
if [ " $1 " = = "pihole" ] ; then
useUpdateVars = true
useUpdateVars = true
else
else
updateD ialogs
update_d ialogs
fi
fi
fi
fi
@ -932,8 +908,18 @@ fi
installerDependencies
installerDependencies
if [ [ ${ useUpdateVars } = = false ] ] ; then
if [ [ ${ useUpdateVars } = = false ] ] ; then
# Display welcome dialogs
welcomeDialogs
welcomeDialogs
# Create directory for Pi-hole storage
mkdir -p /etc/pihole/
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 }
# Stop resolver and webserver while installing proceses
stop_service dnsmasq
stop_service lighttpd
# Find IP used to route to outside world
# Find IP used to route to outside world
findIPRoute
findIPRoute
# Find interfaces and let the user choose one
# Find interfaces and let the user choose one