2020-03-29 21:32:01 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
CURRENT_PATH=$(pwd)
|
|
|
|
PROJECT_PATH=$(dirname "${CURRENT_PATH}")
|
2020-03-30 12:59:22 +08:00
|
|
|
CONFIG_PATH=${PROJECT_PATH}/config
|
2020-03-29 21:32:01 +08:00
|
|
|
BUILD_PATH=${CURRENT_PATH}/build
|
2020-03-30 12:59:22 +08:00
|
|
|
RED='\033[0;31m'
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
BLUE='\033[0;34m'
|
|
|
|
NC='\033[0m'
|
|
|
|
N=4
|
|
|
|
|
|
|
|
function print_blue() {
|
|
|
|
printf "${BLUE}%s${NC}\n" "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# The sed commend with system judging
|
|
|
|
# Examples:
|
|
|
|
# sed -i 's/a/b/g' bob.txt => x_replace 's/a/b/g' bob.txt
|
|
|
|
function x_replace() {
|
|
|
|
system=$(uname)
|
|
|
|
|
|
|
|
if [ "${system}" = "Linux" ]; then
|
|
|
|
sed -i "$@"
|
|
|
|
else
|
|
|
|
sed -i '' "$@"
|
|
|
|
fi
|
|
|
|
}
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
function prepare() {
|
2020-03-30 12:59:22 +08:00
|
|
|
print_blue "===> Generating $N nodes configuration"
|
|
|
|
rm -rf "${BUILD_PATH}"
|
|
|
|
mkdir "${BUILD_PATH}"
|
|
|
|
for ((i = 1; i < N + 1; i = i + 1)); do
|
|
|
|
root=${BUILD_PATH}/node${i}
|
|
|
|
mkdir -p "${root}"
|
|
|
|
|
|
|
|
cp -rf "${CURRENT_PATH}"/certs/node${i}/certs "${root}"
|
|
|
|
cp -rf "${CONFIG_PATH}"/* "${root}"
|
|
|
|
|
|
|
|
echo " #!/usr/bin/env bash" >"${root}"/start.sh
|
|
|
|
echo "./bitxhub --root \$(pwd)" start >>"${root}"/start.sh
|
|
|
|
|
|
|
|
bitxhubConfig=${root}/bitxhub.toml
|
|
|
|
networkConfig=${root}/network.toml
|
|
|
|
x_replace "s/60011/6001${i}/g" "${bitxhubConfig}"
|
|
|
|
x_replace "s/9091/909${i}/g" "${bitxhubConfig}"
|
|
|
|
x_replace "s/53121/5312${i}/g" "${bitxhubConfig}"
|
2020-05-15 15:17:50 +08:00
|
|
|
x_replace "s/40011/4001${i}/g" "${bitxhubConfig}"
|
2021-03-31 20:31:45 +08:00
|
|
|
x_replace "s/8881/888${i}/g" "${bitxhubConfig}"
|
2020-03-30 12:59:22 +08:00
|
|
|
x_replace "1s/1/${i}/" "${networkConfig}"
|
|
|
|
done
|
|
|
|
|
|
|
|
print_blue "===> Building plugin"
|
|
|
|
cd "${PROJECT_PATH}"/internal/plugins
|
2020-12-08 16:32:06 +08:00
|
|
|
make raft${TAGS}
|
2020-03-30 12:59:22 +08:00
|
|
|
|
|
|
|
for ((i = 1; i < N + 1; i = i + 1)); do
|
|
|
|
cp -rf "${PROJECT_PATH}"/internal/plugins/build "${BUILD_PATH}"/node${i}/plugins
|
|
|
|
done
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function compile() {
|
2020-03-30 12:59:22 +08:00
|
|
|
print_blue "===> Compiling bitxhub"
|
2020-03-29 21:32:01 +08:00
|
|
|
cd "${PROJECT_PATH}"
|
2020-12-08 16:32:06 +08:00
|
|
|
make install${TAGS}
|
2020-03-29 21:32:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function splitWindow() {
|
|
|
|
tmux splitw -v -p 50
|
|
|
|
tmux splitw -h -p 50
|
|
|
|
tmux selectp -t 0
|
|
|
|
tmux splitw -h -p 50
|
|
|
|
}
|
|
|
|
|
|
|
|
function start() {
|
2020-03-30 12:59:22 +08:00
|
|
|
print_blue "===> Staring cluster"
|
2020-03-29 21:32:01 +08:00
|
|
|
#osascript ${PROJECT_PATH}/scripts/split.scpt ${N} ${DUMP_PATH}/cluster/node
|
|
|
|
tmux new -d -s bitxhub || (tmux kill-session -t bitxhub && tmux new -d -s bitxhub)
|
|
|
|
|
|
|
|
for ((i = 0; i < N / 4; i = i + 1)); do
|
|
|
|
splitWindow
|
|
|
|
tmux new-window
|
|
|
|
done
|
|
|
|
splitWindow
|
|
|
|
for ((i = 0; i < N; i = i + 1)); do
|
|
|
|
tmux selectw -t $(($i / 4))
|
|
|
|
tmux selectp -t $(($i % 4))
|
|
|
|
tmux send-keys "bitxhub --repo=${BUILD_PATH}/node$(($i + 1)) start" C-m
|
|
|
|
done
|
|
|
|
tmux selectw -t 0
|
|
|
|
tmux attach-session -t bitxhub
|
|
|
|
}
|
|
|
|
|
|
|
|
function clear_config() {
|
|
|
|
for ((i = 1; i < N + 1; i = i + 1)); do
|
|
|
|
rm -rf ~/bitxhub${i}
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare
|
|
|
|
start
|