How to import many Wireguard VPN profiles with a basic script

I created this very basic script to import and configure Wireguard VPN profiles on Debian. Save it to the same folder as your vpn.conf files. In debian it must be run as root.
It will import the profile, set it to not autoconnect, and disconnect it.
I will next work on one that will modify the VM’s firewall rules, unless someone already has one or can do it quickly. I have no idea when I’ll be able to start/finish it.

Script Import-WG-Profiles.sh

#!/bin/bash
#For Debian.
#Save in the same folder as the vpn.conf files and run from a root terminal.
for file in *.conf; do
c="${file%.*}"
sudo nmcli connection import type wireguard file $file && sudo nmcli connection modify $c autoconnect no && sudo nmcli con down $c
done

Edit: All characters are presenting correctly now.

This next script will read through all the vpn.conf files, find the Endpoint IP addresses, and compile them into a text file.

#!/bin/bash
#Save in the same folder as the vpn.conf files and run.
for file in *.conf; do
grep "Endpoint = " $file | grep -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’ >> WGIPs.txt
done

This last script will read all of the Endpoint IPs from the text file and add them to the sys-vpn firewall rules. It must be run from Dom0. Copy both this script and the WG IP list text file to Dom0.
Must still manually run “qvm-firewall sys-vpn reset” first, then the script, then after the script run “qvm-firewall sys-vpn del --rule-no 0” to finish. I’ll add these to the script later.

#!/bin/bash
#Run in Dom0 with WGIPs.txt
#for each line in WGIPs.txt, run a qvm-firewall command on vpn-wg-dvm.
file=$(cat WGIPs.txt)
for line in $file; do
qvm-firewall vpn-wg-dvm add accept dsthost=“$line”
#echo -e “$line”
done

Lastly, I set the Wireguard VM as a disposable template, then created a disposable VM from it.

Thanks user111 for this clear and simple instructions (script) to import a VPN Wireguard connection.

reagards, hitam