mirror of
https://github.com/BluemediaDev/dn42-tools.git
synced 2024-12-22 22:23:16 +01:00
Add command to remove all interfaces
This commit is contained in:
parent
5d5a0d03d7
commit
ed0d0c8ab6
|
@ -97,6 +97,7 @@ create() {
|
||||||
remove() {
|
remove() {
|
||||||
if ip link | grep -q "wg-$1"; then
|
if ip link | grep -q "wg-$1"; then
|
||||||
ip link del "wg-$1"
|
ip link del "wg-$1"
|
||||||
|
echo "Interface wg-$1 removed."
|
||||||
else
|
else
|
||||||
echo "ERROR: Interface \"wg-$1\" could't be removed, because it doesn't exist."
|
echo "ERROR: Interface \"wg-$1\" could't be removed, because it doesn't exist."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -104,7 +105,7 @@ remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call create() for every peer in the configured folder
|
# Call create() for every peer in the configured folder
|
||||||
autostart() {
|
createall() {
|
||||||
echo "Creating interfaces for peers in path \"$PEER_CONFIG_FOLDER\"."
|
echo "Creating interfaces for peers in path \"$PEER_CONFIG_FOLDER\"."
|
||||||
for peer in $(ls $PEER_CONFIG_FOLDER | egrep -i '.*\.wg\.json' ); do
|
for peer in $(ls $PEER_CONFIG_FOLDER | egrep -i '.*\.wg\.json' ); do
|
||||||
peer=$(echo "$peer" | sed 's/.wg.json//g')
|
peer=$(echo "$peer" | sed 's/.wg.json//g')
|
||||||
|
@ -112,6 +113,15 @@ autostart() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Call remove() for every interface that starts with wg-*
|
||||||
|
removeall() {
|
||||||
|
echo "Removing all active interfaces..."
|
||||||
|
for peer in $(ip link | egrep -o "wg-[^:]*"); do
|
||||||
|
peer=$(echo "$peer" | sed 's/wg-//')
|
||||||
|
remove $peer
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Create an empty config file in the script path
|
# Create an empty config file in the script path
|
||||||
config() {
|
config() {
|
||||||
echo "{
|
echo "{
|
||||||
|
@ -165,8 +175,11 @@ case $ACTION in
|
||||||
create $2
|
create $2
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
autostart)
|
allup)
|
||||||
autostart
|
createall
|
||||||
|
;;
|
||||||
|
alldown)
|
||||||
|
removeall
|
||||||
;;
|
;;
|
||||||
config)
|
config)
|
||||||
config
|
config
|
||||||
|
@ -185,9 +198,10 @@ case $ACTION in
|
||||||
echo " up <peername> Create new wireguard interface for a given peer."
|
echo " up <peername> Create new wireguard interface for a given peer."
|
||||||
echo " down <peername> Remove wireguard interface for a given peer."
|
echo " down <peername> Remove wireguard interface for a given peer."
|
||||||
echo " restart <peername> Recreate the wireguard interface for a given peer."
|
echo " restart <peername> Recreate the wireguard interface for a given peer."
|
||||||
|
echo " allup Create interfaces for all peers in configured folder."
|
||||||
|
echo " alldown Remove all active wireguard interfaces."
|
||||||
echo " config Create an empty config file in the script path."
|
echo " config Create an empty config file in the script path."
|
||||||
echo " template <path> Create an empty peer config template."
|
echo " template <path> Create an empty peer config template."
|
||||||
echo " autostart Create interfaces for all peers in configured folder."
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Invalid action \"$ACTION\"."' Use "./wireguard.sh help" to get help.'
|
echo "Invalid action \"$ACTION\"."' Use "./wireguard.sh help" to get help.'
|
||||||
|
|
Loading…
Reference in a new issue