updated code structure and fixed spacing issues, added many features.

This commit is contained in:
crowetic 2024-05-21 18:11:02 -07:00
parent 20eae7c6cb
commit e74dfdb4cc

View File

@ -38,6 +38,43 @@ else
fi fi
} }
check_for_pi(){
if command -v raspi-config >/dev/null 2>&1 ; then
echo "${YELLOW} Raspberry Pi machine detected, checking for 32bit pi...${NC}\n"
if [ "$(uname -m | grep 'armv7l')" != "" ]; then
echo "${WHITE} 32bit ARM detected, using ARM 32bit compatible modified start script${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-modified-memory-args.sh
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron
crontab auto-fix-cron
chmod +x start-modified-memory-args.sh
mv start-modified-memory-args.sh ~/qortal/start.sh
check_qortal
else
echo "${WHITE} Machine is not ARM 32bit, checking RAM amount and adding correct start script...${NC}\n"
totalm=$(free -m | awk '/^Mem:/{print $2}')
echo "${YELLOW} configuring auto-fix cron...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron
crontab auto-fix-cron
rm -rf auto-fix-cron
if [ "$totalm" -le 6000 ]; then
echo "${WHITE} 4GB 64bit pi detected, grabbing correct start script and continuing...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/4GB-start.sh && mv 4GB-start.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
check_qortal
else
echo "${WHITE} 8GB 64bit pi detected, grabbing correct start script and continuing...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-6001-to-16000m.sh && mv start-6001-to-16000m.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
check_qortal
fi
fi
else echo "${YELLOW} Not a Raspberry pi machine, continuing...${NC}\n"
check_memory
fi
}
check_qortal() { check_qortal() {
echo "${YELLOW} Checking the version of qortal on local machine VS the version on github... ${NC}\n" echo "${YELLOW} Checking the version of qortal on local machine VS the version on github... ${NC}\n"
@ -89,43 +126,6 @@ else
fi fi
} }
force_bootstrap() {
echo "${RED} height check found issues, forcing bootstrap... ${NC}\n"
cd qortal
killall -9 java
sleep 3
rm -rf db log.t* qortal.log run.log run.pid
sleep 5
./start.sh
cd
update_script
}
check_for_GUI_already_bootstrapped(){
if [ -n "$DISPLAY" ]; then
echo "${CYAN} Machine is logged in via GUI, setting up auto-fix-visible for GUI-based machines... ${NC}\n"
echo "${YELLOW} Setting up auto-fix-visible on GUI-based system... first, creating new crontab entry without auto-fix-startup... ${NC}\n"
sleep 2
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-GUI-cron
crontab auto-fix-GUI-cron
rm -rf auto-fix-GUI-cron
echo "${YELLOW} Setting up new ${NC}\n ${WHITE} 'auto-fix-qortal-GUI.desktop' ${NC}\n ${YELLOW} file for GUI-based machines to run 7 min after startup in a visual fashion. Entry in 'startup' will be called ${NC}\n ${WHITE} 'auto-fix-visible' ${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal-GUI.desktop
mkdir -p ~/.config/autostart
cp auto-fix-qortal-GUI.desktop ~/.config/autostart
rm -rf ~/auto-fix-qortal-GUI.desktop
echo "${YELLOW} Your machine will now run 'auto-fix-qortal.sh' script in a fashion you can SEE, 7 MIN AFTER YOU REBOOT your machine. The normal 'background' process for auto-fix-qortal will continue as normal.${NC}\n"
echo "${CYAN} continuing to verify node height...${NC}\n"
update_script
else echo "${YELLOW} Non-GUI system detected, skipping 'auto-fix-visible' setup ${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron-new
crontab auto-fix-cron-new
rm -rf auto-fix-cron-new
update_script
fi
}
check_for_GUI(){ check_for_GUI(){
if [ -n "$DISPLAY" ]; then if [ -n "$DISPLAY" ]; then
echo "${CYAN} Machine is logged in via GUI, setting up auto-fix-visible for GUI-based machines... ${NC}\n" echo "${CYAN} Machine is logged in via GUI, setting up auto-fix-visible for GUI-based machines... ${NC}\n"
@ -153,143 +153,61 @@ else echo "${YELLOW} Non-GUI system detected, skipping 'auto-fix-visible' setup.
fi fi
} }
check_memory(){ check_for_GUI_already_bootstrapped(){
totalm=$(free -m | awk '/^Mem:/{print $2}') if [ -n "$DISPLAY" ]; then
echo "${YELLOW} Checking system RAM ... $totalm System RAM ... Configuring system for optimal RAM settings...${NC}\n" echo "${CYAN} Machine is logged in via GUI, setting up auto-fix-visible for GUI-based machines... ${NC}\n"
echo "${YELLOW} Setting up auto-fix-visible on GUI-based system... first, creating new crontab entry without auto-fix-startup... ${NC}\n"
if [ "$totalm" -le 6000 ]; then sleep 2
echo "${WHITE} Machine has less than 6GB of RAM, Downloading correct start script for your configuration...${NC}\n" curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-GUI-cron
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/4GB-start.sh && mv 4GB-start.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh crontab auto-fix-GUI-cron
elif [ "$totalm" -ge 6001 ] && [ "$totalm" -le 16000 ]; then rm -rf auto-fix-GUI-cron
echo "${WHITE} Machine has between 6GB and 16GB of RAM, Downloading correct start script for your configuration...${NC}\n" echo "${YELLOW} Setting up new ${NC}\n ${WHITE} 'auto-fix-qortal-GUI.desktop' ${NC}\n ${YELLOW} file for GUI-based machines to run 7 min after startup in a visual fashion. Entry in 'startup' will be called ${NC}\n ${WHITE} 'auto-fix-visible' ${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-6001-to-16000m.sh && mv start-6001-to-16000m.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal-GUI.desktop
else echo "${WHITE} Machine has more than 16GB of RAM, using high-RAM start script and continuing...${NC}\n" mkdir -p ~/.config/autostart
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-high-RAM.sh && mv start-high-RAM.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh cp auto-fix-qortal-GUI.desktop ~/.config/autostart
fi rm -rf ~/auto-fix-qortal-GUI.desktop
echo "${YELLOW} Your machine will now run 'auto-fix-qortal.sh' script in a fashion you can SEE, 7 MIN AFTER YOU REBOOT your machine. The normal 'background' process for auto-fix-qortal will continue as normal.${NC}\n"
check_qortal echo "${CYAN} continuing to verify node height...${NC}\n"
} update_script
check_for_pi(){
if command -v raspi-config >/dev/null 2>&1 ; then
echo "${YELLOW} Raspberry Pi machine detected, checking for 32bit pi...${NC}\n"
if [ "$(uname -m | grep 'armv7l')" != "" ]; then
echo "${WHITE} 32bit ARM detected, using ARM 32bit compatible modified start script${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-modified-memory-args.sh
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron
crontab auto-fix-cron
chmod +x start-modified-memory-args.sh
mv start-modified-memory-args.sh ~/qortal/start.sh
check_qortal
else
echo "${WHITE} Machine is not ARM 32bit, checking RAM amount and adding correct start script...${NC}\n"
totalm=$(free -m | awk '/^Mem:/{print $2}')
echo "${YELLOW} configuring auto-fix cron...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron
crontab auto-fix-cron
rm -rf auto-fix-cron
if [ "$totalm" -le 6000 ]; then
echo "${WHITE} 4GB 64bit pi detected, grabbing correct start script and continuing...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/4GB-start.sh && mv 4GB-start.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
check_qortal
else
echo "${WHITE} 8GB 64bit pi detected, grabbing correct start script and continuing...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-6001-to-16000m.sh && mv start-6001-to-16000m.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
check_qortal
fi
fi
else echo "${YELLOW} Not a Raspberry pi machine, continuing...${NC}\n"
check_memory
else echo "${YELLOW} Non-GUI system detected, skipping 'auto-fix-visible' setup ${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron-new
crontab auto-fix-cron-new
rm -rf auto-fix-cron-new
update_script
fi fi
} }
update_script(){
mkdir -p ~/qortal/new-scripts
mkdir -p ~/qortal/new-scripts/backups
cp ~/qortal/new-scripts/auto-fix-qortal.sh ~/qortal/new-scripts/backups
rm -rf ~/qortal/new-scripts/auto-fix-qortal.sh
cp ~/auto-fix-qortal.sh ~/qortal/new-scripts/backups/original.sh
cd ~/qortal/new-scripts
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal.sh
chmod +x auto-fix-qortal.sh
cd
cp ~/qortal/new-scripts/auto-fix-qortal.sh .
echo "${YELLOW} Auto-fix script run complete.${NC}\n"
sleep 5
exit
}
# QORTAL BLOCK HEIGHT CHECKS FIRST WITH JQ THEN WITH PYTHON, IF BOTH FAIL, SKIP CHECKS.
check_height() { check_height() {
local_height=$(curl -sS "http://localhost:12391/blocks/height")
if [ -f auto_fix_last_height.txt ]; then if [ -f auto_fix_last_height.txt ]; then
previous_local_height=$(cat auto_fix_last_height.txt) previous_local_height=$(cat auto_fix_last_height.txt)
if [ -n ${previous_local_height} ]; then
if [ "${local_height}" = "${previous_local_height}" ]; then
echo "${RED} local height has not changed since previous script run... waiting 3 minutes and checking height again, if height still hasn't changed, forcing bootstrap... ${NC}\n"
sleep 188
checked_height=$(curl "localhost:12391/blocks/height")
sleep 2
if [ "${checked_height}" = "${previous_local_height}" ]; then
echo "${RED} block height still has not changed... forcing bootstrap... ${NC}\n"
force_bootstrap
fi fi
local_height=$(curl -sS "http://localhost:12391/blocks/height") fi
fi
fi
if [ -z ${local_height} ]; then if [ -z ${local_height} ]; then
echo "${RED} local API call for block height returned empty, IS YOUR QORTAL CORE RUNNING? ${NC}\n" echo "${RED} local API call for block height returned empty, IS YOUR QORTAL CORE RUNNING? ${NC}\n"
echo "${RED} if this doesn't work, then the script encountered an issue that it isn't fully equipped to handle, it may fix it upon a restart, TRY RESTARTING THE COMPUTER and WAITING 15 MINUTES... ${NC}\n" echo "${RED} if this doesn't work, then the script encountered an issue that it isn't fully equipped to handle, it may fix it upon a restart, TRY RESTARTING THE COMPUTER and WAITING 15 MINUTES... ${NC}\n"
no_local_height no_local_height
fi else
echo ${local_height} > auto_fix_last_height.txt
if [ -n ${previous_local_height} ]; then
if [ "${local_height}" = "${previous_local_height}" ]; then
echo "${RED} local height has not changed since previous script run... waiting 3 minutes and checking height again, if height still hasn't changed, forcing bootstrap... ${NC}\n"
sleep 188
checked_height=$(curl "localhost:12391/blocks/height")
sleep 2
if [ "${checked_height}" = "${previous_local_height}" ]; then
echo "${RED} block height still has not changed... forcing bootstrap... ${NC}\n"
force_bootstrap
fi
fi
fi fi
remote_height_checks remote_height_checks
}
check_height_2() {
if [ -f auto_fix_last_height.txt ]; then
previous_local_height=$(cat auto_fix_last_height.txt)
fi
local_height=$(curl -sS "http://localhost:12391/blocks/height")
if [ -z ${local_height} ]; then
echo "${RED} SECOND height check failed, unsure what is going on, but a restart of the node and waiting may fix it... ${NC}\n"
echo "${RED} TRY RESTARTING THE COMPUTER and WAITING 15 MINUTES... ${NC}\n"
echo "Updating script and continuing..."
update_script
fi
if [ -n ${previous_local_height} ]; then
if [ "${local_height}" = "${previous_local_height}" ]; then
echo "${RED} local height has not changed since previous script run... waiting 3 minutes and checking height again, if height still hasn't changed, forcing bootstrap... ${NC}\n"
sleep 188
checked_height=$(curl "localhost:12391/blocks/height")
sleep 2
if [ "${checked_height}" = "${previous_local_height}" ]; then
echo "${RED} block height still has not changed... forcing bootstrap... ${NC}\n"
force_bootstrap
fi
fi
fi
remote_height_checks
} }
no_local_height() { no_local_height() {
@ -312,22 +230,15 @@ else
if [ -f "$log_file" ]; then if [ -f "$log_file" ]; then
old_log_found=true old_log_found=true
echo "Old log method found, backing up old logs and updating logging method..." echo "Old log method found, backing up old logs and updating logging method..."
# Create backup directory if it doesn't exist
mkdir -p ~/qortal/backup/logs mkdir -p ~/qortal/backup/logs
# Move old log files to the backup directory # Move old log files to the backup directory
mv ~/qortal/log.t* ~/qortal/backup/logs mv ~/qortal/log.t* ~/qortal/backup/logs
mv ~/qortal/log4j2.properties ~/qortal/backup/logs mv ~/qortal/log4j2.properties ~/qortal/backup/logs
# Download the new log4j2.properties file # Download the new log4j2.properties file
curl -L -O https://raw.githubusercontent.com/Qortal/qortal/master/log4j2.properties curl -L -O https://raw.githubusercontent.com/Qortal/qortal/master/log4j2.properties
# Move the new log4j2.properties file to the qortal directory # Move the new log4j2.properties file to the qortal directory
mv log4j2.properties ~/qortal mv log4j2.properties ~/qortal
echo -e "${RED}Stopping Qortal to apply new logging method...${NC}\n" echo -e "${RED}Stopping Qortal to apply new logging method...${NC}\n"
# Stop Qortal to apply changes # Stop Qortal to apply changes
cd ~/qortal cd ~/qortal
./stop.sh ./stop.sh
@ -341,10 +252,10 @@ else
fi fi
fi fi
echo "${GREEN} Starting Qortal Core and sleeping for 2+ min to let it startup fully, PLEASE WAIT... ${NC}\n" echo "${GREEN} Starting Qortal Core and sleeping for 2.5 min to let it startup fully, PLEASE WAIT... ${NC}\n"
cd ~/qortal cd ~/qortal
./start.sh ./start.sh
sleep 144 sleep 166
cd cd
echo "${GREEN} Checking if Qortal started correctly... ${NC}\n" echo "${GREEN} Checking if Qortal started correctly... ${NC}\n"
local_height_check=$(curl -sS "http://localhost:12391/blocks/height") local_height_check=$(curl -sS "http://localhost:12391/blocks/height")
@ -358,7 +269,6 @@ else
echo "${RED} starting Qortal Core FAILED... script will exit now until future updates add additional features...sorry the script couldn't resolve your issues! It will update automatically if you h ave it configured to run automatically! It is possible that the script will fix the issue IF YOU RESTART YOUR COMPUTER AND WAIT 15 MINUTES...${NC}\n" echo "${RED} starting Qortal Core FAILED... script will exit now until future updates add additional features...sorry the script couldn't resolve your issues! It will update automatically if you h ave it configured to run automatically! It is possible that the script will fix the issue IF YOU RESTART YOUR COMPUTER AND WAIT 15 MINUTES...${NC}\n"
update_script update_script
fi fi
} }
remote_height_checks() { remote_height_checks() {
@ -367,26 +277,106 @@ remote_height_checks() {
local_height=$(curl -sS --connect-timeout 10 "http://localhost:12391/blocks/height") local_height=$(curl -sS --connect-timeout 10 "http://localhost:12391/blocks/height")
if [ -z "$height_api_qortal_org" ] || [ -z "$height_qortal_link" ]; then if [ -z "$height_api_qortal_org" ] || [ -z "$height_qortal_link" ]; then
echo "${RED}Failed to fetch data from one or more remote URLs. Skipping remote node checks and updating script ${NC}\n" >&2 echo "${RED}Failed to fetch data from one or more remote URLs. Skipping remote node checks and updating script ${NC}\n"
update_script update_script
fi fi
if [ "$height_api_qortal_org" -ge $((local_height - 1500)) ] && [ "$height_api_qortal_org" -le $((local_height + 1500)) ]; then if [ "$height_api_qortal_org" -ge $((local_height - 1500)) ] && [ "$height_api_qortal_org" -le $((local_height + 1500)) ]; then
echo "${YELLOW}Local height (${local_height}) is within 1500 block range of node height (${height_api_qortal_org}).${NC}" >&2 echo "${YELLOW}Local height ${NC}(${CYAN}${local_height}${NC})${YELLOW} is within 1500 block range of node height ${NC}(${GREEN}${height_api_qortal_org}${NC})."
echo "${CYAN}api.qortal.org height checks PASSED updating script...${NC}" echo "${GREEN}api.qortal.org height checks PASSED updating script...${NC}"
update_script update_script
else else
echo "${RED}Node is outside the 1500 block range of api.qortal.org, checking another node to be sure...${NC}" echo "${RED}Node is outside the 1500 block range of api.qortal.org, checking another node to be sure...${NC}"
if [ "$height_qortal_link" -ge $((local_height - 1500)) ] && [ "$height_qortal_link" -le $((local_height+ 1500)) ]; then if [ "$height_qortal_link" -ge $((local_height - 1500)) ] && [ "$height_qortal_link" -le $((local_height+ 1500)) ]; then
echo "${CYAN}qortal.link height checks PASSED updating script...${NC}" echo "${YELLOW}Local height ${NC}(${CYAN}${local_height}${NC})${YELLOW} is within 1500 block range of node height ${NC}(${GREEN}${height_qortal_link}${NC})."
echo "${GREEN}qortal.link height checks PASSED updating script...${NC}"
update_script update_script
else else
echo "${RED}SECOND remote node check FAILED... assuming local node needs bootstrapping... bootstrapping in 5 seconds...${NC}\n" echo "${RED}SECOND remote node check FAILED... ${NC}${YELLOW}assuming local node needs bootstrapping... bootstrapping in 5 seconds...${NC}\n"
force_bootstrap force_bootstrap
fi fi
fi fi
} }
check_height_2() {
local_height=$(curl -sS "http://localhost:12391/blocks/height")
if [ -f auto_fix_last_height.txt ]; then
previous_local_height=$(cat auto_fix_last_height.txt)
if [ -n ${previous_local_height} ]; then
if [ "${local_height}" = "${previous_local_height}" ]; then
echo "${RED} local height has not changed since previous script run... waiting 3 minutes and checking height again, if height still hasn't changed, forcing bootstrap... ${NC}\n"
sleep 188
checked_height=$(curl "localhost:12391/blocks/height")
sleep 2
if [ "${checked_height}" = "${previous_local_height}" ]; then
echo "${RED} block height still has not changed... forcing bootstrap... ${NC}\n"
force_bootstrap
fi
fi
fi
fi
if [ -z ${local_height} ]; then
echo "${RED} SECOND height check failed, unsure what is going on, but a restart of the node and waiting may fix it... ${NC}\n"
echo "${RED} TRY RESTARTING THE COMPUTER and WAITING 15 MINUTES... ${NC}\n"
echo "Updating script and continuing..."
update_script
else
echo ${local_height} > auto_fix_last_height.txt
fi
remote_height_checks
}
force_bootstrap() {
echo "${RED} height check found issues, forcing bootstrap... ${NC}\n"
cd qortal
killall -9 java
sleep 3
rm -rf db log.t* qortal.log run.log run.pid
sleep 5
./start.sh
cd
update_script
}
update_script(){
mkdir -p ~/qortal/new-scripts
mkdir -p ~/qortal/new-scripts/backups
cp ~/qortal/new-scripts/auto-fix-qortal.sh ~/qortal/new-scripts/backups
rm -rf ~/qortal/new-scripts/auto-fix-qortal.sh
cp ~/auto-fix-qortal.sh ~/qortal/new-scripts/backups/original.sh
cd ~/qortal/new-scripts
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-qortal.sh
chmod +x auto-fix-qortal.sh
cd
cp ~/qortal/new-scripts/auto-fix-qortal.sh .
echo "${YELLOW} Auto-fix script run complete.${NC}\n"
sleep 5
exit
}
check_memory(){
totalm=$(free -m | awk '/^Mem:/{print $2}')
echo "${YELLOW} Checking system RAM ... $totalm System RAM ... Configuring system for optimal RAM settings...${NC}\n"
if [ "$totalm" -le 6000 ]; then
echo "${WHITE} Machine has less than 6GB of RAM, Downloading correct start script for your configuration...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/4GB-start.sh && mv 4GB-start.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
elif [ "$totalm" -ge 6001 ] && [ "$totalm" -le 16000 ]; then
echo "${WHITE} Machine has between 6GB and 16GB of RAM, Downloading correct start script for your configuration...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-6001-to-16000m.sh && mv start-6001-to-16000m.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
else echo "${WHITE} Machine has more than 16GB of RAM, using high-RAM start script and continuing...${NC}\n"
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-high-RAM.sh && mv start-high-RAM.sh ~/qortal/start.sh && chmod +x ~/qortal/start.sh
fi
check_qortal
}
check_internet check_internet