From 0988104fc5e68a339a9681892a709edcbf38f21f Mon Sep 17 00:00:00 2001 From: smeb_y Date: Thu, 15 Aug 2024 02:45:10 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20release=5Fautorun.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release_autorun.sh | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 release_autorun.sh diff --git a/release_autorun.sh b/release_autorun.sh new file mode 100644 index 0000000..39d314c --- /dev/null +++ b/release_autorun.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +if [[ "$OSTYPE" == "linux-gnu"* ]]; then + release_os="linux" + if [[ $(uname -m) == "aarch64"* ]]; then + release_arch="arm64" + else + release_arch="amd64" + fi +else + release_os="darwin" + release_arch="arm64" +fi + +start_process() { + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + chmod +x ./node-$version-$release_os-$release_arch + ./node-$version-$release_os-$release_arch & + main_process_id=$! + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo "./node-$version-$release_os-$release_arch" + chmod +x ./node-$version-$release_os-$release_arch + ./node-$version-$release_os-$release_arch & + main_process_id=$! + else + echo "unsupported OS for releases, please build from source" + exit 1 + fi + + echo "process started with PID $main_process_id" +} + +is_process_running() { + ps -p $main_process_id > /dev/null 2>&1 + return $? +} + +kill_process() { + local process_count=$(ps -ef | grep -E "node-.*-(darwin|linux)-(amd64|arm64)" | grep -v grep | wc -l) + local process_pids=$(ps -ef | grep -E "node-.*-(darwin|linux)-(amd64|arm64)" | grep -v grep | awk '{print $2}' | xargs) + + if [ $process_count -gt 0 ]; then + echo "killing processes $process_pids" + kill $process_pids + else + echo "no processes running" + fi +} + +fetch() { + files=$(curl https://releases.quilibrium.com/release | grep $release_os-$release_arch) + new_release=false + + for file in $files; do + version=$(echo "$file" | cut -d '-' -f 2) + if ! test -f "./$file"; then + curl "https://releases.quilibrium.com/$file" > "$file" + new_release=true + fi + done +} + +fetch + +kill_process + +start_process + +while true; do + if ! is_process_running; then + echo "process crashed or stopped. restarting..." + start_process + fi + + fetch + + if $new_release; then + kill_process + + start_process + fi + + sleep 300 +done \ No newline at end of file