diff options
Diffstat (limited to 'lib/_ak_cjdns')
-rwxr-xr-x | lib/_ak_cjdns | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/lib/_ak_cjdns b/lib/_ak_cjdns index 4328c65..51832d3 100755 --- a/lib/_ak_cjdns +++ b/lib/_ak_cjdns @@ -1,13 +1,32 @@ -#!/bin/bash +#!/usr/bin/env bash +### +### arching-kaos-tools +### Tools to interact and build an Arching Kaos Infochain +### Copyright (C) 2021 - 2025 kaotisk +### +### This program is free software: you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation, either version 3 of the License, or +### (at your option) any later version. +### +### This program is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with this program. If not, see <http://www.gnu.org/licenses/>. +### +source $AK_LIBDIR/_ak_lib_load +_ak_lib_load _ak_log +_ak_lib_load _ak_network -source $AK_LIBDIR/_ak_log -source $AK_LIBDIR/_ak_network rust_sh_install_url="https://sh.rustup.rs" cjdns_src_git_repo_url="https://github.com/cjdelisle/cjdns" cjdnstoolspath="$HOME/cjdns/tools" cargo_env="$HOME/.cargo/env" -_ak_cjdns_check_availability(){ +function _ak_cjdns_check_availability(){ declare -a cjdns_bins=("cjdroute" "makekeys" "mkpasswd" "privatetopublic" "publictoip6" "randombytes" "sybilsim") for cbin in "${cjdns_bins[@]}" do @@ -22,19 +41,20 @@ _ak_cjdns_check_availability(){ done } -_ak_cargo_rust_check_install(){ - if [ ! -f $cargo_env ] +function _ak_cargo_rust_check_install(){ + if [ ! -f ${cargo_env} ] then - curl --proto '=https' --tlsv1.2 -sSf $rust_sh_install_url | sh + curl --proto '=https' --tlsv1.2 -sSf ${rust_sh_install_url} | sh fi - source $cargo_env + source ${cargo_env} } -_ak_cjdns_install(){ +function _ak_cjdns_install(){ _ak_cargo_rust_check_install - git clone $cjdns_src_git_repo_url + git clone ${cjdns_src_git_repo_url} + cjdns_install_script="./do" cd cjdns - sh do + sh ${cjdns_install_script} if [ $? -ne 0 ] then _ak_log_error "Failed to compile cjdns" @@ -48,25 +68,24 @@ _ak_cjdns_install(){ sudo cp cjdns/target/release/publictoip6 /usr/bin/publictoip6 sudo cp cjdns/target/release/randombytes /usr/bin/randombytes sudo cp cjdns/target/release/sybilsim /usr/bin/sybilsim - ln -s "$(realpath cjdns/tools/dumpLinks)" $HOME/.arching-kaos/bin/dumpLinks - ln -s "$(realpath cjdns/tools/cexec)" $HOME/.arching-kaos/bin/cjdns-cexec - ln -s "$(realpath cjdns/tools/peerStats)" $HOME/.arching-kaos/bin/peerStats + ln -s "$(realpath cjdns/tools/dumpLinks)" ${HOME}/.arching-kaos/bin/dumpLinks + ln -s "$(realpath cjdns/tools/cexec)" ${HOME}/.arching-kaos/bin/cjdns-cexec + ln -s "$(realpath cjdns/tools/peerStats)" ${HOME}/.arching-kaos/bin/peerStats which systemctl 2> /dev/null 1>&2 if [ $? -ne 0 ] then _ak_log_error "Systemctl not found... TODO" else - sudo cp "$(realpath cjdns/contrib/systemd/cjdns.service)" /etc/systemd/system/cjdns.service - sudo cp "$(realpath cjdns/contrib/systemd/cjdns-resume.service)" /etc/systemd/system/cjdns-resume.service + sudo cp cjdns/contrib/systemd/cjdns.service /etc/systemd/system/cjdns.service + sudo cp cjdns/contrib/systemd/cjdns-resume.service /etc/systemd/system/cjdns-resume.service sudo systemctl enable --now cjdns.service fi } -_ak_cjdns_read_peers_to_vars_with_jq(){ +function _ak_cjdns_read_peers_to_vars_with_jq(){ totalpeers="$(jq '. | length' < $peersfile)" number="0" interface="0" - while [ $number -lt $totalpeers ] do address="$(jq -r '.['$number'].address' < $peersfile)" @@ -85,7 +104,7 @@ _ak_cjdns_read_peers_to_vars_with_jq(){ done } -_ak_cjdns_read_peers_to_vars_natively(){ +function _ak_cjdns_read_peers_to_vars_natively(){ number=-1 cat $peersfile | tr -d $'\n' | sed -e 's/]$/\n/g' | tr -d ' ' | sed -e 's/"//g; s/,/,\n/g; s/}//g; s/,//g' | while read line do @@ -132,8 +151,7 @@ _ak_cjdns_read_peers_to_vars_natively(){ rm peerfile } - -_ak_cjdns_connect_peers(){ +function _ak_cjdns_connect_peers(){ _ak_network_cjdns_connect exit $? # @@ -169,7 +187,7 @@ _ak_cjdns_connect_peers(){ fi } -_ak_cjdns_get_ip(){ +function _ak_cjdns_get_ip(){ which ip > /dev/null 2>&1 if [ $? -ne 0 ] then @@ -181,3 +199,5 @@ _ak_cjdns_get_ip(){ awk '{print $2}' | \ cut -d'/' -f1 } + +_ak_log_debug "_ak_cjdns loaded $(caller)" |