Updated script to use positional arguments
This commit is contained in:
parent
4f36382a6c
commit
f69429aa14
27
README.md
27
README.md
@ -294,16 +294,25 @@ Test batch subscription from an existing CSV file (standalone, no external depen
|
|||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
```bash
|
```bash
|
||||||
./test-subscribe-members2.sh <csv_file> [list_id]
|
./test-subscribe-members.sh <csv_file> <password> [list_id] [connector_url]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Arguments:**
|
||||||
|
- `csv_file` - Path to CSV file with format: email,first_name,last_name
|
||||||
|
- `password` - Secret password for the mailman-connector (required)
|
||||||
|
- `list_id` - Target mailing list (default: members.lists.example.org)
|
||||||
|
- `connector_url` - URL of the mailman-connector (default: https://mailman-connector.example.com)
|
||||||
|
|
||||||
**Examples:**
|
**Examples:**
|
||||||
```bash
|
```bash
|
||||||
# Using default list
|
# Using default list and connector URL
|
||||||
./test-subscribe-members2.sh members.csv
|
./test-subscribe-members.sh members.csv mysecretpassword
|
||||||
|
|
||||||
# Using specific list
|
# With specific list
|
||||||
./test-subscribe-members2.sh members.csv test.lists.example.org
|
./test-subscribe-members.sh members.csv mysecretpassword test.lists.example.org
|
||||||
|
|
||||||
|
# With specific list and connector URL
|
||||||
|
./test-subscribe-members.sh members.csv mysecretpassword test.lists.example.org https://connector.example.com
|
||||||
```
|
```
|
||||||
|
|
||||||
**CSV Format:**
|
**CSV Format:**
|
||||||
@ -313,14 +322,6 @@ user2@example.com,Jane,Smith
|
|||||||
user3@example.com,Bob,Johnson
|
user3@example.com,Bob,Johnson
|
||||||
```
|
```
|
||||||
|
|
||||||
**Configuration:**
|
|
||||||
Edit the script or set environment variables:
|
|
||||||
```bash
|
|
||||||
export CONNECTOR_URL="https://mailman-connector.example.com"
|
|
||||||
export CONNECTOR_PASSWORD="your_secret_password"
|
|
||||||
./test-subscribe-members2.sh members.csv
|
|
||||||
```
|
|
||||||
|
|
||||||
## Response Format
|
## Response Format
|
||||||
|
|
||||||
### Success Response (Single Subscribe)
|
### Success Response (Single Subscribe)
|
||||||
|
|||||||
@ -1,41 +1,78 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Test script for batch subscribing members from an existing CSV file
|
# Production batch subscription script for LWVWV members
|
||||||
# Usage: ./test-subscribe-members.sh <csv_file> [list_id]
|
# Usage: ./subscribe-members.sh <csv_file> <password> [list_id] [connector_url]
|
||||||
|
#
|
||||||
|
# This script reads a CSV file (email,first_name,last_name) and subscribes
|
||||||
|
# all members to the specified Mailman list via the connector API.
|
||||||
|
#
|
||||||
|
# Arguments:
|
||||||
|
# csv_file Path to CSV file with format: email,first_name,last_name
|
||||||
|
# password Secret password for the mailman-connector (required)
|
||||||
|
# list_id Target mailing list (default: members.lists.example.org)
|
||||||
|
# connector_url URL of the mailman-connector (default: https://mailman-connector.example.com)
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
# ./test-subscribe-members.sh test.csv
|
# ./subscribe-members.sh members.csv mysecretpassword
|
||||||
# ./test-subscribe-members.sh test.csv listname.atlists.coollists.org
|
# ./subscribe-members.sh members.csv mysecretpassword test.lists.example.org
|
||||||
|
# ./subscribe-members.sh members.csv mysecretpassword test.lists.example.org https://connector.example.com
|
||||||
|
|
||||||
# Configuration
|
# Show help
|
||||||
CONNECTOR_URL="${CONNECTOR_URL:-https://mailman-connector.coollists.org}"
|
show_help() {
|
||||||
CONNECTOR_PASSWORD="${CONNECTOR_PASSWORD:-your_secret_password}"
|
cat << EOF
|
||||||
LIST_ID="${2:-listname.atlists.coollists.org}"
|
Usage: $0 <csv_file> <password> [list_id] [connector_url]
|
||||||
CSV_FILE="$1"
|
|
||||||
|
|
||||||
# Check if CSV file is provided
|
Arguments:
|
||||||
|
csv_file Path to CSV file with format: email,first_name,last_name
|
||||||
|
password Secret password for the mailman-connector (required)
|
||||||
|
list_id Target mailing list (default: members.lists.example.org)
|
||||||
|
connector_url URL of the mailman-connector (default: https://mailman-connector.example.com)
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
$0 members.csv mysecretpassword
|
||||||
|
$0 members.csv mysecretpassword test.lists.example.org
|
||||||
|
$0 members.csv mysecretpassword test.lists.example.org https://connector.example.com
|
||||||
|
|
||||||
|
CSV Format:
|
||||||
|
The CSV file should have one member per line:
|
||||||
|
email@example.com,FirstName,LastName
|
||||||
|
another@example.com,John,Doe
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check for help flag
|
||||||
|
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||||
|
show_help
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Parse arguments
|
||||||
|
CSV_FILE="${1:-}"
|
||||||
|
CONNECTOR_PASSWORD="${2:-}"
|
||||||
|
LIST_ID="${3:-members.lists.example.org}"
|
||||||
|
CONNECTOR_URL="${4:-https://mailman-connector.example.com}"
|
||||||
|
|
||||||
|
# Validation
|
||||||
if [ -z "$CSV_FILE" ]; then
|
if [ -z "$CSV_FILE" ]; then
|
||||||
echo "Usage: $0 <csv_file> [list_id]"
|
echo "Error: CSV file argument is required"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Arguments:"
|
show_help
|
||||||
echo " csv_file Path to CSV file with format: email,first_name,last_name"
|
exit 1
|
||||||
echo " list_id Optional: Target mailing list (default: listname.atlists.coollists.org)"
|
fi
|
||||||
echo ""
|
|
||||||
echo "Examples:"
|
if [ -z "$CONNECTOR_PASSWORD" ]; then
|
||||||
echo " $0 test.csv"
|
echo "Error: Password argument is required"
|
||||||
echo " $0 members.csv listname.atlists.coollists.org"
|
echo ""
|
||||||
echo ""
|
show_help
|
||||||
echo "Environment Variables:"
|
|
||||||
echo " CONNECTOR_PASSWORD Secret password for connector (can also be set via env)"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if file exists
|
|
||||||
if [ ! -f "$CSV_FILE" ]; then
|
if [ ! -f "$CSV_FILE" ]; then
|
||||||
echo "Error: File not found: $CSV_FILE"
|
echo "Error: File not found: $CSV_FILE"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Validate CSV file format (basic check)
|
# Validate CSV format
|
||||||
if ! grep -q ',' "$CSV_FILE"; then
|
if ! grep -q ',' "$CSV_FILE"; then
|
||||||
echo "Error: CSV file appears invalid (no commas found)"
|
echo "Error: CSV file appears invalid (no commas found)"
|
||||||
echo "Expected format: email,first_name,last_name"
|
echo "Expected format: email,first_name,last_name"
|
||||||
@ -44,12 +81,16 @@ fi
|
|||||||
|
|
||||||
# Read CSV content
|
# Read CSV content
|
||||||
CSV_DATA=$(cat "$CSV_FILE")
|
CSV_DATA=$(cat "$CSV_FILE")
|
||||||
|
if [ -z "$CSV_DATA" ]; then
|
||||||
|
echo "Error: CSV file is empty"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Count members
|
# Count members
|
||||||
MEMBER_COUNT=$(wc -l < "$CSV_FILE" | tr -d ' ')
|
MEMBER_COUNT=$(wc -l < "$CSV_FILE" | tr -d ' ')
|
||||||
|
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "Mailman Connector - Batch Subscribe Test"
|
echo "LWVWV Member Subscription"
|
||||||
echo "=========================================="
|
echo "=========================================="
|
||||||
echo "Connector URL: $CONNECTOR_URL"
|
echo "Connector URL: $CONNECTOR_URL"
|
||||||
echo "Target List: $LIST_ID"
|
echo "Target List: $LIST_ID"
|
||||||
@ -66,7 +107,7 @@ if ! command -v jq &> /dev/null; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Send to connector
|
# Send to connector
|
||||||
echo "Sending request to connector..."
|
echo "Subscribing members..."
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
RESPONSE=$(curl -s -X POST "$CONNECTOR_URL" \
|
RESPONSE=$(curl -s -X POST "$CONNECTOR_URL" \
|
||||||
@ -78,7 +119,7 @@ RESPONSE=$(curl -s -X POST "$CONNECTOR_URL" \
|
|||||||
\"csv_data\": $(echo "$CSV_DATA" | jq -R -s .)
|
\"csv_data\": $(echo "$CSV_DATA" | jq -R -s .)
|
||||||
}")
|
}")
|
||||||
|
|
||||||
# Check if response is valid JSON
|
# Check response
|
||||||
if echo "$RESPONSE" | jq -e . &> /dev/null; then
|
if echo "$RESPONSE" | jq -e . &> /dev/null; then
|
||||||
echo "Response:"
|
echo "Response:"
|
||||||
echo "$RESPONSE" | jq .
|
echo "$RESPONSE" | jq .
|
||||||
@ -87,8 +128,8 @@ if echo "$RESPONSE" | jq -e . &> /dev/null; then
|
|||||||
if echo "$RESPONSE" | jq -e '.summary' &> /dev/null; then
|
if echo "$RESPONSE" | jq -e '.summary' &> /dev/null; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Summary:"
|
echo "Summary:"
|
||||||
echo " Total received: $(echo "$RESPONSE" | jq -r '.summary.total_received // "N/A"')"
|
echo " Total processed: $(echo "$RESPONSE" | jq -r '.summary.total_received // "N/A"')"
|
||||||
echo " Subscribed: $(echo "$RESPONSE" | jq -r '.summary.subscribed // "N/A"')"
|
echo " Newly subscribed: $(echo "$RESPONSE" | jq -r '.summary.subscribed // "N/A"')"
|
||||||
echo " Already subscribed: $(echo "$RESPONSE" | jq -r '.summary.already_subscribed // "N/A"')"
|
echo " Already subscribed: $(echo "$RESPONSE" | jq -r '.summary.already_subscribed // "N/A"')"
|
||||||
echo " Errors: $(echo "$RESPONSE" | jq -r '.summary.errors // "N/A"')"
|
echo " Errors: $(echo "$RESPONSE" | jq -r '.summary.errors // "N/A"')"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user