From 35ba13957734d8864f4d79ee1896e6e8ceaeb298 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 28 Sep 2025 17:03:59 -0700 Subject: [PATCH] enhance --- update.sh | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/update.sh b/update.sh index cf72627..e341cb0 100644 --- a/update.sh +++ b/update.sh @@ -6,40 +6,69 @@ if systemctl is-active --quiet mesh_bot.service; then echo "Stopping mesh_bot.service..." systemctl stop mesh_bot.service + service_stopped=true fi if systemctl is-active --quiet pong_bot.service; then echo "Stopping pong_bot.service..." systemctl stop pong_bot.service + service_stopped=true fi if systemctl is-active --quiet mesh_bot_reporting.service; then echo "Stopping mesh_bot_reporting.service..." systemctl stop mesh_bot_reporting.service + service_stopped=true fi if systemctl is-active --quiet mesh_bot_w3.service; then echo "Stopping mesh_bot_w3.service..." systemctl stop mesh_bot_w3.service + service_stopped=true fi # Update the local repository echo "Updating local repository..." #git fetch --all -#git reset --hard origin/main # Replace 'main' with your branch name if different -git pull origin main --rebase # Fetch and rebase to keep local changes if any + +# if git pull has conflicts, ask to reset hard +if ! git pull origin main --rebase; then + read -p "Git pull resulted in conflicts. Do you want to reset hard to origin/main? This will discard local changes. (y/n): " choice + if [[ "$choice" == "y" || "$choice" == "Y" ]]; then + git fetch --all + git reset --hard origin/main + else + echo "Update aborted due to git conflicts." + exit 1 + fi +fi + echo "Local repository updated." # Install or update dependencies echo "Installing or updating dependencies..." -pip install -r requirements.txt --upgrade +# check for error: externally-managed-environment and ask if user wants to continue with --break-system-packages +if ! pip install -r requirements.txt --upgrade 2>&1 | grep -q "externally-managed-environment"; then + pip install -r requirements.txt --upgrade +else + read -p "Warning: You are in an externally managed environment. Do you want to continue with --break-system-packages? (y/n): " choice + if [[ "$choice" == "y" || "$choice" == "Y" ]]; then + pip install --break-system-packages -r requirements.txt --upgrade + else + echo "Update aborted due to dependency installation issue." + exit 1 + fi +fi echo "Dependencies installed or updated." -# Restart the services -echo "Restarting services..." -systemctl start mesh_bot.service -systemctl start pong_bot.service -systemctl start mesh_bot_reporting.service -systemctl start mesh_bot_w3.service -echo "Services restarted." +# if service was stopped earlier, restart it +if [ "$service_stopped" = true ]; then + echo "Restarting services..." + systemctl start mesh_bot.service + systemctl start pong_bot.service + systemctl start mesh_bot_reporting.service + systemctl start mesh_bot_w3.service + echo "Services restarted." +fi + # Print completion message echo "Update completed successfully?" exit 0