github.com/aergoio/aergo@v1.3.1/consensus/impl/raftv2/test/aergoconf-gen.sh (about)

     1  #!/bin/bash 
     2  # Usage: aergoconf-gen.sh 10001 tmpl.toml 5
     3  #
     4  # gen_start, gen_end: XXXX.toml 을 생성할 범위
     5  # peer_start, peer_end : peer로 들어갈 node의 범위
     6  
     7  # pkgen 명령 위치(path)를 적어줄 것
     8  pkgen="aergocli keygen"
     9  
    10  # pkey는 항상 0~22까지를 생성. 존재하면 생성 skip
    11  
    12  if [ $# != 3 ]; then
    13      echo "Usage: $0 <starting port:10001~> <template> <max>"
    14      exit 100
    15  fi
    16  
    17  
    18  port0=$1
    19  tmpl_file=$2
    20  max=$3
    21  gen_start=0
    22  gen_end=$(($max - 1))
    23  
    24  echo "Generate aergo config file from $tmpl_file, from $port0 to ($port0 + $max - 1)"
    25  
    26  function gen_ids() {
    27  	for ((i=1; i <= $max; i++))
    28  	do
    29  		out[i]=${!i}
    30  	done
    31  
    32  	echo ${out[*]} | sed -e 's= =\,\\n=g' -e 's=\/=\\/=g'
    33  }
    34  
    35  # gen_peers selfno startno endno ( 0 <= *no < $max)
    36  function gen_peers() {
    37  	self=$1
    38  	start=$2
    39  	end=$3
    40  
    41  	j=0
    42  	for ((i=$start; i <= $end; i++))
    43  	do
    44  		if [ $i != $self ]; then
    45  			out[j]=${peer[$i]}
    46  			j=$(($j + 1))
    47  		fi
    48  
    49  	done
    50  
    51      echo ${out[*]} | sed -e 's= =\,=g' -e 's=\/=\\/=g'
    52  }
    53  
    54      
    55  
    56  # generate id[]
    57  for((i=0; i < $max; ++i))
    58  do
    59      rpcport=$(($port0 + $i))
    60      rpc[i]=$rpcport
    61  
    62      profileport=$(($port0 + $i + 100))
    63      prof[i]=$profileport
    64  
    65      restport=$(($port0 + $i + 200))
    66      rest[i]=$restport
    67  	p2pport=$(($port0 + $i + 1000))
    68      p2p[i]=$p2pport
    69  
    70  	httpport=$(($port0 + $i + 3000))
    71      http[i]=$httpport
    72  
    73      pk[i]=${p2pport}.key
    74      pk_id[i]=${p2pport}.id
    75  
    76      ofile[i]=BP${p2pport}.toml
    77  
    78  	# check if file exist
    79  	if [ ! -e ${pk[i]} ]; then
    80  		echo "${pk[i]}: $pkgen $p2pport"
    81  		$pkgen $p2pport
    82  	fi
    83  
    84      tmpid=$(cat ${p2pport}.id)
    85      id[i]="\"${tmpid}\""
    86  	peer[i]="\"/ip4/127.0.0.1/tcp/${p2pport}/p2p/${tmpid}\""
    87  	#echo "peer[ $i ]= ${peer[i]}"
    88  
    89  	raftname[i]="aergo$(($i + 1))"
    90  done
    91  
    92  #ids=$(gen_ids ${id[*]})
    93  #echo $ids
    94  raftbps=$(gen_ids ${raftbp[*]})
    95  echo "raftbps=$raftbps"
    96  
    97  #for((i=0; i < $max; ++i))
    98  
    99  for((i=$gen_start; i <= $gen_end; ++i))
   100  do
   101      peers=$(gen_peers ${i} $gen_start $gen_end)
   102  
   103  #	echo  "${peers}"
   104  
   105      echo "s=_home_=$PWD/${p2p[i]}=g" 
   106      echo "s/_rpc_/${rpc[i]}/g" 
   107      echo "s/_p2p_/${p2p[i]}/g"
   108      echo "s/_peer_/${peers}/g" 
   109      echo "s/_pk_/${pk[i]}/g" 
   110      echo "s/_http_/${http[i]}/g" 
   111  	echo "s/_raftbps_/$raftbps/g" 
   112  
   113  
   114      sed -e "s=_home_=$PWD/${p2p[i]}=g" \
   115          -e "s=_data_=$PWD/data/${p2p[i]}=g" \
   116          -e "s/_rest_/${rest[i]}/g" \
   117  		-e "s/_prof_/${prof[i]}/g" \
   118  		-e "s/_rpc_/${rpc[i]}/g" \
   119          -e "s/_p2p_/${p2p[i]}/g" \
   120          -e "s/_peer_/${peers}/g" \
   121          -e "s/_http_/${http[i]}/g" \
   122          -e "s/_raftname_/${raftname[i]}/g" \
   123          -e "s/_raftbps_/${raftbps}/g" \
   124          -e "s/_pk_/${pk[i]}/g"  $tmpl_file >${ofile[i]}
   125  done
   126  echo $(pwd)