Updated auto-fix script to ensure users will only update if the version is newer on git... also modified everything so that it utilizes functions.
This commit is contained in:
parent
0a32e1e4a0
commit
be34e7bc7d
@ -11,146 +11,164 @@ CYAN='\033[0;36m' # Cyan
|
|||||||
WHITE='\033[0;37m' # White
|
WHITE='\033[0;37m' # White
|
||||||
NC='\033[0m' # No Color
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
echo "${YELLOW} checking internet connection ${NC}\n"
|
check_internet() {
|
||||||
|
echo "${YELLOW} Checking internet connection ${NC}\n"
|
||||||
|
|
||||||
INTERNET_STATUS="UNKNOWN"
|
INTERNET_STATUS="UNKNOWN"
|
||||||
TIMESTAMP=`date +%s`
|
TIMESTAMP=$(date +%s)
|
||||||
|
|
||||||
ping -c 1 -W 0.7 8.8.4.4 > /dev/null 2>&1
|
ping -c 1 -W 0.7 8.8.4.4 > /dev/null 2>&1
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ]; then
|
||||||
if [ "$INTERNET_STATUS" != "UP" ]; then
|
if [ "$INTERNET_STATUS" != "UP" ]; then
|
||||||
echo "${BLUE}Internet connection is UP, continuing${NC}\n `date +%Y-%m-%dT%H:%M:%S%Z` $((`date +%s`-$TIMESTAMP))";
|
echo "${BLUE}Internet connection is UP, continuing${NC}\n $(date +%Y-%m-%dT%H:%M:%S%Z) $(( $(date +%s) - $TIMESTAMP ))"
|
||||||
INTERNET_STATUS="UP"
|
INTERNET_STATUS="UP"
|
||||||
rm -rf ~/Desktop/check-qortal-status.sh
|
rm -rf ~/Desktop/check-qortal-status.sh
|
||||||
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/check-qortal-status.sh && mv check-qortal-status.sh ~/qortal && chmod +x ~/qortal/check-qortal-status.sh
|
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/check-qortal-status.sh && mv check-qortal-status.sh ~/qortal && chmod +x ~/qortal/check-qortal-status.sh
|
||||||
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-qortal.sh && chmod +x start-qortal.sh
|
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-qortal.sh && chmod +x start-qortal.sh
|
||||||
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/refresh-qortal.sh && chmod +x refresh-qortal.sh
|
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/refresh-qortal.sh && chmod +x refresh-qortal.sh
|
||||||
fi
|
check_for_pi
|
||||||
else
|
|
||||||
if [ "$INTERNET_STATUS" = "UP" ]; then
|
|
||||||
echo "${RED}Internet Connection is DOWN, please fix connection and restart device, script will re-run automatically after 7 min.${NC}\n `date +%Y-%m-%dT%H:%M:%S%Z` $((`date +%s`-$TIMESTAMP))";
|
|
||||||
INTERNET_STATUS="DOWN"
|
|
||||||
sleep 30
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
if [ "$INTERNET_STATUS" = "UP" ]; then
|
||||||
|
echo "${RED}Internet Connection is DOWN, please fix connection and restart device, script will re-run automatically after 7 min.${NC}\n $(date +%Y-%m-%dT%H:%M:%S%Z) $(( $(date +%s) - $TIMESTAMP ))"
|
||||||
|
INTERNET_STATUS="DOWN"
|
||||||
|
sleep 30
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_qortal() {
|
||||||
|
echo "${YELLOW} Checking the version of qortal on local machine VS the version on github... ${NC}\n"
|
||||||
|
|
||||||
echo "${YELLOW} Checking hash of qortal.jar on liocal machine VS newest released qortal.jar on github ${NC}\n"
|
LOCAL_VERSION=$(curl -s localhost:12391/admin/info | grep -oP '"buildVersion":"qortal-\K[^-]*' | sed 's/-.*//' | tr -d '.')
|
||||||
|
REMOTE_VERSION=$(curl -s "https://api.github.com/repos/qortal/qortal/releases/latest" | grep -oP '"tag_name": "v\K[^"]*' | tr -d '.')
|
||||||
|
|
||||||
cd ~/qortal
|
if [ "$LOCAL_VERSION" -ge "$REMOTE_VERSION" ]; then
|
||||||
|
echo "${GREEN} Local version is higher than or equal to the remote version, no qortal changes necessary, updating scripts and continuing...${NC}\n"
|
||||||
|
check_for_GUI
|
||||||
|
else
|
||||||
|
update_qortal
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update_qortal() {
|
||||||
|
echo "${YELLOW} Your Qortal version is outdated, checking hash of qortal.jar on local machine VS newest released qortal.jar on github and updating your qortal.jar... ${NC}\n"
|
||||||
|
|
||||||
|
cd ~/qortal || exit
|
||||||
md5sum qortal.jar > "local.md5"
|
md5sum qortal.jar > "local.md5"
|
||||||
cd
|
cd
|
||||||
|
|
||||||
|
|
||||||
echo "${CYAN} Grabbing newest released jar to check hash ${NC}\n"
|
echo "${CYAN} Grabbing newest released jar to check hash ${NC}\n"
|
||||||
|
|
||||||
curl -L -O https://github.com/qortal/qortal/releases/latest/download/qortal.jar
|
curl -L -O https://github.com/qortal/qortal/releases/latest/download/qortal.jar
|
||||||
|
|
||||||
md5sum qortal.jar > "remote.md5"
|
md5sum qortal.jar > "remote.md5"
|
||||||
|
|
||||||
|
|
||||||
LOCAL=$(cat ~/qortal/local.md5)
|
LOCAL=$(cat ~/qortal/local.md5)
|
||||||
REMOTE=$(cat ~/remote.md5)
|
REMOTE=$(cat ~/remote.md5)
|
||||||
|
|
||||||
|
|
||||||
if [ "$LOCAL" = "$REMOTE" ]; then
|
if [ "$LOCAL" = "$REMOTE" ]; then
|
||||||
|
echo "${YELLOW} Hash check says your Qortal core is UP-TO-DATE, checking environment and updating scripts... ${NC}\n"
|
||||||
echo "${BLUE} Your Qortal Core is up-to-date! No action needed. ${NC}\n"
|
check_for_GUI
|
||||||
sleep 3
|
exit 1
|
||||||
rm ~/qortal.jar
|
|
||||||
rm ~/qortal/local.md5 remote.md5
|
|
||||||
mkdir ~/qortal/new-scripts
|
|
||||||
mkdir ~/qortal/new-scripts/backups
|
|
||||||
mv ~/qortal/new-scripts/auto-fix-qortal.sh ~/qortal/new-scripts/backups
|
|
||||||
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 .
|
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
echo "${RED} Hash check confirmed your qortal core is OUTDATED, refreshing and starting qortal...then checking for environment and updating scripts ${NC}\n"
|
||||||
echo "${RED} Your Qortal Core is OUTDATED, refreshing and starting qortal... ${NC}\n"
|
|
||||||
cd qortal
|
cd qortal
|
||||||
killall -9 java
|
killall -9 java
|
||||||
sleep 3
|
sleep 3
|
||||||
rm -rf db
|
rm -rf db log.t* qortal.log run.log run.pid qortal.jar
|
||||||
rm ~/qortal/qortal.jar
|
|
||||||
rm log.t*
|
|
||||||
cp ~/qortal.jar ~/qortal
|
cp ~/qortal.jar ~/qortal
|
||||||
rm ~/qortal.jar
|
rm ~/qortal.jar
|
||||||
rm ~/remote.md5 local.md5
|
rm ~/remote.md5 local.md5
|
||||||
./start.sh
|
./start.sh
|
||||||
mkdir ~/qortal/new-scripts
|
check_for_GUI
|
||||||
mkdir ~/qortal/new-scripts/backups
|
|
||||||
cp ~/qortal/new-scripts/auto-fix-qortal.sh ~/qortal/new-scripts/backups
|
|
||||||
rm ~/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 .
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
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
|
|
||||||
chmod +x start-modified-memory-args.sh
|
|
||||||
mv start-modified-memory-args.sh ~/qortal/start.sh
|
|
||||||
else
|
|
||||||
echo "${WHITE} Machine is not ARM 32bit, continuing to check memory and assign correct start script...${NC}\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if command -v raspi-config >/dev/null 2>&1 ; then
|
|
||||||
echo "${YELLOW} Raspberry Pi machine detected, creating pi cron and exiting...${NC}\n"
|
check_for_GUI(){
|
||||||
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-cron
|
if [ -n "$DISPLAY" ]; then
|
||||||
crontab auto-fix-cron
|
echo "${CYAN} Machine is logged in via GUI, setting up auto-fix-visible for GUI-based machines... ${NC}\n"
|
||||||
rm auto-fix-cron
|
|
||||||
curl -L -o https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-6001-to-16000m.sh
|
echo "${YELLOW} Setting up auto-fix-visible on GUI-based system... first, creating new crontab entry without auto-fix-startup... ${NC}\n"
|
||||||
mv start-6001*.sh ~/qortal/start.sh
|
sleep 2
|
||||||
chmod +x ~/qortal/*.sh
|
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/auto-fix-GUI-cron
|
||||||
exit 1
|
crontab auto-fix-GUI-cron
|
||||||
else echo "${YELLOW} Not a Raspberry pi machine, continuing...${NC}\n"
|
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"
|
||||||
|
update_script
|
||||||
|
|
||||||
|
else echo "${YELLOW} Non-GUI system detected, skipping 'auto-fix-visible' setup ${NC}\n"
|
||||||
|
update_script
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_memory(){
|
||||||
totalm=$(free -m | awk '/^Mem:/{print $2}')
|
totalm=$(free -m | awk '/^Mem:/{print $2}')
|
||||||
|
|
||||||
echo "${YELLOW} Checking system RAM ... $totalm System RAM ... Configuring system for optimal RAM settings...${NC}\n"
|
echo "${YELLOW} Checking system RAM ... $totalm System RAM ... Configuring system for optimal RAM settings...${NC}\n"
|
||||||
if [ "$totalm" -le 6000 ]; then
|
if [ "$totalm" -le 6000 ]; then
|
||||||
echo "${WHITE} Machine has less than 6GB of RAM, Downloading correct start script for your configuration...${NC}\n"
|
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
|
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
|
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"
|
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
|
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"
|
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
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if command -v gnome-terminal >/dev/null 2>&1 ; then
|
|
||||||
|
|
||||||
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 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 ~/.config/autostart
|
|
||||||
cp auto-fix-qortal-GUI.desktop ~/.config/autostart
|
|
||||||
rm ~/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"
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
else echo "${YELLOW} Non-GUI system detected, skipping 'auto-fix-visible' setup ${NC}\n"
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 10
|
check_qortal
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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, adding correct start script and continuing...${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
|
||||||
|
curl -L -O https://raw.githubusercontent.com/crowetic/QORTector-scripts/main/start-6001-to-16000m.sh
|
||||||
|
mv start-6001*.sh ~/qortal/start.sh
|
||||||
|
chmod +x ~/qortal/*.sh
|
||||||
|
check_qortal
|
||||||
|
fi
|
||||||
|
else echo "${YELLOW} Not a Raspberry pi machine, continuing...${NC}\n"
|
||||||
|
check_memory
|
||||||
|
|
||||||
|
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 1
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
check_internet
|
||||||
|
Loading…
x
Reference in New Issue
Block a user