anudeepND / whitelist

A simple tool to add commonly white listed domains to your Pi-Hole setup.
MIT License
4.21k stars 281 forks source link

Docker installation (with Python3 support) #256

Open mfedatto opened 1 year ago

mfedatto commented 1 year ago

I'm working on an automated setup, and for the whitelist to work properly on Pi-hole on Docker, I need an entrypoint script. Since a script is needed, I'm working on installing python, checking if the repo was already cloned, if not, cloning it, and if so, pulling it, then proceeding to invoke the whitelist.py and add it to crontab. But the script I managed to reach is facing a fatal error:

fatal: destination path 'whitelist' already exists and is not an empty directory.

My init.sh as entrypoint:

apt install python3 -y
cd

# The name of the directory to check/create
dir_name="whitelist"

# The Git repository URL to clone/pull from
repo_url="https://github.com/anudeepND/whitelist.git"

# Check if the directory already exists
if [ -d "$dir_name" ]; then
  echo "Directory '$dir_name' already exists. Doing a 'git pull'..."
  cd "$dir_name"
  git pull
else
  echo "Directory '$dir_name' does not exist. Doing a 'git clone'..."
  git clone "$repo_url" "$dir_name"
fi

python3 whitelist/scripts/whitelist.py

cat /etc/crontab >> tmp_crontab
echo "0 1 * * */7     root    /root/whitelist/scripts/whitelist.py" >> tmp_crontab

cp tmp_crontab /etc/crontab
rm tmp_crontab

I'm willing to send a PR with the working instructions once I get it working properly.

LeonardoMor commented 1 year ago

The cd after installing python3, cd to where? I'm not sure how you plan on using this. Will you have this init.sh on the machine that runs docker and then add it to crontab?