diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index fc8a1656..4ae5f31f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -47,16 +47,14 @@ if [[ $EUID -eq 0 ]];then else # Check if sudo is actually installed # If it isn't, exit because the install cannot complete - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else + if [[ ! -x "$(command -v sudo)" ]]; then echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed." exit 1 fi echo "::: sudo utility found and will be used for the install." echo "::: Restarting script with sudo" - exec sudo bash "$0" "$@" - exit $? + exec sudo bash +x "$0" "$@" + exit 0 fi # Compatibility @@ -320,7 +318,7 @@ set_dhcpcd() { echo "## interface $piholeInterface static ip_address=$IPv4addr static routers=$IPv4gw - static domain_name_servers=$IPv4gw" | ${SUDO} tee -a /etc/dhcpcd.conf >/dev/null + static domain_name_servers=$IPv4gw" | tee -a /etc/dhcpcd.conf >/dev/null } set_static_IPv4() { @@ -330,7 +328,7 @@ set_static_IPv4() { echo "::: Static IP already configured" else set_dhcpcd - ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr" + ip addr replace dev "$piholeInterface" "$IPv4addr" echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." echo ":::" @@ -346,20 +344,20 @@ set_static_IPv4() { # Backup existing interface configuration: cp ${IFCFG_FILE} ${IFCFG_FILE}.backup-$(date +%Y-%m-%d-%H%M%S) # Build Interface configuration file: - ${SUDO} echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE} - ${SUDO} echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE} - ${SUDO} echo "BOOTPROTO=none" >> ${IFCFG_FILE} - ${SUDO} echo "ONBOOT=yes" >> ${IFCFG_FILE} - ${SUDO} echo "IPADDR=$IPADDR" >> ${IFCFG_FILE} - ${SUDO} echo "PREFIX=$CIDR" >> ${IFCFG_FILE} - ${SUDO} echo "GATEWAY=$IPv4gw" >> ${IFCFG_FILE} - ${SUDO} echo "DNS1=$piholeDNS1" >> ${IFCFG_FILE} - ${SUDO} echo "DNS2=$piholeDNS2" >> ${IFCFG_FILE} - ${SUDO} echo "USERCTL=no" >> ${IFCFG_FILE} - ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr" + echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE} + echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE} + echo "BOOTPROTO=none" >> ${IFCFG_FILE} + echo "ONBOOT=yes" >> ${IFCFG_FILE} + echo "IPADDR=$IPADDR" >> ${IFCFG_FILE} + echo "PREFIX=$CIDR" >> ${IFCFG_FILE} + echo "GATEWAY=$IPv4gw" >> ${IFCFG_FILE} + echo "DNS1=$piholeDNS1" >> ${IFCFG_FILE} + echo "DNS2=$piholeDNS2" >> ${IFCFG_FILE} + echo "USERCTL=no" >> ${IFCFG_FILE} + ip addr replace dev "$piholeInterface" "$IPv4addr" if [ -x "$(command -v nmcli)" ];then # Tell NetworkManager to read our new sysconfig file - ${SUDO} nmcli con load ${IFCFG_FILE} > /dev/null + nmcli con load ${IFCFG_FILE} > /dev/null fi echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." @@ -494,57 +492,57 @@ version_check_dnsmasq(){ if grep -q ${dnsSearch} ${dnsFile1}; then echo " it is from a previous pi-hole install." echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..." - ${SUDO} mv -f ${dnsFile1} ${dnsFile2} + mv -f ${dnsFile1} ${dnsFile2} echo " done." echo -n "::: Restoring default dnsmasq.conf..." - ${SUDO} cp ${defaultFile} ${dnsFile1} + cp ${defaultFile} ${dnsFile1} echo " done." else echo " it is not a pi-hole file, leaving alone!" fi else echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..." - ${SUDO} cp ${defaultFile} ${dnsFile1} + cp ${defaultFile} ${dnsFile1} echo " done." fi echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..." - ${SUDO} cp ${newFileToInstall} ${newFileFinalLocation} + cp ${newFileToInstall} ${newFileFinalLocation} echo " done." - ${SUDO} sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation} + sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation} if [[ "$piholeDNS1" != "" ]]; then - ${SUDO} sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation} + sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation} else - ${SUDO} sed -i '/^server=@DNS1@/d' ${newFileFinalLocation} + sed -i '/^server=@DNS1@/d' ${newFileFinalLocation} fi if [[ "$piholeDNS2" != "" ]]; then - ${SUDO} sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation} + sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation} else - ${SUDO} sed -i '/^server=@DNS2@/d' ${newFileFinalLocation} + sed -i '/^server=@DNS2@/d' ${newFileFinalLocation} fi - ${SUDO} sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1} + sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1} } install_scripts() { # Install the scripts from /etc/.pihole to their various locations echo ":::" echo -n "::: Installing scripts to /opt/pihole..." - ${SUDO} install -o "${USER}" -m755 -d /opt/pihole + install -o "${USER}" -m755 -d /opt/pihole cd /etc/.pihole/ - ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh - ${SUDO} install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh - ${SUDO} install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole + install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh + install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh + install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole - ${SUDO} install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole + install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole #Tidy up /usr/local/bin directory if installing over previous install. oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) for i in "${oldFiles[@]}"; do if [ -f "/usr/local/bin/$i.sh" ]; then - ${SUDO} rm /usr/local/bin/"$i".sh + rm /usr/local/bin/"$i".sh fi done @@ -557,15 +555,15 @@ install_configs() { echo "::: Installing configs..." version_check_dnsmasq if [ ! -d "/etc/lighttpd" ]; then - ${SUDO} mkdir /etc/lighttpd - ${SUDO} chown "$USER":root /etc/lighttpd - ${SUDO} mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig + mkdir /etc/lighttpd + chown "$USER":root /etc/lighttpd + mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi - ${SUDO} cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf - ${SUDO} mkdir -p /var/run/lighttpd - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd - ${SUDO} mkdir -p /var/cache/lighttpd/compress - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress + cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf + mkdir -p /var/run/lighttpd + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd + mkdir -p /var/cache/lighttpd/compress + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress } stop_service() { @@ -574,9 +572,9 @@ stop_service() { echo -n "::: Stopping services..." #$SUDO service dnsmasq stop & spinner $! || true if [ -x "$(command -v systemctl)" ]; then - ${SUDO} systemctl stop lighttpd & spinner $! || true + systemctl stop lighttpd & spinner $! || true else - ${SUDO} service lighttpd stop & spinner $! || true + service lighttpd stop & spinner $! || true fi echo " done." } @@ -590,7 +588,7 @@ install_packages() { package_check "${i}" if ! [[ "$?" -eq 0 ]]; then echo -n " Not found! Installing...." - ${SUDO} ${PKG_INSTALL} "$i" > /dev/null 2>&1 + ${PKG_INSTALL} "$i" > /dev/null 2>&1 echo " done!" else echo " already installed!" @@ -617,12 +615,12 @@ installer_dependencies() { #update package lists echo ":::" echo -n "::: $PKG_MANAGER update has not been run today. Running now..." - ${SUDO} ${UPDATE_PKG_CACHE} > /dev/null 2>&1 + ${UPDATE_PKG_CACHE} > /dev/null 2>&1 echo " done!" fi echo ":::" echo -n "::: Checking $PKG_MANAGER for upgraded packages...." - updatesToInstall=$(eval "${SUDO} ${PKG_COUNT}") + updatesToInstall=$(eval "${PKG_COUNT}") echo " done!" echo ":::" if [[ ${updatesToInstall} -eq "0" ]]; then @@ -682,8 +680,8 @@ is_repo() { make_repo() { # Remove the non-repod interface and clone the interface echo -n "::: Cloning $2 into $1..." - ${SUDO} rm -rf "$1" - ${SUDO} git clone --depth 1 -q "$2" "$1" > /dev/null & spinner $! + rm -rf "$1" + git clone --depth 1 -q "$2" "$1" > /dev/null & spinner $! echo " done!" } @@ -691,7 +689,7 @@ update_repo() { # Pull the latest commits echo -n "::: Updating repo in $1..." cd "$1" || exit - ${SUDO} git pull -q > /dev/null & spinner $! + git pull -q > /dev/null & spinner $! echo " done!" } @@ -700,9 +698,9 @@ create_log_file() { echo ":::" echo -n "::: Creating log file and changing owner to dnsmasq..." if [ ! -f /var/log/pihole.log ]; then - ${SUDO} touch /var/log/pihole.log - ${SUDO} chmod 644 /var/log/pihole.log - ${SUDO} chown dnsmasq:root /var/log/pihole.log + touch /var/log/pihole.log + chmod 644 /var/log/pihole.log + chown dnsmasq:root /var/log/pihole.log echo " done!" else echo " already exists!" @@ -716,20 +714,20 @@ install_admin_web() { if [ -d "/var/www/html/pihole" ]; then echo " Existing page detected, not overwriting" else - ${SUDO} mkdir /var/www/html/pihole + mkdir /var/www/html/pihole if [ -f /var/www/html/index.lighttpd.html ]; then - ${SUDO} mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - ${SUDO} cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. + cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. echo " done!" fi # Install Sudoer file echo -n "::: Installing sudoer file..." - ${SUDO} mkdir -p /etc/sudoers.d/ - ${SUDO} cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole - ${SUDO} chmod 0440 /etc/sudoers.d/pihole + mkdir -p /etc/sudoers.d/ + cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole + chmod 0440 /etc/sudoers.d/pihole echo " done!" } @@ -737,7 +735,7 @@ install_cron() { # Install the cron job echo ":::" echo -n "::: Installing latest Cron script..." - ${SUDO} cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole + cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole echo " done!" } @@ -747,10 +745,10 @@ run_gravity() { echo "::: Preparing to run gravity.sh to refresh hosts..." if ls /etc/pihole/list* 1> /dev/null 2>&1; then echo "::: Cleaning up previous install (preserving whitelist/blacklist)" - ${SUDO} rm /etc/pihole/list.* + rm /etc/pihole/list.* fi echo "::: Running gravity.sh" - ${SUDO} /opt/pihole/gravity.sh + /opt/pihole/gravity.sh } set_user(){ @@ -760,28 +758,28 @@ set_user(){ echo "::: User 'pihole' already exists" else echo "::: User 'pihole' doesn't exist. Creating..." - ${SUDO} useradd -r -s /usr/sbin/nologin pihole + useradd -r -s /usr/sbin/nologin pihole fi } configure_firewall() { # Allow HTTP and DNS traffic if [ -x "$(command -v firewall-cmd)" ]; then - ${SUDO} firewall-cmd --state > /dev/null + firewall-cmd --state > /dev/null if [[ $? -eq 0 ]]; then - ${SUDO} echo "::: Configuring firewalld for httpd and dnsmasq.." - ${SUDO} firewall-cmd --permanent --add-port=80/tcp - ${SUDO} firewall-cmd --permanent --add-port=53/tcp - ${SUDO} firewall-cmd --permanent --add-port=53/udp - ${SUDO} firewall-cmd --reload + echo "::: Configuring firewalld for httpd and dnsmasq.." + firewall-cmd --permanent --add-port=80/tcp + firewall-cmd --permanent --add-port=53/tcp + firewall-cmd --permanent --add-port=53/udp + firewall-cmd --reload fi elif [ -x "$(command -v iptables)" ]; then - ${SUDO} echo "::: Configuring iptables for httpd and dnsmasq.." - ${SUDO} iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT - ${SUDO} iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT - ${SUDO} iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT + echo "::: Configuring iptables for httpd and dnsmasq.." + iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT + iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT + iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT else - ${SUDO} echo "::: No firewall detected.. skipping firewall configuration." + echo "::: No firewall detected.. skipping firewall configuration." fi } @@ -792,22 +790,22 @@ configure_SELinux() { package_check "selinux-policy-devel" > /dev/null if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." - ${SUDO} ${PKG_INSTALL} "selinux-policy-devel" > /dev/null & spinner $! + ${PKG_INSTALL} "selinux-policy-devel" > /dev/null & spinner $! echo " done!" else echo " already installed!" fi printf "::: Enabling httpd server side includes (SSI).. " - ${SUDO} setsebool -P httpd_ssi_exec on + setsebool -P httpd_ssi_exec on if [ $? -eq 0 ]; then echo -n "Success" fi printf "\n:::\tCompiling Pi-Hole SELinux policy..\n" - ${SUDO} checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te - ${SUDO} semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod - ${SUDO} semodule -i /etc/pihole/pihole.pp - ${SUDO} rm -f /etc/pihole/pihole.mod - ${SUDO} semodule -l | grep pihole > /dev/null + checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te + semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod + semodule -i /etc/pihole/pihole.pp + rm -f /etc/pihole/pihole.mod + semodule -l | grep pihole > /dev/null if [ $? -eq 0 ]; then printf "::: Successfully installed Pi-Hole SELinux policy\n" else @@ -819,29 +817,29 @@ configure_SELinux() { final_exports() { #If it already exists, lets overwrite it with the new values. if [[ -f ${setupVars} ]];then - ${SUDO} rm ${setupVars} + rm ${setupVars} fi - ${SUDO} echo "piholeInterface=${piholeInterface}" >> ${setupVars} - ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars} - ${SUDO} echo "piholeIPv6=${IPv6addr}" >> ${setupVars} - ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars} - ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars} + echo "piholeInterface=${piholeInterface}" >> ${setupVars} + echo "IPv4addr=${IPv4addr}" >> ${setupVars} + echo "piholeIPv6=${IPv6addr}" >> ${setupVars} + echo "piholeDNS1=${piholeDNS1}" >> ${setupVars} + echo "piholeDNS2=${piholeDNS2}" >> ${setupVars} } -install() { +install_pihole() { # Install base files and web interface check_dependencies # done stop_service set_user if [ ! -d "/var/www/html" ]; then - ${SUDO} mkdir -p /var/www/html + mkdir -p /var/www/html fi - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - ${SUDO} chmod 775 /var/www/html - ${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html + chmod 775 /var/www/html + usermod -a -G ${LIGHTTPD_GROUP} pihole if [ -x "$(command -v lighty-enable-mod)" ]; then - ${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null + 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 @@ -948,13 +946,13 @@ main () { # Decide what upstream DNS Servers to use set_upstream_dns # Install and log everything to a file - install | tee ${tmpLog} + install_pihole | tee ${tmpLog} else update | tee ${tmpLog} fi # Move the log file into /etc/pihole for storage - ${SUDO} mv ${tmpLog} ${instalLogLoc} + mv ${tmpLog} ${instalLogLoc} if [[ ${useUpdateVars} == false ]]; then displayFinalMessage @@ -963,13 +961,13 @@ main () { echo -n "::: Restarting services..." # Start services if [ -x "$(command -v systemctl)" ]; then - ${SUDO} systemctl enable dnsmasq - ${SUDO} systemctl restart dnsmasq - ${SUDO} systemctl enable lighttpd - ${SUDO} systemctl start lighttpd + systemctl enable dnsmasq + systemctl restart dnsmasq + systemctl enable lighttpd + systemctl restart lighttpd else - ${SUDO} service dnsmasq restart - ${SUDO} service lighttpd start + service dnsmasq restart + service lighttpd restart fi echo " done."