44# This script installs and configures the webhook provider on Firewalla
55#
66# Usage:
7- # ./scripts/install.sh [domain-filter]
8- # curl -fsSL https://raw.githubusercontent.com/.../install.sh | bash -s -- "example.com,*.example.com"
7+ # 1. Create config file with your domain filter:
8+ # echo "home.local,*.home.local" > /tmp/external-dns-domain-filter
9+ # 2. Run the installation:
10+ # curl -fsSL https://raw.githubusercontent.com/.../install.sh | bash
911#
1012set -e
1113
@@ -15,22 +17,57 @@ GREEN='\033[0;32m'
1517YELLOW=' \033[1;33m'
1618NC=' \033[0m' # No Color
1719
18- # Get domain filter from first argument if provided
19- DOMAIN_FILTER=" ${1:- } "
20-
2120# Configuration
2221INSTALL_DIR=" /opt/external-dns-firewalla-webhook"
2322SERVICE_NAME=" external-dns-firewalla-webhook"
2423SERVICE_FILE=" external-dns-firewalla-webhook.service"
2524DNSMASQ_DIR=" /home/pi/.firewalla/config/dnsmasq_local"
2625SUDOERS_FILE=" /etc/sudoers.d/external-dns-webhook"
2726GITHUB_REPO=" https://github.com/TheOutdoorProgrammer/external-dns-firewalla-webhook.git"
27+ CONFIG_FILE=" /tmp/external-dns-domain-filter"
2828
2929echo " ========================================="
3030echo " External-DNS Firewalla Webhook Installer"
3131echo " ========================================="
3232echo " "
3333
34+ # Check for config file first
35+ if [ ! -f " $CONFIG_FILE " ]; then
36+ echo -e " ${RED} ERROR: Configuration file not found${NC} "
37+ echo " "
38+ echo " Before running this installer, you must create a config file with your domain filter."
39+ echo " "
40+ echo " Step 1: Create the config file with your domain(s):"
41+ echo " echo \" home.local,*.home.local\" > $CONFIG_FILE "
42+ echo " "
43+ echo " Step 2: Run the installer:"
44+ echo " curl -fsSL https://raw.githubusercontent.com/TheOutdoorProgrammer/external-dns-firewalla-webhook/main/scripts/install.sh | bash"
45+ echo " "
46+ echo " For interactive installation:"
47+ echo " git clone $GITHUB_REPO "
48+ echo " cd external-dns-firewalla-webhook"
49+ echo " echo \" home.local,*.home.local\" > $CONFIG_FILE "
50+ echo " ./scripts/install.sh"
51+ echo " "
52+ exit 1
53+ fi
54+
55+ # Read domain filter from config file
56+ DOMAIN_FILTER=$( cat " $CONFIG_FILE " | tr -d ' \n\r' | xargs)
57+
58+ if [ -z " $DOMAIN_FILTER " ]; then
59+ echo -e " ${RED} ERROR: Config file is empty${NC} "
60+ echo " "
61+ echo " The file $CONFIG_FILE exists but contains no domain filter."
62+ echo " Please add your domain filter to the file:"
63+ echo " echo \" home.local,*.home.local\" > $CONFIG_FILE "
64+ echo " "
65+ exit 1
66+ fi
67+
68+ echo -e " ${GREEN} Found domain filter:${NC} $DOMAIN_FILTER "
69+ echo " "
70+
3471# Check if running as pi user
3572if [ " $( whoami) " != " pi" ]; then
3673 echo -e " ${RED} ERROR: Please run as pi user (not root)${NC} "
@@ -123,44 +160,13 @@ echo "Dependencies verified (bundled in repository)"
123160
124161# Configure environment
125162echo -e " ${GREEN} [6/9]${NC} Configuring environment..."
126- if [ ! -s " $INSTALL_DIR /.env" ] || ! grep -q " DOMAIN_FILTER=" " $INSTALL_DIR /.env" || grep -q " DOMAIN_FILTER=example.com" " $INSTALL_DIR /.env" ; then
127- # If domain filter not provided as argument, try to read from stdin
128- if [ -z " $DOMAIN_FILTER " ]; then
129- # Check if stdin is a terminal (interactive)
130- if [ -t 0 ]; then
131- echo " "
132- echo -e " ${YELLOW} Please enter your domain filter (comma-separated, e.g., example.com,*.example.com):${NC} "
133- read -p " Domain filter: " DOMAIN_FILTER
134- else
135- # Not interactive (piped from curl)
136- echo " "
137- echo -e " ${RED} ERROR: Domain filter is required but not provided${NC} "
138- echo " "
139- echo " When using the one-line install, provide your domain filter as an argument:"
140- echo " "
141- echo " curl -fsSL https://raw.githubusercontent.com/.../install.sh | bash -s -- \" example.com,*.example.com\" "
142- echo " "
143- echo " Alternatively, run the installation interactively:"
144- echo " "
145- echo " git clone $GITHUB_REPO "
146- echo " cd external-dns-firewalla-webhook"
147- echo " ./scripts/install.sh"
148- echo " "
149- exit 1
150- fi
151- fi
152-
153- if [ -z " $DOMAIN_FILTER " ]; then
154- echo -e " ${RED} ERROR: Domain filter cannot be empty${NC} "
155- exit 1
156- fi
157-
158- # Update .env file
159- sed -i " s/DOMAIN_FILTER=.*/DOMAIN_FILTER=$DOMAIN_FILTER /" " $INSTALL_DIR /.env"
160- echo " Domain filter configured: $DOMAIN_FILTER "
161- else
162- echo " Using existing .env configuration"
163- fi
163+ # Update .env file with domain filter from config file
164+ sed -i " s/DOMAIN_FILTER=.*/DOMAIN_FILTER=$DOMAIN_FILTER /" " $INSTALL_DIR /.env"
165+ echo " Domain filter configured: $DOMAIN_FILTER "
166+
167+ # Clean up config file after successful configuration
168+ rm -f " $CONFIG_FILE "
169+ echo " Removed temporary config file"
164170
165171# Create dnsmasq directory
166172echo -e " ${GREEN} [7/9]${NC} Creating dnsmasq directory..."
0 commit comments