-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f20c6d0
commit b7db02c
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
## Intial settings | ||
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
CONFIG_PATH="$SCRIPT_DIR/settings.conf" | ||
DOMAINS_PATH="$SCRIPT_DIR/domains.conf" | ||
|
||
## Check and read configuration file | ||
if [ ! -f "$CONFIG_PATH" ]; then | ||
echo "Configuration file is not exist!" >&2 | ||
exit 1 | ||
fi | ||
|
||
source "$CONFIG_PATH" | ||
|
||
## Check TUN settings | ||
if [ -z "$TUN" ]; then | ||
echo "Settings [TUN] is empty!" >&2 | ||
exit 1 | ||
fi | ||
|
||
## Check domain configuration file | ||
if [ ! -f "$DOMAINS_PATH" ]; then | ||
echo "Domains file is not exit!" >&2 | ||
exit 1 | ||
fi | ||
|
||
## Process domains | ||
while read -r DOMAIN | ||
do | ||
echo "Start to process domain [$DOMAIN]..." >&2 | ||
|
||
DOMAIN_IPS="$(host -t a "$DOMAIN" | awk '{print $4}' | egrep ^[1-9] | sort | uniq)" | ||
|
||
for IP in ${DOMAIN_IPS[*]} | ||
do | ||
echo " * Adding route for IP [$IP]" | ||
#route add -net "$IP" dev "$TUN" | ||
done | ||
|
||
echo "End of process domain [$DOMAIN]" >&2 | ||
echo "" >&2 | ||
done < "$DOMAINS_PATH" | ||
|
||
exit 0 |