├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── Dockerfile ├── ENV.md ├── LICENSE ├── README.md ├── VERSION ├── gravity-sync ├── gravity-sync.sh ├── images └── gs-logo.svg ├── templates ├── gravity-sync.conf.example ├── gravity-sync.service ├── gravity-sync.timer └── gs-nopasswd.sudo └── update.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: vmstan 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Help improve Gravity Sync 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | **Issue Description** 12 | 13 | **Configuration Details** 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | _Is your feature request related to a problem? If so maybe a Bug Report is more approprate? Otherwise, please give clear and concise description of what prompted your request -- Ex. "I'm always frustrated when [...]" -- then provide a clear and concise description of what you want to happen. If you're willing to commit code changes with your suggestions the project would welcome pull requests._ 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dev 2 | .vscode 3 | .DS_Store 4 | .nova 5 | settings/* 6 | logs/* -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM photon:4.0 2 | LABEL maintainer="Michael Stanclift " 3 | 4 | RUN tdnf update -y \ 5 | && tdnf install -y curl git rsync openssh 6 | 7 | RUN curl -sSL http://gravity.vmstan.com/beta | GS_DOCKER=1 && GS_DEV=4.0.0 bash 8 | 9 | CMD gravity-sync version -------------------------------------------------------------------------------- /ENV.md: -------------------------------------------------------------------------------- 1 |

2 | Gravity Sync 3 |

4 | 5 | 6 | 7 | # Gravity Sync ENVs 8 | 9 | 10 | 11 | These tables are a list of all Gravity Sync settings, that can be tweaked via ENVs. Keep in mind that some of them are stored in `/etc/gravity-sync/gravity-sync.conf` after running `gravity-sync configure` and that `gravity-sync.conf` has higher priority than ENVs. 12 | 13 | ### Local and remote paths & settings 14 | These settings will determine, from where (locally) to where (remotely) will be synced and with which account/permissions 15 | | Variable | Default | Value | Description | 16 | |----------------------------|------------------|------------|----------------------------------------------------| 17 | | `LOCAL_PIHOLE_DIRECTORY` | `/etc/pihole` | path | Path to local pi-hole instance in the filesystem | 18 | | `REMOTE_PIHOLE_DIRECTORY` | `/etc/pihole` | path | Path to remote pi-hole instance in the filesystem | 19 | | `LOCAL_DNSMASQ_DIRECTORY` | `/etc/dnsmasq.d` | path | Path to local dnsmasqd instance in the filesystem | 20 | | `REMOTE_DNSMASQ_DIRECTORY` | `/etc/dnsmasq.d` | path | Path to remote dnsmasqd instance in the filesystem | 21 | | `LOCAL_FILE_OWNER` | `pihole:pihole` | user:group | Local owner and group of the pi-hole config | 22 | | `REMOTE_FILE_OWNER` | `pihole:pihole` | user:group | Remote owner and group of the pi-hole config | 23 | 24 | ### Docker specific settings 25 | Gravity-sync will check your system for a native Pi-hole install first (on local and remote site) and if does not detect any, tests against Docker/Podman Pi-hole instances. 26 | Here, you can specific the Docker or Podman container name, that Gravity Sync should interact with. 27 | | Variable | Default | Value | Description | 28 | |---------------------------|----------|----------------|--------------------------------------------| 29 | | `LOCAL_DOCKER_CONTAINER` | `pihole` | container name | Container name of pi-hole running locally | 30 | | `REMOTE_DOCKER_CONTAINER` | `pihole` | container name | Container name of pi-hole running remotely | 31 | 32 | ### Paths to standard files and folders 33 | These settings are most likely the same on all systems. No need to touch them but nice to be able to touch them, if necessary. 34 | | Variable | Default | Value | Description | 35 | |----------------------------|-------------------------|-------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 36 | | `DEFAULT_PIHOLE_DIRECTORY` | `/etc/pihole` | path | Docker/Podman: Path to Pi-hole instance within a Docker/Podman container. Don't mix up with `LOCAL_PIHOLE_DIRECTORY`, which is only used against local Pi-hole instances (non-dockerized). | 37 | | `LOCAL_PIHOLE_BINARY` | `/usr/local/bin/pihole` | path | Path to `pihole` binary on local system | 38 | | `REMOTE_PIHOLE_BINARY` | `/usr/local/bin/pihole` | path | Path to `pihole` binary on remote system | 39 | | `LOCAL_FTL_BINARY` | `/usr/bin/pihole-FTL` | path | Path to `pihole-FTL` binary on local system | 40 | | `REMOTE_FTL_BINARY` | `/usr/bin/pihole-FTL` | path | Path to `pihole-FTL` binary on remote system | 41 | | `LOCAL_DOCKER_BINARY` | `/usr/bin/docker` | path | Path to `docker` binary on local system | 42 | | `REMOTE_DOCKER_BINARY` | `/usr/bin/docker` | path | Path to `docker` binary on remote system | 43 | | `LOCAL_PODMAN_BINARY` | `/usr/bin/podman` | path | Path to `podman` binary on local system | 44 | | `REMOTE_PODMAN_BINARY` | `/usr/bin/podman` | path | Path to `podman` binary on remote system | 45 | | `PIHOLE_CONTAINER_IMAGE` | `pihole/pihole` | path | Name of the default pi-hole docker image | 46 | 47 | ### Nitty-gritty finetuning the target files 48 | Here, you can specifiy the Gravity, DNS (A, CNAME) and DHCP settings file of Pi-hole. It is almost certain, that these filenames do never change (except if upstream Pi-hole decides so). 49 | | Variable | Default | Value | Description | 50 | |-----------------|-------------------------------|-------|--------------------------------------------| 51 | | `PH_GRAVITY_FI` | `gravity.db` | file | The gravity filename (blocklist) of pihole | 52 | | `PH_CUSTOM_DNS` | `custom.list` | file | The custom DNS (A) filename of pihole | 53 | | `PH_CNAME_CONF` | `05-pihole-custom-cname.conf` | file | The custom DNS (CNAME) filename of pihole | 54 | | `PH_SDHCP_CONF` | `04-pihole-static-dhcp.conf` | file | The custom DHCP filename of pihole | 55 | 56 | ### Backup Customization 57 | | Variable | Default | Value | Description | 58 | |----------------------------|---------|----------------|-----------------------------------------------------------------------------------------------| 59 | | `GS_BACKUP_TIMEOUT` | `240` | seconds | How long shall we allow a gravity.db backup task to run, before it is deemed to be timed out? | 60 | | `GS_BACKUP_INTEGRITY_WAIT` | `5` | seconds | Some wait time, before integrity checks are performed on gravity.db | 61 | | `GS_BACKUP_EXT` | `gsb` | file-extension | Local and remote gravity.db backup files will get this file-extension added before merge. | 62 | 63 | ### GS Folder/File Locations 64 | | Variable | Default | Value | Description | 65 | |-------------------------|-----------------------------------|-------|--------------------------------------------------------------------------------------------| 66 | | `GS_ETC_PATH` | `/etc/gravity-sync` | path | Path to the gravity-sync work & config directory | 67 | | `GS_CONFIG_FILE` | `gravity-sync.conf` | file | Name of the gravity.sync config file | 68 | | `GS_SYNCING_LOG` | `gs-sync.log` | file | Logfile for gravity-sync | 69 | | `GS_GRAVITY_FI_MD5_LOG` | `gs-gravity.md5` | file | Filename for storing `PH_GRAVITY_FI` hash (used for sync comparison locally and on remote) | 70 | | `GS_CUSTOM_DNS_MD5_LOG` | `gs-clist.md5` | file | Filename for storing `PH_CUSTOM_DNS` hash (used for sync comparison locally and on remote) | 71 | | `GS_CNAME_CONF_MD5_LOG` | `05-pihole-custom-cname.conf.md5` | file | Filename for storing `PH_CNAME_CONF` hash (used for sync comparison locally and on remote) | 72 | | `GS_SDHCP_CONF_MD5_LOG` | `04-pihole-static-dhcp.conf.md5` | file | Filename for storing `PH_SDHCP_CONF` hash (used for sync comparison locally and on remote) | 73 | 74 | ### Remote SSH config 75 | Customize parameters for accessing the remote end via SSH 76 | | Variable | Default | Value | Description | 77 | |---------------|----------------------------------|-------|---------------------------------------------------------------------------------------------------------| 78 | | `GS_SSH_PORT` | `22` | port | Port of the remote gravity-sync container/host | 79 | | `GS_SSH_PKIF` | `/gravity-sync.rsa` | file | Path to the local SSH private key of gravity-sync, that will be used for pubkey auth against the remote | 80 | 81 | ### Upgrade: Gravity Sync sourcecode location 82 | Gravity Sync is locally installed as a GitHub repo. In order to upgrade your local Gravity Sync instance via `gravity-sync upgrade` to the latest version, the path to that git repo must be known and can be specified below. 83 | | Variable | Default | Value | Description | 84 | |-----------------|---------------------|-------|---------------------------------------------| 85 | | `GS_LOCAL_REPO` | `/.gs` | path | Local install path of the gravity-sync repo | 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Gravity Sync 3 |

