Move exporting the setupConf files to a function to be run at the end of the script only. If script is cancelled, then they are not written. Simples.

Also I'm surprised nobody noticed the duplicate installPihole() function :S
This commit is contained in:
Promofaux 2016-08-26 22:45:38 +01:00
parent d217626318
commit e4295f5d3c

View file

@ -195,11 +195,9 @@ chooseInterface() {
piholeInterface=${desiredInterface} piholeInterface=${desiredInterface}
echo "::: Using interface: $piholeInterface" echo "::: Using interface: $piholeInterface"
echo "${piholeInterface}" > /tmp/piholeINT echo "${piholeInterface}" > /tmp/piholeINT
echo "piholeInterface=${piholeInterface}" >> ${setupVars}
done done
else else
echo "::: Cancel selected, exiting...." echo "::: Cancel selected, exiting...."
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
@ -230,7 +228,6 @@ use4andor6() {
if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then
getStaticIPv4Settings getStaticIPv4Settings
setStaticIPv4 setStaticIPv4
${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars}
echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv4 on $IPv4addr"
echo "::: IPv6 will NOT be used." echo "::: IPv6 will NOT be used."
fi fi
@ -242,7 +239,6 @@ use4andor6() {
if [ ${useIPv4} ] && [ ${useIPv6} ]; then if [ ${useIPv4} ] && [ ${useIPv6} ]; then
getStaticIPv4Settings getStaticIPv4Settings
setStaticIPv4 setStaticIPv4
${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars}
useIPv6dialog useIPv6dialog
echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv4 on $IPv4addr"
echo "::: Using IPv6 on $piholeIPv6" echo "::: Using IPv6 on $piholeIPv6"
@ -250,13 +246,11 @@ use4andor6() {
if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then
echo "::: Cannot continue, neither IPv4 or IPv6 selected" echo "::: Cannot continue, neither IPv4 or IPv6 selected"
echo "::: Exiting" echo "::: Exiting"
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
cleanupIPv6 cleanupIPv6
else else
echo "::: Cancel selected. Exiting..." echo "::: Cancel selected. Exiting..."
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
} }
@ -264,7 +258,6 @@ use4andor6() {
useIPv6dialog() { useIPv6dialog() {
# Show the IPv6 address used for blocking # Show the IPv6 address used for blocking
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars}
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c} whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c}
${SUDO} touch /etc/pihole/.useIPv6 ${SUDO} touch /etc/pihole/.useIPv6
@ -314,14 +307,12 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
# Cancelling gateway settings window # Cancelling gateway settings window
ipSettingsCorrect=False ipSettingsCorrect=False
echo "::: Cancel selected. Exiting..." echo "::: Cancel selected. Exiting..."
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
else else
# Cancelling IPv4 settings window # Cancelling IPv4 settings window
ipSettingsCorrect=False ipSettingsCorrect=False
echo "::: Cancel selected. Exiting..." echo "::: Cancel selected. Exiting..."
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
done done
@ -379,7 +370,6 @@ setStaticIPv4() {
fi fi
else else
echo "::: Warning: Unable to locate configuration file to set static IPv4 address!" echo "::: Warning: Unable to locate configuration file to set static IPv4 address!"
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
} }
@ -464,7 +454,6 @@ setDNS(){
fi fi
else else
echo "::: Cancel selected, exiting...." echo "::: Cancel selected, exiting...."
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then
@ -489,12 +478,8 @@ setDNS(){
esac esac
else else
echo "::: Cancel selected. Exiting..." echo "::: Cancel selected. Exiting..."
${SUDO} rm ${setupVars}
exit 1 exit 1
fi fi
${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars}
${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars}
} }
versionCheckDNSmasq(){ versionCheckDNSmasq(){
@ -807,36 +792,19 @@ configureFirewall() {
fi fi
} }
installPihole() { finalExports() {
# Install base files and web interface #If it already exists, lets overwrite it with the new values.
checkForDependencies # done if [[ -f ${setupVars} ]];then
stopServices ${SUDO} rm ${setupVars}
setUser fi
${SUDO} mkdir -p /etc/pihole/ ${SUDO} echo "piholeInterface=${piholeInterface}" >> ${setupVars}
if [ ! -d "/var/www/html" ]; then ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars}
${SUDO} mkdir -p /var/www/html ${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars}
fi ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars}
${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars}
${SUDO} chmod 775 /var/www/html
${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole
if [ -x "$(command -v lighty-enable-mod)" ]; then
${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null
else
printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
fi
getGitFiles
installScripts
installConfigs
installConfigs
CreateLogFile
configureSelinux
installPiholeWeb
installCron
runGravity
configureFirewall
} }
installPihole() { installPihole() {
# Install base files and web interface # Install base files and web interface
checkForDependencies # done checkForDependencies # done
@ -865,6 +833,7 @@ installPihole() {
installCron installCron
runGravity runGravity
configureFirewall configureFirewall
finalExports
} }
updatePihole() { updatePihole() {
@ -967,7 +936,7 @@ if [[ ${useUpdateVars} == false ]]; then
# Verify there is enough disk space for the install # Verify there is enough disk space for the install
verifyFreeDiskSpace verifyFreeDiskSpace
${SUDO} mkdir -p /etc/pihole/ ${SUDO} mkdir -p /etc/pihole/
${SUDO} echo "" > ${setupVars}
# 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