From 158a1388bc5e6d6b1dc98edabf2ed994923f3564 Mon Sep 17 00:00:00 2001 From: Frank Qing Date: Wed, 28 May 2025 03:40:25 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(install=5Fmerlin=5Fworker.sh):=20e?= =?UTF-8?q?nhance=20installation=20script=20with=20error=20handling,=20cro?= =?UTF-8?q?ss-platform=20compatibility=20for=20sed,=20and=20improved=20dir?= =?UTF-8?q?ectory=20management=20for=20merlin=5Fworker.zsh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- install_merlin_worker.sh | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/install_merlin_worker.sh b/install_merlin_worker.sh index 40ecb74..78afb59 100644 --- a/install_merlin_worker.sh +++ b/install_merlin_worker.sh @@ -1,6 +1,13 @@ #!/bin/bash -curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s merlin_worker +# Exit on any error +set -e + +# Download and execute the patch script +if ! curl -s https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s merlin_worker; then + echo "Error: Failed to download or execute patch script" + exit 1 +fi # Check if ~/.bashrc exists and contains PYTHONPATH export if [ -f "$HOME/.bashrc" ]; then @@ -13,20 +20,27 @@ if [ -f "$HOME/.bashrc" ]; then # Path to the merlin_worker.zsh file MERLIN_CONFIG="$HOME/.config/zshrc/merlin_worker.zsh" + # Create directory if it doesn't exist + mkdir -p "$(dirname "$MERLIN_CONFIG")" + if [ -f "$MERLIN_CONFIG" ]; then - # Create a backup - cp "$MERLIN_CONFIG" "$MERLIN_CONFIG.backup" - - # Replace the last PYTHONPATH line in merlin_worker.zsh with the one from ~/.bashrc - # First, remove existing PYTHONPATH lines - sed -i '/^export PYTHONPATH=/d' "$MERLIN_CONFIG" + # Cross-platform sed: remove existing PYTHONPATH lines + if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + sed -i '' '/^export PYTHONPATH=/d' "$MERLIN_CONFIG" + else + # Linux/Ubuntu and others + sed -i '/^export PYTHONPATH=/d' "$MERLIN_CONFIG" + fi # Then append the PYTHONPATH from ~/.bashrc echo "$BASHRC_PYTHONPATH" >> "$MERLIN_CONFIG" echo "Updated PYTHONPATH in $MERLIN_CONFIG with value from ~/.bashrc" else - echo "Warning: $MERLIN_CONFIG not found" + # Create the file with just the PYTHONPATH + echo "$BASHRC_PYTHONPATH" > "$MERLIN_CONFIG" + echo "Created $MERLIN_CONFIG with PYTHONPATH from ~/.bashrc" fi else echo "No PYTHONPATH export found in ~/.bashrc"