add files

This commit is contained in:
2024-11-29 19:21:48 -05:00
commit 41065242f6
5 changed files with 88 additions and 0 deletions

9
LICENSE Normal file
View File

@ -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.

3
README.md Normal file
View File

@ -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

3
env Normal file
View File

@ -0,0 +1,3 @@
# environment file used to setup all the important variables
PEER1_PUBLIC_KEY=

65
install.sh Normal file
View File

@ -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

8
scripts/hooks/pre-commit Normal file
View File

@ -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