En, hieronder de eerste ( engelse versie ) om op openSUSE zonder gebruik te maken van een terminal. Maak een script 'pihole-docker-install.sh' aan in de ~/bin van je gebruiker, met onderstaande inhoud. Maak middels Dolphin het script uitvoerbaar, en klik erop. Dolphin zal je vragen of je het wilt uitvoeren, bevestig dat. Daarna wijst het zich vanzelf. Vergeet niet de poorten in de firewall te openen, 53 tcp, 67 udp en de beide in het script gekozen poorten.
Code:
#!/bin/bash
# Name:
# Description: Script to install and run a pihole server
# License: Creative Commons, shared copyright
# Current distros supported: openSUSE Leap, openSUSE Tumbleweed
# VARS here
VERSION=0.4
AUTHORS='Gertjan Lettink; Wesley Landaal'
COPYRIGHT='2018'
# END VARS
# FUNCTIONS
check_for_zenity()
{
ZENITY_INSTALLED=$(which zenity)
if [ ! "$ZENITY_INSTALLED"] ; then
xmessage "Zenity is not installed. \
Please install before running the script." ;
exit 4
fi
}
# ask the user for the root password to make the 'sudo' commands work
get_sudo_password()
{
PASSWD=$(zenity --password --title=Authentication --text="The script needs root permissions\nEnter your root/sudo password" --width=600) ;
if [[ ${?} != 0 || -z ${PASSWD} ]] ; then
exit 4
fi
if ! sudo -kSp '' [ 1 ] <<<${PASSWD} 2>/dev/null ; then
exit 4
fi
}
# initial info screen
show_info()
{
START_Y_N=$(zenity --question --text="This script will install and configure your own Pihole server\nVersion: $VERSION AUTHORS: $AUTHORS ©$COPYRIGHT" --width=600 && echo YES || echo NO) ;
if [ "$START_Y_N" == "NO" ] ; then
exit 1
fi
}
# ask the user for the distro used
# Add your distro to DISTROS below if you want to extend the script with your own distro's commands
DISTROS="openSUSE"
get_os()
{
OS=$(zenity --list --title="Linux Distro" --text="Pick your linux distro" --column="Distro" $DISTROS --width=600 --height=300) ;
}
# have the user confirm his distro to install on
confirm_os()
{
OS_CONFIRM=$(zenity --question --text="$OS is the distro you entered\n\nSure this the correct one? " --width=600 && echo YES || echo NO) ;
if [ "$OS_CONFIRM" == "NO" ] ; then
get_os
fi
}
# announce install of dependencies and system preparation
prepare_system_msg()
{
zenity --info --text="The script will now setup your system for the pihole server" --width=600 ;
prepare_system
}
# perform install of depencies and activate services
# Add your distro's routines here.
prepare_system()
{
if [ "$OS" == "openSUSE" ] ; then
DOCKER_INSTALLED=$(rpm -qa | grep -i docker-[0-9]);
if [ "$DOCKER_INSTALLED" == "" ] ; then
zenity --info --text="Docker packages will be installed now\n\nThis may take a minute" --width=600 ;
sudo -Sp '' zypper install --no-confirm docker <<<${PASSWD}
fi
fi
# Enter package install for other distros here
# See openSUSE example
zenity --info --text="Docker packages installed" --width=600 ;
start_docker
}
# start the docker service
start_docker()
{
DOCKER_RUNNING=$(systemctl show -p SubState --value docker)
DOCKER_ENABLED=$(systemctl is-enabled docker.service)
if [ ! "$DOCKER_ENABLED" == "enabled" ] ; then
zenity --info --text="Enabling docker service" --width=600 ;
sudo -Sp '' systemctl enable docker <<<${PASSWD}
zenity --info --text="Starting docker service" --width=600 ;
sudo -Sp '' systemctl start docker <<<${PASSWD}
else
if [ "$DOCKER_RUNNING" == "running" ] ; then
zenity --info --text="Docker service already enabled and running" --width=600;
else
zenity --info --text="Starting docker service" --width=600 ;
sudo -Sp '' systemctl start docker <<<${PASSWD}
fi
fi
zenity --info --text="Docker service now started\n\nStarting configuration of your pihole server" --width=600 ;
}
# ask for the Pihole server IP address | could be picked from ip addr or something like that
get_ipaddress()
{
GET_IP=$(hostname -I | cut -d' ' -f1)
IP=$(zenity --entry --text="Enter the pihole IP Address" --entry-text=$GET_IP --width=600) ;
}
# have the user confirm the entered IP address
confirm_ipaddress()
{
IP_CONFIRM=$(zenity --question --text="$IP is the IP you entered\n\nSure this the correct IP address? " --width=600 && echo YES || echo NO) ;
if [ "$IP_CONFIRM" == "NO" ] ; then
get_ipaddress
fi
}
# ask the user for the path to the pihole docker configs
get_docker_configs()
{
DOCKER_CONFIGS=$(zenity --entry --text="Enter the path for you Pihole docker configs\n\nLeave default if you don't know what you're changing" --entry-text="/opt/pihole" --width=600) ;
}
# have the user confirm the entered path for docker configs
confirm_docker_configs()
{
DOCKER_CONFIGS_CONFIRM=$(zenity --question --text="$DOCKER_CONFIGS is the docker config path you entered\n\nSure this the docker config path you want to use? " --width=600 && echo YES || echo NO) ;
if [ "$DOCKER_CONFIGS_CONFIRM" == "NO" ] ; then
get_docker_configs
fi
}
# ask the user which port to access the pihole server for port 80
get_port_80()
{
PORT_80=$(zenity --entry --text="Enter the port to access the pihole server through http\n\nLeave default if you don't know what you're changing" --entry-text="8081" --width=600) ;
}
# have the user confirm the port to access the pihole server for port 80
confirm_port_80()
{
PORT_80_CONFIRM=$(zenity --question --text="$PORT_80 is the port serving port 80 you entered\n\nSure this is the port you want to use? " --width=600 && echo YES || echo NO) ;
if [ "$PORT_80_CONFIRM" == "NO" ] ; then
get_port_80
fi
}
# ask the user which port to access the pihole server for port 443
get_port_443()
{
PORT_443=$(zenity --entry --text="Enter the port to access the pihole server through https\n\nLeave default if you don't know what you're changing" --entry-text="4443" --width=600) ;
}
# have the user confirm the port to access the pihole server for port 443
confirm_port_443()
{
PORT_443_CONFIRM=$(zenity --question --text="$PORT_443 is the port serving port 443 you entered\n\nSure this is the port you want to use? " --width=600 && echo YES || echo NO) ;
if [ "$PORT_443_CONFIRM" == "NO" ] ; then
get_port_443
fi
}
# have the user confirm all entered data
confirm_all()
{
ALL_CONFIRM=$(zenity --question --text="Are you sure the following entries are correct?\n\nIP Address: $IP\nDocker configs: $DOCKER_CONFIGS\nPort 80: served on $PORT_80\nPort 443: served on $PORT_443\n\nClick No if you're in doubt." --width=600 --width=600 && echo YES || echo NO)
if [ "$ALL_CONFIRM" == "NO" ] ; then
show_info
else
start_docker_pihole
fi
}
# start the docker container with provided data
start_docker_pihole()
{
sudo -Sp '' docker run -d \
--name pihole \
-p 53:53/tcp -p 53:53/udp \
-p 67:67/udp \
-p $PORT_80:80 \
-p $PORT_443:443 \
-v "${DOCKER_CONFIGS}/pihole/:/etc/pihole/" \
-v "${DOCKER_CONFIGS}/dnsmasq.d/:/etc/dnsmasq.d/" \
-e ServerIP="$IP" \
--restart=unless-stopped \
pihole/pihole:latest <<<${PASSWD};
}
# show DONE and provide URL and password for admin access
show_done()
{
DOCKER_PW=docker logs pihole 2> /dev/null | grep 'password:' ;
zenity --info --text="Your password for http://$IP:$PORT_80/admin/ is $DOCKER_PW\nYour password for https://$IP:$PORT_443/admin/ is $DOCKER_PW\n\nMake sure you open ports 53, 67 udp, $PORT_80 and $PORT_443 in the firewall\n\nTo start using Pihole:\nChange DNS 1 of your router or computer to $IPi\nand reconnect your devices with the network" --width=600;
}
#END FUNCTIONS
#INSTALLER
check_for_zenity
show_info
get_os
confirm_os
get_sudo_password
prepare_system_msg
get_ipaddress
confirm_ipaddress
get_docker_configs
confirm_docker_configs
get_port_80
confirm_port_80
get_port_443
confirm_port_443
confirm_all
show_done
#END INSTALLER
Bookmarks