diff --git a/README.md b/README.md
new file mode 100644
index 0000000..cd12c07
--- /dev/null
+++ b/README.md
@@ -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
+```
\ No newline at end of file
diff --git a/autogre.sh b/autogre.sh
index db33c3f..651c840 100755
--- a/autogre.sh
+++ b/autogre.sh
@@ -6,15 +6,13 @@
# If not defined in the environment, the following variables will be used
if [[ -z $GRE_TUNNEL_NAME ]]; then
- GRE_TUNNEL_NAME="gre1"
GRE_TUNNEL_NAME="gre1"
GRE_LOCAL_IP="45.13.XX.XX"
GRE_LAN_IP_4="192.168.100.1/24"
GRE_LAN_IP_6="2a0e:fd45:2a0c::1/64"
+ FQDN="remote.example.com"
fi
-FQDN=$1 # The remote host FQDN
-
# FUNCTIONS
function usage() {
echo "Usage: $0 <remote_host_fqdn>"
@@ -28,14 +26,6 @@ function check_root() {
fi
}
-
-function check_fqdn() {
- if [[ -z $FQDN ]]; then
- echo "Please provide the remote host FQDN"
- usage
- fi
-}
-
function get_current_ip() {
# Get the dst IP on the GRE tunnel
CURRENT_IP=$(ip addr show $GRE_TUNNEL_NAME | grep -Po 'peer \K[\d.]+')
@@ -98,7 +88,6 @@ function check_remote_ip() {
# MAIN
function main() {
check_root
- check_fqdn
echo "LOG - $(date) - Starting autogre.sh"
echo "LOG - $(date) - FQDN: $FQDN"
diff --git a/default.example b/default.example
new file mode 100644
index 0000000..7500338
--- /dev/null
+++ b/default.example
@@ -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"
\ No newline at end of file
diff --git a/install.sh b/install.sh
new file mode 100644
index 0000000..5988a0d
--- /dev/null
+++ b/install.sh
@@ -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
\ No newline at end of file