push code
This commit is contained in:
parent
a78bc9450b
commit
b76487e91e
4 changed files with 79 additions and 12 deletions
11
README.md
Normal file
11
README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# AutoGRE
|
||||||
|
|
||||||
|
Tool to dynamically update GRE tunnels in a network based on a FQDN.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Not good looking install command by curl and bash:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -s https://git.gnous.eu/mael/autogre/raw/branch/main/install.sh | bash
|
||||||
|
```
|
13
autogre.sh
13
autogre.sh
|
@ -6,15 +6,13 @@
|
||||||
# If not defined in the environment, the following variables will be used
|
# If not defined in the environment, the following variables will be used
|
||||||
|
|
||||||
if [[ -z $GRE_TUNNEL_NAME ]]; then
|
if [[ -z $GRE_TUNNEL_NAME ]]; then
|
||||||
GRE_TUNNEL_NAME="gre1"
|
|
||||||
GRE_TUNNEL_NAME="gre1"
|
GRE_TUNNEL_NAME="gre1"
|
||||||
GRE_LOCAL_IP="45.13.XX.XX"
|
GRE_LOCAL_IP="45.13.XX.XX"
|
||||||
GRE_LAN_IP_4="192.168.100.1/24"
|
GRE_LAN_IP_4="192.168.100.1/24"
|
||||||
GRE_LAN_IP_6="2a0e:fd45:2a0c::1/64"
|
GRE_LAN_IP_6="2a0e:fd45:2a0c::1/64"
|
||||||
|
FQDN="remote.example.com"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FQDN=$1 # The remote host FQDN
|
|
||||||
|
|
||||||
# FUNCTIONS
|
# FUNCTIONS
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "Usage: $0 <remote_host_fqdn>"
|
echo "Usage: $0 <remote_host_fqdn>"
|
||||||
|
@ -28,14 +26,6 @@ function check_root() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function check_fqdn() {
|
|
||||||
if [[ -z $FQDN ]]; then
|
|
||||||
echo "Please provide the remote host FQDN"
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_current_ip() {
|
function get_current_ip() {
|
||||||
# Get the dst IP on the GRE tunnel
|
# Get the dst IP on the GRE tunnel
|
||||||
CURRENT_IP=$(ip addr show $GRE_TUNNEL_NAME | grep -Po 'peer \K[\d.]+')
|
CURRENT_IP=$(ip addr show $GRE_TUNNEL_NAME | grep -Po 'peer \K[\d.]+')
|
||||||
|
@ -98,7 +88,6 @@ function check_remote_ip() {
|
||||||
# MAIN
|
# MAIN
|
||||||
function main() {
|
function main() {
|
||||||
check_root
|
check_root
|
||||||
check_fqdn
|
|
||||||
|
|
||||||
echo "LOG - $(date) - Starting autogre.sh"
|
echo "LOG - $(date) - Starting autogre.sh"
|
||||||
echo "LOG - $(date) - FQDN: $FQDN"
|
echo "LOG - $(date) - FQDN: $FQDN"
|
||||||
|
|
8
default.example
Normal file
8
default.example
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Default environment variables example
|
||||||
|
# Copy in /etc/default/autogre - and edit
|
||||||
|
|
||||||
|
GRE_TUNNEL_NAME="gre_ren"
|
||||||
|
GRE_LOCAL_IP="10.10.10.10"
|
||||||
|
GRE_LAN_IP_4="192.168.100.1/24"
|
||||||
|
GRE_LAN_IP_6="2a0e:fd45:2a0e::/126"
|
||||||
|
FQDN="example.infra.tech"
|
59
install.sh
Normal file
59
install.sh
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# INSTALLATION SCRIPT FOR autogre.sh
|
||||||
|
# Will install the script in /usr/local/bin/autogre.sh
|
||||||
|
# Will install the systemd service in /etc/systemd/system/autogre.service
|
||||||
|
# Will install the systemd timer in /etc/systemd/system/autogre.timer
|
||||||
|
|
||||||
|
# FUNCTIONS
|
||||||
|
|
||||||
|
function copy_auto_gre() {
|
||||||
|
curl https://git.gnous.eu/mael/autogre/raw/branch/main/autogre.sh > /usr/local/bin/autogre.sh
|
||||||
|
chmod +x /usr/local/bin/autogre.sh
|
||||||
|
}
|
||||||
|
|
||||||
|
function generate_systemd_service() {
|
||||||
|
cat << EOF > /etc/systemd/system/autogre.service
|
||||||
|
[Unit]
|
||||||
|
Description=Auto GRE tunnel service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
EnvironmentFile=/etc/default/autogre
|
||||||
|
Type=simple
|
||||||
|
ExecStart=/usr/local/bin/autogre.sh
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function generate_systemd_timer() {
|
||||||
|
cat << EOF > /etc/systemd/system/autogre.timer
|
||||||
|
[Unit]
|
||||||
|
Description=Auto GRE tunnel timer
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnBootSec=1min
|
||||||
|
OnUnitActiveSec=1min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function enable_systemd_timer_and_service() {
|
||||||
|
systemctl enable autogre.service
|
||||||
|
systemctl start autogre.service
|
||||||
|
systemctl enable autogre.timer
|
||||||
|
systemctl start autogre.timer
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
copy_auto_gre
|
||||||
|
generate_systemd_service
|
||||||
|
generate_systemd_timer
|
||||||
|
enable_systemd_timer_and_service
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
Loading…
Reference in a new issue