Skip to content

Commit e50e853

Browse files
README.md
1 parent 0c18ba7 commit e50e853

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,39 @@ Automate adding domains and IP addresses to Postfix and Postgrey whitelists on M
2323

2424
---
2525

26-
## 📝 Overview
27-
2826
## 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.
2958

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.
3959

4060
Keeping your whitelist entries in a separate file lets you safely publish this script on GitHub without exposing private data.
4161

0 commit comments

Comments
 (0)