From dc91d4b1f90192fb71aa73e8af85c338bda2882e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:06:57 +0000 Subject: [PATCH 1/7] basic_install: If a static interface is already set up we are done Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8666e70a..acf5b92d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -873,6 +873,13 @@ setStaticIPv4() { # Local, named variables local IFCFG_FILE local CONNECTION_NAME + + # If a static interface is already configured, we are done. + if [[ -r "/etc/sysconfig/network/ifcfg-${PIHOLE_INTERFACE}" ]]; then + if grep -q '^BOOTPROTO=.static.' "/etc/sysconfig/network/ifcfg-${PIHOLE_INTERFACE}"; then + return 0 + fi + fi # For the Debian family, if dhcpcd.conf exists, if [[ -f "/etc/dhcpcd.conf" ]]; then # configure networking via dhcpcd From d5bbb2b6404301b07aecac2f7a8c913223f5af8d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:17:53 +0000 Subject: [PATCH 2/7] basic_install: Use a varibale for the pihole dashboard dir Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index acf5b92d..87347541 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -62,6 +62,7 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi # This directory is where the Pi-hole scripts will be installed PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" +PI_HOLE_BLOCKPAGE_DIR="/var/www/html/pihole" useUpdateVars=false adlistFile="/etc/pihole/adlists.list" @@ -1387,7 +1388,7 @@ installConfigs() { # Make sure the external.conf file exists, as lighttpd v1.4.50 crashes without it touch /etc/lighttpd/external.conf # if there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config - if [[ -f "/var/www/html/pihole/custom.php" ]]; then + if [[ -f "${PI_HOLE_BLOCKPAGE_DIR}/custom.php" ]]; then sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"pihole\/custom\.php"/' /etc/lighttpd/lighttpd.conf fi # Make the directories if they do not exist and set the owners @@ -1653,13 +1654,13 @@ installPiholeWeb() { local str="Creating directory for blocking page, and copying files" printf " %b %s..." "${INFO}" "${str}" # Install the directory - install -d /var/www/html/pihole + install -d ${PI_HOLE_BLOCKPAGE_DIR} # and the blockpage - install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* ${PI_HOLE_BLOCKPAGE_DIR}/ # Remove superseded file - if [[ -e "/var/www/html/pihole/index.js" ]]; then - rm "/var/www/html/pihole/index.js" + if [[ -e "${PI_HOLE_BLOCKPAGE_DIR}/index.js" ]]; then + rm "${PI_HOLE_BLOCKPAGE_DIR}/index.js" fi printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" From 838e1b19ecb6a58ba58a72acfd008810c8a7e07c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:23:23 +0000 Subject: [PATCH 3/7] basic_install: Set permissons for PI_HOLE_DASHBOARD_DIR Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 87347541..4e3e0636 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1654,7 +1654,7 @@ installPiholeWeb() { local str="Creating directory for blocking page, and copying files" printf " %b %s..." "${INFO}" "${str}" # Install the directory - install -d ${PI_HOLE_BLOCKPAGE_DIR} + install -d -m 0755 ${PI_HOLE_BLOCKPAGE_DIR} # and the blockpage install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* ${PI_HOLE_BLOCKPAGE_DIR}/ From f187b42a98b984f49d2df2ba20672f5f2497ceca Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:30:43 +0000 Subject: [PATCH 4/7] basic_install: Define webroot globally as a variable Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4e3e0636..5d0f6e23 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -52,9 +52,12 @@ lighttpdConfig=/etc/lighttpd/lighttpd.conf # This is a file used for the colorized output coltable=/opt/pihole/COL_TABLE +# Root of the web server +webroot="/var/www/html" + # We store several other directories and webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" -webInterfaceDir="/var/www/html/admin" +webInterfaceDir="${webroot}/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" PI_HOLE_LOCAL_REPO="/etc/.pihole" # These are the names of pi-holes files, stored in an array @@ -62,7 +65,7 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi # This directory is where the Pi-hole scripts will be installed PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" -PI_HOLE_BLOCKPAGE_DIR="/var/www/html/pihole" +PI_HOLE_BLOCKPAGE_DIR="${webroot}/pihole" useUpdateVars=false adlistFile="/etc/pihole/adlists.list" @@ -1668,9 +1671,9 @@ installPiholeWeb() { local str="Backing up index.lighttpd.html" printf " %b %s..." "${INFO}" "${str}" # If the default index file exists, - if [[ -f "/var/www/html/index.lighttpd.html" ]]; then + if [[ -f "${webroot}/index.lighttpd.html" ]]; then # back it up - mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + mv ${webroot}/index.lighttpd.html ${webroot}/index.lighttpd.orig printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" # Otherwise, else @@ -1880,15 +1883,15 @@ installPihole() { # If the user wants to install the Web interface, if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - if [[ ! -d "/var/www/html" ]]; then + if [[ ! -d "${webroot}" ]]; then # make the Web directory if necessary - mkdir -p /var/www/html + install -d -m 0755 ${webroot} fi if [[ "${INSTALL_WEB_SERVER}" == true ]]; then # Set the owner and permissions - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - chmod 775 /var/www/html + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} ${webroot} + chmod 0775 ${webroot} # Give pihole access to the Web server group usermod -a -G ${LIGHTTPD_GROUP} pihole # If the lighttpd command is executable, From 2f0e6a6dda2cbfc7719d5197aaf2721889633002 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:33:31 +0000 Subject: [PATCH 5/7] basic_install: Make sure the PI_HOLE_CONFIG_DIR exists Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5d0f6e23..bc8daa35 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1362,7 +1362,8 @@ installConfigs() { echo "${DNS_SERVERS}" > "${PI_HOLE_CONFIG_DIR}/dns-servers.conf" # Install empty file if it does not exist - if [[ ! -f "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then + if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then + install -d -m 0755 ${PI_HOLE_CONFIG_DIR} if ! install -o pihole -g pihole -m 664 /dev/null "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then printf " %bError: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 From 2f189cd0762daf725862e7d10a3c7cf2771fec6f Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:40:47 +0000 Subject: [PATCH 6/7] basic_install: There is no pihole group, remove it Only a user has been created beforehand. Only some distributions create a group with the same name based on their configuration. We cannot assume this is always the default. Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bc8daa35..087e0b38 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1364,7 +1364,7 @@ installConfigs() { # Install empty file if it does not exist if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then install -d -m 0755 ${PI_HOLE_CONFIG_DIR} - if ! install -o pihole -g pihole -m 664 /dev/null "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then + if ! install -o pihole -m 664 /dev/null "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then printf " %bError: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 fi From 860ec1a7c4313412456d7858ac86f0305105f3a7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 13:45:52 +0100 Subject: [PATCH 7/7] basic_install: Use install for sudoers Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 087e0b38..110399f8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1689,7 +1689,7 @@ installPiholeWeb() { # Make the .d directory if it doesn't exist mkdir -p /etc/sudoers.d/ # and copy in the pihole sudoers file - cp ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.sudo /etc/sudoers.d/pihole + install -m 0640 ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.sudo /etc/sudoers.d/pihole # Add lighttpd user (OS dependent) to sudoers file echo "${LIGHTTPD_USER} ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole