From 31bee4542964b03ede9458e694aae5c28f7eb675 Mon Sep 17 00:00:00 2001 From: Stanislas Lange Date: Fri, 31 Jul 2020 15:02:26 +0200 Subject: [PATCH] Format with shfmt --- wireguard-install.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index 707b4e3..7c428e0 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -70,7 +70,7 @@ function installQuestions() { # Detect public IPv4 or IPv6 address and pre-fill for the user SERVER_PUB_IP=$(ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | head -1) - if [[ -z "${SERVER_PUB_IP}" ]]; then + if [[ -z ${SERVER_PUB_IP} ]]; then # Detect public IPv6 address SERVER_PUB_IP=$(ip -6 addr | sed -ne 's|^.* inet6 \([^/]*\)/.* scope global.*$|\1|p' | head -1) fi @@ -78,36 +78,36 @@ function installQuestions() { # Detect public interface and pre-fill for the user SERVER_NIC="$(ip -4 route ls | grep default | grep -Po '(?<=dev )(\S+)' | head -1)" - until [[ "${SERVER_PUB_NIC}" =~ ^[a-zA-Z0-9_]+$ ]]; do + until [[ ${SERVER_PUB_NIC} =~ ^[a-zA-Z0-9_]+$ ]]; do read -rp "Public interface: " -e -i "${SERVER_NIC}" SERVER_PUB_NIC done - until [[ "${SERVER_WG_NIC}" =~ ^[a-zA-Z0-9_]+$ ]]; do + until [[ ${SERVER_WG_NIC} =~ ^[a-zA-Z0-9_]+$ ]]; do # shellcheck disable=SC2034 read -rp "WireGuard interface name: " -e -i wg0 SERVER_WG_NIC done - until [[ "${SERVER_WG_IPV4}" =~ ^([0-9]{1,3}\.){3} ]]; do + until [[ ${SERVER_WG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do read -rp "Server's WireGuard IPv4: " -e -i 10.66.66.1 SERVER_WG_IPV4 done - until [[ "${SERVER_WG_IPV6}" =~ ^([a-f0-9]{1,4}:){3,4}: ]]; do + until [[ ${SERVER_WG_IPV6} =~ ^([a-f0-9]{1,4}:){3,4}: ]]; do read -rp "Server's WireGuard IPv6: " -e -i fd42:42:42::1 SERVER_WG_IPV6 done # Generate random number within private ports range RANDOM_PORT=$(shuf -i49152-65535 -n1) - until [[ "${SERVER_PORT}" =~ ^[0-9]+$ ]] && [ "${SERVER_PORT}" -ge 1 ] && [ "${SERVER_PORT}" -le 65535 ]; do + until [[ ${SERVER_PORT} =~ ^[0-9]+$ ]] && [ "${SERVER_PORT}" -ge 1 ] && [ "${SERVER_PORT}" -le 65535 ]; do read -rp "Server's WireGuard port [1-65535]: " -e -i "${RANDOM_PORT}" SERVER_PORT done # Adguard DNS by default - until [[ "${CLIENT_DNS_1}" =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do + until [[ ${CLIENT_DNS_1} =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do read -rp "First DNS resolver to use for the clients: " -e -i 176.103.130.130 CLIENT_DNS_1 done - until [[ "${CLIENT_DNS_2}" =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do + until [[ ${CLIENT_DNS_2} =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]; do read -rp "Second DNS resolver to use for the clients (optional): " -e -i 176.103.130.131 CLIENT_DNS_2 - if [[ "${CLIENT_DNS_2}" == "" ]]; then + if [[ ${CLIENT_DNS_2} == "" ]]; then CLIENT_DNS_2="${CLIENT_DNS_1}" fi done @@ -123,13 +123,13 @@ function installWireGuard() { installQuestions # Install WireGuard tools and module - if [[ "${OS}" == 'ubuntu' ]]; then + if [[ ${OS} == 'ubuntu' ]]; then apt-get install -y software-properties-common add-apt-repository -y ppa:wireguard/wireguard apt-get update apt-get install -y "linux-headers-$(uname -r)" apt-get install -y wireguard iptables resolvconf qrencode - elif [[ "${OS}" == 'debian' ]]; then + 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 apt-get update @@ -137,18 +137,18 @@ function installWireGuard() { apt update apt-get install -y iptables resolvconf qrencode apt-get install -y -t buster-backports wireguard - elif [[ "${OS}" == 'fedora' ]]; then - if [[ "${VERSION_ID}" -lt 32 ]]; then + 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 fi dnf install -y wireguard-tools iptables qrencode - elif [[ "${OS}" == 'centos' ]]; then + elif [[ ${OS} == 'centos' ]]; then curl -Lo /etc/yum.repos.d/wireguard.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo yum -y install epel-release kernel kernel-devel kernel-headers yum -y install wireguard-dkms wireguard-tools iptables qrencode - elif [[ "${OS}" == 'arch' ]]; then + elif [[ ${OS} == 'arch' ]]; then pacman -S --noconfirm linux-headers pacman -S --noconfirm wireguard-tools iptables qrencode fi @@ -204,7 +204,7 @@ net.ipv6.conf.all.forwarding = 1" >/etc/sysctl.d/wg.conf WG_RUNNING=$? # WireGuard might not work if we updated the kernel. Tell the user to reboot - if [[ "${WG_RUNNING}" -ne 0 ]]; then + if [[ ${WG_RUNNING} -ne 0 ]]; then echo -e "\nWARNING: WireGuard does not seem to be running." echo "You can check if WireGuard is running with: systemctl status wg-quick@${SERVER_WG_NIC}" echo 'If you get something like "Cannot find device wg0", please reboot!' @@ -222,11 +222,11 @@ function newClient() { ENDPOINT="${SERVER_PUB_IP}:${SERVER_PORT}" printf "\n" - until [[ "${CLIENT_WG_IPV4}" =~ ^([0-9]{1,3}\.?){4}$ ]]; do + until [[ ${CLIENT_WG_IPV4} =~ ^([0-9]{1,3}\.?){4}$ ]]; do read -rp "Client's WireGuard IPv4: " -e -i "${SERVER_WG_IPV4::-1}"2 CLIENT_WG_IPV4 done - until [[ "${CLIENT_WG_IPV6}" =~ ^([a-f0-9]{1,4}:?:?){3,5} ]]; do + until [[ ${CLIENT_WG_IPV6} =~ ^([a-f0-9]{1,4}:?:?){3,5} ]]; do read -rp "Client's WireGuard IPv6 : " -e -i "${SERVER_WG_IPV6::-1}"2 CLIENT_WG_IPV6 done @@ -285,7 +285,7 @@ function manageMenu() { echo "What do you want to do?" echo " 1) Add a new user" echo " 2) Exit" - until [[ "${MENU_OPTION}" =~ ^[1-2]$ ]]; do + until [[ ${MENU_OPTION} =~ ^[1-2]$ ]]; do read -rp "Select an option [1-2]: " MENU_OPTION done case "${MENU_OPTION}" in