You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-11Lines changed: 31 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,19 +23,39 @@ Automate adding domains and IP addresses to Postfix and Postgrey whitelists on M
23
23
24
24
---
25
25
26
-
## 📝 Overview
27
-
28
26
## Overview
27
+
`add_whitelists.sh` is a universal script to add domains and IP addresses to Postfix and Postgrey whitelists. It supports **single-entry** and **bulk-from-file** modes. The script **auto-creates** missing files/directories, makes **timestamped backups** before changes, **ignores** blank lines and `#` comments, **deduplicates** entries, and **restarts** Postfix/Postgrey only when changes are made. At the end it prints how many entries were added and a list of what was actually added.
28
+
29
+
### Usage
30
+
31
+
**Single entry**
32
+
33
+
sudo ./add_whitelists.sh example.com
34
+
# or
35
+
sudo ./add_whitelists.sh 203.0.113.7
36
+
37
+
**Bulk from a file**
38
+
39
+
1) Create a file `whitelists.txt` with one domain or IP per line (blank lines and `#` comments are ignored):
40
+
41
+
example.com
42
+
mail.example.org
43
+
192.168.1.10
44
+
# comment
45
+
46
+
2) Run:
47
+
48
+
sudo ./add_whitelists.sh -f whitelists.txt
49
+
50
+
### What the script does
51
+
-**Auto-creates** required files if missing:
52
+
-`/etc/postfix/client_whitelist`
53
+
-`/etc/postgrey/whitelist_clients.local`
54
+
-**Backs up** whitelist files with timestamps before modifying them.
55
+
-**Skips duplicates** (doesn’t add the same entry twice).
56
+
-**Rebuilds** Postfix hash map (`postmap`) and **restarts** Postfix/Postgrey only when changes occurred.
57
+
-**Shows a summary**: totals added to Postfix/Postgrey and a list of actually added entries.
29
58
30
-
`add_whitelists.sh` reads a simple text file (`whitelist.txt`) with one domain or IP (CIDR supported) per line, then:
31
-
32
-
1.**Automatically creates missing whitelist files** if they do not exist:
33
-
-`/etc/postfix/client_whitelist`
34
-
-`/etc/postgrey/whitelist_clients.local`
35
-
2. Creates timestamped backups of your existing whitelist files.
36
-
3. Adds entries to Postfix (`/etc/postfix/client_whitelist`) suffixed with `OK`.
37
-
4. Adds domain entries to Postgrey (`/etc/postgrey/whitelist_clients.local`).
38
-
5. Rebuilds the Postfix hash database and restarts both services.
39
59
40
60
Keeping your whitelist entries in a separate file lets you safely publish this script on GitHub without exposing private data.
0 commit comments