(install_merlin_worker.sh): enhance installation script with error handling, cross-platform compatibility for sed, and improved directory management for merlin_worker.zsh

This commit is contained in:
Frank Qing
2025-05-28 03:40:25 +08:00
parent 68625d2e21
commit 158a1388bc

View File

@@ -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"