feat(new-wg): now checking if run as root + some fixes in arguments parsing
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
#! /usr/bin/env bash
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
echo "[!!] This program must be run as root"
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
|
|
||||||
function usage()
|
function usage()
|
||||||
{
|
{
|
||||||
echo "usage: $(basename $0) [-h] [-i interface] [-d nameserver] [-a address]"
|
echo "usage: $(basename $0) [-h] [-i interface] [-d nameserver] [-a address]"
|
||||||
@@ -19,7 +24,7 @@ function checks()
|
|||||||
|
|
||||||
# Si aucun serveur DNS n'a ete renseigne, on prend le premier du resolv.conf
|
# Si aucun serveur DNS n'a ete renseigne, on prend le premier du resolv.conf
|
||||||
if [ ${#nameserver} -eq 0 ]; then
|
if [ ${#nameserver} -eq 0 ]; then
|
||||||
namerserver="$(sed -n -r "s|nameserver (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*|\1|p" /etc/resolv.conf | head -1)"
|
nameserver="$(sed -n -r "s|nameserver (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*|\1|p" /etc/resolv.conf | head -1)"
|
||||||
fi
|
fi
|
||||||
# Si aucun nom de domaine ou adresse IP est resignee, on prend le nom de domaine complet
|
# Si aucun nom de domaine ou adresse IP est resignee, on prend le nom de domaine complet
|
||||||
# du server
|
# du server
|
||||||
@@ -53,7 +58,7 @@ interface="wg0"
|
|||||||
nameserver=""
|
nameserver=""
|
||||||
serv_addr=""
|
serv_addr=""
|
||||||
|
|
||||||
opts=":hida"
|
opts=":i:d:a:h"
|
||||||
while getopts "$opts" arg; do
|
while getopts "$opts" arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
h)
|
h)
|
||||||
|
|||||||
Reference in New Issue
Block a user