Last active
May 8, 2023 01:46
-
-
Save sub314xxl/2ca47c75115b4c15ab9817530bc37520 to your computer and use it in GitHub Desktop.
NetworkManager tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mass add VPN profiles with NetworkManager | |
for file in $(pwd)/*; | |
do | |
export config=$(ls -l $file | awk -F "$(pwd)/" '{print $2}'| cut -d . -f1) | |
nmcli connection import type wireguard file "$config.conf" && \ | |
nmcli connection modify "$config" connection.autoconnect no && \ | |
nmcli connection down "$config" | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove all active connections | |
active="$(nmcli -p -f uuid,type,active connection show | grep wireguard | grep yes | awk '{print $1}' | sed 1,1d)" | |
for prof in $active; | |
do | |
nmcli connection delete $active | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nmcli c | awk -f nmcli-parser.awk | |
# oneliner | |
# nmcli c | awk -f 'NR==1{ st=end=$0; sub(/UUID.*$/,"",st);stL=length(st)+1;sub(/TYPE.*$/,"",end); endL=length(end)-stL} NR!=1{print substr($0,stL,endL)}' | |
# given as intput | |
# NAME UUID TYPE DEVICE | |
# Wi-Fi connection 1 fb03ea1d-7aa5-48f2-b94d-c7f0f8249a7e 802-11-wireless wlp2s0 | |
# Wired connection 1 4091d179-ccde-34be-938e-5bc792fd1e1b 802-3-ethernet eno1 | |
# | |
NR==1{ | |
start=end=$0 | |
sub(/UUID.*$/,"",start) | |
startL=length(start)+1 | |
sub(/TYPE.*$/,"",end) | |
endL=length(end)-startL | |
#dbg print "#dbg:startL=" startL "\tendL="endL | |
} | |
NR!=1{ | |
print substr($0,startL,endL) | |
} | |
# for output | |
# fb03ea1d-7aa5-48f2-b94d-c7f0f8249a7e | |
# 4091d179-ccde-34be-938e-5bc792fd1e1b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment