mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-24 23:23:42 +00:00
Reorder a few functions to get ready to local/global variables and start to migrate to using setupVars for storage.
This commit is contained in:
parent
af2d9055fc
commit
711fcd7ae0
1 changed files with 48 additions and 30 deletions
|
@ -124,15 +124,6 @@ spinner()
|
||||||
printf " \b\b\b\b"
|
printf " \b\b\b\b"
|
||||||
}
|
}
|
||||||
|
|
||||||
find_IPv4_route() {
|
|
||||||
# Find IP used to route to outside world
|
|
||||||
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
|
|
||||||
IPv4addr=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
|
|
||||||
IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}')
|
|
||||||
availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1 | cut -d'@' -f1)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
welcome_dialogs() {
|
welcome_dialogs() {
|
||||||
# Display the welcome dialog
|
# Display the welcome dialog
|
||||||
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" ${r} ${c}
|
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" ${r} ${c}
|
||||||
|
@ -192,7 +183,7 @@ choose_interface() {
|
||||||
mode="ON"
|
mode="ON"
|
||||||
fi
|
fi
|
||||||
interfacesArray+=("$line" "available" "$mode")
|
interfacesArray+=("$line" "available" "$mode")
|
||||||
done <<< "$availableInterfaces"
|
done <<< "$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1 | cut -d'@' -f1)"
|
||||||
|
|
||||||
# Find out how many interfaces are available to choose from
|
# Find out how many interfaces are available to choose from
|
||||||
interfaceCount="$(echo "$availableInterfaces" | wc -l)"
|
interfaceCount="$(echo "$availableInterfaces" | wc -l)"
|
||||||
|
@ -210,6 +201,13 @@ choose_interface() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_IPv4_route() {
|
||||||
|
# Find IP used to route to outside world
|
||||||
|
IPv4dev="$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')"
|
||||||
|
IPv4addr="$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')"
|
||||||
|
IPv4gw="$(ip route get 8.8.8.8 | awk '{print $3}')"
|
||||||
|
}
|
||||||
|
|
||||||
whiptail_IPv6_address() {
|
whiptail_IPv6_address() {
|
||||||
# Show the IPv6 address used for blocking
|
# Show the IPv6 address used for blocking
|
||||||
IPv6addr=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
IPv6addr=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||||
|
@ -262,7 +260,7 @@ use_IPv4_and_or_IPv6() {
|
||||||
}
|
}
|
||||||
|
|
||||||
get_static_IPv4_settings() {
|
get_static_IPv4_settings() {
|
||||||
local ipSettingsCorrect = False
|
local ipSettingsCorrect=False
|
||||||
|
|
||||||
# Ask if the user wants to use DHCP settings as their static IP
|
# Ask if the user wants to use DHCP settings as their static IP
|
||||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
|
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
|
||||||
|
@ -490,7 +488,7 @@ version_check_dnsmasq(){
|
||||||
|
|
||||||
if [ -f ${dnsFile1} ]; then
|
if [ -f ${dnsFile1} ]; then
|
||||||
echo -n "::: Existing dnsmasq.conf found..."
|
echo -n "::: Existing dnsmasq.conf found..."
|
||||||
if grep -q ${dnsSearch} ${dnsFile1}; then
|
if grep -q "${dnsSearch}" "${dnsFile1}"; then
|
||||||
echo " it is from a previous pi-hole install."
|
echo " it is from a previous pi-hole install."
|
||||||
echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..."
|
echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..."
|
||||||
mv -f ${dnsFile1} ${dnsFile2}
|
mv -f ${dnsFile1} ${dnsFile2}
|
||||||
|
@ -583,14 +581,37 @@ install_configs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service() {
|
stop_service() {
|
||||||
# Stop dnsmasq and lighttpd
|
# Stop service passed in via argument
|
||||||
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" & spinner $! || true
|
||||||
else
|
else
|
||||||
service lighttpd stop & spinner $! || true
|
service "$1" stop & spinner $! || true
|
||||||
|
fi
|
||||||
|
echo " done."
|
||||||
|
}
|
||||||
|
|
||||||
|
start_service() {
|
||||||
|
# Start service passed in via argument
|
||||||
|
echo ":::"
|
||||||
|
echo -n "::: Starting $1 service..."
|
||||||
|
if [ -x "$(command -v systemctl)" ]; then
|
||||||
|
systemctl restart "$1" & spinner $! || true
|
||||||
|
else
|
||||||
|
service "$1" restart & spinner $! || true
|
||||||
|
fi
|
||||||
|
echo " done."
|
||||||
|
}
|
||||||
|
|
||||||
|
enable_service() {
|
||||||
|
# Start service passed in via argument
|
||||||
|
echo ":::"
|
||||||
|
echo -n "::: Enabling $1 service..."
|
||||||
|
if [ -x "$(command -v systemctl)" ]; then
|
||||||
|
systemctl enable "$1" & spinner $! || true
|
||||||
|
else
|
||||||
|
update-rc.d "$1" defaults & spinner $! || true
|
||||||
fi
|
fi
|
||||||
echo " done."
|
echo " done."
|
||||||
}
|
}
|
||||||
|
@ -827,7 +848,8 @@ final_exports() {
|
||||||
install_pihole() {
|
install_pihole() {
|
||||||
# Install base files and web interface
|
# Install base files and web interface
|
||||||
check_dependencies # done
|
check_dependencies # done
|
||||||
stop_service
|
stop_service dnsmasq
|
||||||
|
stop_service lighttpd
|
||||||
set_user
|
set_user
|
||||||
if [ ! -d "/var/www/html" ]; then
|
if [ ! -d "/var/www/html" ]; then
|
||||||
mkdir -p /var/www/html
|
mkdir -p /var/www/html
|
||||||
|
@ -856,7 +878,8 @@ install_pihole() {
|
||||||
update() {
|
update() {
|
||||||
# Install base files and web interface
|
# Install base files and web interface
|
||||||
check_dependencies # done
|
check_dependencies # done
|
||||||
stop_service
|
stop_service dnsmasq
|
||||||
|
stop_service lighttpd
|
||||||
setup_local_repos
|
setup_local_repos
|
||||||
install_scripts
|
install_scripts
|
||||||
install_configs
|
install_configs
|
||||||
|
@ -955,19 +978,14 @@ main () {
|
||||||
displayFinalMessage
|
displayFinalMessage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -n "::: Restarting services..."
|
echo "::: Restarting services..."
|
||||||
# Start services
|
# Start services
|
||||||
if [ -x "$(command -v systemctl)" ]; then
|
start_service dnsmasq
|
||||||
systemctl enable dnsmasq
|
start_service lighttpd
|
||||||
systemctl restart dnsmasq
|
|
||||||
systemctl enable lighttpd
|
|
||||||
systemctl restart lighttpd
|
|
||||||
else
|
|
||||||
service dnsmasq restart
|
|
||||||
service lighttpd restart
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo " done."
|
echo "::: Enabling services on restart..."
|
||||||
|
enable_service dnsmasq
|
||||||
|
enable_service lighttpd
|
||||||
|
|
||||||
echo ":::"
|
echo ":::"
|
||||||
if [[ ${useUpdateVars} == false ]]; then
|
if [[ ${useUpdateVars} == false ]]; then
|
||||||
|
|
Loading…
Reference in a new issue