Skip to content

Commit 542eecf

Browse files
authored
Merge pull request #10 from CESSProject/feat/enhanceCodeWithGeminiCli
fix: fix error after use gemini-cli with always accept...(v2)
2 parents 57a95c3 + a9b7ca5 commit 542eecf

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

scripts/utils.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ ensure_root() {
8686
fi
8787
}
8888

89+
is_ports_valid() {
90+
local ports=$(yq eval '.miners[].port' $config_path | xargs)
91+
for port in $ports; do
92+
check_port $port
93+
done
94+
}
95+
8996
# Detects the Linux distribution and package manager.
9097
get_packageManager_type() {
9198
if [ -f /etc/os-release ]; then
@@ -298,6 +305,130 @@ set_profile() {
298305
esac
299306
}
300307

308+
309+
is_processors_satisfied() {
310+
local miner_num=$(get_miners_num)
311+
local cur_processors=$(get_cur_processors)
312+
313+
# Calculate basic CPU requirements
314+
local basic_miners_cpu_need=$(($miner_num * $each_miner_cpu_req))
315+
local basic_rpcnode_cpu_need=0
316+
if [[ $skip_chain == "false" ]]; then
317+
basic_rpcnode_cpu_need=$each_rpcnode_cpu_req
318+
fi
319+
local basic_cpu_req=$(($basic_miners_cpu_need + $basic_rpcnode_cpu_need))
320+
321+
# Calculate actual CPU requirements
322+
local miners_cpu_req_in_cfg=$(yq eval '.miners[].UseCpu' $config_path | xargs | awk '{ sum = 0; for (i = 1; i <= NF; i++) sum += $i; print sum }')
323+
local actual_cpu_req=$(($miners_cpu_req_in_cfg + $basic_rpcnode_cpu_need))
324+
325+
# Validate CPU requirements
326+
if [ $basic_cpu_req -gt $cur_processors ]; then
327+
log_info "Each miner node request $each_miner_cpu_req processors at least, each chain node request $each_rpcnode_cpu_req processors at least"
328+
log_info "Basic installation request: $basic_cpu_req processors in total, but $cur_processors in current"
329+
log_info "Run too much storage node might make your server overload"
330+
log_err "Please modify configuration in $config_path and execute: [ sudo mineradm config generate ] again"
331+
exit 1
332+
fi
333+
334+
if [ $actual_cpu_req -gt $cur_processors ]; then
335+
log_info "Totally request: $actual_cpu_req processors in $config_path, but $cur_processors in current"
336+
log_err "Please modify configuration in $config_path and execute: [ sudo mineradm config generate ] again"
337+
exit 1
338+
fi
339+
}
340+
341+
is_ram_satisfied() {
342+
local miner_num=$(get_miners_num)
343+
344+
local basic_miners_ram_need=$(($miner_num * $each_miner_ram_req))
345+
local basic_rpcnode_ram_need=0
346+
347+
if [[ $skip_chain == "false" ]]; then
348+
basic_rpcnode_ram_need=$each_rpcnode_ram_req
349+
fi
350+
351+
local total_ram_req=$(($basic_miners_ram_need + $basic_rpcnode_ram_need))
352+
local cur_ram=$(get_cur_ram)
353+
354+
if [ $total_ram_req -gt $cur_ram ]; then
355+
log_info "Each miner request $each_miner_ram_req GB ram at least, each chain request $each_rpcnode_ram_req GB ram at least"
356+
log_info "Installation request: $total_ram_req GB in total, but $cur_ram GB in current"
357+
log_info "Run too much storage node might make your server overload"
358+
log_err "Please modify configuration in $config_path and execute: [ sudo mineradm config generate ] again"
359+
exit 1
360+
fi
361+
}
362+
363+
is_sminer_disk_satisfied() {
364+
local diskPath useSpace
365+
diskPath=$(yq eval '(.miners | unique_by(.diskPath)) | .[].diskPath' "$config_path")
366+
useSpace=$(yq eval '.miners[].UseSpace' "$config_path")
367+
368+
readarray -t diskPath_arr <<<"$diskPath"
369+
readarray -t useSpace_arr <<<"$useSpace"
370+
371+
local total_avail=0
372+
local total_req=0
373+
374+
# Calculate total available disk space
375+
for path in "${diskPath_arr[@]}"; do
376+
if [ ! -d "$path" ]; then
377+
log_err "Directory does not exist: $path"
378+
exit 1
379+
fi
380+
381+
local size_value=$(df -B1G "$path" | awk 'NR==2 {print $2}')
382+
383+
if [ -z "$size_value" ]; then
384+
log_err "Failed to retrieve disk size for path: $path"
385+
exit 1
386+
fi
387+
388+
total_avail=$(echo "$total_avail + $size_value" | bc)
389+
done
390+
391+
# Calculate total required disk space
392+
for space in "${useSpace_arr[@]}"; do
393+
if ! is_num "$space"; then
394+
log_err "Invalid UseSpace value: $space"
395+
exit 1
396+
fi
397+
total_req=$(echo "$total_req + $space" | bc)
398+
done
399+
400+
# Compare available and required space
401+
if (($(echo "$total_avail < $total_req" | bc))); then
402+
log_info "Only $total_avail GB available in $(echo "${diskPath_arr[*]}" | tr ' ' ','), but set $total_req GB UseSpace in total in: $config_path"
403+
log_info "This configuration could make your storage nodes be frozen after running"
404+
log_info "Please modify configuration in $config_path and execute: [ sudo mineradm config generate ] again"
405+
exit 1
406+
fi
407+
}
408+
409+
# https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository
410+
add_docker_ubuntu_repo() {
411+
# Add Docker's official GPG key:
412+
sudo apt-get update
413+
sudo apt-get install ca-certificates curl
414+
sudo install -m 0755 -d /etc/apt/keyrings
415+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
416+
sudo chmod a+r /etc/apt/keyrings/docker.asc
417+
418+
# Add the repository to Apt sources:
419+
echo \
420+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
421+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" |
422+
sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
423+
sudo apt-get update
424+
}
425+
426+
# https://docs.docker.com/engine/install/centos/#set-up-the-repository
427+
add_docker_centos_repo() {
428+
sudo yum install -y yum-utils
429+
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
430+
}
431+
301432
# --- Docker & Network Utilities ---
302433

303434
# Enables the Docker Remote API on localhost.

0 commit comments

Comments
 (0)