-
Notifications
You must be signed in to change notification settings - Fork 1
/
mikrotik_gen.sh
executable file
·77 lines (60 loc) · 1.62 KB
/
mikrotik_gen.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash -e
ARGUMENT_LIST=(
"country:"
"gateway:"
"help"
)
# read arguments
opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "$0")" \
--options "" \
-- "$@"
)
eval set --$opts
while [[ $# -gt 0 ]]; do
case "$1" in
--country)
countryiso=$2
shift 2
;;
--gateway)
gateway=$2
shift 2
;;
--help)
echo "This script helps you to add routes for a specific country."
echo ""
echo "In order to run interactiveley just call this script without the --help switch."
echo "This command requires superuser privilages! (MUST run as root)"
echo ""
echo "Arguments:"
echo -e "\t--country\tCountry of your choice as 2-letter ISO code. Example: US, IR"
echo -e "\t--gateway\tGateway used to route to these ip addresses. Example: 192.168.0.1 OR vpn0"
echo -e "\t--help\t\tShows this help."
exit
;;
*)
break
;;
esac
done
if [ -z ${countryiso+x} ];
then
read -p 'Country ISO code (example US): ' countryiso
else
echo "Country: $countryiso"
fi
if [ -z ${gateway+x} ];
then
read -p "Enter the gateway that you want to use for $countryiso (example 192.168.0.1 OR vpn0): " gateway
else
echo "Gateway: $gateway"
fi
countryiso=$(echo "$countryiso" | tr '[:upper:]' '[:lower:]')
input="db/country/$countryiso/ipv4.cidr"
while IFS= read -r line
do
echo "ip route add dst-address=$line gateway=$gateway">>mikrotik_script.txt
echo "ip route remove [find dst-address=$line gateway=$gateway]">>mikrotik_restore_script.txt
done < "$input"