From 47f8bdc8b23948db253bc7a61df6ae6ba83f1b88 Mon Sep 17 00:00:00 2001 From: dkoukoul Date: Fri, 1 Dec 2023 13:25:47 +0200 Subject: [PATCH] add peers --- doc/ADMIN.md | 6 ------ doc/PRE_INSTALL.md | 1 - scripts/install | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) delete mode 100644 doc/ADMIN.md delete mode 100644 doc/PRE_INSTALL.md diff --git a/doc/ADMIN.md b/doc/ADMIN.md deleted file mode 100644 index 3422a0c..0000000 --- a/doc/ADMIN.md +++ /dev/null @@ -1,6 +0,0 @@ -Security - -Upgrading - -Other -... \ No newline at end of file diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md deleted file mode 100644 index 1c5eb48..0000000 --- a/doc/PRE_INSTALL.md +++ /dev/null @@ -1 +0,0 @@ -What you need to know before installing cjdns... \ No newline at end of file diff --git a/scripts/install b/scripts/install index 6c9d1a3..1014091 100755 --- a/scripts/install +++ b/scripts/install @@ -34,6 +34,43 @@ $install_dir/cjdroute --genconf | $install_dir/cjdroute --cleanconf > $install_d jq '.security[0].setuser = 0' $install_dir/cjdroute.conf > $install_dir/cjdroute.conf.tmp && mv $install_dir/cjdroute.conf.tmp $install_dir/cjdroute.conf jq '.noBackground = 1' $install_dir/cjdroute.conf > $install_dir/cjdroute.conf.tmp && mv $install_dir/cjdroute.conf.tmp $install_dir/cjdroute.conf +#================================================= +# UPGRADE PEERS +#================================================= +ynh_script_progression --message="Getting cjdns peers..." --weight=1 +# Fetch the JSON data +json=$(curl -s https://vpn.anode.co/api/0.3/vpn/cjdns/peeringlines/) +echo "Got peering lines" + +config=$(cat $install_dir/cjdroute.conf | jq .) + +length=$(echo $json | jq '. | length') +ynh_script_progression --message="Adding $length cjdns peers..." --weight=1 +for (( i=0; i<$length; i++ )) +do + # Parse the JSON data + ip=$(echo $json | jq -r --argjson i $i '.[$i].ip') + port=$(echo $json | jq -r --argjson i $i '.[$i].port') + login=$(echo $json | jq -r --argjson i $i '.[$i].login') + password=$(echo $json | jq -r --argjson i $i '.[$i].password') + publicKey=$(echo $json | jq -r --argjson i $i '.[$i].publicKey') + #echo "Read peer $ip:$port $login $password $publicKey" + #read -p "Enter to continue" + # Prepare the peer to be inserted + peer=$(jq -n \ + --arg ip_port "$ip:$port" \ + --arg login "$login" \ + --arg password "$password" \ + --arg publicKey "$publicKey" \ + '{($ip_port): {"login": $login, "password": $password, "publicKey": $publicKey}}') + #echo "Prepared peer $peer" + # Insert the peer into the cjdroute.conf file + + config=$(echo $config | jq --argjson peer "$peer" '(.interfaces.UDPInterface[] | select(.beaconPort == 64512) .connectTo) |= . + $peer') +done + +echo $config > $install_dir/cjdroute.conf + #================================================= # SETUP SYSTEMD #=================================================