From 0665813fc16e85e8037ed24aaa16970e71a2f631 Mon Sep 17 00:00:00 2001 From: Jaminmc Date: Sun, 7 Feb 2021 11:54:25 -0500 Subject: [PATCH 1/2] Detect WireGuard in Containers, and allow install. --- wireguard-install.sh | 64 +++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 15 deletions(-) mode change 100644 => 100755 wireguard-install.sh diff --git a/wireguard-install.sh b/wireguard-install.sh old mode 100644 new mode 100755 index 746dd5ff..b80abf48 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -12,17 +12,32 @@ function isRoot() { function checkVirt() { if [ "$(systemd-detect-virt)" == "openvz" ]; then - echo "OpenVZ is not supported" - exit 1 + if ip link add wg999 type wireguard 2> /dev/null ; then + echo "OpenVZ is not supported, but it seems to have correct kernel modules." + ip link del wg999 + read -rp "Press enter to continue at your own risk, or CTRL-C to quit." + Container=1 + else + echo "OpenVZ is not supported" + exit 1 + fi fi - if [ "$(systemd-detect-virt)" == "lxc" ]; then - echo "LXC is not supported (yet)." - echo "WireGuard can technically run in an LXC container," - echo "but the kernel module has to be installed on the host," - echo "the container has to be run with some specific parameters" - echo "and only the tools need to be installed in the container." - exit 1 + if ip link add wg999 type wireguard 2> /dev/null ; then + ip link del wg999 + echo "LXC is currently in Beta." + echo "WireGuard can technically run in an LXC container," + echo "but the kernel module has to be installed on the host," + echo "the container has to be run with some specific parameters" + echo "and only the tools need to be installed in the container." + echo "The Kernel seems to support Wireguard." + read -rp "Press enter to continue at your own risk, or CTRL-C to quit." + Container=1 + else + echo "Your LXC host does not have the WireGuard Kernel Module." + echo "If you have access to the host, try installing wireguard-dkms on it." + exit 1 + fi fi } @@ -121,7 +136,13 @@ function installWireGuard() { # Install WireGuard tools and module if [[ ${OS} == 'ubuntu' ]]; then apt-get update - apt-get install -y wireguard iptables resolvconf qrencode + if [[ $Container == 1 ]]; then + apt-get install -y wireguard-tools --no-install-recommends + apt-get install -y iptables resolvconf qrencode + else + apt-get install -y wireguard iptables resolvconf qrencode + fi + elif [[ ${OS} == 'debian' ]]; then if ! grep -rqs "^deb .* buster-backports" /etc/apt/; then echo "deb http://deb.debian.org/debian buster-backports main" >/etc/apt/sources.list.d/backports.list @@ -129,20 +150,33 @@ function installWireGuard() { fi apt update apt-get install -y iptables resolvconf qrencode - apt-get install -y -t buster-backports wireguard + if [[ $Container == 1 ]]; then + apt-get install -y -t buster-backports wireguard-tools --no-install-recommends + else + apt-get install -y -t buster-backports wireguard + fi + elif [[ ${OS} == 'fedora' ]]; then if [[ ${VERSION_ID} -lt 32 ]]; then dnf install -y dnf-plugins-core dnf copr enable -y jdoss/wireguard - dnf install -y wireguard-dkms + if [[ $Container != 1 ]]; then + dnf install -y wireguard-dkms + fi fi dnf install -y wireguard-tools iptables qrencode + elif [[ ${OS} == 'centos' ]]; then yum -y install epel-release elrepo-release if [[ ${VERSION_ID} -eq 7 ]]; then yum -y install yum-plugin-elrepo fi - yum -y install kmod-wireguard wireguard-tools iptables qrencode + if [[ $Container == 1 ]]; then + yum -y install wireguard-tools iptables qrencode + else + yum -y install kmod-wireguard wireguard-tools iptables qrencode + fi + elif [[ ${OS} == 'arch' ]]; then # Check if current running kernel is LTS ARCH_KERNEL_RELEASE=$(uname -r) @@ -353,9 +387,9 @@ function uninstallWg() { systemctl disable "wg-quick@${SERVER_WG_NIC}" if [[ ${OS} == 'ubuntu' ]]; then - apt-get autoremove --purge -y wireguard qrencode + apt-get autoremove --purge -y wireguard wireguard-tools qrencode elif [[ ${OS} == 'debian' ]]; then - apt-get autoremove --purge -y wireguard qrencode + apt-get autoremove --purge -y wireguard wireguard-tools qrencode elif [[ ${OS} == 'fedora' ]]; then dnf remove -y wireguard-tools qrencode if [[ ${VERSION_ID} -lt 32 ]]; then From b2bbdc48d874cf23411b14d00614e9ed13204be6 Mon Sep 17 00:00:00 2001 From: jaminmc Date: Fri, 19 Feb 2021 21:05:56 -0500 Subject: [PATCH 2/2] Cleaner display of container differences. Co-authored-by: Stanislas --- wireguard-install.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index b80abf48..eceb874a 100755 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -136,13 +136,12 @@ function installWireGuard() { # Install WireGuard tools and module if [[ ${OS} == 'ubuntu' ]]; then apt-get update + apt-get install -y iptables resolvconf qrencode if [[ $Container == 1 ]]; then apt-get install -y wireguard-tools --no-install-recommends - apt-get install -y iptables resolvconf qrencode else - apt-get install -y wireguard iptables resolvconf qrencode + apt-get install -y wireguard fi - elif [[ ${OS} == 'debian' ]]; then if ! grep -rqs "^deb .* buster-backports" /etc/apt/; then echo "deb http://deb.debian.org/debian buster-backports main" >/etc/apt/sources.list.d/backports.list