Delete Wireguard peers with uci commands in script?

Hi,

I'm trying to delete Wireguard peers in a bash script via SSH:

    UCI_CMD=''

    # Delete peers
    for PEER in `seq 0 10`; do {
	UCI_CMD+="$DEL network.@wireguard_bartschnet[$PEER];"
    }; done

Which executes

/sbin/uci delete network.@wireguard_bartschnet[0];
/sbin/uci delete network.@wireguard_bartschnet[1];
/sbin/uci delete network.@wireguard_bartschnet[2];
/sbin/uci delete network.@wireguard_bartschnet[3];
/sbin/uci delete network.@wireguard_bartschnet[4];
/sbin/uci delete network.@wireguard_bartschnet[5];
/sbin/uci delete network.@wireguard_bartschnet[6];
/sbin/uci delete network.@wireguard_bartschnet[7];
/sbin/uci delete network.@wireguard_bartschnet[8];
/sbin/uci delete network.@wireguard_bartschnet[9];
/sbin/uci delete network.@wireguard_bartschnet[10];
/sbin/uci commit;

via

ssh root@192.168.1.1 "$UCI_CMD"

Peers 3-5 are deleted but not peers 0-2.

Does anyone have an idea what's going wrong with UCI?

Thanx for any hint! :smile:

Side question -- do you want to delete all of them or just the first 10?

I want to delete all of them before setting up a new configuration.

while uci -q delete network.@wireguard_foo[0]; do :; done
1 Like

@vgaetera
Works. Thank you! :smile:

When you delete an anonymous section, the index do not stay the same. The sections that you actually deleted in your script, taking into account initial numeration were: 0, 2, 4, 6 and so on. As after every deletion the entire array shifts left.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.