Maddcow / Lancache-Pihole

19 stars 3 forks source link

Truecharts + Pihole script not working #2

Closed liquidfrollo closed 1 year ago

liquidfrollo commented 1 year ago

Greetings and thank you for your work! I am running truecharts with Traefik + Pihole + lancache. Your script needed to be added to my pihole container located in my pod. The container by default runs as root and the commands are slightly different. I edited the script (including the host ip part because if my guess is correct once setup it will need the ip to the container host not local ip of the pihole instance though will continue looking there)

This may be more appropriate to provide a merge or something to create an option to accommodate those scenarios including requesting an IP as the ip needed for lancache is in a different container.

here is the script modified (note i also had the issue reported earlier about needing to modify the script due to end of line breaks)

`#!/bin/bash

if [ "$(id -un)" != "root" ]; then echo " " echo " We need root access for certain task..." echo " Please run as 'root'." echo " " exit fi

if !( service pihole-FTL status || docker ps -a | grep -o "pihole" > /dev/null 2>&1 ); then echo " " echo " Pihole is currently not installed on this system." echo " Install Pihole (https://pi-hole.net/) before running this script." echo " " exit fi

echo " " echo "---------------------------------------------------------------" echo " $(date)" echo " Pihole DNS redirect for Lancache " echo " Creating setup files... "

loc=$(pwd) cd /home/$(logname) git clone https://github.com//uklans/cache-domains > /dev/null 2>&1

Get host ip address

Hostip="""$(hostname -I | sed -r 's/[^], :[]+/"&"/g')"""

Hostip="""10.0.0.55"""

Setting up config.json file

{ echo '{' echo ' "ips": {' echo ' "generic": '$Hostip echo ' },' echo ' "cache_domains": {' echo ' "default": "generic"' echo ' }' echo '}' } >> config.json

echo " Generating cache-domains files... "

      #### Automating cache-domains files

cp /$loc/lancache-dns-updates.sh /root/lancache-dns-updates.sh cd /root chmod +x lancache-dns-updates.sh ./lancache-dns-updates.sh

echo " Creating crontab job... "

      #### Adding the script to a cron job

(crontab -u $(whoami) -l; echo "30 3 * /bin/bash /root/lancache-dns-updates.sh" ) | crontab -u $(whoami) -

service cron reload > /dev/null 2>&1

echo " Install Complete " echo " Enjoy! " echo "---------------------------------------------------------------" echo " "`

liquidfrollo commented 1 year ago

I resolved my issue. The issue was that when attempting to set the IP it was not getting enclosed in quotes properly. This wouldn't cascade down the line in a way the script liked. adding the ip manually such as '"172.2.3.135"' in single and then double worked.