Automated WireGuard Server and Multi-client

In section a) Named Peers with IDs

This failed for me, I identified a couple of errors.

  1. My own error, using Mac double quote instead of existing double quote caused some chaos.

  2. I think there is a problem in the loops for X clients.

I only want 2 peers so removed the lines

export user_3="Charlie"
export user_4="Delta"

Then later there is a for loop after the while loop

# Loop
n="0"
while [ "$n" -lt ${quantity} ] ; 
do
 
	for username in ${user_1} ${user_2} ${user_3} ${user_4}
	do

I think the for loop is unnecessary, and will fail because the ${user_3} ${user_4} do not exist, and will also fail for more than 4.

I would test but I've already brought the router down (and recovered just about)

maybe someone can confirm/check and update.
Thanks

I've tested and those two loops definitely double up.
I suggest this:

For the scripts:
2 a) Named Peers with IDs
and
2 c) Add Additional Set Number of Peers with Names and IDs

Replace the "for username ... " loop with this (and remove the 'done')

username="user_$((n+1))"
username="${!username}"

There is still room for error if the variable quantity does not equal the number of usernames specified, but that gets a little more complicated to trap.

Hmm.
it's ash not bash so ! indirect substitution fails
back to drawing board

this

username="user_$((n+1))"
eval "username=\$${username}"