commit 41065242f647eff72965d530d5fdf65d3591bd44 Author: Remi Date: Fri Nov 29 19:21:48 2024 -0500 add files diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f96fb0d --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024 remi + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..90e6394 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# wireguardforward + +set of automations to enable port forwarding using wireguard. Please read each file before running as this is not built as a published product \ No newline at end of file diff --git a/env b/env new file mode 100644 index 0000000..df0c168 --- /dev/null +++ b/env @@ -0,0 +1,3 @@ +# environment file used to setup all the important variables +PEER1_PUBLIC_KEY= + diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..8795fa8 --- /dev/null +++ b/install.sh @@ -0,0 +1,65 @@ +#!/bin/bash +##--------------admin to setup the hooks of the repo +# Copy hooks to .git/hooks +cp scripts/hooks/* .git/hooks/ + +# Make the pre-commit hook executable +chmod +x .git/hooks/pre-commit +##----------------- + + +# Source the environment file +source envfile + +# Extract variable names from the environment file +required_vars=$(grep -o '^[^#]*' envfile | cut -d= -f1) + +# Check each required variable +for var in ${required_vars}; do + if [ -z "${!var}" ]; then + echo "Error: $var is not set in the environment file." + exit 1 + fi +done + +# Update the system +sudo apt update && sudo apt upgrade -y + +# Install WireGuard +sudo apt install wireguard -y + +# Generate key pairs +sudo wg genkey | sudo tee /etc/wireguard/privatekey | sudo wg pubkey > /etc/wireguard/publickey + +# Create the WireGuard configuration file +cat << EOF | sudo tee /etc/wireguard/wg0.conf +[Interface] +Address = 10.0.0.1/24 +PrivateKey = $(sudo cat /etc/wireguard/privatekey) + +[Peer] +PublicKey = ${PEER1_PUBLIC_KEY} +AllowedIPs = 10.0.0.2/32 +EOF + +# Enable IP forwarding +sudo sysctl -w net.ipv4.ip_forward=1 +echo 'net.ipv4.ip_forward=1' | sudo tee -a /etc/sysctl.conf + +# Set up firewall rules +sudo iptables -A FORWARD -i wg0 -j ACCEPT +sudo iptables -A FORWARD -o wg0 -j ACCEPT +sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE +sudo iptables-save | sudo tee /etc/iptables/rules.v4 + +# Start and enable the WireGuard service +sudo systemctl start wg-quick@wg0 +sudo systemctl enable wg-quick@wg0 + +echo "WireGuard server setup complete!" + +# Check WireGuard status every second for 30 seconds +for i in {1..30}; do + sudo wg + sleep 1 +done \ No newline at end of file diff --git a/scripts/hooks/pre-commit b/scripts/hooks/pre-commit new file mode 100644 index 0000000..617bb69 --- /dev/null +++ b/scripts/hooks/pre-commit @@ -0,0 +1,8 @@ +#!/bin/bash + +# List of files to ignore +ignore_files=("envfile") #("file1" "file2") + +for file in "${ignore_files[@]}"; do + git update-index --skip-worktree $file +done \ No newline at end of file