diff --git a/README.md b/README.md
index b71397f..b8ad4bc 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,10 @@
# `pihole-cloudsync`
-A script to help synchronize Pi-hole adlist/blocklist, blacklist, whitelist, regex, custom DNS hostnames, and custom CNAME hostnames across multiple Pi-holes using a Git repository.
# Why `pihole-cloudsync`?
+
I was running six Pi-holes on three different networks at three different physical locations. I wanted all six Pi-holes to share the same adlists, blacklists, whitelists, and regex files, but it was time-consuming to manually synchronize all of them (modify the local Pi-holes, VPN into the second network and modify those, then VPN into the third network and modify those). I also wanted the ability to share custom DNS hostnames between multiple Pi-holes so that the Pi-hole UI stats display the proper local hostnames instead of IP addresses.
I wanted to use Pi-hole's built-in web UI to manage only *one* set of lists on *one* Pi-hole -- and then securely synchronize an unlimited number of additional Pi-holes. I couldn't find an existing script that did exactly what I wanted... so I wrote `pihole-cloudsync`.
@@ -12,6 +14,7 @@ I wanted to use Pi-hole's built-in web UI to manage only *one* set of lists on *
Feedback, suggestions, bug fixes, and code contributions are welcome.
# How `pihole-cloudsync` Works
+
`pihole-cloudsync` allows you to designate any Pi-hole on any network to act as your "Master" or "Primary." This is the only Pi-hole whose list settings you will need to manage using Pi-hole's built-in web UI. The Primary Pi-hole then uses `pihole-cloudsync` in **Push** mode to *upload* four files to a private Git repository that you control (such as GitHub) that contain:
1. Your adlists/blocklists (queried from Pi-hole's database at `/etc/pihole/gravity.db`)
@@ -24,39 +27,48 @@ All other Secondary Pi-holes that you wish to keep synchronized use `pihole-clou
The script is designed to work with any Git repo that your Pi-holes can access, but I have only personally tested it with GitHub.
## No more Pi-hole v4 support
+
This script was originally written to work on Pi-hole version 4. However, as of Pi-hole version 5, most of the settings needed for sync between Pi-holes is no longer stored in individual text files -- they are now all stored in a single database file called `gravity.db`. The changes required to `pihole-cloudsync` to work with Pi-hole v5 means it will no longer with with version of Pi-hole earlier than v5.
**Before proceeding, verify that your Primary and *all* Secondary Pi-holes are running Pi-hole v5 or later.**
+## Docker Support
+
+This script supports docker containers running the `pihole/pihole` image.
+The container must be started when the script is run. The `pihole-cloudsync` should work out of the box with no changes required.
+
# Setup
-Prior to running `pihole-cloudsync`, you must first create a new dedicated Git respository to store your lists, then clone that new repository to all Pi-holes (both Primary and Secondary) that you wish to keep in sync. The easiest way to do that is to fork my own `my-pihole-lists` GitHub repository. Don't worry if the example lists in that repo are different than yours. You'll overwrite your forked version of the repo with your own Pi-hole lists the first time you run `pihole-cloudsync` in **Push** mode.
+
+Prior to running `pihole-cloudsync`, you must first create a new dedicated Git repository to store your lists, then clone that new repository to all Pi-holes (both Primary and Secondary) that you wish to keep in sync. The easiest way to do that is to fork my own `my-pihole-lists` GitHub repository. Don't worry if the example lists in that repo are different than yours. You'll overwrite your forked version of the repo with your own Pi-hole lists the first time you run `pihole-cloudsync` in **Push** mode.
**On GitHub**
+
1. Sign into GitHub.
-2. Go to https://github.com/stevejenkins/my-pihole-lists.
-3. Press **Fork**.
-4. *Optional:* If you wish to make your forked version of the repo private, press **Settings**, scroll down to the **Danger Zone**, then press **Make private**.
-5. On your new repo's main page, press the **Clone or download** button and copy the **Clone with HTTPS** link to your clipboard.
+1. Go to https://github.com/stevejenkins/my-pihole-lists.
+1. Press **Fork**.
+1. *Optional:* If you wish to make your forked version of the repo private, press **Settings**, scroll down to the **Danger Zone**, then press **Make private**.
+1. On your new repo's main page, press the **Clone or download** button and copy the **Clone with HTTPS** link to your clipboard.
**On your Primary Pi-hole device**
+
1. Install Git (on Raspbian/Debian do `sudo apt-get install git`).
-2. Do `cd /usr/local/bin`.
-3. Install `pihole-cloudsync` with `sudo git clone https://github.com/stevejenkins/pihole-cloudsync.git`.
-4. Create your private local Git repo with `sudo git clone https://github.com//my-pihole-lists.git` (paste the URL you copied from GitHub).
-5. If you're using a repo name other than `my-pihole-lists`, edit `/usr/local/bin/pihole-cloudsync/pihole-cloudsync` and edit the `personal_git_dir` variable to match your local Git repo location.
-6. Run `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --initpush` to initialize the local Pi-hole in "Push" mode. It will grab your Primary Pi-hole's list files (both from the `gravity.db` database and `/etc/pihole`) and add them to your new local Git repo. The `--initpush` mode should only need to be run once on your Primary Pi-hole.
-7. Run `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --push` to push/upload your Primary Pi-hole's lists from your local Git repo to your remote Git repo. You will have to manually enter your GitHub email address and password the first time you do this, but read below for how to save your login credentials so you can run this script unattended.
+1. Do `cd /usr/local/bin`.
+1. Install `pihole-cloudsync` with `sudo git clone https://github.com/stevejenkins/pihole-cloudsync.git`.
+1. Create your private local Git repo with `sudo git clone https://github.com//my-pihole-lists.git` (paste the URL you copied from GitHub).
+1. Run `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --initpush` to initialize the local Pi-hole in "Push" mode. It will grab your Primary Pi-hole's list files (both from the `gravity.db` database and `/etc/pihole`) and add them to your new local Git repo. The `--initpush` mode should only need to be run once on your Primary Pi-hole.
+1. Run `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --push` to push/upload your Primary Pi-hole's lists from your local Git repo to your remote Git repo. You will have to manually enter your GitHub email address and password the first time you do this, but read below for how to save your login credentials so you can run this script unattended.
**On all Secondary Pi-hole devices**
+
1. Install Git (on Raspbian/Debian do `sudo apt-get install git`)
-2. Do `cd /usr/local/bin`
-3. Install `pihole-cloudsync` with `sudo git clone https://github.com/stevejenkins/pihole-cloudsync.git`
-4. Create your private local Git repo with `sudo git clone https://github.com//my-pihole-lists.git` (paste the URL you copied from GitHub)
-5. If you're using a repo name other than `my-pihole-lists`, edit `/usr/local/bin/pihole-cloudsync/pihole-cloudsync` and edit the `personal_git_dir` variable to match your local Git repo location.
-6. Run `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --initpull` to initialize the local Pi-hole in Pull/Download mode. You will have to manually enter your GitHub email address and password the first time you do this, but read below for how to save your login credentials so you can run this script unattended. The `--initpull` option will also perform your first pull automatically and only needs to be run once on each Secondary Pi-hole. All future pulls can be performed with `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --pull`.
-7. Running `pihole-cloudsync --pull` will pull/download your Primary Pi-hole's lists from your remote Git repo to your Secondary Pi-hole's local Git repo. The `--pull` option will automatically copy the downloaded file(s) to your Pi-hole directory and tell Pi-hole to do a `pihole -g` command to update its lists.
+1. Do `cd /usr/local/bin`
+1. Install `pihole-cloudsync` with `sudo git clone https://github.com/stevejenkins/pihole-cloudsync.git`
+1. Create your private local Git repo with `sudo git clone https://github.com//my-pihole-lists.git` (paste the URL you copied from GitHub)
+1. Run `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --initpull` to initialize the local Pi-hole in Pull/Download mode. You will have to manually enter your GitHub email address and password the first time you do this, but read below for how to save your login credentials so you can run this script unattended. The `--initpull` option will also perform your first pull automatically and only needs to be run once on each Secondary Pi-hole. All future pulls can be performed with `/usr/local/bin/pihole-cloudsync/pihole-cloudsync --pull`.
+1. Running `pihole-cloudsync --pull` will pull/download your Primary Pi-hole's lists from your remote Git repo to your Secondary Pi-hole's local Git repo. The `--pull` option will automatically copy the downloaded file(s) to your Pi-hole directory and tell Pi-hole to do a `pihole -g` command to update its lists.
# Running `pihole-cloudsync` Unattended
+
**The following steps must be performed on each Pi-hole you wish to use with `pihole-cloudsync`.**
In order to automate or run `pihole-cloudsync` unattended, you will need to either store your GitHub login credentials locally or create an SSH key for your Pi-hole's root user and upload the public key to GitHub. You will need to do this on the Primary Pi-hole as well as all Secondary Pi-holes.
@@ -76,9 +88,11 @@ to enter and save your credentials. Now you can run `pihole-cloudsync` unattende
Again, **the above steps must be performed on each Pi-hole you wish to use with `pihole-cloudsync`.**
# Automating `pihole-cloudsync`
-Once each Pi-hole's local Git repo has been configured to save your login credentials, you can automate your Primary Pi-hole's "push" and your Secondary Pi-holes' "pull" in any number of ways. The simplest method is to run a [cron job](#Automating-with-cron) a few times a day. If you want more flexibilty over schedule and resource use, you can also use [systemd](#Automating-with-systemd) to automate. Both methods are explained below.
+
+Once each Pi-hole's local Git repo has been configured to save your login credentials, you can automate your Primary Pi-hole's "push" and your Secondary Pi-holes' "pull" in any number of ways. The simplest method is to run a [cron job](#Automating-with-cron) a few times a day. If you want more flexibility over schedule and resource use, you can also use [systemd](#Automating-with-systemd) to automate. Both methods are explained below.
## Automating with cron
+
The simplest way is to automate `pihole-cloudsync` is to set a "push" cron job on your Primary Pi-hole that runs a few times a day, then set a "pull" cron job on each Secondary Pi-hole that pulls in any changes a few minutes after your Primary pushes them.
Once you can successfully run `pihole-cloudsync --push` from the command line on your Primary Pi-hole, do `crontab -e` (or `sudo crontab -e` if you're not logged in as the root user) and create a cron entry such as:
@@ -89,15 +103,18 @@ And once you can successfully run `pihole-cloudsync --pull` from the command lin
`05 01,07,13,19 * * * sudo /usr/local/bin/pihole-cloudsync/pihole-cloudsync --pull > /dev/null 2>&1 #Pull Master Pi-hole Lists from remote Git repo`
-**NOTE:** On Raspian, the script won't execute via cron without the `sudo` command (as shown above). If you're having trouble getting the script to run unattended on Raspian, try including `sudo` in the cron command.
+**NOTE:** On Raspbian/Raspberry Pi OS, the script won't execute via cron without the `sudo` command (as shown above). If you're having trouble getting the script to run unattended on Raspbian/Raspberry Pi OS, try including `sudo` in the cron command.
## Automating with systemd
-`pihole-cloudsync` pulls can also be automated with systemd, if your Pi-hole is running on a systemd-supported distro. Once you're able to successfully run `pihole-cloudsync --pull` from the command line on each of your Secondary Pi-holes, you can proceed with systemd setup. You must install three `[Unit]` files on your Pi-hole to ensure a stable and non-intrusve update process: a `.service` file, a `.timer` file, and a `.slice` file.
+
+`pihole-cloudsync` pulls can also be automated with systemd, if your Pi-hole is running on a systemd-supported distro. Once you're able to successfully run `pihole-cloudsync --pull` from the command line on each of your Secondary Pi-holes, you can proceed with systemd setup. You must install three `[Unit]` files on your Pi-hole to ensure a stable and non-intrusive update process: a `.service` file, a `.timer` file, and a `.slice` file.
### Quick Start
+
1. Copy the each of the three `[Unit]` files in the **systemd Details** section below into `/etc/systemd/system` on your Pi-hole
-2. Tell systemd you changed its configuration files with `systemctl daemon-reload`
-3. Enable and start the service/timer
+1. Tell systemd you changed its configuration files with `systemctl daemon-reload`
+1. Enable and start the service/timer
+
```bash
# Enable the relevant configs
systemctl enable pihole-cloudsync-update.service
@@ -108,7 +125,9 @@ systemctl start pihole-cloudsync-update.timer
```
### systemd Details
+
1. **.service** - `/etc/systemd/system/pihole-cloudsync-update.service` - The core service file. Configured as a 'oneshot' in order to be run via a [systemd timer](https://wiki.archlinux.org/index.php/Systemd/Timers).
+
```ini
[Unit]
Description=PiHole Cloud Sync Data Puller service
@@ -124,6 +143,7 @@ WantedBy=multi-user.target
```
2. **.timer** - `/etc/systemd/system/pihole-cloudsync-update.timer` - The timer file. Determines when the `.service` file is executed. systemd timers are highly flexible and can be executed under a variety of timed and trigger-based circumstances. The [ArchLinux systemd/Timer documentation](https://wiki.archlinux.org/index.php/Systemd/Timers) is some of the best around. See their [examples](https://wiki.archlinux.org/index.php/Systemd/Timers#Examples) for many more ways to configure this systemd timer unit.
+
```ini
[Unit]
Description=PiHole Cloud Synd Data Puller timer
@@ -139,6 +159,7 @@ WantedBy=timers.target
```
3. **.slice** - `/etc/systemd/system/pihole-cloudsync-update.slice` - The slice file. Determines how much of the total system resources the `.service` is allowed to consume. This slice is in place to keep the update process in check and ensure that there will always be *plenty* of room for the Pi-hole service to answer DNS queries without being obstructed by potential `pihole-cloudsync` updates. If you'd like to learn more about systemd slices, check out [this wiki page](https://wikitech.wikimedia.org/wiki/Systemd_resource_control).
+
```ini
[Unit]
Description=PiHole Cloud Sync Puller resource limiter slice
@@ -147,16 +168,19 @@ Before=slices.target
[Slice]
CPUQuota=50%
```
+
*Special thanks to [Conroman16](https://github.com/Conroman16) for contributing the systemd automation instructions*
# Updating `pihole-cloudsync`
+
To upgrade to the latest version of `pihole-cloudsync`, do the following on *all* Primary and Secondary Pi-holes. Note that this will completely over-write any previous modifications you've made to `pihole-cloudsync`.
1. Do `cd /usr/local/bin/pihole-cloudsync`
-2. Do `git fetch --all`
-3. Do `git reset --hard origin/master`
+1. Do `git fetch --all`
+1. Do `git reset --hard origin/master`
-Your local version of `pihole-cloudsync` is now updated to the lastest release version.
+Your local version of `pihole-cloudsync` is now updated to the latest release version.
# Disclaimer
+
You are totally responsible for anything this script does to your system. Whether it launches a nice game of Tic Tac Toe or global thermonuclear war, you're on your own. :)
diff --git a/pihole-cloudsync b/pihole-cloudsync
index 08555d9..9e1b307 100755
--- a/pihole-cloudsync
+++ b/pihole-cloudsync
@@ -32,10 +32,10 @@ update='December 26, 2020'
# Project Home: https://github.com/stevejenkins/pihole-cloudsync
###########################################################################
# CONSTANTS
-personal_git_dir='/usr/local/bin/my-pihole-lists'
-pihole_dir='/etc/pihole'
-gravity_db='/etc/pihole/gravity.db'
-dnsmasq_dir='/etc/dnsmasq.d/'
+personal_git_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+pihole_dir='/etc/pihole' # No trailing slash '/'
+dnsmasq_dir='/etc/dnsmasq.d' # No trailing slash '/'
+gravity_db_filename='gravity.db'
ad_list='adlist.csv'
custom_list='custom.list'
domain_list='domainlist.csv'
@@ -46,9 +46,36 @@ cname_list='05-pihole-custom-cname.conf'
# Force sudo if not running with root privileges
SUDO=''
if [ "$EUID" -ne 0 ]
- then SUDO='sudo'
+then
+ SUDO='sudo'
fi
+# Send pihole commands via docker exec if pihole is running in docker container
+PIHOLECONTAINER=''
+DOCKER=''
+if [ -x "$(command -v docker)" ]
+then
+ PIHOLECONTAINER=$(docker ps -f "ancestor=pihole/pihole" --format "{{.Names}}")
+ if [ -n "${PIHOLECONTAINER}" ] && $(docker inspect -f "{{.State.Running}}" "${PIHOLECONTAINER}")
+ then
+ if ! command -v jq >/dev/null 2>&1 ; then
+ echo "jq not found. Please install using 'sudo apt-get install jq' or equivalent for your distro."
+ fi
+
+ echo "pihole is running under docker. Using container '$PIHOLECONTAINER'"
+
+ pihole_dir=$(docker inspect -f "{{json .Mounts}}" "${PIHOLECONTAINER}" | jq -r --arg pihole_dir "$pihole_dir" '.[] | select(.Destination==$pihole_dir) | .Source')
+ dnsmasq_dir=$(docker inspect -f "{{json .Mounts}}" "${PIHOLECONTAINER}" | jq -r --arg dnsmasq_dir "$dnsmasq_dir" '.[] | select(.Destination==$dnsmasq_dir) | .Source')
+
+ echo "Found pihole directory mapping at $pihole_dir"
+ echo "Found dnsmasq directory mapping at $dnsmasq_dir"
+
+ DOCKER="docker exec -i ${PIHOLECONTAINER}"
+ fi
+fi
+
+gravity_db="$pihole_dir/$gravity_db_filename"
+
# FUNCTIONS
push_initialize () {
# Go to Pi-hole directory, exit if doesn't exist
@@ -66,6 +93,8 @@ push_initialize () {
cd $personal_git_dir || exit
# Export Ad and Domain lists from Gravity database
+ echo "Reading from gravity db located at $gravity_db"
+
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM adlist" >$ad_list
$SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM domainlist" >$domain_list
@@ -85,7 +114,7 @@ pull_initialize () {
$SUDO git reset --hard origin/master -q
# Stop DNS server
- $SUDO service pihole-FTL stop
+ $SUDO $DOCKER service pihole-FTL stop
# Overwrite local files
$SUDO cp $custom_list $pihole_dir
@@ -98,120 +127,132 @@ pull_initialize () {
$SUDO sqlite3 $gravity_db -header -csv ".import domainlist.csv domainlist"
# Restart Pi-hole to pick up changes
- $SUDO pihole -g
+ $SUDO $DOCKER pihole -g
# Display success messages
echo "Local Pi-hole initialized in Pull mode and first pull successfully completed.";
echo "Future pulls can now be perfomed with 'pihole-cloudsync --pull'.";
}
push () {
- # Go to Pi-hole directory, exit if doesn't exist
+ # Go to Pi-hole directory, exit if doesn't exist
cd $pihole_dir || exit
- # Copy local Custom and CNAME lists to local Git repo
- $SUDO cp $custom_list $personal_git_dir
- $SUDO cp $dnsmasq_dir/$cname_list $personal_git_dir
+ # Copy local Custom and CNAME lists to local Git repo
+ $SUDO cp $custom_list $personal_git_dir
+ $SUDO cp $dnsmasq_dir/$cname_list $personal_git_dir
# Go to local Git repo directory
- cd $personal_git_dir || exit
+ cd $personal_git_dir || exit
- # Export Ad and Domain lists from Gravity database
- $SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM adlist" >$ad_list
- $SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM domainlist" >$domain_list
+ # Export Ad and Domain lists from Gravity database
+ $SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM adlist" >$ad_list
+ $SUDO sqlite3 $gravity_db -header -csv "SELECT * FROM domainlist" >$domain_list
# Compare local files to remote Git repo
$SUDO git remote update > /dev/null
# If local files are different than remote, update remote Git repo
- CHANGED=$($SUDO git --work-tree=$personal_git_dir status --porcelain)
- if [ -n "${CHANGED}" ]; then
- echo 'Local Pi-hole lists are different than remote Git repo. Updating remote repo...';
+ CHANGED=$($SUDO git --work-tree=$personal_git_dir status --porcelain)
+ if [ -n "${CHANGED}" ]
+ then
+ echo 'Local Pi-hole lists are different than remote Git repo. Updating remote repo...'
rightnow=$(date +"%B %e, %Y %l:%M%p")
# Remove -q option if you don't want to run in "quiet" mode
$SUDO git commit -a -m "Updated $rightnow" -q
$SUDO git push -q
echo 'Done!';
exit 0
- else
- # If local files are the same as remote, do nothing and exit
- echo 'Remote Git repo matches local Pi-hole lists. No further action required.';
+ else
+ # If local files are the same as remote, do nothing and exit
+ echo 'Remote Git repo matches local Pi-hole lists. No further action required.';
exit 0
- fi
+ fi
}
pull () {
- # Go to Pi-hole directory, exit if doesn't exist
+ # Go to Pi-hole directory, exit if doesn't exist
cd $personal_git_dir || exit
# Update local Git repo from remote Git repo
$SUDO git remote update > /dev/null
CHANGED=$($SUDO git log HEAD..origin/master --oneline)
- if [ -n "${CHANGED}" ]; then
- echo 'Remote Git repo is different than local Pi-hole lists. Updating local lists...';
- # Remove -q option if you don't want to run in "quiet" mode
- $SUDO git fetch --all -q
+ if [ -n "${CHANGED}" ]
+ then
+ echo 'Remote Git repo is different than local Pi-hole lists. Updating local lists...';
+ # Remove -q option if you don't want to run in "quiet" mode
+ $SUDO git fetch --all -q
$SUDO git reset --hard origin/master -q
- $SUDO service pihole-FTL stop
- $SUDO cp $custom_list $pihole_dir
- $SUDO cp $cname_list $dnsmasq_dir
- $SUDO sqlite3 $gravity_db "DROP TABLE adlist;"
- $SUDO sqlite3 $gravity_db -header -csv ".import adlist.csv adlist"
- $SUDO sqlite3 $gravity_db "DROP TABLE domainlist;"
- $SUDO sqlite3 $gravity_db -header -csv ".import domainlist.csv domainlist"
- $SUDO pihole -g
- echo 'Done!';
- exit 0
- else
- echo 'Local Pi-hole lists match remote Git repo. No further action required.';
- exit 0
- fi
+ $SUDO $DOCKER service pihole-FTL stop
+ $SUDO cp $custom_list $pihole_dir
+ $SUDO cp $cname_list $dnsmasq_dir
+ $SUDO sqlite3 $gravity_db "DROP TABLE adlist;"
+ $SUDO sqlite3 $gravity_db -header -csv ".import adlist.csv adlist"
+ $SUDO sqlite3 $gravity_db "DROP TABLE domainlist;"
+ $SUDO sqlite3 $gravity_db -header -csv ".import domainlist.csv domainlist"
+ $SUDO $DOCKER pihole -g
+ echo 'Done!';
+ exit 0
+ else
+ echo 'Local Pi-hole lists match remote Git repo. No further action required.';
+ exit 0
+ fi
+}
+docker_test() {
+ $DOCKER printenv
}
###########################################################################
# Check to see whether a command line option was provided
if [ -z "$1" ]
- then
- echo "Missing command line option. Try --push, --pull, or --help."
- exit 1
+then
+ echo "Missing command line option. Try --push, --pull, or --help."
+ exit 1
fi
# Determine which action to perform (InitPush, InitPull, Push, Pull, or Help)
for arg in "$@"
do
- # Initialize - adds primary Pi-hole's lists to local Git repo before first push/upload
- if [ "$arg" == "--initpush" ]
- then
- echo "$arg option detected. Initializing local Git repo for Push/Upload.";
- push_initialize
- exit 0
- # Initialize - adds primary Pi-hole's lists to local Git repo before first push/upload
- elif [ "$arg" == "--initpull" ]
- then
- echo "$arg option detected. Initializing local Git repo for Pull/Download.";
- pull_initialize
- exit 0
- # Push / Upload - Pushes updated local Pi-hole lists to remote Git repo
- elif [ "$arg" == "--push" ] || [ "$arg" == "--upload" ] || [ "$arg" == "--up" ] || [ "$arg" == "-u" ]
- then
- echo "$arg option detected. Running in Push/Upload mode."
- push
- exit 0
- # Pull / Download - Pulls updated Pi-hole lists from remote Git repo
- elif [ "$arg" == "--pull" ] || [ "$arg" == "--download" ] || [ "$arg" == "--down" ]|| [ "$arg" == "-d" ]
- then
- echo "$arg option detected. Running in Pull/Download mode."
- pull
- exit 0
- # Help - Displays help dialog
- elif [ "$arg" == "--help" ] || [ "$arg" == "-h" ] || [ "$arg" == "-?" ]
- then
- cat << EOF
+ # Test sending commands to docker container
+ if [ "$arg" == "--dockertest" ]
+ then
+ echo "$arg option detected. Testing docker container commands with 'printenv'.";
+ docker_test
+ exit 0
+ # Initialize - adds primary Pi-hole's lists to local Git repo before first push/upload
+ elif [ "$arg" == "--initpush" ]
+ then
+ echo "$arg option detected. Initializing local Git repo for Push/Upload.";
+ push_initialize
+ exit 0
+ # Initialize - adds primary Pi-hole's lists to local Git repo before first push/upload
+ elif [ "$arg" == "--initpull" ]
+ then
+ echo "$arg option detected. Initializing local Git repo for Pull/Download.";
+ pull_initialize
+ exit 0
+ # Push / Upload - Pushes updated local Pi-hole lists to remote Git repo
+ elif [ "$arg" == "--push" ] || [ "$arg" == "--upload" ] || [ "$arg" == "--up" ] || [ "$arg" == "-u" ]
+ then
+ echo "$arg option detected. Running in Push/Upload mode."
+ push
+ exit 0
+ # Pull / Download - Pulls updated Pi-hole lists from remote Git repo
+ elif [ "$arg" == "--pull" ] || [ "$arg" == "--download" ] || [ "$arg" == "--down" ] || [ "$arg" == "-d" ]
+ then
+ echo "$arg option detected. Running in Pull/Download mode."
+ pull
+ exit 0
+ # Help - Displays help dialog
+ elif [ "$arg" == "--help" ] || [ "$arg" == "-h" ] || [ "$arg" == "-?" ]
+ then
+ cat << EOF
Usage: pihole-cloudsync