4 | 5 | 6 | 7 | # Gravity Sync 8 | 9 | 10 | 11 | ### Effective July 26, 2024, this project has been retired. Thank you for your use and enthusiasm for a project that began as a few lines of bash in a Slack channel and envolved into something far more complex, and used by many thousands of Pi-hole enthusiasts over the last four years. 12 | 13 | ### The last released version of Gravity Sync (4.0.7) should continue to work with Pi-hole 5.x, but not with Pi-hole 6+ due to architecture changes. 14 | 15 | What is better than a [Pi-hole](https://github.com/pi-hole/pi-hole) blocking trackers, advertisements, and other malicious domains on your network? That's right, **two** Pi-hole blocking all that junk on your network! 16 | 17 | - [Seriously. Why two Pi-hole?](https://github.com/vmstan/gravity-sync/wiki/Frequent-Questions#why-do-i-need-more-than-one-pi-hole) 18 | 19 | But if you have redundant Pi-hole in your network you'll want a simple way to keep the list configurations and local DNS settings identical between the two. That's where Gravity Sync comes in. Setup should only take a few minutes. 20 | 21 | ## Features 22 | 23 | Gravity Sync replicates the core of Pi-hole's ad/telemetry blocking settings, which includes: 24 | 25 | - Adlist settings with status and comments. 26 | - Domain/RegEx whitelists and blacklist along with status and comments. 27 | - Clients and group assignments, along with status and descriptions. 28 | 29 | Gravity Sync also replicates local network DNS/DHCP settings, which includes: 30 | 31 | - Local DNS Records. 32 | - Local CNAME Records. 33 | - Static DHCP Assignments. 34 | 35 | ### Limitations 36 | 37 | Gravity Sync will **not**: 38 | 39 | - Modify or sync the individual Pi-hole's upstream DNS resolvers. 40 | - Merge query logs, statistics, long-term data, caches, or other resolution information. 41 | - Sync individual Pi-hole DHCP scoping information or leases. 42 | 43 | ## Setup Steps 44 | 45 | 1. [Review System Requirements](https://github.com/vmstan/gravity-sync/wiki/System-Requirements) 46 | 2. [Install Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing) 47 | 3. [Configure Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Installing#configuration) 48 | 4. [Execute Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Engaging) 49 | 5. [Automate Gravity Sync](https://github.com/vmstan/gravity-sync/wiki/Automation) 50 | 51 | ## Disclaimer 52 | 53 | Gravity Sync is not developed by or affiliated with the Pi-hole project. This is project an unofficial, community effort, that seeks to implement replication (which is currently not a part of the core Pi-hole product) in a way that provides stability and value to Pi-hole users. The code has been tested across multiple user environments but there always is an element of risk involved with running any arbitrary software you find on the Internet. 54 | 55 | Pi-hole is and the Pi-hole logo are [registered trademarks](https://pi-hole.net/trademark-rules-and-brand-guidelines/) of Pi-hole LLC. 56 | 57 | ## Additional Documentation 58 | 59 | Please refer to the [Wiki](https://github.com/vmstan/gravity-sync/wiki) for more information: 60 | 61 | - [Frequently Asked Questions](https://github.com/vmstan/gravity-sync/wiki/Frequent-Questions) 62 | - [Changelog](https://github.com/vmstan/gravity-sync/wiki/Changelog) 63 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | 4.0.7 2 | -------------------------------------------------------------------------------- /gravity-sync: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck disable=SC2086,SC1091 3 | GS_RUN_START=$SECONDS 4 | 5 | # GRAVITY SYNC BY VMSTAN ##################### 6 | PROGRAM='Gravity Sync' 7 | GS_VERSION='4.0.7' 8 | 9 | # For documentation or the changelog/updates visit https://github.com/vmstan/gravity-sync 10 | # Requires Pi-Hole 5.x or higher already be installed, for help visit https://pi-hole.net 11 | 12 | # REQUIRED SETTINGS ########################## 13 | 14 | # Run 'gravity-sync config' to get started, it will customize the script for your environment 15 | # You should NOT to change the values of any variables here, to customize your install 16 | # Only add replacement variables to gravity-sync.conf, which will overwrite these defaults 17 | # Gravity Sync 4.0 introduces a new configuration file format, there is no direct upgrade path 18 | 19 | # CUSTOM VARIABLES ########################### 20 | 21 | # Pi-hole Folder/File Customization - Only need to be customized when using containers 22 | LOCAL_PIHOLE_DIRECTORY=${LOCAL_PIHOLE_DIRECTORY:-'/etc/pihole'} # replace in gravity-sync.conf to overwrite 23 | REMOTE_PIHOLE_DIRECTORY=${REMOTE_PIHOLE_DIRECTORY:-'/etc/pihole'} # replace in gravity-sync.conf to overwrite 24 | LOCAL_DNSMASQ_DIRECTORY=${LOCAL_DNSMASQ_DIRECTORY:-'/etc/dnsmasq.d'} # replace in gravity-sync.conf to overwrite 25 | REMOTE_DNSMASQ_DIRECTORY=${REMOTE_DNSMASQ_DIRECTORY:-'/etc/dnsmasq.d'} # replace in gravity-sync.conf to overwrite 26 | LOCAL_FILE_OWNER=${LOCAL_FILE_OWNER:-'pihole:pihole'} # replace in gravity-sync.conf to overwrite 27 | REMOTE_FILE_OWNER=${REMOTE_FILE_OWNER:-'pihole:pihole'} # replace in gravity-sync.conf to overwrite 28 | 29 | # Pi-hole Docker/Podman container name - Docker will pattern match anything set below 30 | LOCAL_DOCKER_CONTAINER=${LOCAL_DOCKER_CONTAINER:-'pihole'} # replace in gravity-sync.conf to overwrite 31 | REMOTE_DOCKER_CONTAINER=${REMOTE_DOCKER_CONTAINER:-'pihole'} # replace in gravity-sync.conf to overwrite 32 | 33 | # STANDARD VARIABLES ######################### 34 | 35 | DEFAULT_PIHOLE_DIRECTORY=${DEFAULT_PIHOLE_DIRECTORY:-'/etc/pihole'} # Default Pi-hole data directory 36 | LOCAL_PIHOLE_BINARY=${LOCAL_PIHOLE_BINARY:-'/usr/local/bin/pihole'} # Local Pi-hole binary directory (default) 37 | REMOTE_PIHOLE_BINARY=${REMOTE_PIHOLE_BINARY:-'/usr/local/bin/pihole'} # Remote Pi-hole binary directory (default) 38 | LOCAL_FTL_BINARY=${LOCAL_FTL_BINARY:-'/usr/bin/pihole-FTL'} # Local FTL binary directory (default) 39 | REMOTE_FTL_BINARY=${REMOTE_FTL_BINARY:-'/usr/bin/pihole-FTL'} # Remote FTL binary directory (default) 40 | LOCAL_DOCKER_BINARY=${LOCAL_DOCKER_BINARY:-'/usr/bin/docker'} # Local Docker binary directory (default) 41 | REMOTE_DOCKER_BINARY=${REMOTE_DOCKER_BINARY:-'/usr/bin/docker'} # Remote Docker binary directory (default) 42 | LOCAL_PODMAN_BINARY=${LOCAL_PODMAN_BINARY:-'/usr/bin/podman'} # Local Podman binary directory (default) 43 | REMOTE_PODMAN_BINARY=${REMOTE_PODMAN_BINARY:-'/usr/bin/podman'} # Remote Podman binary directory (default) 44 | PIHOLE_CONTAINER_IMAGE=${PIHOLE_CONTAINER_IMAGE:-'pihole/pihole'} # Official Pi-hole container image name 45 | 46 | ############################################### 47 | ####### THE NEEDS OF THE MANY, OUTWEIGH ####### 48 | ############ THE NEEDS OF THE FEW ############# 49 | ############################################### 50 | 51 | PH_GRAVITY_FI=${PH_GRAVITY_FI:-'gravity.db'} # Pi-hole database file name 52 | PH_CUSTOM_DNS=${PH_CUSTOM_DNS:-'custom.list'} # Pi-hole DNS lookup filename 53 | PH_CNAME_CONF=${PH_CNAME_CONF:-'05-pihole-custom-cname.conf'} # DNSMASQ CNAME alias file 54 | PH_SDHCP_CONF=${PH_SDHCP_CONF:-'04-pihole-static-dhcp.conf'} # DNSMASQ Static DHCP file 55 | 56 | # Backup Customization 57 | GS_BACKUP_TIMEOUT=${GS_BACKUP_TIMEOUT:-'240'} # replace in gravity-sync.conf to overwrite 58 | GS_BACKUP_INTEGRITY_WAIT=${GS_BACKUP_INTEGRITY_WAIT:-'5'} # replace in gravity-sync.conf to overwrite 59 | GS_BACKUP_EXT=${GS_BACKUP_EXT:-'gsb'} # replace in gravity-sync.conf to overwrite 60 | 61 | # GS Folder/File Locations 62 | GS_FILEPATH='/usr/local/bin/gravity-sync' 63 | GS_ETC_PATH=${GS_ETC_PATH:-"/etc/gravity-sync"} # replace in gravity-sync.conf to overwrite 64 | GS_CONFIG_FILE=${GS_CONFIG_FILE:-'gravity-sync.conf'} # replace in gravity-sync.conf to overwrite 65 | GS_SYNCING_LOG=${GS_SYNCING_LOG:-'gs-sync.log'} # replace in gravity-sync.conf to overwrite 66 | GS_GRAVITY_FI_MD5_LOG=${GS_GRAVITY_FI_MD5_LOG:-'gs-gravity.md5'} # replace in gravity-sync.conf to overwrite 67 | GS_CUSTOM_DNS_MD5_LOG=${GS_CUSTOM_DNS_MD5_LOG:-'gs-clist.md5'} # replace in gravity-sync.conf to overwrite 68 | GS_CNAME_CONF_MD5_LOG=${GS_CNAME_CONF_MD5_LOG:-'05-pihole-custom-cname.conf.md5'} # replace in gravity-sync.conf to overwrite 69 | GS_SDHCP_CONF_MD5_LOG=${GS_SDHCP_CONF_MD5_LOG:-'04-pihole-static-dhcp.conf.md5'} # replace in gravity-sync.conf to overwrite 70 | 71 | # SSH Customization 72 | GS_SSH_PORT=${GS_SSH_PORT:-'22'} # replace in gravity-sync.conf to overwrite 73 | GS_SSH_PKIF=${GS_SSH_PKIF:-"${GS_ETC_PATH}/gravity-sync.rsa"} # replace in gravity-sync.conf to overwrite 74 | 75 | # Github Customization 76 | GS_LOCAL_REPO=${GS_LOCAL_REPO:-"${GS_ETC_PATH}/.gs"} # replace in gravity-sync.conf to overwrite 77 | 78 | # OS Settings 79 | OS_DAEMON_PATH='/etc/systemd/system' 80 | OS_TMP='/tmp' 81 | OS_SSH_CMD='ssh' 82 | 83 | # Interface Settings 84 | UI_GRAVITY_NAME='Gravity Database' 85 | UI_CUSTOM_NAME='DNS Records' 86 | UI_CNAME_NAME='DNS CNAMEs' 87 | UI_SDHCP_NAME='Static DHCP Addresses' 88 | # Reused UI Text 89 | UI_CORE_LOADING='Loading' 90 | UI_CORE_EVALUATING='Evaluating arguments' 91 | UI_CORE_INIT="Initializing ${PROGRAM} (${GS_VERSION})" 92 | UI_CORE_APP='Pi-hole' 93 | UI_CORE_APP_DNS='DNSMASQ' 94 | UI_EXIT_CALC_END='after' 95 | UI_EXIT_ABORT='exited' 96 | UI_EXIT_COMPLETE='completed' 97 | UI_EXIT_CALC_TIMER='seconds' 98 | UI_HASHING_HASHING='Hashing the remote' 99 | UI_HASHING_COMPARING='Comparing to the local' 100 | UI_HASHING_DIFFERENCE='Differences detected in the' 101 | UI_HASHING_DETECTED='has been detected on the' 102 | UI_HASHING_NOT_DETECTED='not detected on the' 103 | UI_HASHING_REMOTE="remote ${UI_CORE_APP}" 104 | UI_HASHING_LOCAL="local ${UI_CORE_APP}" 105 | UI_HASHING_REHASHING='Rehashing the remote' 106 | UI_HASHING_RECOMPARING='Recomparing to local' 107 | UI_VALIDATING='Validating pathways to' 108 | UI_VALIDATING_FAIL_CONTAINER='Unable to validate running container instance of' 109 | UI_VALIDATING_FAIL_FOLDER='Unable to validate configuration folder for' 110 | UI_VALIDATING_FAIL_BINARY='Unable to validate the availability of' 111 | UI_SET_LOCAL_FILE_OWNERSHIP='Setting file ownership on' 112 | UI_SET_FILE_PERMISSION='Setting file permissions on' 113 | UI_PULL_REMOTE='Pulling the remote' 114 | UI_PUSH_LOCAL='Pushing the local' 115 | UI_REPLACE_LOCAL='Replacing the local' 116 | UI_FTLDNS_CONFIG_PULL_RELOAD='Reloading local FTLDNS services' 117 | UI_FTLDNS_CONFIG_PUSH_RELOAD='Reloading remote FTLDNS services' 118 | UI_LOGGING_RECENT_COMPLETE='Recent complete executions of' 119 | UI_BACKUP_REMOTE='Performing backup of remote' 120 | UI_BACKUP_LOCAL='Performing backup of local' 121 | UI_BACKUP_INTEGRITY="Checking ${UI_GRAVITY_NAME} copy integrity" 122 | UI_BACKUP_INTEGRITY_FAILED='Integrity check has failed for the remote' 123 | UI_BACKUP_INTEGRITY_DELETE='Removing failed copies' 124 | UI_CONFIG_ALREADY='already exists' 125 | UI_CONFIG_CONFIRM='Proceeding will replace your existing configuration' 126 | UI_CONFIG_ERASING='Erasing existing' 127 | UI_CONFIG_LOCAL='local host' 128 | UI_CONFIG_CONTAINER_NAME='container name' 129 | UI_CONFIG_SAVING='Saving' 130 | UI_CONFIG_ETC_VOLUME_PATH="'etc' volume path" 131 | UI_CONFIG_VOLUME_OWNER='volume ownership' 132 | 133 | ## Script Colors 134 | RED='\033[0;91m' 135 | GREEN='\033[0;92m' 136 | CYAN='\033[0;96m' 137 | YELLOW='\033[0;93m' 138 | PURPLE='\033[0;95m' 139 | BLUE='\033[0;94m' 140 | BOLD='\033[1m' 141 | NC='\033[0m' 142 | 143 | ## Message Codes 144 | FAIL="${RED}✗${NC}" 145 | WARN="${PURPLE}!${NC}" 146 | GOOD="${GREEN}✓${NC}" 147 | STAT="${CYAN}∞${NC}" 148 | INFO="${YELLOW}»${NC}" 149 | INF1="${CYAN}›${NC}" 150 | NEED="${BLUE}?${NC}" 151 | LOGO="${PURPLE}∞${NC}" 152 | 153 | ## Echo Stack 154 | ### Informative 155 | function echo_info { 156 | echo -e "${INFO} ${YELLOW}${MESSAGE}${NC}" 157 | } 158 | 159 | function echo_prompt { 160 | echo -e "${INF1} ${CYAN}${MESSAGE}${NC}" 161 | } 162 | 163 | ### Warning 164 | function echo_warn { 165 | echo -e "${WARN} ${PURPLE}${MESSAGE}${NC}" 166 | } 167 | 168 | ### Executing 169 | function echo_stat { 170 | echo -en "${STAT} ${MESSAGE}" 171 | } 172 | 173 | ### Success 174 | function echo_good { 175 | echo -e "\r${GOOD} ${MESSAGE}" 176 | } 177 | 178 | ### Success 179 | function echo_good_clean { 180 | echo -e "\r${GOOD} ${MESSAGE}" 181 | } 182 | 183 | ### Failure 184 | function echo_fail { 185 | echo -e "\r${FAIL} ${MESSAGE}" 186 | } 187 | 188 | ### Request 189 | function echo_need { 190 | echo -en "${NEED} ${BOLD}${MESSAGE}:${NC} " 191 | } 192 | 193 | ### Indent 194 | function echo_over { 195 | echo -e " ${MESSAGE}" 196 | } 197 | 198 | ### Gravity Sync Logo 199 | function echo_grav { 200 | echo -e "${LOGO} ${BOLD}${MESSAGE}${NC}" 201 | } 202 | 203 | ### Lines 204 | function echo_blank { 205 | echo -e "" 206 | } 207 | 208 | # Standard Output 209 | function start_gs { 210 | MESSAGE="${UI_CORE_INIT}" 211 | echo_grav 212 | 213 | import_gs_config 214 | detect_local_pihole 215 | detect_remote_pihole 216 | detect_gs_peer 217 | set_pihole_exec 218 | 219 | MESSAGE="${UI_CORE_EVALUATING}" 220 | echo_stat 221 | 222 | validate_sudo_status 223 | } 224 | 225 | # Standard Output No Config 226 | function start_gs_no_config { 227 | MESSAGE="${UI_CORE_INIT}" 228 | echo_grav 229 | 230 | MESSAGE="${UI_CORE_EVALUATING}" 231 | echo_stat 232 | } 233 | 234 | ## Import Settings 235 | function import_gs_config { 236 | MESSAGE="${UI_CORE_LOADING} ${GS_CONFIG_FILE}" 237 | echo -en "${STAT} $MESSAGE" 238 | if [ -f ${GS_ETC_PATH}/${GS_CONFIG_FILE} ]; then 239 | # shellcheck source=/etc/gravity-sync/gravity-sync.conf 240 | source ${GS_ETC_PATH}/${GS_CONFIG_FILE} 241 | error_validate 242 | else 243 | echo_fail 244 | 245 | MESSAGE="Missing ${GS_CONFIG_FILE}" 246 | echo_warn 247 | 248 | GS_TASK_TYPE='CONFIG' 249 | config_generate 250 | fi 251 | } 252 | 253 | ## Invalid Tasks 254 | function task_invalid { 255 | start_gs_no_config 256 | echo_fail 257 | list_gs_arguments 258 | } 259 | 260 | ## Error Validation 261 | function error_validate { 262 | if [ "$?" != "0" ]; then 263 | echo_fail 264 | exit 1 265 | else 266 | echo_good 267 | fi 268 | } 269 | 270 | function set_pihole_exec { 271 | if [ "$LOCAL_PIHOLE_TYPE" == "default" ]; then 272 | PH_EXEC="${LOCAL_PIHOLE_BINARY}" 273 | FTL_EXEC="${LOCAL_FTL_BINARY}" 274 | elif [ "$LOCAL_PIHOLE_TYPE" == "docker" ]; then 275 | PH_EXEC="sudo ${LOCAL_DOCKER_BINARY} exec $(sudo ${LOCAL_DOCKER_BINARY} ps -qf name=^${LOCAL_DOCKER_CONTAINER}$) pihole" 276 | FTL_EXEC="sudo ${LOCAL_DOCKER_BINARY} exec $(sudo ${LOCAL_DOCKER_BINARY} ps -qf name=^${LOCAL_DOCKER_CONTAINER}$) pihole-FTL" 277 | elif [ "$LOCAL_PIHOLE_TYPE" == "podman" ]; then 278 | PH_EXEC="sudo ${LOCAL_PODMAN_BINARY} exec ${LOCAL_DOCKER_CONTAINER} pihole" 279 | FTL_EXEC="sudo ${LOCAL_PODMAN_BINARY} exec ${LOCAL_DOCKER_CONTAINER} pihole-FTL" 280 | fi 281 | 282 | if [ "$REMOTE_PIHOLE_TYPE" == "default" ]; then 283 | RH_EXEC="${REMOTE_PIHOLE_BINARY}" 284 | RFTL_EXEC="${REMOTE_FTL_BINARY}" 285 | elif [ "$REMOTE_PIHOLE_TYPE" == "docker" ]; then 286 | RH_EXEC="sudo ${REMOTE_DOCKER_BINARY} exec \$(sudo ${REMOTE_DOCKER_BINARY} ps -qf name=^${REMOTE_DOCKER_CONTAINER}$) pihole" 287 | RFTL_EXEC="sudo ${REMOTE_DOCKER_BINARY} exec \$(sudo ${REMOTE_DOCKER_BINARY} ps -qf name=^${REMOTE_DOCKER_CONTAINER}$) pihole-FTL" 288 | elif [ "$REMOTE_PIHOLE_TYPE" == "podman" ]; then 289 | RH_EXEC="sudo ${REMOTE_PODMAN_BINARY} exec ${REMOTE_DOCKER_CONTAINER} pihole" 290 | RFTL_EXEC="sudo ${REMOTE_PODMAN_BINARY} exec ${REMOTE_DOCKER_CONTAINER} pihole-FTL" 291 | fi 292 | } 293 | 294 | ## Compare Task 295 | function task_compare { 296 | start_gs 297 | 298 | GS_TASK_TYPE='COMPARE' 299 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 300 | echo_good 301 | 302 | show_target 303 | validate_ph_folders 304 | validate_dns_folders 305 | previous_md5 306 | md5_compare 307 | exit_with_changes 308 | } 309 | 310 | ## Pull Task 311 | function task_pull { 312 | start_gs 313 | 314 | GS_TASK_TYPE='PULL' 315 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 316 | echo_good 317 | show_target 318 | validate_ph_folders 319 | validate_dns_folders 320 | pull_gs 321 | exit 322 | } 323 | 324 | ## Pull Gravity 325 | function pull_gs_grav { 326 | 327 | backup_local_gravity 328 | backup_remote_gravity 329 | backup_remote_gravity_integrity 330 | 331 | MESSAGE="${UI_PULL_REMOTE} ${UI_GRAVITY_NAME}" 332 | echo_stat 333 | RSYNC_REPATH="sudo rsync" 334 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}" 335 | RSYNC_TARGET="${OS_TMP}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}" 336 | create_rsync_cmd 337 | 338 | MESSAGE="${UI_REPLACE_LOCAL} ${UI_GRAVITY_NAME}" 339 | echo_stat 340 | sudo mv ${OS_TMP}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} >/dev/null 2>&1 341 | error_validate 342 | 343 | validate_gravity_permissions 344 | } 345 | 346 | ## Pull Custom 347 | function pull_gs_custom { 348 | if [ "$REMOTE_PH_CUSTOM_DNS" == "1" ]; then 349 | backup_local_custom 350 | backup_remote_custom 351 | 352 | MESSAGE="${UI_PULL_REMOTE} ${UI_CUSTOM_NAME}" 353 | echo_stat 354 | RSYNC_REPATH="sudo rsync" 355 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}.${GS_BACKUP_EXT}" 356 | RSYNC_TARGET="${OS_TMP}/${PH_CUSTOM_DNS}.${GS_BACKUP_EXT}" 357 | create_rsync_cmd 358 | 359 | MESSAGE="${UI_REPLACE_LOCAL} ${UI_CUSTOM_NAME}" 360 | echo_stat 361 | sudo mv ${OS_TMP}/${PH_CUSTOM_DNS}.${GS_BACKUP_EXT} ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} >/dev/null 2>&1 362 | error_validate 363 | 364 | validate_custom_permissions 365 | fi 366 | } 367 | 368 | ## Pull CNAME 369 | function pull_gs_cname { 370 | if [ "$REMOTE_CNAME_DNS" == "1" ]; then 371 | backup_local_cname 372 | backup_remote_cname 373 | 374 | MESSAGE="${UI_PULL_REMOTE} ${UI_CNAME_NAME}" 375 | echo_stat 376 | RSYNC_REPATH="sudo rsync" 377 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PIHOLE_DIRECTORY}/${PH_CNAME_CONF}.${GS_BACKUP_EXT}" 378 | RSYNC_TARGET="${OS_TMP}/${PH_CNAME_CONF}.${GS_BACKUP_EXT}" 379 | create_rsync_cmd 380 | 381 | MESSAGE="${UI_REPLACE_LOCAL} ${UI_CNAME_NAME}" 382 | echo_stat 383 | sudo mv ${OS_TMP}/${PH_CNAME_CONF}.${GS_BACKUP_EXT} ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} >/dev/null 2>&1 384 | error_validate 385 | 386 | validate_cname_permissions 387 | fi 388 | } 389 | 390 | ## Pull DHCP 391 | function pull_gs_sdhcp { 392 | if [ "$REMOTE_SDHCP_DNS" == "1" ]; then 393 | backup_local_sdhcp 394 | backup_remote_sdhcp 395 | 396 | MESSAGE="${UI_PULL_REMOTE} ${UI_SDHCP_NAME}" 397 | echo_stat 398 | RSYNC_REPATH="sudo rsync" 399 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PIHOLE_DIRECTORY}/${PH_SDHCP_CONF}.${GS_BACKUP_EXT}" 400 | RSYNC_TARGET="${OS_TMP}/${PH_SDHCP_CONF}.${GS_BACKUP_EXT}" 401 | create_rsync_cmd 402 | 403 | MESSAGE="${UI_REPLACE_LOCAL} ${UI_SDHCP_NAME}" 404 | echo_stat 405 | sudo mv ${OS_TMP}/${PH_SDHCP_CONF}.${GS_BACKUP_EXT} ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} >/dev/null 2>&1 406 | error_validate 407 | 408 | validate_sdhcp_permissions 409 | fi 410 | } 411 | 412 | ## Pull Reload 413 | function pull_gs_reload { 414 | sleep 1 415 | 416 | MESSAGE="Updating local FTLDNS configuration" 417 | echo_stat 418 | ${PH_EXEC} restartdns reload-lists >/dev/null 2>&1 419 | error_validate 420 | 421 | if [ "${GS_TASK_TYPE}" == SMART ]; then 422 | if [ "${REMOTE_DNS_CHANGE}" == "1" ] || [ "${LOCAL_DNS_CHANGE}" == "1" ] || [ "${REMOTE_CNAME_CHANGE}" == "1" ] || [ "${LOCAL_CNAME_CHANGE}" == "1" ] || [ "${REMOTE_SDHCP_CHANGE}" == "1" ] || [ "${LOCAL_SDHCP_CHANGE}" == "1" ]; then 423 | MESSAGE="${UI_FTLDNS_CONFIG_PULL_RELOAD}" 424 | echo_stat 425 | ${PH_EXEC} restartdns >/dev/null 2>&1 426 | error_validate 427 | fi 428 | else 429 | MESSAGE="${UI_FTLDNS_CONFIG_PULL_RELOAD}" 430 | echo_stat 431 | ${PH_EXEC} restartdns >/dev/null 2>&1 432 | error_validate 433 | fi 434 | } 435 | 436 | ## Pull Function 437 | function pull_gs { 438 | previous_md5 439 | md5_compare 440 | pull_gs_grav 441 | pull_gs_custom 442 | pull_gs_cname 443 | pull_gs_sdhcp 444 | pull_gs_reload 445 | md5_recheck 446 | logs_export 447 | exit_with_changes 448 | } 449 | 450 | ## Push Task 451 | function task_push { 452 | start_gs 453 | 454 | GS_TASK_TYPE='PUSH' 455 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 456 | echo_good 457 | 458 | show_target 459 | validate_ph_folders 460 | validate_dns_folders 461 | push_gs 462 | exit 463 | } 464 | 465 | ## Push Gravity 466 | function push_gs_grav { 467 | backup_remote_gravity 468 | backup_local_gravity 469 | backup_local_gravity_integrity 470 | 471 | MESSAGE="${UI_PUSH_LOCAL} ${UI_GRAVITY_NAME}" 472 | echo_stat 473 | RSYNC_REPATH="sudo rsync" 474 | RSYNC_SOURCE="${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}" 475 | RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}" 476 | create_rsync_cmd 477 | 478 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_GRAVITY_NAME}" 479 | echo_stat 480 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 481 | CMD_REQUESTED="sudo chown ${REMOTE_FILE_OWNER} ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}" 482 | create_ssh_cmd 483 | 484 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_GRAVITY_NAME}" 485 | echo_stat 486 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 487 | CMD_REQUESTED="sudo chmod 664 ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}" 488 | create_ssh_cmd 489 | } 490 | 491 | ## Push Custom 492 | function push_gs_custom { 493 | if [ "$REMOTE_PH_CUSTOM_DNS" == "1" ]; then 494 | backup_remote_custom 495 | backup_local_custom 496 | 497 | MESSAGE="${UI_PUSH_LOCAL} ${UI_CUSTOM_NAME}" 498 | echo_stat 499 | RSYNC_REPATH="sudo rsync" 500 | RSYNC_SOURCE="${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}.${GS_BACKUP_EXT}" 501 | RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}" 502 | create_rsync_cmd 503 | 504 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_CUSTOM_NAME}" 505 | echo_stat 506 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 507 | CMD_REQUESTED="sudo chown ${REMOTE_FILE_OWNER} ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}" 508 | create_ssh_cmd 509 | 510 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_CUSTOM_NAME}" 511 | echo_stat 512 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 513 | CMD_REQUESTED="sudo chmod 644 ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}" 514 | create_ssh_cmd 515 | fi 516 | } 517 | 518 | ## Push Custom 519 | function push_gs_cname { 520 | if [ "$REMOTE_CNAME_DNS" == "1" ]; then 521 | backup_remote_cname 522 | backup_local_cname 523 | 524 | MESSAGE="${UI_PUSH_LOCAL} ${UI_CNAME_NAME}" 525 | echo_stat 526 | RSYNC_REPATH="sudo rsync" 527 | RSYNC_SOURCE="${LOCAL_PIHOLE_DIRECTORY}/${PH_CNAME_CONF}.${GS_BACKUP_EXT}" 528 | RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}" 529 | create_rsync_cmd 530 | 531 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_CNAME_NAME}" 532 | echo_stat 533 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 534 | CMD_REQUESTED="sudo chown ${REMOTE_FILE_OWNER} ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}" 535 | create_ssh_cmd 536 | 537 | 538 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_CNAME_NAME}" 539 | echo_stat 540 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 541 | CMD_REQUESTED="sudo chmod 644 ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}" 542 | create_ssh_cmd 543 | fi 544 | } 545 | 546 | ## Push Custom 547 | function push_gs_sdhcp { 548 | if [ "$REMOTE_SDHCP_DNS" == "1" ]; then 549 | backup_remote_sdhcp 550 | backup_local_sdhcp 551 | 552 | MESSAGE="${UI_PUSH_LOCAL} ${UI_SDHCP_NAME}" 553 | echo_stat 554 | RSYNC_REPATH="sudo rsync" 555 | RSYNC_SOURCE="${LOCAL_PIHOLE_DIRECTORY}/${PH_SDHCP_CONF}.${GS_BACKUP_EXT}" 556 | RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}" 557 | create_rsync_cmd 558 | 559 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_SDHCP_NAME}" 560 | echo_stat 561 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 562 | CMD_REQUESTED="sudo chown ${REMOTE_FILE_OWNER} ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}" 563 | create_ssh_cmd 564 | 565 | 566 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_SDHCP_NAME}" 567 | echo_stat 568 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 569 | CMD_REQUESTED="sudo chmod 644 ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}" 570 | create_ssh_cmd 571 | fi 572 | } 573 | 574 | ## Push Reload 575 | function push_gs_reload { 576 | sleep 1 577 | 578 | MESSAGE="Updating remote FTLDNS configuration" 579 | echo_stat 580 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 581 | CMD_REQUESTED="${RH_EXEC} restartdns reload-lists" 582 | create_ssh_cmd 583 | 584 | if [ "${GS_TASK_TYPE}" == SMART ]; then 585 | if [ "${REMOTE_DNS_CHANGE}" == "1" ] || [ "${LOCAL_DNS_CHANGE}" == "1" ] || [ "${REMOTE_CNAME_CHANGE}" == "1" ] || [ "${LOCAL_CNAME_CHANGE}" == "1" ] || [ "${REMOTE_SDHCP_CHANGE}" == "1" ] || [ "${LOCAL_SDHCP_CHANGE}" == "1" ]; then 586 | MESSAGE="${UI_FTLDNS_CONFIG_PUSH_RELOAD}" 587 | echo_stat 588 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 589 | CMD_REQUESTED="${RH_EXEC} restartdns" 590 | create_ssh_cmd 591 | fi 592 | else 593 | MESSAGE="${UI_FTLDNS_CONFIG_PUSH_RELOAD}" 594 | echo_stat 595 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 596 | CMD_REQUESTED="${RH_EXEC} restartdns" 597 | create_ssh_cmd 598 | fi 599 | } 600 | 601 | ## Push Function 602 | function push_gs { 603 | previous_md5 604 | md5_compare 605 | push_gs_grav 606 | push_gs_custom 607 | push_gs_cname 608 | push_gs_sdhcp 609 | push_gs_reload 610 | md5_recheck 611 | logs_export 612 | exit_with_changes 613 | } 614 | 615 | ## Smart Task 616 | function task_smart { 617 | start_gs 618 | 619 | GS_TASK_TYPE='SMART' 620 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 621 | echo_good 622 | 623 | show_target 624 | validate_ph_folders 625 | validate_dns_folders 626 | smart_gs 627 | exit 628 | } 629 | 630 | ## Smart Sync Function 631 | function smart_gs { 632 | MESSAGE="Starting ${GS_TASK_TYPE} Analysis" 633 | echo_info 634 | 635 | previous_md5 636 | md5_compare 637 | 638 | REMOTE_GRAVITY_CHANGE="0" 639 | LOCAL_GRAVITY_CHANGE="0" 640 | REMOTE_DNS_CHANGE="0" 641 | LOCAL_DNS_CHANGE="0" 642 | REMOTE_CNAME_CHANGE="0" 643 | LOCAL_CNAME_CHANGE="0" 644 | REMOTE_SDHCP_CHANGE="0" 645 | LOCAL_SDHCP_CHANGE="0" 646 | 647 | if [ "${REMOTE_DB_MD5}" != "${LAST_REMOTE_DB_MD5}" ]; then 648 | REMOTE_GRAVITY_CHANGE="1" 649 | fi 650 | 651 | if [ "${LOCAL_DB_MD5}" != "${LAST_LOCAL_DB_MD5}" ]; then 652 | LOCAL_GRAVITY_CHANGE="1" 653 | fi 654 | 655 | if [ "${REMOTE_GRAVITY_CHANGE}" == "${LOCAL_GRAVITY_CHANGE}" ]; then 656 | if [ "${REMOTE_GRAVITY_CHANGE}" != "0" ]; then 657 | MESSAGE="Both ${UI_GRAVITY_NAME} have changed" 658 | echo_warn 659 | 660 | REMOTE_GRAVITY_DATE=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}") 661 | LOCAL_GRAVITY_DATE=$(stat -c %Y ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}) 662 | 663 | if (( "$REMOTE_GRAVITY_DATE" >= "$LOCAL_GRAVITY_DATE" )); then 664 | MESSAGE="Remote ${UI_GRAVITY_NAME} was last changed" 665 | echo_warn 666 | 667 | pull_gs_grav 668 | GS_PULL_RESTART="1" 669 | else 670 | MESSAGE="Local ${UI_GRAVITY_NAME} was last changed" 671 | echo_warn 672 | 673 | push_gs_grav 674 | GS_PUSH_RESTART="1" 675 | fi 676 | fi 677 | else 678 | if [ "${REMOTE_GRAVITY_CHANGE}" != "0" ]; then 679 | pull_gs_grav 680 | GS_PULL_RESTART="1" 681 | elif [ "${LOCAL_GRAVITY_CHANGE}" != "0" ]; then 682 | push_gs_grav 683 | GS_PUSH_RESTART="1" 684 | fi 685 | fi 686 | 687 | if [ "${REMOTE_CL_MD5}" != "${LAST_REMOTE_CL_MD5}" ]; then 688 | REMOTE_DNS_CHANGE="1" 689 | fi 690 | 691 | if [ "${LOCAL_CL_MD5}" != "${LAST_LOCAL_CL_MD5}" ]; then 692 | LOCAL_DNS_CHANGE="1" 693 | fi 694 | 695 | if [ -f "${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}" ]; then 696 | if [ "${REMOTE_DNS_CHANGE}" == "${LOCAL_DNS_CHANGE}" ]; then 697 | if [ "${REMOTE_DNS_CHANGE}" != "0" ]; then 698 | MESSAGE="Both ${UI_CUSTOM_NAME} have changed" 699 | echo_warn 700 | 701 | REMOTE_DNS_DATE=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}") 702 | LOCAL_DNS_DATE=$(stat -c %Y ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}) 703 | 704 | if (( "$REMOTE_DNS_DATE" >= "$LOCAL_DNS_DATE" )); then 705 | MESSAGE="Remote ${UI_CUSTOM_NAME} was last changed" 706 | echo_warn 707 | 708 | pull_gs_custom 709 | GS_PULL_RESTART="1" 710 | else 711 | MESSAGE="Local ${UI_CUSTOM_NAME} was last changed" 712 | echo_warn 713 | 714 | push_gs_custom 715 | GS_PUSH_RESTART="1" 716 | fi 717 | fi 718 | else 719 | if [ "${REMOTE_DNS_CHANGE}" != "0" ]; then 720 | pull_gs_custom 721 | GS_PULL_RESTART="1" 722 | elif [ "${LOCAL_DNS_CHANGE}" != "0" ]; then 723 | push_gs_custom 724 | GS_PUSH_RESTART="1" 725 | fi 726 | fi 727 | else 728 | pull_gs_custom 729 | GS_PULL_RESTART="1" 730 | fi 731 | 732 | if [ "${REMOTE_CN_MD5}" != "${LAST_REMOTE_CN_MD5}" ]; then 733 | REMOTE_CNAME_CHANGE="1" 734 | fi 735 | 736 | if [ "${LOCAL_CN_MD5}" != "${LAST_LOCAL_CN_MD5}" ]; then 737 | LOCAL_CNAME_CHANGE="1" 738 | fi 739 | 740 | if [ -f "${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}" ]; then 741 | if [ "${REMOTE_CNAME_CHANGE}" == "${LOCAL_CNAME_CHANGE}" ]; then 742 | if [ "${REMOTE_CNAME_CHANGE}" != "0" ]; then 743 | MESSAGE="Both ${UI_CNAME_NAME} have Changed" 744 | echo_warn 745 | 746 | REMOTE_CNAME_DATE=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}") 747 | LOCAL_CNAME_DATE=$(stat -c %Y ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}) 748 | 749 | if (( "$REMOTE_CNAME_DATE" >= "$LOCAL_CNAME_DATE" )); then 750 | MESSAGE="Remote ${UI_CNAME_NAME} was last changed" 751 | echo_warn 752 | 753 | pull_gs_cname 754 | GS_PULL_RESTART="1" 755 | else 756 | MESSAGE="Local ${UI_CNAME_NAME} was last changed" 757 | echo_warn 758 | 759 | push_gs_cname 760 | GS_PUSH_RESTART="1" 761 | fi 762 | fi 763 | else 764 | if [ "${REMOTE_CNAME_CHANGE}" != "0" ]; then 765 | pull_gs_cname 766 | GS_PULL_RESTART="1" 767 | elif [ "${LOCAL_CNAME_CHANGE}" != "0" ]; then 768 | push_gs_cname 769 | GS_PUSH_RESTART="1" 770 | fi 771 | fi 772 | else 773 | pull_gs_cname 774 | GS_PULL_RESTART="1" 775 | fi 776 | 777 | if [ "${REMOTE_SDHCP_MD5}" != "${LAST_REMOTE_SDHCP_MD5}" ]; then 778 | REMOTE_SDHCP_CHANGE="1" 779 | fi 780 | 781 | if [ "${LOCAL_SDHCP_MD5}" != "${LAST_LOCAL_SDHCP_MD5}" ]; then 782 | LOCAL_SDHCP_CHANGE="1" 783 | fi 784 | 785 | if [ -f "${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}" ]; then 786 | if [ "${REMOTE_SDHCP_CHANGE}" == "${LOCAL_SDHCP_CHANGE}" ]; then 787 | if [ "${REMOTE_SDHCP_CHANGE}" != "0" ]; then 788 | MESSAGE="Both ${UI_SDHCP_NAME} have Changed" 789 | echo_warn 790 | 791 | REMOTE_SDHCP_DATE=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "stat -c %Y ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}") 792 | LOCAL_SDHCP_DATE=$(stat -c %Y ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}) 793 | 794 | if (( "$REMOTE_SDHCP_DATE" >= "$LOCAL_SDHCP_DATE" )); then 795 | MESSAGE="Remote ${UI_SDHCP_NAME} was last changed" 796 | echo_warn 797 | 798 | pull_gs_sdhcp 799 | GS_PULL_RESTART="1" 800 | else 801 | MESSAGE="Local ${UI_SDHCP_NAME} was last changed" 802 | echo_warn 803 | 804 | push_gs_sdhcp 805 | GS_PUSH_RESTART="1" 806 | fi 807 | fi 808 | else 809 | if [ "${REMOTE_SDHCP_CHANGE}" != "0" ]; then 810 | pull_gs_sdhcp 811 | GS_PULL_RESTART="1" 812 | elif [ "${LOCAL_SDHCP_CHANGE}" != "0" ]; then 813 | push_gs_sdhcp 814 | GS_PUSH_RESTART="1" 815 | fi 816 | fi 817 | else 818 | pull_gs_sdhcp 819 | GS_PULL_RESTART="1" 820 | fi 821 | 822 | if [ "$GS_PULL_RESTART" == "1" ]; then 823 | pull_gs_reload 824 | fi 825 | 826 | if [ "$GS_PUSH_RESTART" == "1" ]; then 827 | push_gs_reload 828 | fi 829 | 830 | md5_recheck 831 | 832 | logs_export 833 | exit_with_changes 834 | } 835 | 836 | function backup_local_gravity { 837 | MESSAGE="${UI_BACKUP_LOCAL} ${UI_GRAVITY_NAME}" 838 | echo_stat 839 | 840 | if [ "$LOCAL_PIHOLE_TYPE" == "default" ]; then 841 | sudo ${FTL_EXEC} sql ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} ".backup '${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}'" 842 | error_validate 843 | elif [ "$LOCAL_PIHOLE_TYPE" == "docker" ]; then 844 | sudo ${FTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} ".backup '${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}'" 845 | error_validate 846 | elif [ "$LOCAL_PIHOLE_TYPE" == "podman" ]; then 847 | sudo ${FTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} ".backup '${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}'" 848 | error_validate 849 | fi 850 | } 851 | 852 | function backup_local_gravity_integrity { 853 | MESSAGE="${UI_BACKUP_INTEGRITY}" 854 | echo_stat 855 | 856 | sleep $GS_BACKUP_INTEGRITY_WAIT 857 | 858 | if [ "$LOCAL_PIHOLE_TYPE" == "default" ]; then 859 | LOCAL_INTEGRITY_CHECK=$(${FTL_EXEC} sql ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 'PRAGMA integrity_check;' | sed 's/\s.*$//') 860 | error_validate 861 | elif [ "$LOCAL_PIHOLE_TYPE" == "docker" ]; then 862 | LOCAL_INTEGRITY_CHECK=$(${FTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 'PRAGMA integrity_check;' | sed 's/\s.*$//') 863 | error_validate 864 | elif [ "$LOCAL_PIHOLE_TYPE" == "podman" ]; then 865 | LOCAL_INTEGRITY_CHECK=$(${FTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 'PRAGMA integrity_check;' | sed 's/\s.*$//') 866 | error_validate 867 | fi 868 | 869 | if [ "$LOCAL_INTEGRITY_CHECK" != 'ok' ]; then 870 | MESSAGE="${UI_BACKUP_INTEGRITY_FAILED} ${UI_GRAVITY_NAME}" 871 | echo_fail 872 | 873 | MESSAGE="${UI_BACKUP_INTEGRITY_DELETE} ${UI_GRAVITY_NAME}" 874 | echo_stat 875 | 876 | sudo rm ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 877 | error_validate 878 | 879 | exit_no_change 880 | fi 881 | } 882 | 883 | function backup_local_custom { 884 | if [ -f ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} ]; then 885 | MESSAGE="${UI_BACKUP_LOCAL} ${UI_CUSTOM_NAME}" 886 | echo_stat 887 | 888 | sudo cp ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}.${GS_BACKUP_EXT} 889 | error_validate 890 | else 891 | MESSAGE="No local ${PH_CUSTOM_DNS} detected" 892 | echo_warn 893 | fi 894 | } 895 | 896 | function backup_local_cname { 897 | if [ -f ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} ]; then 898 | MESSAGE="${UI_BACKUP_LOCAL} ${UI_CNAME_NAME}" 899 | echo_stat 900 | 901 | sudo cp ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} ${LOCAL_PIHOLE_DIRECTORY}/${PH_CNAME_CONF}.${GS_BACKUP_EXT} 902 | error_validate 903 | else 904 | MESSAGE="No local ${PH_CNAME_CONF} detected" 905 | echo_warn 906 | fi 907 | } 908 | 909 | function backup_local_sdhcp { 910 | if [ -f ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} ]; then 911 | MESSAGE="${UI_BACKUP_LOCAL} ${UI_SDHCP_NAME}" 912 | echo_stat 913 | 914 | sudo cp ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} ${LOCAL_PIHOLE_DIRECTORY}/${PH_SDHCP_CONF}.${GS_BACKUP_EXT} 915 | error_validate 916 | else 917 | MESSAGE="No local ${PH_SDHCP_CONF} detected" 918 | echo_warn 919 | fi 920 | } 921 | 922 | function backup_remote_gravity { 923 | MESSAGE="${UI_BACKUP_REMOTE} ${UI_GRAVITY_NAME}" 924 | echo_stat 925 | 926 | if [ "$REMOTE_PIHOLE_TYPE" == "default" ]; then 927 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 928 | CMD_REQUESTED="sudo ${RFTL_EXEC} sql ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} \".backup '${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}'\"" 929 | create_ssh_cmd 930 | elif [ "$REMOTE_PIHOLE_TYPE" == "docker" ]; then 931 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 932 | CMD_REQUESTED="sudo ${RFTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} \".backup '${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}'\"" 933 | create_ssh_cmd 934 | elif [ "$REMOTE_PIHOLE_TYPE" == "podman" ]; then 935 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 936 | CMD_REQUESTED="sudo ${RFTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} \".backup '${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}'\"" 937 | create_ssh_cmd 938 | fi 939 | } 940 | 941 | function backup_remote_gravity_integrity { 942 | MESSAGE="${UI_BACKUP_INTEGRITY}" 943 | echo_stat 944 | 945 | sleep $GS_BACKUP_INTEGRITY_WAIT 946 | 947 | if [ "$REMOTE_PIHOLE_TYPE" == "default" ]; then 948 | REMOTE_INTEGRITY_CHECK=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${RFTL_EXEC} sql ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 'PRAGMA integrity_check;'" | sed 's/\s.*$//') 949 | error_validate 950 | elif [ "$REMOTE_PIHOLE_TYPE" == "docker" ]; then 951 | REMOTE_INTEGRITY_CHECK=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${RFTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 'PRAGMA integrity_check;'" | sed 's/\s.*$//') 952 | error_validate 953 | elif [ "$REMOTE_PIHOLE_TYPE" == "podman" ]; then 954 | REMOTE_INTEGRITY_CHECK=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "${RFTL_EXEC} sql ${DEFAULT_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT} 'PRAGMA integrity_check;'" | sed 's/\s.*$//') 955 | error_validate 956 | fi 957 | 958 | if [ "$REMOTE_INTEGRITY_CHECK" != 'ok' ]; then 959 | MESSAGE="${UI_BACKUP_INTEGRITY_FAILED} ${UI_GRAVITY_NAME}" 960 | echo_fail 961 | 962 | MESSAGE="${UI_BACKUP_INTEGRITY_DELETE} ${UI_GRAVITY_NAME}" 963 | echo_stat 964 | 965 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 966 | CMD_REQUESTED="sudo rm ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}.${GS_BACKUP_EXT}" 967 | create_ssh_cmd 968 | 969 | exit_no_change 970 | fi 971 | } 972 | 973 | function backup_remote_custom { 974 | MESSAGE="${UI_BACKUP_REMOTE} ${UI_CUSTOM_NAME}" 975 | echo_stat 976 | 977 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 978 | CMD_REQUESTED="sudo cp ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}.${GS_BACKUP_EXT}" 979 | create_ssh_cmd 980 | } 981 | 982 | function backup_remote_cname { 983 | MESSAGE="${UI_BACKUP_REMOTE} ${UI_CNAME_NAME}" 984 | echo_stat 985 | 986 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 987 | CMD_REQUESTED="sudo cp ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} ${REMOTE_PIHOLE_DIRECTORY}/${PH_CNAME_CONF}.${GS_BACKUP_EXT}" 988 | create_ssh_cmd 989 | } 990 | 991 | function backup_remote_sdhcp { 992 | MESSAGE="${UI_BACKUP_REMOTE} ${UI_SDHCP_NAME}" 993 | echo_stat 994 | 995 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 996 | CMD_REQUESTED="sudo cp ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} ${REMOTE_PIHOLE_DIRECTORY}/${PH_SDHCP_CONF}.${GS_BACKUP_EXT}" 997 | create_ssh_cmd 998 | } 999 | 1000 | function backup_cleanup { 1001 | MESSAGE="Purging backups" 1002 | echo_stat 1003 | # git clean -fq 1004 | sudo rm -f ${LOCAL_PIHOLE_DIRECTORY}/*.${GS_BACKUP_EXT} 1005 | error_validate 1006 | 1007 | # MESSAGE="${UI_BACKUP_PURGE} on remote" 1008 | # echo_stat 1009 | # CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 1010 | # CMD_REQUESTED="sudo rm -f ${REMOTE_PIHOLE_DIRECTORY}/*.${GS_BACKUP_EXT}" 1011 | # create_ssh_cmd 1012 | } 1013 | 1014 | function md5_compare { 1015 | GS_HASH_MARK='0' 1016 | 1017 | MESSAGE="${UI_HASHING_HASHING} ${UI_GRAVITY_NAME}" 1018 | echo_stat 1019 | REMOTE_DB_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}" | sed 's/\s.*$//') 1020 | error_validate 1021 | 1022 | MESSAGE="${UI_HASHING_COMPARING} ${UI_GRAVITY_NAME}" 1023 | echo_stat 1024 | LOCAL_DB_MD5=$(md5sum ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} | sed 's/\s.*$//') 1025 | error_validate 1026 | 1027 | if [ "$REMOTE_DB_MD5" == "$LAST_REMOTE_DB_MD5" ] && [ "$LOCAL_DB_MD5" == "$LAST_LOCAL_DB_MD5" ]; then 1028 | GS_HASH_MARK=$((GS_HASH_MARK+0)) 1029 | else 1030 | MESSAGE="${UI_HASHING_DIFFERENCE} ${UI_GRAVITY_NAME}" 1031 | echo_warn 1032 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1033 | fi 1034 | 1035 | if [ -f ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} ]; then 1036 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}; then 1037 | REMOTE_PH_CUSTOM_DNS="1" 1038 | MESSAGE="${UI_HASHING_HASHING} ${UI_CUSTOM_NAME}" 1039 | echo_stat 1040 | 1041 | REMOTE_CL_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} | sed 's/\s.*$//'") 1042 | error_validate 1043 | 1044 | MESSAGE="${UI_HASHING_COMPARING} ${UI_CUSTOM_NAME}" 1045 | echo_stat 1046 | LOCAL_CL_MD5=$(md5sum ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} | sed 's/\s.*$//') 1047 | error_validate 1048 | 1049 | if [ "$REMOTE_CL_MD5" == "$LAST_REMOTE_CL_MD5" ] && [ "$LOCAL_CL_MD5" == "$LAST_LOCAL_CL_MD5" ]; then 1050 | GS_HASH_MARK=$((GS_HASH_MARK+0)) 1051 | else 1052 | MESSAGE="${UI_HASHING_DIFFERENCE} ${UI_CUSTOM_NAME}" 1053 | echo_warn 1054 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1055 | fi 1056 | else 1057 | MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1058 | echo_warn 1059 | fi 1060 | else 1061 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}; then 1062 | REMOTE_PH_CUSTOM_DNS="1" 1063 | MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_DETECTED} ${UI_HASHING_REMOTE}" 1064 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1065 | echo_warn 1066 | fi 1067 | MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_LOCAL}" 1068 | echo_warn 1069 | fi 1070 | 1071 | if [ -f ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} ]; then 1072 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}; then 1073 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 1074 | CMD_REQUESTED="sudo touch ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}" 1075 | create_ssh_cmd 1076 | 1077 | REMOTE_CNAME_DNS="1" 1078 | MESSAGE="${UI_HASHING_HASHING} ${UI_CNAME_NAME}" 1079 | echo_stat 1080 | 1081 | REMOTE_CN_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} | sed 's/\s.*$//'") 1082 | error_validate 1083 | 1084 | MESSAGE="${UI_HASHING_COMPARING} ${UI_CNAME_NAME}" 1085 | echo_stat 1086 | LOCAL_CN_MD5=$(md5sum ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} | sed 's/\s.*$//') 1087 | error_validate 1088 | 1089 | if [ "$REMOTE_CN_MD5" == "$LAST_REMOTE_CN_MD5" ] && [ "$LOCAL_CN_MD5" == "$LAST_LOCAL_CN_MD5" ]; then 1090 | GS_HASH_MARK=$((GS_HASH_MARK+0)) 1091 | else 1092 | MESSAGE="${UI_HASHING_DIFFERENCE} ${UI_CNAME_NAME}" 1093 | echo_warn 1094 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1095 | fi 1096 | else 1097 | MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1098 | echo_warn 1099 | fi 1100 | else 1101 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}; then 1102 | REMOTE_CNAME_DNS="1" 1103 | MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_DETECTED} ${UI_HASHING_REMOTE}" 1104 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1105 | echo_warn 1106 | fi 1107 | 1108 | MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_LOCAL}" 1109 | echo_warn 1110 | fi 1111 | 1112 | if [ -f ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} ]; then 1113 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}; then 1114 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 1115 | CMD_REQUESTED="sudo touch ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}" 1116 | create_ssh_cmd 1117 | 1118 | REMOTE_SDHCP_DNS="1" 1119 | MESSAGE="${UI_HASHING_HASHING} ${UI_SDHCP_NAME}" 1120 | echo_stat 1121 | 1122 | REMOTE_SDHCP_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} | sed 's/\s.*$//'") 1123 | error_validate 1124 | 1125 | MESSAGE="${UI_HASHING_COMPARING} ${UI_SDHCP_NAME}" 1126 | echo_stat 1127 | LOCAL_SDHCP_MD5=$(md5sum ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} | sed 's/\s.*$//') 1128 | error_validate 1129 | 1130 | if [ "$REMOTE_SDHCP_MD5" == "$LAST_REMOTE_SDHCP_MD5" ] && [ "$LOCAL_SDHCP_MD5" == "$LAST_LOCAL_SDHCP_MD5" ]; then 1131 | GS_HASH_MARK=$((GS_HASH_MARK+0)) 1132 | else 1133 | MESSAGE="${UI_HASHING_DIFFERENCE} ${UI_SDHCP_NAME}" 1134 | echo_warn 1135 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1136 | fi 1137 | else 1138 | MESSAGE="${UI_SDHCP_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1139 | echo_warn 1140 | fi 1141 | else 1142 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}; then 1143 | REMOTE_SDHCP_DNS="1" 1144 | MESSAGE="${UI_SDHCP_NAME} ${UI_HASHING_DETECTED} ${UI_HASHING_REMOTE}" 1145 | GS_HASH_MARK=$((GS_HASH_MARK+1)) 1146 | echo_warn 1147 | fi 1148 | 1149 | MESSAGE="${UI_SDHCP_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_LOCAL}" 1150 | echo_warn 1151 | fi 1152 | 1153 | if [ "$GS_HASH_MARK" != "0" ]; then 1154 | MESSAGE="Replication of ${UI_CORE_APP} settings is required" 1155 | echo_warn 1156 | GS_HASH_MARK=$((GS_HASH_MARK+0)) 1157 | else 1158 | MESSAGE="No replication is required at this time" 1159 | echo_warn 1160 | exit_no_change 1161 | fi 1162 | } 1163 | 1164 | function previous_md5 { 1165 | if [ -f "${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG}" ]; then 1166 | LAST_REMOTE_DB_MD5=$(sed "1q;d" ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG}) 1167 | LAST_LOCAL_DB_MD5=$(sed "2q;d" ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG}) 1168 | else 1169 | LAST_REMOTE_DB_MD5="0" 1170 | LAST_LOCAL_DB_MD5="0" 1171 | fi 1172 | 1173 | if [ -f "${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG}" ]; then 1174 | LAST_REMOTE_CL_MD5=$(sed "1q;d" ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG}) 1175 | LAST_LOCAL_CL_MD5=$(sed "2q;d" ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG}) 1176 | else 1177 | LAST_REMOTE_CL_MD5="0" 1178 | LAST_LOCAL_CL_MD5="0" 1179 | fi 1180 | 1181 | if [ -f "${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG}" ]; then 1182 | LAST_REMOTE_CN_MD5=$(sed "1q;d" ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG}) 1183 | LAST_LOCAL_CN_MD5=$(sed "2q;d" ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG}) 1184 | else 1185 | LAST_REMOTE_CN_MD5="0" 1186 | LAST_LOCAL_CN_MD5="0" 1187 | fi 1188 | 1189 | if [ -f "${GS_ETC_PATH}/${GS_SDHCP_CONF_MD5_LOG}" ]; then 1190 | LAST_REMOTE_SDHCP_MD5=$(sed "1q;d" ${GS_ETC_PATH}/${GS_SDHCP_CONF_MD5_LOG}) 1191 | LAST_LOCAL_SDHCP_MD5=$(sed "2q;d" ${GS_ETC_PATH}/${GS_SDHCP_CONF_MD5_LOG}) 1192 | else 1193 | LAST_REMOTE_SDHCP_MD5="0" 1194 | LAST_LOCAL_SDHCP_MD5="0" 1195 | fi 1196 | } 1197 | 1198 | function md5_recheck { 1199 | MESSAGE="Performing replicator diagnostics" 1200 | echo_prompt 1201 | 1202 | GS_HASH_MARK='0' 1203 | 1204 | MESSAGE="${UI_HASHING_REHASHING} ${UI_GRAVITY_NAME}" 1205 | echo_stat 1206 | REMOTE_DB_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI}" | sed 's/\s.*$//') 1207 | error_validate 1208 | 1209 | MESSAGE="${UI_HASHING_RECOMPARING} ${UI_GRAVITY_NAME}" 1210 | echo_stat 1211 | LOCAL_DB_MD5=$(md5sum ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} | sed 's/\s.*$//') 1212 | error_validate 1213 | 1214 | if [ -f ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} ]; then 1215 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}; then 1216 | REMOTE_PH_CUSTOM_DNS="1" 1217 | MESSAGE="${UI_HASHING_REHASHING} ${UI_CUSTOM_NAME}" 1218 | echo_stat 1219 | 1220 | REMOTE_CL_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} | sed 's/\s.*$//'") 1221 | error_validate 1222 | 1223 | MESSAGE="${UI_HASHING_RECOMPARING} ${UI_CUSTOM_NAME}" 1224 | echo_stat 1225 | LOCAL_CL_MD5=$(md5sum ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} | sed 's/\s.*$//') 1226 | error_validate 1227 | else 1228 | MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1229 | echo_warn 1230 | fi 1231 | else 1232 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS}; then 1233 | REMOTE_PH_CUSTOM_DNS="1" 1234 | MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_DETECTED} ${UI_HASHING_REMOTE}" 1235 | echo_warn 1236 | fi 1237 | MESSAGE="${UI_CUSTOM_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_LOCAL}" 1238 | echo_warn 1239 | fi 1240 | 1241 | if [ -f ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} ]; then 1242 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}; then 1243 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 1244 | CMD_REQUESTED="sudo touch ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}" 1245 | create_ssh_cmd 1246 | 1247 | REMOTE_CNAME_DNS="1" 1248 | MESSAGE="${UI_HASHING_REHASHING} ${UI_CNAME_NAME}" 1249 | echo_stat 1250 | 1251 | REMOTE_CN_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} | sed 's/\s.*$//'") 1252 | error_validate 1253 | 1254 | MESSAGE="${UI_HASHING_RECOMPARING} ${UI_CNAME_NAME}" 1255 | echo_stat 1256 | LOCAL_CN_MD5=$(md5sum ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} | sed 's/\s.*$//') 1257 | error_validate 1258 | else 1259 | MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1260 | echo_warn 1261 | fi 1262 | else 1263 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF}; then 1264 | REMOTE_CNAME_DNS="1" 1265 | MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1266 | echo_warn 1267 | fi 1268 | 1269 | MESSAGE="${UI_CNAME_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_LOCAL}" 1270 | echo_warn 1271 | fi 1272 | 1273 | if [ -f ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} ]; then 1274 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}; then 1275 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 1276 | CMD_REQUESTED="sudo touch ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}" 1277 | create_ssh_cmd 1278 | 1279 | REMOTE_SDHCP_DNS="1" 1280 | MESSAGE="${UI_HASHING_REHASHING} ${UI_SDHCP_NAME}" 1281 | echo_stat 1282 | 1283 | REMOTE_SDHCP_MD5=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "md5sum ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} | sed 's/\s.*$//'") 1284 | error_validate 1285 | 1286 | MESSAGE="${UI_HASHING_RECOMPARING} ${UI_SDHCP_NAME}" 1287 | echo_stat 1288 | LOCAL_SDHCP_MD5=$(md5sum ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} | sed 's/\s.*$//') 1289 | error_validate 1290 | else 1291 | MESSAGE="${UI_SDHCP_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1292 | echo_warn 1293 | fi 1294 | else 1295 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF}; then 1296 | REMOTE_SDHCP_DNS="1" 1297 | MESSAGE="${UI_SDHCP_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_REMOTE}" 1298 | echo_warn 1299 | fi 1300 | 1301 | MESSAGE="${UI_SDHCP_NAME} ${UI_HASHING_NOT_DETECTED} ${UI_HASHING_LOCAL}" 1302 | echo_warn 1303 | fi 1304 | } 1305 | 1306 | ## Determine SSH Pathways 1307 | function create_ssh_cmd { 1308 | timeout --preserve-status ${CMD_TIMEOUT} ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i ${GS_SSH_PKIF} -o StrictHostKeyChecking=no ${REMOTE_USER}@${REMOTE_HOST} "${CMD_REQUESTED}" 1309 | error_validate 1310 | } 1311 | 1312 | ## Determine SSH Pathways 1313 | function create_rsync_cmd { 1314 | rsync --rsync-path="${RSYNC_REPATH}" -e "${OS_SSH_CMD} -p ${GS_SSH_PORT} -i ${GS_SSH_PKIF}" ${RSYNC_SOURCE} ${RSYNC_TARGET} >/dev/null 2>&1 1315 | error_validate 1316 | } 1317 | 1318 | function generate_ssh_key { 1319 | if [ -z $INPUT_REMOTE_PASS ]; then 1320 | if [ -f ${GS_SSH_PKIF} ]; then 1321 | MESSAGE="Using existing SSH key" 1322 | echo_good_clean 1323 | else 1324 | if hash ssh-keygen >/dev/null 2>&1; then 1325 | MESSAGE="Generating new SSH key" 1326 | echo_stat 1327 | 1328 | ssh-keygen -q -P "" -t rsa -f ${OS_TMP}/gravity-sync.rsa >/dev/null 2>&1 1329 | error_validate 1330 | 1331 | MESSAGE="Moving private key to ${GS_SSH_PKIF}" 1332 | sudo mv ${OS_TMP}/gravity-sync.rsa ${GS_SSH_PKIF} 1333 | error_validate 1334 | 1335 | MESSAGE="Moving public key to ${GS_SSH_PKIF}.pub" 1336 | sudo mv ${OS_TMP}/gravity-sync.rsa.pub ${GS_SSH_PKIF}.pub 1337 | error_validate 1338 | else 1339 | MESSAGE="No SSH-KEYGEN available" 1340 | echo_warn 1341 | exit_no_change 1342 | fi 1343 | fi 1344 | fi 1345 | } 1346 | 1347 | function export_ssh_key { 1348 | if [ -z $REMOTE_PASS ]; then 1349 | if [ -f ${GS_SSH_PKIF} ]; then 1350 | MESSAGE="Registering SSH key to ${REMOTE_HOST}" 1351 | echo_prompt 1352 | 1353 | ssh-copy-id -f -p ${GS_SSH_PORT} -i ${GS_SSH_PKIF}.pub ${REMOTE_USER}@${REMOTE_HOST} 1354 | else 1355 | MESSAGE="Error registering SSH key to ${REMOTE_HOST}" 1356 | echo_warn 1357 | fi 1358 | fi 1359 | } 1360 | 1361 | function show_target { 1362 | if [ "${GS_SSH_PORT}" != '22' ]; then 1363 | MESSAGE="Remote target ${REMOTE_USER}@${REMOTE_HOST}:${GS_SSH_PORT}" 1364 | else 1365 | MESSAGE="Remote target ${REMOTE_USER}@${REMOTE_HOST}" 1366 | fi 1367 | 1368 | echo_info 1369 | } 1370 | 1371 | ## Logs Task 1372 | function task_logs { 1373 | start_gs_no_config 1374 | 1375 | GS_TASK_TYPE='LOGS' 1376 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 1377 | echo_good 1378 | logs_gs 1379 | } 1380 | 1381 | ## Core Logging 1382 | ### Write Logs Out 1383 | function logs_export { 1384 | MESSAGE="Saving updated data hashes" 1385 | echo_stat 1386 | sudo rm -f ${GS_ETC_PATH}/*.md5 1387 | echo -e ${REMOTE_DB_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 1388 | echo -e ${LOCAL_DB_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 1389 | echo -e ${REMOTE_CL_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 1390 | echo -e ${LOCAL_CL_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 1391 | echo -e ${REMOTE_CN_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 1392 | echo -e ${LOCAL_CN_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 1393 | echo -e ${REMOTE_SDHCP_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_SDHCP_CONF_MD5_LOG} 1> /dev/null 1394 | echo -e ${LOCAL_SDHCP_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_SDHCP_CONF_MD5_LOG} 1> /dev/null 1395 | 1396 | if [ "${GS_PEERLESS_MODE}" != "1" ]; then 1397 | sudo rm -f ${OS_TMP}/*.md5 1398 | echo -e ${LOCAL_DB_MD5} | sudo tee -a ${OS_TMP}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 1399 | echo -e ${REMOTE_DB_MD5} | sudo tee -a ${OS_TMP}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 1400 | echo -e ${LOCAL_CL_MD5} | sudo tee -a ${OS_TMP}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 1401 | echo -e ${REMOTE_CL_MD5} | sudo tee -a ${OS_TMP}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 1402 | echo -e ${LOCAL_CN_MD5} | sudo tee -a ${OS_TMP}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 1403 | echo -e ${REMOTE_CN_MD5} | sudo tee -a ${OS_TMP}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 1404 | echo -e ${LOCAL_SDHCP_MD5} | sudo tee -a ${OS_TMP}/${GS_SDHCP_CONF_MD5_LOG} 1> /dev/null 1405 | echo -e ${REMOTE_SDHCP_MD5} | sudo tee -a ${OS_TMP}/${GS_SDHCP_CONF_MD5_LOG} 1> /dev/null 1406 | error_validate 1407 | 1408 | MESSAGE="Sending hashes to ${PROGRAM} peer" 1409 | echo_stat 1410 | 1411 | RSYNC_REPATH="sudo rsync" 1412 | RSYNC_SOURCE="${OS_TMP}/*.md5" 1413 | RSYNC_TARGET="${REMOTE_USER}@${REMOTE_HOST}:${GS_ETC_PATH}/" 1414 | create_rsync_cmd 1415 | 1416 | MESSAGE="Setting permissions on remote hashing files" 1417 | echo_stat 1418 | CMD_TIMEOUT=$GS_BACKUP_TIMEOUT 1419 | CMD_REQUESTED="sudo chmod 644 ${GS_ETC_PATH}/*.md5" 1420 | create_ssh_cmd 1421 | 1422 | sudo rm -f ${OS_TMP}/*.md5 1423 | fi 1424 | 1425 | MESSAGE="Logging successful ${GS_TASK_TYPE}" 1426 | echo_stat 1427 | echo -e "$(date) [${GS_TASK_TYPE}]" | sudo tee -a ${GS_ETC_PATH}/${GS_SYNCING_LOG} 1> /dev/null 1428 | error_validate 1429 | } 1430 | 1431 | ### Output Sync Logs 1432 | function logs_gs { 1433 | MESSAGE="Displaying output of previous jobs" 1434 | echo_info 1435 | 1436 | echo -e "${UI_LOGGING_RECENT_COMPLETE} ${YELLOW}SMART${NC}" 1437 | tail -n 7 "${GS_ETC_PATH}/${GS_SYNCING_LOG}" | grep SMART 1438 | echo -e "${UI_LOGGING_RECENT_COMPLETE} ${YELLOW}PULL${NC}" 1439 | tail -n 7 "${GS_ETC_PATH}/${GS_SYNCING_LOG}" | grep PULL 1440 | echo -e "${UI_LOGGING_RECENT_COMPLETE} ${YELLOW}PUSH${NC}" 1441 | tail -n 7 "${GS_ETC_PATH}/${GS_SYNCING_LOG}" | grep PUSH 1442 | 1443 | exit_no_change 1444 | } 1445 | 1446 | ## Validate Pi-hole Folders 1447 | function validate_ph_folders { 1448 | MESSAGE="${UI_VALIDATING} ${UI_CORE_APP}" 1449 | echo_stat 1450 | 1451 | if [ "$LOCAL_PIHOLE_TYPE" == "default" ]; then 1452 | if [ ! -f ${LOCAL_PIHOLE_BINARY} ]; then 1453 | MESSAGE="${UI_VALIDATING_FAIL_BINARY} ${UI_CORE_APP}" 1454 | echo_fail 1455 | exit_no_change 1456 | fi 1457 | elif [ "$LOCAL_PIHOLE_TYPE" == "docker" ]; then 1458 | PH_FTL_CHECK=$(sudo docker container ls | grep "${PIHOLE_CONTAINER_IMAGE}") 1459 | if [ "$PH_FTL_CHECK" == "" ]; then 1460 | MESSAGE="${UI_VALIDATING_FAIL_CONTAINER} ${UI_CORE_APP}" 1461 | echo_fail 1462 | exit_no_change 1463 | fi 1464 | elif [ "$LOCAL_PIHOLE_TYPE" == "podman" ]; then 1465 | PH_FTL_CHECK=$(sudo podman container ls | grep "${PIHOLE_CONTAINER_IMAGE}") 1466 | if [ "$PH_FTL_CHECK" == "" ]; then 1467 | MESSAGE="${UI_VALIDATING_FAIL_CONTAINER} ${UI_CORE_APP}" 1468 | echo_fail 1469 | exit_no_change 1470 | fi 1471 | fi 1472 | 1473 | if [ ! -d ${LOCAL_PIHOLE_DIRECTORY} ]; then 1474 | MESSAGE="${UI_VALIDATING_FAIL_FOLDER} ${UI_CORE_APP}" 1475 | echo_fail 1476 | exit_no_change 1477 | fi 1478 | 1479 | echo_good 1480 | } 1481 | 1482 | function detect_local_pihole { 1483 | MESSAGE="Detecting local ${UI_CORE_APP} installation" 1484 | echo_stat 1485 | 1486 | if hash pihole 2>/dev/null; then 1487 | LOCAL_PIHOLE_TYPE="default" 1488 | echo_good 1489 | elif hash docker 2>/dev/null; then 1490 | PH_FTL_CHECK=$(sudo docker container ls | grep ${PIHOLE_CONTAINER_IMAGE}) 1491 | if [ "$PH_FTL_CHECK" != "" ]; then 1492 | LOCAL_PIHOLE_TYPE="docker" 1493 | echo_good 1494 | else 1495 | LOCAL_PIHOLE_TYPE="none" 1496 | echo_fail 1497 | fi 1498 | elif hash podman 2>/dev/null; then 1499 | PH_FTL_CHECK=$(sudo podman container ls | grep ${PIHOLE_CONTAINER_IMAGE}) 1500 | if [ "$PH_FTL_CHECK" != "" ]; then 1501 | LOCAL_PIHOLE_TYPE="podman" 1502 | echo_good 1503 | else 1504 | LOCAL_PIHOLE_TYPE="none" 1505 | echo_fail 1506 | fi 1507 | else 1508 | LOCAL_PIHOLE_TYPE="none" 1509 | echo_fail 1510 | fi 1511 | } 1512 | 1513 | function detect_remote_pihole { 1514 | MESSAGE="Detecting remote ${UI_CORE_APP} installation" 1515 | echo_stat 1516 | 1517 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${REMOTE_PIHOLE_BINARY}; then 1518 | REMOTE_PIHOLE_TYPE="default" 1519 | echo_good 1520 | else 1521 | REMOTE_DETECT_DOCKER=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo ${REMOTE_DOCKER_BINARY} container ls | grep ${PIHOLE_CONTAINER_IMAGE}" 2>/dev/null) 1522 | REMOTE_DETECT_PODMAN=$(${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo ${REMOTE_PODMAN_BINARY} container ls | grep ${PIHOLE_CONTAINER_IMAGE}" 2>/dev/null) 1523 | 1524 | if [ "${REMOTE_DETECT_DOCKER}" != "" ]; then 1525 | REMOTE_PIHOLE_TYPE="docker" 1526 | MESSAGE="${MESSAGE} - docker" 1527 | echo_good 1528 | elif [ "${REMOTE_DETECT_PODMAN}" != "" ]; then 1529 | REMOTE_PIHOLE_TYPE="podman" 1530 | MESSAGE="${MESSAGE} - podman" 1531 | echo_good 1532 | else 1533 | REMOTE_PIHOLE_TYPE="none" 1534 | echo_fail 1535 | fi 1536 | fi 1537 | } 1538 | 1539 | function detect_gs_peer { 1540 | MESSAGE="Checking on peer" 1541 | echo_stat 1542 | 1543 | if ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} test -e ${GS_ETC_PATH}/${GS_CONFIG_FILE}; then 1544 | MESSAGE="${PROGRAM} remote peer is configured" 1545 | echo_good 1546 | else 1547 | GS_PEERLESS_MODE="1" 1548 | MESSAGE="${PROGRAM} falling back to peerless mode" 1549 | echo_good 1550 | 1551 | MESSAGE="Please configure ${PROGRAM} on remote host" 1552 | echo_warn 1553 | fi 1554 | } 1555 | 1556 | ## Validate DNSMASQ Folders 1557 | function validate_dns_folders { 1558 | MESSAGE="${UI_VALIDATING} ${UI_CORE_APP_DNS}" 1559 | echo_stat 1560 | 1561 | if [ ! -d ${LOCAL_DNSMASQ_DIRECTORY} ]; then 1562 | MESSAGE="${UI_VALIDATING_FAIL_FOLDER} ${UI_CORE_APP_DNS}" 1563 | echo_fail 1564 | exit_no_change 1565 | fi 1566 | echo_good 1567 | } 1568 | 1569 | ## Validate Domain Database Permissions 1570 | function validate_gravity_permissions { 1571 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_GRAVITY_NAME}" 1572 | echo_stat 1573 | sudo chown ${LOCAL_FILE_OWNER} ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} >/dev/null 2>&1 1574 | error_validate 1575 | 1576 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_GRAVITY_NAME}" 1577 | echo_stat 1578 | sudo chmod 664 ${LOCAL_PIHOLE_DIRECTORY}/${PH_GRAVITY_FI} >/dev/null 2>&1 1579 | error_validate 1580 | } 1581 | 1582 | ## Validate Local DNS Records Permissions 1583 | function validate_custom_permissions { 1584 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_CUSTOM_NAME}" 1585 | echo_stat 1586 | sudo chown ${LOCAL_FILE_OWNER} ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} >/dev/null 2>&1 1587 | error_validate 1588 | 1589 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_CUSTOM_NAME}" 1590 | echo_stat 1591 | sudo chmod 644 ${LOCAL_PIHOLE_DIRECTORY}/${PH_CUSTOM_DNS} >/dev/null 2>&1 1592 | error_validate 1593 | } 1594 | 1595 | ## Validate Local DNS CNAME Permissions 1596 | function validate_cname_permissions { 1597 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_CNAME_NAME}" 1598 | echo_stat 1599 | sudo chown ${LOCAL_FILE_OWNER} ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} >/dev/null 2>&1 1600 | error_validate 1601 | 1602 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_CNAME_NAME}" 1603 | echo_stat 1604 | sudo chmod 644 ${LOCAL_DNSMASQ_DIRECTORY}/${PH_CNAME_CONF} >/dev/null 2>&1 1605 | error_validate 1606 | } 1607 | 1608 | function validate_sdhcp_permissions { 1609 | MESSAGE="${UI_SET_LOCAL_FILE_OWNERSHIP} ${UI_SDHCP_NAME}" 1610 | echo_stat 1611 | sudo chown ${LOCAL_FILE_OWNER} ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} >/dev/null 2>&1 1612 | error_validate 1613 | 1614 | MESSAGE="${UI_SET_FILE_PERMISSION} ${UI_SDHCP_NAME}" 1615 | echo_stat 1616 | sudo chmod 644 ${LOCAL_DNSMASQ_DIRECTORY}/${PH_SDHCP_CONF} >/dev/null 2>&1 1617 | error_validate 1618 | } 1619 | 1620 | ## Validate Intent 1621 | function intent_validate { 1622 | PHASER=$((( RANDOM % 4 ) + 1 )) 1623 | if [ "$PHASER" = "1" ]; then 1624 | INTENT="FIRE PHOTON TORPEDOES" 1625 | elif [ "$PHASER" = "2" ]; then 1626 | INTENT="FIRE ALL PHASERS" 1627 | elif [ "$PHASER" = "3" ]; then 1628 | INTENT="EJECT THE WARP CORE" 1629 | elif [ "$PHASER" = "4" ]; then 1630 | INTENT="ENGAGE TRACTOR BEAM" 1631 | fi 1632 | 1633 | MESSAGE="Type ${INTENT} to confirm" 1634 | echo_need 1635 | 1636 | read -r INPUT_INTENT 1637 | 1638 | if [ "${INPUT_INTENT}" != "${INTENT}" ]; then 1639 | MESSAGE="${GS_TASK_TYPE} excited" 1640 | echo_info 1641 | exit_no_change 1642 | fi 1643 | } 1644 | 1645 | ## Sudo Creation Task 1646 | function task_sudo { 1647 | start_gs_no_config 1648 | 1649 | GS_TASK_TYPE='SUDO' 1650 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 1651 | echo_good 1652 | 1653 | MESSAGE="Creating sudoers.d template file" 1654 | echo_stat 1655 | 1656 | NEW_SUDO_USER=$(whoami) 1657 | echo -e "${NEW_SUDO_USER} ALL=(ALL) NOPASSWD: ALL" | sudo tee ${GS_LOCAL_REPO}/templates/gs-nopasswd.sudo 1> /dev/null 1658 | error_validate 1659 | 1660 | MESSAGE="Installing sudoers.d file on $HOSTNAME" 1661 | echo_stat 1662 | 1663 | sudo install -m 0440 ${GS_LOCAL_REPO}/templates/gs-nopasswd.sudo /etc/sudoers.d/gs-nopasswd 1664 | error_validate 1665 | 1666 | exit_with_changes 1667 | } 1668 | 1669 | function validate_sudo_status { 1670 | OS_CURRENT_USER=$(whoami) 1671 | if [ ! "$EUID" -ne 0 ]; then 1672 | OS_LOCAL_ADMIN="" 1673 | else 1674 | /usr/bin/sudo -u ${OS_CURRENT_USER} --validate 1675 | OS_SUDO_CHECK=$? 1676 | if [ $OS_SUDO_CHECK -ne 0 ]; then 1677 | OS_LOCAL_ADMIN="nosudo" 1678 | else 1679 | OS_LOCAL_ADMIN="sudo" 1680 | fi 1681 | fi 1682 | 1683 | if [ "$OS_LOCAL_ADMIN" == "nosudo" ]; then 1684 | GS_TASK_TYPE='ROOT' 1685 | MESSAGE="${MESSAGE} ${GS_TASK_TYPE}" 1686 | echo_fail 1687 | 1688 | MESSAGE="${OS_CURRENT_USER} has insufficient user rights for ${PROGRAM}" 1689 | echo_warn 1690 | 1691 | exit_no_change 1692 | fi 1693 | } 1694 | 1695 | ## Configure Task 1696 | function task_configure { 1697 | 1698 | start_gs_no_config 1699 | 1700 | GS_TASK_TYPE='CONFIGURE' 1701 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 1702 | echo_good 1703 | 1704 | if [[ ${INPUT_SSH} =~ ^[0-9]+$ ]]; then 1705 | GS_SSH_PORT=${INPUT_SSH} 1706 | MESSAGE="TARGET HOST SSH PORT SET TO ${GS_SSH_PORT}" 1707 | echo_warn 1708 | fi 1709 | 1710 | if [ -f ${GS_ETC_PATH}/${GS_CONFIG_FILE} ]; then 1711 | config_delete 1712 | else 1713 | config_generate 1714 | fi 1715 | 1716 | exit_with_changes 1717 | } 1718 | 1719 | ## Generate New Configuration 1720 | function config_generate { 1721 | MESSAGE="Creating new ${GS_CONFIG_FILE}" 1722 | echo_stat 1723 | sudo cp ${GS_LOCAL_REPO}/templates/${GS_CONFIG_FILE}.example ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1724 | error_validate 1725 | 1726 | echo_blank 1727 | echo -e " Welcome to the ${PURPLE}${PROGRAM}${NC} Configuration Wizard" 1728 | echo -e " Please read through ${BLUE}https://github.com/vmstan/gravity-sync/wiki${NC} before you continue" 1729 | echo -e " Make sure that ${UI_CORE_APP} is running on this system before your configure ${PROGRAM}" 1730 | echo_blank 1731 | 1732 | MESSAGE="${PROGRAM} Remote Host Settings" 1733 | echo_info 1734 | 1735 | MESSAGE="Remote ${UI_CORE_APP} host address" 1736 | echo_prompt 1737 | 1738 | MESSAGE="IP" 1739 | echo_need 1740 | read -r INPUT_REMOTE_HOST 1741 | 1742 | if [ "${INPUT_REMOTE_HOST}" == "" ]; then 1743 | MESSAGE="Remote host cannot be blank!" 1744 | echo_fail 1745 | exit_no_change 1746 | fi 1747 | 1748 | MESSAGE="${UI_CONFIG_SAVING} ${INPUT_REMOTE_HOST} host to ${GS_CONFIG_FILE}" 1749 | echo_stat 1750 | sudo sed -i "/REMOTE_HOST=''/c\REMOTE_HOST='${INPUT_REMOTE_HOST}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1751 | error_validate 1752 | 1753 | MESSAGE="Remote ${UI_CORE_APP} host username" 1754 | echo_prompt 1755 | 1756 | MESSAGE="User" 1757 | echo_need 1758 | read -r INPUT_REMOTE_USER 1759 | 1760 | if [ "${INPUT_REMOTE_USER}" == "" ]; then 1761 | MESSAGE="User name cannot be blank!" 1762 | echo_fail 1763 | exit_no_change 1764 | fi 1765 | 1766 | MESSAGE="${UI_CONFIG_SAVING} ${INPUT_REMOTE_USER}@${INPUT_REMOTE_HOST} to ${GS_CONFIG_FILE}" 1767 | echo_stat 1768 | sudo sed -i "/REMOTE_USER=''/c\REMOTE_USER='${INPUT_REMOTE_USER}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1769 | error_validate 1770 | 1771 | MESSAGE="${PROGRAM} SSH Key Settings" 1772 | echo_info 1773 | 1774 | generate_ssh_key 1775 | 1776 | MESSAGE="${UI_CORE_LOADING} ${GS_CONFIG_FILE}" 1777 | echo_stat 1778 | 1779 | if [ "${GS_SSH_PORT}" != '22' ]; then 1780 | MESSAGE="${UI_CONFIG_SAVING} custom SSH port to ${GS_CONFIG_FILE}" 1781 | echo_stat 1782 | echo -e "GS_SSH_PORT='${GS_SSH_PORT}'" | sudo tee -a ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1> /dev/null 1783 | error_validate 1784 | fi 1785 | 1786 | # shellcheck source=/etc/gravity-sync/gravity-sync.conf 1787 | source ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1788 | error_validate 1789 | 1790 | export_ssh_key 1791 | 1792 | MESSAGE="SSH key registered to ${INPUT_REMOTE_HOST}" 1793 | echo_good_clean 1794 | 1795 | MESSAGE="${UI_CORE_APP} Installation Settings" 1796 | echo_info 1797 | 1798 | detect_local_pihole 1799 | if [ "${LOCAL_PIHOLE_TYPE}" == "default" ]; then 1800 | MESSAGE="Default install of ${UI_CORE_APP} detected" 1801 | echo_good_clean 1802 | elif [ "${LOCAL_PIHOLE_TYPE}" == "docker" ]; then 1803 | MESSAGE="Docker container ${UI_CORE_APP} install detected" 1804 | echo_good_clean 1805 | elif [ "${LOCAL_PIHOLE_TYPE}" == "podman" ]; then 1806 | MESSAGE="Podman container ${UI_CORE_APP} install detected" 1807 | echo_good_clean 1808 | elif [ "${LOCAL_PIHOLE_TYPE}" == "none" ]; then 1809 | MESSAGE="No local ${UI_CORE_APP} installed detected" 1810 | echo_warn 1811 | end_config_no_pi 1812 | fi 1813 | 1814 | detect_remote_pihole 1815 | if [ "${REMOTE_PIHOLE_TYPE}" == "default" ]; then 1816 | MESSAGE="Remote install of ${UI_CORE_APP} detected" 1817 | echo_good_clean 1818 | elif [ "${REMOTE_PIHOLE_TYPE}" == "docker" ]; then 1819 | MESSAGE="Remote Docker container of ${UI_CORE_APP} detected" 1820 | echo_good_clean 1821 | elif [ "${REMOTE_PIHOLE_TYPE}" == "podman" ]; then 1822 | MESSAGE="Remote Podman container of ${UI_CORE_APP} detected" 1823 | echo_good_clean 1824 | elif [ "${REMOTE_PIHOLE_TYPE}" == "none" ]; then 1825 | MESSAGE="No remote ${UI_CORE_APP} installed detected" 1826 | echo_warn 1827 | end_config_no_pi 1828 | fi 1829 | 1830 | if [ "${LOCAL_PIHOLE_TYPE}" == "default" ] && [ "${REMOTE_PIHOLE_TYPE}" == "default" ]; then 1831 | end_config 1832 | else 1833 | advanced_config_generate 1834 | fi 1835 | } 1836 | 1837 | function end_config { 1838 | echo_blank 1839 | echo -e " Configuration has been completed successfully, once ${PROGRAM} has been installed your other" 1840 | echo -e " node, your next step is to push all of the of data from the currently authoritative" 1841 | echo -e " ${UI_CORE_APP} instance to the other." 1842 | echo -e " ex: ${YELLOW}gravity-sync push${NC}" 1843 | echo_blank 1844 | echo -e " If that completes successfully you can automate future sync jobs to run at a regular interval on" 1845 | echo -e " both of your ${PROGRAM} peers." 1846 | echo -e " ex: ${YELLOW}gravity-sync auto${NC}" 1847 | echo_blank 1848 | } 1849 | 1850 | function end_config_no_pi { 1851 | echo_blank 1852 | echo -e " Configuration could not be completed successfully, as no instances of ${UI_CORE_APP} could be detected" 1853 | echo -e " on one or more of your systems. Please make sure they are running on both peers and try again." 1854 | echo_blank 1855 | } 1856 | 1857 | ## Advanced Configuration Options 1858 | function advanced_config_generate { 1859 | if [ "${LOCAL_PIHOLE_TYPE}" == "docker" ] || [ "${LOCAL_PIHOLE_TYPE}" == "podman" ]; then 1860 | MESSAGE="Local Container Image Configuration" 1861 | echo_info 1862 | 1863 | MESSAGE="Displaying running containers on $HOSTNAME" 1864 | echo_good_clean 1865 | 1866 | if [ "${LOCAL_PIHOLE_TYPE}" == "docker" ]; then 1867 | sudo docker ps -a --format 'table {{.ID}}\t{{.Names}}' 1868 | elif [ "${LOCAL_PIHOLE_TYPE}" == "podman" ]; then 1869 | sudo podman container ls 1870 | fi 1871 | 1872 | MESSAGE="Enter local ${UI_CORE_APP} container name" 1873 | echo_prompt 1874 | MESSAGE="ex, 'pihole'" 1875 | echo_need 1876 | read -r INPUT_LOCAL_DOCKER_CONTAINER 1877 | 1878 | if [ "${INPUT_LOCAL_DOCKER_CONTAINER}" == "" ]; then 1879 | MESSAGE="Container name cannot be blank!" 1880 | echo_fail 1881 | exit_no_change 1882 | fi 1883 | 1884 | MESSAGE="${UI_CONFIG_SAVING} ${UI_CONFIG_LOCAL} ${UI_CONFIG_CONTAINER_NAME} to ${GS_CONFIG_FILE}" 1885 | echo_stat 1886 | sudo sed -i "/# LOCAL_DOCKER_CONTAINER=''/c\LOCAL_DOCKER_CONTAINER='${INPUT_LOCAL_DOCKER_CONTAINER}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1887 | error_validate 1888 | 1889 | MESSAGE="Examining local container configuration" 1890 | echo_stat 1891 | 1892 | if [ "${LOCAL_PIHOLE_TYPE}" == "docker" ]; then 1893 | sudo docker container inspect ${INPUT_LOCAL_DOCKER_CONTAINER} | grep -i -B 1 '"Destination": "/etc/pihole"' > ${OS_TMP}/local_container_pihole_etc.log; sed -i '$d' ${OS_TMP}/local_container_pihole_etc.log; sed -i 's/"Source": "//' ${OS_TMP}/local_container_pihole_etc.log; sed -i 's/",//' ${OS_TMP}/local_container_pihole_etc.log; sed -i 's/ //g' ${OS_TMP}/local_container_pihole_etc.log 1894 | sudo docker container inspect ${INPUT_LOCAL_DOCKER_CONTAINER} | grep -i -B 1 '"Destination": "/etc/dnsmasq.d"' > ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i '$d' ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i 's/"Source": "//' ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i 's/",//' ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i 's/ //g' ${OS_TMP}/local_container_dnsmasq_etc.log 1895 | elif [ "${LOCAL_PIHOLE_TYPE}" == "podman" ]; then 1896 | sudo podman container inspect ${INPUT_LOCAL_DOCKER_CONTAINER} | grep -i -B 1 '"Destination": "/etc/pihole"' > ${OS_TMP}/local_container_pihole_etc.log; sed -i '$d' ${OS_TMP}/local_container_pihole_etc.log; sed -i 's/"Source": "//' ${OS_TMP}/local_container_pihole_etc.log; sed -i 's/",//' ${OS_TMP}/local_container_pihole_etc.log; sed -i 's/ //g' ${OS_TMP}/local_container_pihole_etc.log 1897 | sudo podman container inspect ${INPUT_LOCAL_DOCKER_CONTAINER} | grep -i -B 1 '"Destination": "/etc/dnsmasq.d"' > ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i '$d' ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i 's/"Source": "//' ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i 's/",//' ${OS_TMP}/local_container_dnsmasq_etc.log; sed -i 's/ //g' ${OS_TMP}/local_container_dnsmasq_etc.log 1898 | fi 1899 | 1900 | INPUT_LOCAL_PIHOLE_DIRECTORY=$(cat ${OS_TMP}/local_container_pihole_etc.log) 1901 | INPUT_LOCAL_DNSMASQ_DIRECTORY=$(cat ${OS_TMP}/local_container_dnsmasq_etc.log) 1902 | 1903 | echo_good 1904 | 1905 | MESSAGE="${UI_CONFIG_SAVING} ${UI_CONFIG_LOCAL} ${UI_CORE_APP} ${UI_CONFIG_ETC_VOLUME_PATH} to ${GS_CONFIG_FILE}" 1906 | echo_stat 1907 | sudo sed -i "/# LOCAL_PIHOLE_DIRECTORY=''/c\LOCAL_PIHOLE_DIRECTORY='${INPUT_LOCAL_PIHOLE_DIRECTORY}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1908 | error_validate 1909 | 1910 | MESSAGE="${UI_CONFIG_SAVING} ${UI_CONFIG_LOCAL} ${UI_CORE_APP_DNS} ${UI_CONFIG_ETC_VOLUME_PATH} to ${GS_CONFIG_FILE}" 1911 | echo_stat 1912 | sudo sed -i "/# LOCAL_DNSMASQ_DIRECTORY=''/c\LOCAL_DNSMASQ_DIRECTORY='${INPUT_LOCAL_DNSMASQ_DIRECTORY}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1913 | error_validate 1914 | 1915 | MESSAGE="${UI_CONFIG_SAVING} ${UI_CONFIG_LOCAL} ${UI_CONFIG_VOLUME_OWNER} to ${GS_CONFIG_FILE}" 1916 | echo_stat 1917 | sudo sed -i "/# LOCAL_FILE_OWNER=''/c\LOCAL_FILE_OWNER='999:999'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1918 | error_validate 1919 | fi 1920 | 1921 | if [ "${REMOTE_PIHOLE_TYPE}" == "docker" ] || [ "${REMOTE_PIHOLE_TYPE}" == "podman" ]; then 1922 | MESSAGE="Remote Container Image Configuration" 1923 | echo_info 1924 | 1925 | MESSAGE="Querying running containers on ${REMOTE_HOST}" 1926 | echo_stat 1927 | if [ "${REMOTE_PIHOLE_TYPE}" == "docker" ]; then 1928 | ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo docker ps -a --format 'table {{.Image}}\t{{.Names}}' > /tmp/gs_local_container.log" 1929 | error_validate 1930 | elif [ "${REMOTE_PIHOLE_TYPE}" == "podman" ]; then 1931 | ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo podman container ls > /tmp/gs_local_container.log" 1932 | error_validate 1933 | fi 1934 | 1935 | MESSAGE="Retrieving container list from ${REMOTE_HOST}" 1936 | RSYNC_REPATH="sudo rsync" 1937 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${OS_TMP}/gs_local_container.log" 1938 | RSYNC_TARGET="${OS_TMP}/gs_remote_container.log" 1939 | create_rsync_cmd 1940 | 1941 | MESSAGE="Displaying running containers on ${REMOTE_HOST}" 1942 | echo_good_clean 1943 | 1944 | cat ${OS_TMP}/gs_remote_container.log 1945 | 1946 | MESSAGE="Enter remote ${UI_CORE_APP} container name" 1947 | echo_prompt 1948 | MESSAGE="ex, 'pihole'" 1949 | echo_need 1950 | read -r INPUT_REMOTE_DOCKER_CONTAINER 1951 | 1952 | if [ "${INPUT_REMOTE_DOCKER_CONTAINER}" == "" ]; then 1953 | MESSAGE="Container name cannot be blank!" 1954 | echo_fail 1955 | exit_no_change 1956 | fi 1957 | 1958 | MESSAGE="${UI_CONFIG_SAVING} remote host ${UI_CONFIG_CONTAINER_NAME} to ${GS_CONFIG_FILE}" 1959 | echo_stat 1960 | sudo sed -i "/# REMOTE_DOCKER_CONTAINER=''/c\REMOTE_DOCKER_CONTAINER='${INPUT_REMOTE_DOCKER_CONTAINER}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1961 | error_validate 1962 | 1963 | MESSAGE="Examining remote container configuration" 1964 | echo_stat 1965 | 1966 | if [ "${REMOTE_PIHOLE_TYPE}" == "docker" ]; then 1967 | ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo docker container inspect ${INPUT_REMOTE_DOCKER_CONTAINER} | grep -i -B 1 '\"Destination\": \"/etc/pihole\"' > ${OS_TMP}/local_container_pihole_etc.log" 1968 | ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo docker container inspect ${INPUT_REMOTE_DOCKER_CONTAINER} | grep -i -B 1 '\"Destination\": \"/etc/dnsmasq.d\"' > ${OS_TMP}/local_container_dnsmasq_etc.log" 1969 | error_validate 1970 | elif [ "${REMOTE_PIHOLE_TYPE}" == "podman" ]; then 1971 | ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo podman container inspect ${INPUT_REMOTE_DOCKER_CONTAINER} | grep -i -B 1 '\"Destination\": \"/etc/pihole\"' > ${OS_TMP}/local_container_pihole_etc.log" 1972 | ${OS_SSH_CMD} -p ${GS_SSH_PORT} -i "${GS_SSH_PKIF}" ${REMOTE_USER}@${REMOTE_HOST} "sudo podman container inspect ${INPUT_REMOTE_DOCKER_CONTAINER} | grep -i -B 1 '\"Destination\": \"/etc/dnsmasq.d\"' > ${OS_TMP}/local_container_dnsmasq_etc.log" 1973 | error_validate 1974 | fi 1975 | 1976 | MESSAGE="Retrieving remote ${UI_CORE_APP} configuration settings" 1977 | RSYNC_REPATH="sudo rsync" 1978 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${OS_TMP}/local_container_pihole_etc.log" 1979 | RSYNC_TARGET="${OS_TMP}/remote_container_pihole_etc.log" 1980 | create_rsync_cmd 1981 | 1982 | MESSAGE="Retrieving remote ${UI_CORE_APP_DNS} configuration settings" 1983 | RSYNC_REPATH="sudo rsync" 1984 | RSYNC_SOURCE="${REMOTE_USER}@${REMOTE_HOST}:${OS_TMP}/local_container_dnsmasq_etc.log" 1985 | RSYNC_TARGET="${OS_TMP}/remote_container_dnsmasq_etc.log" 1986 | create_rsync_cmd 1987 | 1988 | sed -i '$d' ${OS_TMP}/remote_container_pihole_etc.log; sed -i 's/"Source": "//' ${OS_TMP}/remote_container_pihole_etc.log; sed -i 's/",//' ${OS_TMP}/remote_container_pihole_etc.log; sed -i 's/ //g' ${OS_TMP}/remote_container_pihole_etc.log 1989 | sed -i '$d' ${OS_TMP}/remote_container_dnsmasq_etc.log; sed -i 's/"Source": "//' ${OS_TMP}/remote_container_dnsmasq_etc.log; sed -i 's/",//' ${OS_TMP}/remote_container_dnsmasq_etc.log; sed -i 's/ //g' ${OS_TMP}/remote_container_dnsmasq_etc.log 1990 | 1991 | INPUT_REMOTE_PIHOLE_DIRECTORY=$(cat ${OS_TMP}/remote_container_pihole_etc.log) 1992 | INPUT_REMOTE_DNSMASQ_DIRECTORY=$(cat ${OS_TMP}/remote_container_dnsmasq_etc.log) 1993 | 1994 | echo_good 1995 | 1996 | MESSAGE="${UI_CONFIG_SAVING} remote host ${UI_CORE_APP} ${UI_CONFIG_ETC_VOLUME_PATH} to ${GS_CONFIG_FILE}" 1997 | echo_stat 1998 | sudo sed -i "/# REMOTE_PIHOLE_DIRECTORY=''/c\REMOTE_PIHOLE_DIRECTORY='${INPUT_REMOTE_PIHOLE_DIRECTORY}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 1999 | error_validate 2000 | 2001 | MESSAGE="${UI_CONFIG_SAVING} remote host ${UI_CORE_APP_DNS} ${UI_CONFIG_ETC_VOLUME_PATH} to ${GS_CONFIG_FILE}" 2002 | echo_stat 2003 | sudo sed -i "/# REMOTE_DNSMASQ_DIRECTORY=''/c\REMOTE_DNSMASQ_DIRECTORY='${INPUT_REMOTE_DNSMASQ_DIRECTORY}'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 2004 | error_validate 2005 | 2006 | MESSAGE="${UI_CONFIG_SAVING} remote host ${UI_CONFIG_VOLUME_OWNER} to ${GS_CONFIG_FILE}" 2007 | echo_stat 2008 | sudo sed -i "/# REMOTE_FILE_OWNER=''/c\REMOTE_FILE_OWNER='999:999'" ${GS_ETC_PATH}/${GS_CONFIG_FILE} 2009 | error_validate 2010 | fi 2011 | 2012 | end_config 2013 | } 2014 | 2015 | ## Delete Existing Configuration 2016 | function config_delete { 2017 | # shellcheck source=/etc/gravity-sync/gravity-sync.conf 2018 | if [ -n "${GS_SSH_PORT}" ]; then 2019 | _GS_SSH_PORT=${GS_SSH_PORT} 2020 | fi 2021 | source ${GS_ETC_PATH}/${GS_CONFIG_FILE} 2022 | if [ -n "${_GS_SSH_PORT}" ]; then 2023 | GS_SSH_PORT=${_GS_SSH_PORT} 2024 | fi 2025 | MESSAGE="${GS_CONFIG_FILE} ${UI_CONFIG_ALREADY}" 2026 | echo_warn 2027 | 2028 | MESSAGE="${UI_CONFIG_CONFIRM}" 2029 | echo_prompt 2030 | 2031 | intent_validate 2032 | 2033 | MESSAGE="${UI_CONFIG_ERASING} ${GS_CONFIG_FILE}" 2034 | echo_stat 2035 | sudo mv ${GS_ETC_PATH}/${GS_CONFIG_FILE} ${GS_ETC_PATH}/${GS_CONFIG_FILE}.${GS_BACKUP_EXT} 2036 | error_validate 2037 | 2038 | config_generate 2039 | } 2040 | 2041 | ## Master Branch 2042 | function update_gs { 2043 | bash ${GS_LOCAL_REPO}/update.sh 2044 | } 2045 | 2046 | ## Show Version 2047 | function show_version { 2048 | if [ -f ${GS_LOCAL_REPO}/dev ]; then 2049 | GS_DEV_VERSION="Beta" 2050 | else 2051 | GS_DEV_VERSION="" 2052 | fi 2053 | 2054 | MESSAGE="Running version: ${GREEN}${GS_VERSION}${NC} ${GS_DEV_VERSION}" 2055 | echo_info 2056 | 2057 | GS_GIT_VERSION=$(curl -sf https://raw.githubusercontent.com/vmstan/gravity-sync/master/VERSION) 2058 | if [ -z "$GS_GIT_VERSION" ]; then 2059 | MESSAGE="Latest version: ${RED}Unknown${NC}" 2060 | else 2061 | if [[ ! "${GS_GIT_VERSION}" > "${GS_VERSION}" ]]; then 2062 | MESSAGE="Latest version: ${GREEN}${GS_GIT_VERSION}${NC}" 2063 | else 2064 | MESSAGE="Update available: ${RED}${GS_GIT_VERSION}${NC}" 2065 | fi 2066 | fi 2067 | echo_info 2068 | } 2069 | 2070 | function show_info { 2071 | echo -e "${YELLOW}Local Software Versions${NC}" 2072 | echo -e "${BLUE}${UI_CORE_APP}${NC}" 2073 | if [ "${LOCAL_PIHOLE_TYPE}" == "default" ]; then 2074 | pihole version 2075 | elif [ "${LOCAL_PIHOLE_TYPE}" == "docker" ]; then 2076 | sudo docker exec -it pihole pihole -v 2077 | elif [ "${LOCAL_PIHOLE_TYPE}" == "podman" ]; then 2078 | sudo podman exec -it pihole pihole -v 2079 | fi 2080 | 2081 | if [ -f /etc/os-release ]; then 2082 | . /etc/os-release 2083 | OS_OS=$NAME 2084 | OS_VER=$VERSION_ID 2085 | echo -e "${BLUE}${OS_OS} ${OS_VER}${NC}" 2086 | fi 2087 | 2088 | uname -srm 2089 | echo -e "bash $BASH_VERSION" 2090 | ssh -V 2091 | rsync --version | grep version 2092 | sudo --version | grep "Sudo version" 2093 | git --version 2094 | 2095 | if hash docker 2>/dev/null; then 2096 | docker --version 2097 | fi 2098 | 2099 | if hash podman 2>/dev/null; then 2100 | podman --version 2101 | fi 2102 | 2103 | echo -e "" 2104 | 2105 | echo -e "${YELLOW}Global Instance Settings${NC}" 2106 | if [ ${GS_SSH_PORT} == '22' ]; then 2107 | echo -e "SSH Port: 22 (default)" 2108 | else 2109 | echo -e "SSH Port: ${GS_SSH_PORT} (custom)" 2110 | fi 2111 | 2112 | echo -e "SSH Key: ${GS_SSH_PKIF}" 2113 | 2114 | if systemctl is-active --quiet gravity-sync.timer; then 2115 | echo -e "Automated Replication: Enabled" 2116 | else 2117 | echo -e "Automated Replication: Disabled" 2118 | fi 2119 | 2120 | echo -e "" 2121 | 2122 | echo -e "${YELLOW}Local Instance Settings${NC}" 2123 | echo -e "Local Hostname: $HOSTNAME" 2124 | echo -e "Local ${UI_CORE_APP} Type: ${LOCAL_PIHOLE_TYPE}" 2125 | echo -e "Local ${UI_CORE_APP} Config Directory: ${LOCAL_PIHOLE_DIRECTORY}" 2126 | echo -e "Local ${UI_CORE_APP_DNS} Config Directory: ${LOCAL_DNSMASQ_DIRECTORY}" 2127 | echo -e "Local ${PROGRAM} Binary: ${GS_FILEPATH}" 2128 | echo -e "Local ${PROGRAM} Config Directory: ${GS_ETC_PATH}" 2129 | 2130 | if [ "${LOCAL_PIHOLE_TYPE}" == "default" ]; then 2131 | echo -e "Local ${UI_CORE_APP} Binary Directory: ${LOCAL_PIHOLE_BINARY}" 2132 | elif [ "${LOCAL_PIHOLE_TYPE}" == "docker" ]; then 2133 | echo -e "Local ${UI_CORE_APP} Container Name: ${LOCAL_DOCKER_CONTAINER}" 2134 | echo -e "Local Docker Binary Directory: ${LOCAL_DOCKER_BINARY}" 2135 | elif [ "${LOCAL_PIHOLE_TYPE}" == "podman" ]; then 2136 | echo -e "Local ${UI_CORE_APP} Container Name: ${LOCAL_DOCKER_CONTAINER}" 2137 | echo -e "Local Podman Binary Directory: ${LOCAL_PODMAN_BINARY}" 2138 | fi 2139 | 2140 | echo -e "Local File Owner Settings: ${LOCAL_FILE_OWNER}" 2141 | 2142 | echo -e "" 2143 | echo -e "${YELLOW}Remote Instance Settings${NC}" 2144 | echo -e "Remote Hostname/IP: ${REMOTE_HOST}" 2145 | echo -e "Remote Username: ${REMOTE_USER}" 2146 | echo -e "Remote ${UI_CORE_APP} Type: ${REMOTE_PIHOLE_TYPE}" 2147 | echo -e "Remote ${UI_CORE_APP} Config Directory: ${REMOTE_PIHOLE_DIRECTORY}" 2148 | echo -e "Remote ${UI_CORE_APP_DNS} Config Directory: ${REMOTE_DNSMASQ_DIRECTORY}" 2149 | 2150 | if [ "${REMOTE_PIHOLE_TYPE}" == "default" ]; then 2151 | echo -e "Remote ${UI_CORE_APP} Binary Directory: ${REMOTE_PIHOLE_BINARY}" 2152 | elif [ "${REMOTE_PIHOLE_TYPE}" == "docker" ]; then 2153 | echo -e "Remote ${UI_CORE_APP} Container Name: ${REMOTE_DOCKER_CONTAINER}" 2154 | echo -e "Remote Docker Binary Directory: ${REMOTE_DOCKER_BINARY}" 2155 | elif [ "${REMOTE_PIHOLE_TYPE}" == "podman" ]; then 2156 | echo -e "Remote ${UI_CORE_APP} Container Name: ${REMOTE_DOCKER_CONTAINER}" 2157 | echo -e "Remote Podman Binary Directory: ${REMOTE_PODMAN_BINARY}" 2158 | fi 2159 | 2160 | echo -e "Remote File Owner Settings: ${REMOTE_FILE_OWNER}" 2161 | } 2162 | 2163 | ## Dev Task 2164 | function task_dev { 2165 | start_gs_no_config 2166 | 2167 | GS_TASK_TYPE='DEV' 2168 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2169 | echo_good 2170 | 2171 | if [ -f ${GS_LOCAL_REPO}/dev ]; then 2172 | MESSAGE="Disabling ${GS_TASK_TYPE}" 2173 | echo_stat 2174 | sudo rm -f ${GS_LOCAL_REPO}/dev 2175 | error_validate 2176 | else 2177 | MESSAGE="Enabling ${GS_TASK_TYPE}" 2178 | echo_stat 2179 | sudo touch ${GS_LOCAL_REPO}/dev 2180 | error_validate 2181 | 2182 | MESSAGE="Checking available branches" 2183 | echo_stat 2184 | (cd ${GS_LOCAL_REPO} || exit; sudo git fetch --all >/dev/null 2>&1) 2185 | error_validate 2186 | 2187 | (cd ${GS_LOCAL_REPO} || exit; sudo git branch -r) 2188 | 2189 | MESSAGE="Select GitHub branch to update against" 2190 | echo_need 2191 | read -r INPUT_BRANCH 2192 | 2193 | echo -e "BRANCH='${INPUT_BRANCH}'" | sudo tee ${GS_LOCAL_REPO}/dev 1> /dev/null 2194 | fi 2195 | 2196 | update_gs 2197 | exit_with_changes 2198 | } 2199 | 2200 | ## Update Task 2201 | function task_update { 2202 | start_gs_no_config 2203 | 2204 | GS_TASK_TYPE='UPDATE' 2205 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2206 | echo_good 2207 | update_gs 2208 | exit_with_changes 2209 | } 2210 | 2211 | ## Version Task 2212 | function task_version { 2213 | start_gs_no_config 2214 | 2215 | GS_TASK_TYPE='VERSION' 2216 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2217 | echo_good 2218 | show_version 2219 | exit_no_change 2220 | } 2221 | 2222 | ## Info Task 2223 | 2224 | function task_info { 2225 | start_gs 2226 | 2227 | GS_TASK_TYPE='INFO' 2228 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2229 | echo_good 2230 | show_info 2231 | exit_no_change 2232 | } 2233 | 2234 | ## Automate Task 2235 | function task_automate { 2236 | start_gs 2237 | 2238 | GS_TASK_TYPE='AUTOMATE' 2239 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2240 | echo_good 2241 | 2242 | sudo cp ${GS_LOCAL_REPO}/templates/gravity-sync.service ${OS_TMP}/gravity-sync.service 2243 | sudo cp ${GS_LOCAL_REPO}/templates/gravity-sync.timer ${OS_TMP}/gravity-sync.timer 2244 | 2245 | MESSAGE="Customizing service file username" 2246 | echo_stat 2247 | OS_CURRENT_USER=$(whoami) 2248 | sudo sed -i "/User=unknown/c\User=${OS_CURRENT_USER}" ${OS_TMP}/gravity-sync.service 2249 | error_validate 2250 | 2251 | MESSAGE="Customizing service file executable path" 2252 | echo_stat 2253 | sudo sed -i "/ExecStart=/c\ExecStart=${GS_FILEPATH}" ${OS_TMP}/gravity-sync.service 2254 | error_validate 2255 | 2256 | if [ "${GS_SYSLOG_REDIRECT}" != '' ]; then 2257 | MESSAGE="Customizing standard output location" 2258 | echo_stat 2259 | sudo sed -i "/Type=simple/a\StandardOutput=file:${GS_SYSLOG_REDIRECT}" ${OS_TMP}/gravity-sync.service 2260 | sudo sed -i "/Type=simple/a\StandardError=file:${GS_SYSLOG_REDIRECT}" ${OS_TMP}/gravity-sync.service 2261 | error_validate 2262 | fi 2263 | 2264 | if [ "${INPUT_SPEED}" == 'slow' ] || [ "${INPUT_SPEED}" == 'hour' ]; then 2265 | MESSAGE="Randomizing service timers (hour)" 2266 | echo_stat 2267 | ACTIVE_REP=$(shuf -i 50-55 -n1) 2268 | RANDOM_REP=$(shuf -i 7-10 -n1) 2269 | elif [ "${INPUT_SPEED}" == 'half' ]; then 2270 | MESSAGE="Randomizing service timers (half)" 2271 | echo_stat 2272 | ACTIVE_REP=$(shuf -i 25-30 -n1) 2273 | RANDOM_REP=$(shuf -i 5-7 -n1) 2274 | elif [ "${INPUT_SPEED}" == 'quad' ]; then 2275 | MESSAGE="Randomizing service timers (quad)" 2276 | echo_stat 2277 | ACTIVE_REP=$(shuf -i 12-15 -n1) 2278 | RANDOM_REP=$(shuf -i 3-5 -n1) 2279 | else 2280 | MESSAGE="Randomizing service timers" 2281 | echo_stat 2282 | ACTIVE_REP=$(shuf -i 3-10 -n1) 2283 | RANDOM_REP=$(shuf -i 2-5 -n1) 2284 | fi 2285 | 2286 | sudo sed -i "/OnUnitInactiveSec=5m/c\OnUnitInactiveSec=${ACTIVE_REP}m" ${OS_TMP}/gravity-sync.timer 2287 | sudo sed -i "/RandomizedDelaySec=5m/c\RandomizedDelaySec=${RANDOM_REP}m" ${OS_TMP}/gravity-sync.timer 2288 | error_validate 2289 | 2290 | if systemctl is-active --quiet gravity-sync.timer; then 2291 | MESSAGE="Stopping existing systemd service" 2292 | echo_stat 2293 | sudo systemctl stop gravity-sync 2294 | error_validate 2295 | fi 2296 | 2297 | MESSAGE="Moving systemd timer into place" 2298 | echo_stat 2299 | sudo cp ${OS_TMP}/gravity-sync.timer ${OS_DAEMON_PATH} 2300 | error_validate 2301 | 2302 | MESSAGE="Moving systemd service into place" 2303 | echo_stat 2304 | sudo cp ${OS_TMP}/gravity-sync.service ${OS_DAEMON_PATH} 2305 | error_validate 2306 | 2307 | MESSAGE="Reloading systemd daemon" 2308 | echo_stat 2309 | sudo systemctl daemon-reload --quiet 2310 | error_validate 2311 | 2312 | MESSAGE="Enabling ${PROGRAM} timer" 2313 | echo_stat 2314 | sudo systemctl enable gravity-sync.timer --quiet 2315 | error_validate 2316 | 2317 | MESSAGE="Starting ${PROGRAM} service" 2318 | echo_stat 2319 | sudo systemctl start gravity-sync --quiet 2320 | error_validate 2321 | 2322 | exit_with_changes 2323 | } 2324 | 2325 | function task_disable_automate { 2326 | start_gs_no_config 2327 | 2328 | GS_TASK_TYPE='DISABLE' 2329 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2330 | echo_good 2331 | 2332 | kill_automation_service 2333 | exit_with_changes 2334 | } 2335 | 2336 | function task_monitor { 2337 | start_gs_no_config 2338 | 2339 | GS_TASK_TYPE='MONITOR' 2340 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2341 | echo_good 2342 | 2343 | MESSAGE="Press CTRL+Z to exit MONITOR mode" 2344 | echo_warn 2345 | 2346 | sudo journalctl -fu gravity-sync 2347 | } 2348 | 2349 | function kill_automation_service { 2350 | if systemctl is-active --quiet gravity-sync.timer; then 2351 | MESSAGE="Stopping ${PROGRAM} timer" 2352 | echo_stat 2353 | sudo systemctl stop gravity-sync 2354 | error_validate 2355 | 2356 | MESSAGE="Disabling ${PROGRAM} automation service" 2357 | echo_stat 2358 | sudo systemctl disable gravity-sync --quiet 2359 | error_validate 2360 | 2361 | MESSAGE="Removing systemd timer" 2362 | echo_stat 2363 | sudo rm -f ${OS_DAEMON_PATH}/gravity-sync.timer 2364 | error_validate 2365 | 2366 | MESSAGE="Removing systemd service" 2367 | echo_stat 2368 | sudo rm -f ${OS_DAEMON_PATH}/gravity-sync.service 2369 | error_validate 2370 | 2371 | MESSAGE="Reloading systemd daemon" 2372 | echo_stat 2373 | sudo systemctl daemon-reload --quiet 2374 | error_validate 2375 | fi 2376 | } 2377 | 2378 | ## Purge Task 2379 | function task_purge { 2380 | start_gs_no_config 2381 | 2382 | GS_TASK_TYPE="PURGE" 2383 | MESSAGE="${MESSAGE}: ${GS_TASK_TYPE}" 2384 | echo_good 2385 | 2386 | echo_blank 2387 | echo -e " THIS WILL REMOVE YOUR ENTIRE GRAVITY SYNC INSTALLATION" 2388 | echo -e " ${UI_CORE_APP} binaries, configuration and services ARE NOT impacted!" 2389 | echo -e " Your devices will continue to resolve and block DNS requests," 2390 | echo -e " but your ${UI_GRAVITY_NAME} and ${UI_CUSTOM_NAME} WILL NOT sync anymore," 2391 | echo -e " until you reconfigure ${PROGRAM} on this device." 2392 | echo_blank 2393 | echo -e " In order to fully remove ${PROGRAM} from your infrastructure, you will also" 2394 | echo -e " need to run this same command from the peer instance as well." 2395 | echo_blank 2396 | 2397 | intent_validate 2398 | 2399 | kill_automation_service 2400 | 2401 | MESSAGE="Removing ${PROGRAM} backup files" 2402 | echo_stat 2403 | sudo rm -f ${OS_TMP}/*.${GS_BACKUP_EXT} 2404 | error_validate 2405 | 2406 | MESSAGE="Removing ${PROGRAM} configuration and logs" 2407 | echo_stat 2408 | sudo rm -fr ${GS_ETC_PATH} 2409 | error_validate 2410 | 2411 | MESSAGE="Removing ${PROGRAM} binary" 2412 | echo_stat 2413 | sudo rm ${GS_FILEPATH} 2414 | error_validate 2415 | 2416 | exit_with_changes 2417 | } 2418 | 2419 | ## No Changes Made 2420 | function exit_no_change { 2421 | GS_RUN_END=$SECONDS 2422 | ((GS_RUNTIME=GS_RUN_END-GS_RUN_START)) 2423 | 2424 | if [ "${GS_TASK_TYPE}" == "" ]; then 2425 | MESSAGE="${PROGRAM} ${UI_EXIT_ABORT} ${UI_EXIT_CALC_END} ${GS_RUNTIME} ${UI_EXIT_CALC_TIMER}" 2426 | else 2427 | MESSAGE="${PROGRAM} ${GS_TASK_TYPE} ${UI_EXIT_ABORT} ${UI_EXIT_CALC_END} ${GS_RUNTIME} ${UI_EXIT_CALC_TIMER}" 2428 | fi 2429 | 2430 | echo_grav 2431 | exit 0 2432 | } 2433 | 2434 | ## Changes Made 2435 | function exit_with_changes { 2436 | GS_RUN_END=$SECONDS 2437 | ((GS_RUNTIME=GS_RUN_END-GS_RUN_START)) 2438 | 2439 | if [ "${GS_TASK_TYPE}" == "" ]; then 2440 | MESSAGE="${PROGRAM} ${UI_EXIT_COMPLETE} ${UI_EXIT_CALC_END} ${GS_RUNTIME} ${UI_EXIT_CALC_TIMER}" 2441 | else 2442 | MESSAGE="${PROGRAM} ${GS_TASK_TYPE} ${UI_EXIT_COMPLETE} ${UI_EXIT_CALC_END} ${GS_RUNTIME} ${UI_EXIT_CALC_TIMER}" 2443 | fi 2444 | 2445 | echo_grav 2446 | exit 0 2447 | } 2448 | 2449 | ## List GS Arguments 2450 | function list_gs_arguments { 2451 | echo -e "Usage: $0 [options]" 2452 | echo -e "Example: '$0 pull'" 2453 | echo_blank 2454 | echo -e "Setup Options:" 2455 | echo -e " ${YELLOW}config${NC} Creates a new ${PROGRAM} configuration file" 2456 | echo -e " ${YELLOW}version${NC} Lists the installed version of ${PROGRAM} and checks for updates" 2457 | echo -e " ${YELLOW}update${NC} Upgrades ${PROGRAM} to the latest available version on GitHub" 2458 | echo -e " ${YELLOW}dev${NC} Sets upgrade command to use a development version of ${PROGRAM} (toggle on/off)" 2459 | echo -e " ${YELLOW}sudo${NC} Enables password-less sudo for current user" 2460 | echo -e " ${YELLOW}purge${NC} Uninstalls ${PROGRAM} from this system" 2461 | echo_blank 2462 | echo -e "Replication Options:" 2463 | echo -e " ${YELLOW}smart${NC} Reviews all ${UI_CORE_APP} changes syncs them (default)" 2464 | echo -e " ${YELLOW}pull${NC} Syncs only the remote ${UI_CORE_APP} configuration to this server" 2465 | echo -e " ${YELLOW}push${NC} Syncs only the local ${UI_CORE_APP} configuration to the remote" 2466 | echo -e " ${YELLOW}compare${NC} Checks for ${UI_CORE_APP} differences without making changes" 2467 | echo_blank 2468 | echo -e "Automation Options:" 2469 | echo -e " ${YELLOW}auto${NC} Schedules ${PROGRAM} replication tasks using systemd timers" 2470 | echo -e " ${YELLOW}monitor${NC} Monitors the ${PROGRAM} replication job in real time" 2471 | echo -e " ${YELLOW}disable${NC} Disables the ${PROGRAM} automated replication task" 2472 | echo_blank 2473 | echo -e "Debug Options:" 2474 | echo -e " ${YELLOW}logs${NC} Shows the recent successful replication jobs/times" 2475 | echo -e " ${YELLOW}info${NC} Shows information about the current configuration" 2476 | echo_blank 2477 | exit_no_change 2478 | } 2479 | 2480 | # SCRIPT EXECUTION ########################### 2481 | 2482 | case "${1}" in 2483 | "" | "smart" | "sync" ) task_smart;; 2484 | "pull" ) task_pull;; 2485 | "push" ) task_push;; 2486 | "compare" ) task_compare;; 2487 | "config" | "conf" | "configure" ) INPUT_SSH=$2; task_configure;; 2488 | "auto" | "automate" ) INPUT_SPEED=$2 task_automate;; 2489 | "disable" | "stop" ) task_disable_automate;; 2490 | "monitor" | "follow" ) task_monitor;; 2491 | "purge" | "uninstall" | "remove" ) task_purge;; 2492 | "sudo" ) task_sudo;; 2493 | "version" | "ver" ) task_version;; 2494 | "info" ) task_info;; 2495 | "update" | "upgrade" | "up" ) task_update;; 2496 | "dev" | "beta" ) task_dev;; 2497 | "logs" | "log" ) task_logs;; 2498 | * ) task_invalid;; 2499 | esac 2500 | 2501 | # END OF SCRIPT ############################## 2502 | -------------------------------------------------------------------------------- /gravity-sync.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # GRAVITY SYNC BY VMSTAN ##################### 4 | # GS 3.x to 4.0 Upgrade Utility ############## 5 | 6 | # Run only to upgrade your existing Gravity Sync 3.x installation to 4.0 format 7 | PROGRAM='Gravity Sync' 8 | 9 | GS_FILEPATH=$(realpath $0) 10 | LOCAL_FOLDR=$(dirname $GS_FILEPATH) 11 | 12 | GS_ETC_PATH="/etc/gravity-sync" 13 | GS_GRAVITY_FI_MD5_LOG='gs-gravity.md5' 14 | GS_CUSTOM_DNS_MD5_LOG='gs-clist.md5' 15 | GS_CNAME_CONF_MD5_LOG='05-pihole-custom-cname.conf.md5' 16 | 17 | OS_DAEMON_PATH='/etc/systemd/system' 18 | 19 | ## Script Colors 20 | RED='\033[0;91m' 21 | GREEN='\033[0;92m' 22 | CYAN='\033[0;96m' 23 | YELLOW='\033[0;93m' 24 | PURPLE='\033[0;95m' 25 | BLUE='\033[0;94m' 26 | BOLD='\033[1m' 27 | NC='\033[0m' 28 | 29 | ## Message Codes 30 | FAIL="${RED}✗${NC}" 31 | WARN="${PURPLE}!${NC}" 32 | GOOD="${GREEN}✓${NC}" 33 | STAT="${CYAN}∞${NC}" 34 | INFO="${YELLOW}»${NC}" 35 | INF1="${CYAN}›${NC}" 36 | NEED="${BLUE}?${NC}" 37 | LOGO="${PURPLE}∞${NC}" 38 | 39 | ## Echo Stack 40 | ### Informative 41 | function echo_info { 42 | echo -e "${INFO} ${YELLOW}${MESSAGE}${NC}" 43 | } 44 | 45 | function echo_prompt { 46 | echo -e "${INF1} ${CYAN}${MESSAGE}${NC}" 47 | } 48 | 49 | ### Warning 50 | function echo_warn { 51 | echo -e "${WARN} ${PURPLE}${MESSAGE}${NC}" 52 | } 53 | 54 | ### Executing 55 | function echo_stat { 56 | echo -en "${STAT} ${MESSAGE}" 57 | } 58 | 59 | ### Success 60 | function echo_good { 61 | echo -e "\r${GOOD} ${MESSAGE}" 62 | } 63 | 64 | ### Success 65 | function echo_good_clean { 66 | echo -e "\r${GOOD} ${MESSAGE}" 67 | } 68 | 69 | ### Failure 70 | function echo_fail { 71 | echo -e "\r${FAIL} ${MESSAGE}" 72 | } 73 | 74 | ### Request 75 | function echo_need { 76 | echo -en "${NEED} ${BOLD}${MESSAGE}:${NC} " 77 | } 78 | 79 | ### Indent 80 | function echo_over { 81 | echo -e " ${MESSAGE}" 82 | } 83 | 84 | ### Gravity Sync Logo 85 | function echo_grav { 86 | echo -e "${LOGO} ${BOLD}${MESSAGE}${NC}" 87 | } 88 | 89 | ### Lines 90 | function echo_blank { 91 | echo -e "" 92 | } 93 | 94 | ## Error Validation 95 | function error_validate { 96 | if [ "$?" != "0" ]; then 97 | echo_fail 98 | exit 1 99 | else 100 | echo_good 101 | fi 102 | } 103 | 104 | function start_gs_no_config { 105 | MESSAGE="Gravity Sync 3.x to 4.0 Migration Utility" 106 | echo_grav 107 | } 108 | 109 | function check_old_version { 110 | MESSAGE="Checking for 3.x Configuration File" 111 | echo_stat 112 | 113 | if [ -f settings/gravity-sync.conf ]; then 114 | echo_good 115 | else 116 | echo_fail 117 | exit 1 118 | fi 119 | 120 | } 121 | 122 | function install_new_gravity { 123 | MESSAGE="Installing Gravity Sync 4.0" 124 | echo_info 125 | 126 | if [ -d /etc/gravity-sync/.gs ]; then 127 | MESSAGE="Removing existing GitHub cache" 128 | echo_stat 129 | sudo rm -fr /etc/gravity-sync/.gs 130 | error_validate 131 | fi 132 | 133 | if [ ! -d /etc/gravity-sync ]; then 134 | MESSAGE="Creating new configuration directory" 135 | echo_stat 136 | sudo mkdir /etc/gravity-sync 137 | error_validate 138 | fi 139 | 140 | MESSAGE="Validating configuration directory permissions" 141 | echo_stat 142 | sudo chmod 775 /etc/gravity-sync 143 | error_validate 144 | 145 | if [ -f /usr/local/bin/gravity-sync ]; then 146 | MESSAGE="Removing old Gravity Sync binary" 147 | echo_stat 148 | sudo rm -f /usr/local/bin/gravity-sync 149 | error_validate 150 | fi 151 | 152 | MESSAGE="Creating new GitHub cache" 153 | echo_prompt 154 | 155 | sudo git clone https://github.com/vmstan/gravity-sync.git /etc/gravity-sync/.gs 156 | 157 | # MESSAGE="Enabling beta updates" 158 | # echo_stat 159 | # sudo touch /etc/gravity-sync/.gs/dev 160 | # echo -e "BRANCH='origin/4.0.0'" | sudo tee /etc/gravity-sync/.gs/dev 1> /dev/null 161 | # error_validate 162 | 163 | sudo cp /etc/gravity-sync/.gs/gravity-sync /usr/local/bin 164 | } 165 | 166 | function upgrade_to_4 { 167 | MESSAGE="Migrating Previous Configuration" 168 | echo_info 169 | 170 | REMOTE_HOST='' 171 | REMOTE_USER='' 172 | 173 | PIHOLE_DIR='' 174 | RIHOLE_DIR='' 175 | DNSMAQ_DIR='' 176 | RNSMAQ_DIR='' 177 | FILE_OWNER='' 178 | RILE_OWNER='' 179 | DOCKER_CON='' 180 | ROCKER_CON='' 181 | 182 | SSH_PORT='' 183 | SSH_PKIF='' 184 | 185 | MESSAGE="Reviewing old configuration file settings" 186 | echo_stat 187 | source settings/gravity-sync.conf 188 | error_validate 189 | 190 | MESSAGE="Creating new configuration file from template" 191 | echo_stat 192 | sudo cp /etc/gravity-sync/.gs/templates/gravity-sync.conf.example /etc/gravity-sync/gravity-sync.conf 193 | error_validate 194 | 195 | LOCAL_PIHOLE_DIRECTORY=${PIHOLE_DIR} 196 | REMOTE_PIHOLE_DIRECTORY=${RIHOLE_DIR} 197 | LOCAL_DNSMASQ_DIRECTORY=${DNSMAQ_DIR} 198 | REMOTE_DNSMASQ_DIRECTORY=${RNSMAQ_DIR} 199 | LOCAL_FILE_OWNER=${FILE_OWNER} 200 | REMOTE_FILE_OWNER=${RILE_OWNER} 201 | LOCAL_DOCKER_CONTAINER=${DOCKER_CON} 202 | REMOTE_DOCKER_CONTAINER=${ROCKER_CON} 203 | 204 | CURRENTUSER=$(whoami) 205 | MESSAGE="Transferring SSH keys" 206 | echo_stat 207 | if [ "${SSH_PKIF}" == "" ]; then 208 | sudo cp $HOME/.ssh/id_rsa /etc/gravity-sync/gravity-sync.rsa 209 | sudo cp $HOME/.ssh/id_rsa.pub /etc/gravity-sync/gravity-sync.rsa.pub 210 | else 211 | sudo cp ${SSH_PKIF} /etc/gravity-sync/gravity-sync.rsa 212 | sudo cp ${SSH_PKIF}.pub /etc/gravity-sync/gravity-sync.rsa.pub 213 | fi 214 | error_validate 215 | 216 | MESSAGE="Setting SSH key owner" 217 | echo_stat 218 | sudo chown ${CURRENTUSER}:${CURRENTUSER} /etc/gravity-sync/gravity-sync.rsa 219 | sudo chown ${CURRENTUSER}:${CURRENTUSER} /etc/gravity-sync/gravity-sync.rsa.pub 220 | error_validate 221 | 222 | MESSAGE="Migrating remote host settings" 223 | echo_stat 224 | sudo sed -i "/REMOTE_HOST=''/c\REMOTE_HOST='${REMOTE_HOST}'" /etc/gravity-sync/gravity-sync.conf 225 | error_validate 226 | 227 | MESSAGE="Migrating remote user settings" 228 | echo_stat 229 | sudo sed -i "/REMOTE_USER=''/c\REMOTE_USER='${REMOTE_USER}'" /etc/gravity-sync/gravity-sync.conf 230 | error_validate 231 | 232 | if [ "${SSH_PORT}" != "" ]; then 233 | GS_SSH_PORT=${SSH_PORT} 234 | MESSAGE="Migrating target host SSH settings" 235 | echo_stat 236 | echo -e "GS_SSH_PORT='${GS_SSH_PORT}" | sudo tee -a /etc/gravity-sync/gravity-sync.conf 1> /dev/null 237 | error_validate 238 | fi 239 | 240 | if [ "${LOCAL_PIHOLE_DIRECTORY}" == '' ] || [ "${LOCAL_PIHOLE_DIRECTORY}" == '/etc/pihole' ]; then 241 | MESSAGE="Defaulting local Pi-hole directory setting" 242 | echo_good_clean 243 | else 244 | MESSAGE="Migrating local Pi-hole directory setting" 245 | echo_stat 246 | sudo sed -i "/LOCAL_PIHOLE_DIRECTORY=''/c\LOCAL_PIHOLE_DIRECTORY='${LOCAL_PIHOLE_DIRECTORY}'" /etc/gravity-sync/gravity-sync.conf 247 | error_validate 248 | fi 249 | 250 | if [ "${REMOTE_PIHOLE_DIRECTORY}" == '' ] || [ "${REMOTE_PIHOLE_DIRECTORY}" == '/etc/pihole' ]; then 251 | MESSAGE="Defaulting remote Pi-hole directory setting" 252 | echo_good_clean 253 | else 254 | MESSAGE="Migrating remote Pi-hole directory setting" 255 | echo_stat 256 | sudo sed -i "/REMOTE_PIHOLE_DIRECTORY=''/c\REMOTE_PIHOLE_DIRECTORY='${REMOTE_PIHOLE_DIRECTORY}'" /etc/gravity-sync/gravity-sync.conf 257 | error_validate 258 | fi 259 | 260 | if [ "${LOCAL_DNSMASQ_DIRECTORY}" == '' ] || [ "${LOCAL_DNSMASQ_DIRECTORY}" == '/etc/dnsmasq.d' ]; then 261 | MESSAGE="Defaulting local DNSMASQ directory setting" 262 | echo_good_clean 263 | else 264 | MESSAGE="Migrating local DNSMASQ directory setting" 265 | echo_stat 266 | sudo sed -i "/LOCAL_DNSMASQ_DIRECTORY=''/c\LOCAL_DNSMASQ_DIRECTORY='${LOCAL_DNSMASQ_DIRECTORY}'" /etc/gravity-sync/gravity-sync.conf 267 | error_validate 268 | fi 269 | 270 | if [ "${REMOTE_DNSMASQ_DIRECTORY}" == '' ] || [ "${REMOTE_DNSMASQ_DIRECTORY}" == '/etc/dnsmasq.d' ]; then 271 | MESSAGE="Defaulting remote DNSMASQ directory setting" 272 | echo_good_clean 273 | else 274 | MESSAGE="Migrating remote DNSMASQ directory setting" 275 | echo_stat 276 | sudo sed -i "/REMOTE_DNSMASQ_DIRECTORY=''/c\REMOTE_DNSMASQ_DIRECTORY='${REMOTE_DNSMASQ_DIRECTORY}'" /etc/gravity-sync/gravity-sync.conf 277 | error_validate 278 | fi 279 | 280 | if [ "${LOCAL_FILE_OWNER}" == '' ]; then 281 | MESSAGE="Defaulting local file owner setting" 282 | echo_good_clean 283 | else 284 | MESSAGE="Migrating local file owner setting" 285 | echo_stat 286 | sudo sed -i "/LOCAL_FILE_OWNER=''/c\LOCAL_FILE_OWNER='${LOCAL_FILE_OWNER}'" /etc/gravity-sync/gravity-sync.conf 287 | error_validate 288 | fi 289 | 290 | if [ "${REMOTE_FILE_OWNER}" == '' ]; then 291 | MESSAGE="Defaulting remote file owner setting" 292 | echo_good_clean 293 | else 294 | MESSAGE="Migrating remote file owner setting" 295 | echo_stat 296 | sudo sed -i "/REMOTE_FILE_OWNER=''/c\REMOTE_FILE_OWNER='${REMOTE_FILE_OWNER}'" /etc/gravity-sync/gravity-sync.conf 297 | error_validate 298 | fi 299 | 300 | if [ "${LOCAL_DOCKER_CONTAINER}" == '' ] || [ "${LOCAL_DOCKER_CONTAINER}" == 'pihole' ]; then 301 | MESSAGE="Defaulting local Pi-hole container setting" 302 | echo_good_clean 303 | else 304 | MESSAGE="Migrating local Pi-hole container setting" 305 | echo_stat 306 | sudo sed -i "/LOCAL_DOCKER_CONTAINER=''/c\LOCAL_DOCKER_CONTAINER='${LOCAL_DOCKER_CONTAINER}'" /etc/gravity-sync/gravity-sync.conf 307 | error_validate 308 | fi 309 | 310 | if [ "${REMOTE_DOCKER_CONTAINER}" == '' ] || [ "${REMOTE_DOCKER_CONTAINER}" == 'pihole' ]; then 311 | MESSAGE="Defaulting remote Pi-hole container setting" 312 | echo_good_clean 313 | else 314 | MESSAGE="Migrating local Pi-hole container setting" 315 | echo_stat 316 | sudo sed -i "/REMOTE_DOCKER_CONTAINER=''/c\REMOTE_DOCKER_CONTAINER='${REMOTE_DOCKER_CONTAINER}'" /etc/gravity-sync/gravity-sync.conf 317 | error_validate 318 | fi 319 | 320 | MESSAGE="Migrating task history" 321 | echo_stat 322 | sudo cp logs/gravity-sync.log /etc/gravity-sync/gs-sync.log 323 | error_validate 324 | 325 | MESSAGE="Migrating hashing tables" 326 | echo_stat 327 | if [ -f "logs/gravity-sync.md5" ]; then 328 | REMOTE_DB_MD5=$(sed "1q;d" logs/gravity-sync.md5) 329 | LOCAL_DB_MD5=$(sed "2q;d" logs/gravity-sync.md5) 330 | REMOTE_CL_MD5=$(sed "3q;d" logs/gravity-sync.md5) 331 | LOCAL_CL_MD5=$(sed "4q;d" logs/gravity-sync.md5) 332 | REMOTE_CN_MD5=$(sed "5q;d" logs/gravity-sync.md5) 333 | LOCAL_CN_MD5=$(sed "6q;d" logs/gravity-sync.md5) 334 | 335 | echo -e ${REMOTE_DB_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 336 | echo -e ${LOCAL_DB_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 337 | echo -e ${REMOTE_CL_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 338 | echo -e ${LOCAL_CL_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 339 | echo -e ${REMOTE_CN_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 340 | echo -e ${LOCAL_CN_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 341 | else 342 | REMOTE_DB_MD5="0" 343 | LOCAL_DB_MD5="0" 344 | REMOTE_CL_MD5="0" 345 | LOCAL_CL_MD5="0" 346 | REMOTE_CN_MD5="0" 347 | LOCAL_CN_MD5="0" 348 | 349 | echo -e ${REMOTE_DB_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 350 | echo -e ${LOCAL_DB_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_GRAVITY_FI_MD5_LOG} 1> /dev/null 351 | echo -e ${REMOTE_CL_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 352 | echo -e ${LOCAL_CL_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CUSTOM_DNS_MD5_LOG} 1> /dev/null 353 | echo -e ${REMOTE_CN_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 354 | echo -e ${LOCAL_CN_MD5} | sudo tee -a ${GS_ETC_PATH}/${GS_CNAME_CONF_MD5_LOG} 1> /dev/null 355 | fi 356 | error_validate 357 | } 358 | 359 | function remove_old_version { 360 | MESSAGE="Removing Old Version & Settings" 361 | echo_info 362 | 363 | if hash crontab 2>/dev/null; then 364 | MESSAGE="Clearing automation from crontab" 365 | echo_stat 366 | crontab -l > cronjob-old.tmp 367 | sed "/gravity-sync.sh/d" cronjob-old.tmp > cronjob-new.tmp 368 | crontab cronjob-new.tmp 369 | error_validate 370 | fi 371 | 372 | kill_automation_service 373 | 374 | if [ -f /etc/bash.bashrc ]; then 375 | MESSAGE="Cleaning up bash.bashrc" 376 | echo_info 377 | sudo sed -i "/gravity-sync.sh/d" /etc/bash.bashrc 378 | error_validate 379 | fi 380 | 381 | MESSAGE="Removing old Gravity Sync folder" 382 | echo_stat 383 | sudo rm -fr ${LOCAL_FOLDR} 384 | error_validate 385 | } 386 | 387 | function kill_automation_service { 388 | if systemctl is-active --quiet gravity-sync.timer; then 389 | MESSAGE="Stopping ${PROGRAM} timer" 390 | echo_stat 391 | sudo systemctl stop gravity-sync 392 | error_validate 393 | 394 | MESSAGE="Disabling ${PROGRAM} automation service" 395 | echo_stat 396 | sudo systemctl disable gravity-sync --quiet 397 | error_validate 398 | 399 | MESSAGE="Removing systemd timer" 400 | echo_stat 401 | sudo rm -f ${OS_DAEMON_PATH}/gravity-sync.timer 402 | error_validate 403 | 404 | MESSAGE="Removing systemd service" 405 | echo_stat 406 | sudo rm -f ${OS_DAEMON_PATH}/gravity-sync.service 407 | error_validate 408 | 409 | MESSAGE="Reloading systemd daemon" 410 | echo_stat 411 | sudo systemctl daemon-reload --quiet 412 | error_validate 413 | fi 414 | } 415 | 416 | function end_migration { 417 | MESSAGE="Migration Complete" 418 | echo_info 419 | 420 | 421 | } 422 | 423 | # SCRIPT EXECUTION ########################### 424 | 425 | case $# in 426 | 0) 427 | start_gs_no_config 428 | check_old_version 429 | install_new_gravity 430 | upgrade_to_4 431 | remove_old_version 432 | end_migration ;; 433 | 1) 434 | case $1 in 435 | *) 436 | start_gs_no_config 437 | check_old_version 438 | install_new_gravity 439 | upgrade_to_4 440 | remove_old_version 441 | end_migration ;; 442 | esac 443 | ;; 444 | 445 | *) 446 | start_gs_no_config 447 | check_old_version 448 | install_new_gravity 449 | upgrade_to_4 450 | remove_old_version 451 | end_migration ;; 452 | esac 453 | 454 | # END OF SCRIPT ############################## -------------------------------------------------------------------------------- /images/gs-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /templates/gravity-sync.conf.example: -------------------------------------------------------------------------------- 1 | # REQUIRED SETTINGS ########################## 2 | 3 | REMOTE_HOST='' 4 | REMOTE_USER='' 5 | 6 | # CUSTOM VARIABLES ########################### 7 | 8 | # Pi-hole Folder/File Customization - Only need to be customized when using containers 9 | # LOCAL_PIHOLE_DIRECTORY='' # Local Pi-hole data directory 10 | # REMOTE_PIHOLE_DIRECTORY='' # Remote Pi-hole data directory 11 | # LOCAL_DNSMASQ_DIRECTORY='' # Local DNSMASQ/FTL data directory 12 | # REMOTE_DNSMASQ_DIRECTORY='' # Remote DNSMASQ/FTL data directory 13 | # LOCAL_FILE_OWNER='' # Local file owner for Pi-hole 14 | # REMOTE_FILE_OWNER='' # Remote file owner for Pi-hole 15 | 16 | # Pi-hole Docker/Podman container name - Docker will pattern match anything set below 17 | # LOCAL_DOCKER_CONTAINER='' # Local Pi-hole container name 18 | # REMOTE_DOCKER_CONTAINER='' # Remote Pi-hole container name 19 | 20 | # HIDDEN FIGURES ############################# 21 | # See https://github.com/vmstan/gravity-sync/wiki/Hidden-Figures 22 | -------------------------------------------------------------------------------- /templates/gravity-sync.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Synchronize Pi-hole instances 3 | After=network-online.target 4 | Wants=gravity-sync.timer 5 | 6 | [Service] 7 | Type=simple 8 | User=unknown 9 | ExecStart= 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /templates/gravity-sync.timer: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Synchronize Pi-hole instances 3 | RefuseManualStart=no 4 | RefuseManualStop=no 5 | Requires=gravity-sync.service 6 | 7 | [Timer] 8 | Unit=gravity-sync.service 9 | Persistent=true 10 | OnBootSec=120 11 | OnUnitInactiveSec=5m 12 | RandomizedDelaySec=5m 13 | 14 | [Install] 15 | WantedBy=timers.target 16 | -------------------------------------------------------------------------------- /templates/gs-nopasswd.sudo: -------------------------------------------------------------------------------- 1 | pi ALL=NOPASSWD: /etc/pihole -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | GS_LOCAL_REPO='/etc/gravity-sync/.gs' 4 | 5 | if [ -f "${GS_LOCAL_REPO}/dev" ]; then 6 | source ${GS_LOCAL_REPO}/dev 7 | else 8 | BRANCH='origin/master' 9 | fi 10 | 11 | if [ "$BRANCH" != "origin/master" ]; then 12 | echo -e "Pulling from ${BRANCH}" 13 | fi 14 | 15 | (cd ${GS_LOCAL_REPO}; sudo git fetch --all; sudo git reset --hard ${BRANCH}; sudo cp gravity-sync /usr/local/bin; sudo git clean -fq) 16 | 17 | --------------------------------------------------------------------------------