Wrap script in main() - prepare for no more sudo

This commit is contained in:
Dan Schaper 2016-10-07 18:22:40 -07:00
parent 10ad32de9b
commit 962d162d75

View file

@ -909,7 +909,8 @@ updateDialogs(){
} }
######## MAIN MAIN MAIN ######## ######## MAIN MAIN MAIN ########
if [[ -f ${setupVars} ]];then main () {
if [[ -f ${setupVars} ]];then
. ${setupVars} . ${setupVars}
if [ "$1" == "pihole" ]; then if [ "$1" == "pihole" ]; then
@ -918,21 +919,21 @@ if [[ -f ${setupVars} ]];then
updateDialogs updateDialogs
fi fi
fi fi
# Start the installer # Start the installer
# Verify there is enough disk space for the install # Verify there is enough disk space for the install
if [[ $1 = "--i_do_not_follow_recommendations" ]]; then if [[ $1 = "--i_do_not_follow_recommendations" ]]; then
echo "::: --i_do_not_follow_recommendations passed to script" echo "::: --i_do_not_follow_recommendations passed to script"
echo "::: skipping free disk space verification!" echo "::: skipping free disk space verification!"
else else
verify_free_disk_space verify_free_disk_space
fi fi
# Install packages used by this installation script # Install packages used by this installation script
installer_dependencies installer_dependencies
if [[ ${useUpdateVars} == false ]]; then if [[ ${useUpdateVars} == false ]]; then
welcome_dialogs welcome_dialogs
${SUDO} mkdir -p /etc/pihole/ ${SUDO} mkdir -p /etc/pihole/
# Find IP used to route to outside world # Find IP used to route to outside world
@ -945,42 +946,45 @@ if [[ ${useUpdateVars} == false ]]; then
set_upstream_dns set_upstream_dns
# Install and log everything to a file # Install and log everything to a file
install | tee ${tmpLog} install | tee ${tmpLog}
else else
update | tee ${tmpLog} update | tee ${tmpLog}
fi fi
# Move the log file into /etc/pihole for storage # Move the log file into /etc/pihole for storage
${SUDO} mv ${tmpLog} ${instalLogLoc} ${SUDO} mv ${tmpLog} ${instalLogLoc}
if [[ ${useUpdateVars} == false ]]; then if [[ ${useUpdateVars} == false ]]; then
displayFinalMessage displayFinalMessage
fi fi
echo -n "::: Restarting services..." echo -n "::: Restarting services..."
# Start services # Start services
if [ -x "$(command -v systemctl)" ]; then if [ -x "$(command -v systemctl)" ]; then
${SUDO} systemctl enable dnsmasq ${SUDO} systemctl enable dnsmasq
${SUDO} systemctl restart dnsmasq ${SUDO} systemctl restart dnsmasq
${SUDO} systemctl enable lighttpd ${SUDO} systemctl enable lighttpd
${SUDO} systemctl start lighttpd ${SUDO} systemctl start lighttpd
else else
${SUDO} service dnsmasq restart ${SUDO} service dnsmasq restart
${SUDO} service lighttpd start ${SUDO} service lighttpd start
fi fi
echo " done." echo " done."
echo ":::" echo ":::"
if [[ ${useUpdateVars} == false ]]; then if [[ ${useUpdateVars} == false ]]; then
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
echo "::: ${IPv4addr%/*}" echo "::: ${IPv4addr%/*}"
echo "::: $IPv6addr" echo "::: $IPv6addr"
echo ":::" echo ":::"
echo "::: If you set a new IP address, you should restart the Pi." echo "::: If you set a new IP address, you should restart the Pi."
else else
echo "::: Update complete!" echo "::: Update complete!"
fi fi
echo ":::" echo ":::"
echo "::: The install log is located at: /etc/pihole/install.log" echo "::: The install log is located at: /etc/pihole/install.log"
echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin"
}
main "$@"