1
1
mirror of https://github.com/angristan/wireguard-install.git synced 2024-11-01 03:02:35 +00:00

little update

This commit is contained in:
liberodark 2019-12-17 22:32:59 +01:00
parent b902889ad3
commit ae13aaf796

View File

@ -1,9 +1,25 @@
#!/bin/bash #!/bin/bash
#
# About: Install WireGuard automatically
# Author: angristan
# Thanks : shyamjos, outis151, Leopere, ucawen, Shagon94, shoujii, liberodark
# License: MIT
if [ "$EUID" -ne 0 ]; then version="1.0.0"
echo "You need to run this script as root"
exit 1 echo "Welcome on WireGuard Install Script $version"
fi
#=================================================
# CHECK ROOT
#=================================================
if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST AND VAR
#=================================================
distribution=$(cat /etc/*release | grep "PRETTY_NAME" | sed 's/PRETTY_NAME=//g' | sed 's/["]//g' | awk '{print $1}')
if [ "$(systemd-detect-virt)" == "openvz" ]; then if [ "$(systemd-detect-virt)" == "openvz" ]; then
echo "OpenVZ is not supported" echo "OpenVZ is not supported"
@ -19,21 +35,6 @@ if [ "$(systemd-detect-virt)" == "lxc" ]; then
exit exit
fi fi
# Check OS version
if [[ -e /etc/debian_version ]]; then
source /etc/os-release
OS=$ID # debian or ubuntu
elif [[ -e /etc/fedora-release ]]; then
OS=fedora
elif [[ -e /etc/centos-release ]]; then
OS=centos
elif [[ -e /etc/arch-release ]]; then
OS=arch
else
echo "Looks like you aren't running this installer on a Debian, Ubuntu, Fedora, CentOS or Arch Linux system"
exit 1
fi
# Detect public IPv4 address and pre-fill for the user # Detect public IPv4 address and pre-fill for the user
SERVER_PUB_IPV4=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1) SERVER_PUB_IPV4=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
read -rp "IPv4 or IPv6 public address: " -e -i "$SERVER_PUB_IPV4" SERVER_PUB_IP read -rp "IPv4 or IPv6 public address: " -e -i "$SERVER_PUB_IPV4" SERVER_PUB_IP
@ -80,29 +81,44 @@ else
ENDPOINT="$SERVER_PUB_IP:$SERVER_PORT" ENDPOINT="$SERVER_PUB_IP:$SERVER_PORT"
fi fi
# Install WireGuard tools and module install_wg(){
if [[ "$OS" = 'ubuntu' ]]; then echo "Install WireGuard Server ($distribution)"
# Check OS & WireGuard
if ! command -v wg-quick > /dev/null 2>&1; then
if [ "$distribution" = "CentOS" ] || [ "$distribution" = "Red\ Hat" ] || [ "$distribution" = "Oracle" ]; then
curl -Lo /etc/yum.repos.d/wireguard.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo > /dev/null 2>&1
yum install -y epel-release > /dev/null 2>&1
yum install -y wireguard-dkms wireguard-tools iptables > /dev/null 2>&1
elif [ "$distribution" = "Fedora" ]; then
dnf copr enable jdoss/wireguard > /dev/null 2>&1
dnf install -y wireguard-dkms wireguard-tools iptables > /dev/null 2>&1
elif [ "$distribution" = "Ubuntu" ] || [ "$distribution" = "Deepin" ]; then
add-apt-repository ppa:wireguard/wireguard add-apt-repository ppa:wireguard/wireguard
apt-get update apt-get update > /dev/null 2>&1
apt-get install "linux-headers-$(uname -r)" apt-get install -y "linux-headers-$(uname -r)" > /dev/null 2>&1
apt-get install wireguard iptables resolvconf apt-get install -y wireguard iptables resolvconf --force-yes > /dev/null 2>&1
elif [[ "$OS" = 'debian' ]]; then
echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable.list elif [ "$distribution" = "Debian" ]; then
printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable add-apt-repository ppa:wireguard/wireguard
apt update apt-get update > /dev/null 2>&1
apt-get install "linux-headers-$(uname -r)" apt-get install -y "linux-headers-$(uname -r)" > /dev/null 2>&1
apt install wireguard iptables resolvconf apt-get install -y wireguard iptables resolvconf --force-yes > /dev/null 2>&1
elif [[ "$OS" = 'fedora' ]]; then
dnf copr enable jdoss/wireguard elif [ "$distribution" = "Manjaro" ] || [ "$distribution" = "Arch\ Linux" ]; then
dnf install wireguard-dkms wireguard-tools iptables pacman -S linux-headers dkms --noconfirm > /dev/null 2>&1
elif [[ "$OS" = 'centos' ]]; then pacman -S wireguard-dkms wireguard-tools iptables openresolv --noconfirm > /dev/null 2>&1
curl -Lo /etc/yum.repos.d/wireguard.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo
yum install epel-release fi
yum install wireguard-dkms wireguard-tools iptables
elif [[ "$OS" = 'arch' ]]; then
pacman -S linux-headers
pacman -S wireguard-tools iptables wireguard-arch
fi fi
}
# Install WireGuard
install_wg
# Make sure the directory exists (this does not seem the be the case on fedora) # Make sure the directory exists (this does not seem the be the case on fedora)
mkdir /etc/wireguard > /dev/null 2>&1 mkdir /etc/wireguard > /dev/null 2>&1